parent
ec38f76403
commit
4571408590
@ -0,0 +1,25 @@
|
||||
package com.ruoyi.cache.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 缓存的关键字ID
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD})
|
||||
@Documented
|
||||
public @interface OrgCacheKey {
|
||||
String id() default "user";
|
||||
/**
|
||||
* 缓存的类型:目前可以是CacheStaffInfo,CacheDeptInfo,CacheCompanyInfo
|
||||
* @return
|
||||
*/
|
||||
OrgCacheTypeNum type() default OrgCacheTypeNum.CacheUserInfo;
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.ruoyi.cache.annotation;
|
||||
/**
|
||||
* 缓存的类型
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
public enum OrgCacheTypeNum {
|
||||
CacheUserInfo, //员工的cache
|
||||
CacheDeptInfo,//部门的cache
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.ruoyi.cache.domain;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.lang.Mirror;
|
||||
|
||||
public class BaseCache {
|
||||
|
||||
/**
|
||||
* POJO转换成Map
|
||||
* @return
|
||||
*/
|
||||
public Map<String,String> toMap(){
|
||||
Mirror<?> mirror = Mirror.me(getClass());
|
||||
Field[] flds = mirror.getFields();
|
||||
Map<String,String> pojoMap=new HashMap<String,String>();
|
||||
for (Field fld : flds) {
|
||||
Object v = mirror.getValue(this, fld);
|
||||
if (null == v) {//等与null就不生成map
|
||||
continue;
|
||||
} else if(fld.isAnnotationPresent(Column.class)){
|
||||
String cv = fld.getAnnotation(Column.class).value();
|
||||
pojoMap.put(cv, v.toString());
|
||||
} else{
|
||||
pojoMap.put(fld.getName(), v.toString());
|
||||
}
|
||||
}
|
||||
return pojoMap;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package com.ruoyi.cache.domain;
|
||||
|
||||
import com.ruoyi.system.api.domain.SysDept;
|
||||
|
||||
public class CacheSysDept extends BaseCache{
|
||||
/**
|
||||
* @OrgCacheValue的 value类型
|
||||
*/
|
||||
public final static String ANNOTAION_DEPT_ID="deptId";
|
||||
public final static String ANNOTAION_PARENT_ID="parentId";
|
||||
public final static String ANNOTAION_DEPT_NAME="deptName";
|
||||
public final static String ANNOTAION_PARENT_NAME="parentName";
|
||||
|
||||
/** 部门ID */
|
||||
private Long deptId;
|
||||
|
||||
/** 父部门ID */
|
||||
private Long parentId;
|
||||
|
||||
/** 部门名称 */
|
||||
private String deptName;
|
||||
|
||||
/** 父部门名称 */
|
||||
private String parentName;
|
||||
|
||||
public CacheSysDept(SysDept dept) {
|
||||
this.deptId=dept.getDeptId();
|
||||
this.parentId=dept.getParentId();
|
||||
this.deptName=dept.getDeptName();
|
||||
this.parentName=dept.getParentName();
|
||||
}
|
||||
|
||||
public CacheSysDept() {
|
||||
|
||||
}
|
||||
|
||||
public Long getDeptId() {
|
||||
return deptId;
|
||||
}
|
||||
|
||||
public void setDeptId(Long deptId) {
|
||||
this.deptId = deptId;
|
||||
}
|
||||
|
||||
public Long getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setParentId(Long parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public String getDeptName() {
|
||||
return deptName;
|
||||
}
|
||||
|
||||
public void setDeptName(String deptName) {
|
||||
this.deptName = deptName;
|
||||
}
|
||||
|
||||
public String getParentName() {
|
||||
return parentName;
|
||||
}
|
||||
|
||||
public void setParentName(String parentName) {
|
||||
this.parentName = parentName;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.ruoyi.cache.domain;
|
||||
|
||||
import com.ruoyi.system.api.domain.SysUser;
|
||||
/**
|
||||
* 存储在redis上的用户缓存
|
||||
* @author condy
|
||||
*
|
||||
*/
|
||||
public class CacheSysUser extends BaseCache {
|
||||
/**
|
||||
* @OrgCacheValue的 value类型
|
||||
*/
|
||||
public final static String ANNOTAION_USER_ID="userId";
|
||||
public final static String ANNOTAION_USER_NAME="userName";
|
||||
public final static String ANNOTAION_DEPT_ID="deptId";
|
||||
public final static String ANNOTAION_EMAIL="email";
|
||||
public final static String ANNOTAION_PHONENUMBER="phonenumber";
|
||||
|
||||
|
||||
|
||||
private Long userId;
|
||||
private String userName;
|
||||
private Long deptId;
|
||||
private String nickName;
|
||||
private String email;
|
||||
private String phonenumber;
|
||||
|
||||
public CacheSysUser(SysUser user) {
|
||||
this.userId=user.getUserId();
|
||||
this.userName=user.getUserName();
|
||||
this.deptId=user.getDeptId();
|
||||
this.nickName=user.getNickName();
|
||||
this.email=user.getEmail();
|
||||
this.phonenumber=user.getEmail();
|
||||
}
|
||||
public CacheSysUser()
|
||||
{
|
||||
|
||||
}
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
public Long getDeptId() {
|
||||
return deptId;
|
||||
}
|
||||
public void setDeptId(Long deptId) {
|
||||
this.deptId = deptId;
|
||||
}
|
||||
public String getNickName() {
|
||||
return nickName;
|
||||
}
|
||||
public void setNickName(String nickName) {
|
||||
this.nickName = nickName;
|
||||
}
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
public String getPhonenumber() {
|
||||
return phonenumber;
|
||||
}
|
||||
public void setPhonenumber(String phonenumber) {
|
||||
this.phonenumber = phonenumber;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.ruoyi.system;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ruoyi.common.redis.service.RedisService;
|
||||
import com.ruoyi.util.RedisNotifyService;
|
||||
import com.ruoyi.util.SpringLoadComplete;
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
@Component
|
||||
public class CacheConfigurer {
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
@Bean
|
||||
public SpringLoadComplete getSpringLoadComplete() {
|
||||
return new SpringLoadComplete();
|
||||
}
|
||||
@Bean
|
||||
public RedisNotifyService getRedisNotifyService() {
|
||||
RedisNotifyService notifyService= new RedisNotifyService(redisService);
|
||||
return notifyService;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.ruoyi.util;
|
||||
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
/**
|
||||
* 接收到HttpServerRedis消息的处理类
|
||||
* @author 林桦
|
||||
*
|
||||
*/
|
||||
public interface IRedisNotifyHandle {
|
||||
/**
|
||||
* 处理json格式的消息
|
||||
* @param jsonMessage
|
||||
*/
|
||||
public void handle(String method,NutMap params);
|
||||
/**
|
||||
* 获取注册的ID,不同的ID之间不能重复.
|
||||
* @return
|
||||
*/
|
||||
public String getRegisterId();
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.ruoyi.util;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
public interface ISpringLoadComplete {
|
||||
/**
|
||||
* 回调实现类
|
||||
* @param applicationContext
|
||||
*/
|
||||
void callback(ApplicationContext applicationContext);
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.cache.annotation.OrgCacheKey;
|
||||
import com.ruoyi.cache.annotation.OrgCacheTypeNum;
|
||||
import com.ruoyi.cache.annotation.OrgCacheValue;
|
||||
import com.ruoyi.cache.domain.CacheSysUser;
|
||||
|
||||
public class CacheCallBackPojo {
|
||||
@OrgCacheKey
|
||||
private Long userId;
|
||||
@OrgCacheValue(value = CacheSysUser.ANNOTAION_DEPT_ID)
|
||||
private Long deptId;
|
||||
@OrgCacheValue(value = CacheSysUser.ANNOTAION_USER_NAME)
|
||||
private String userName;
|
||||
@OrgCacheValue(value = CacheSysUser.ANNOTAION_PHONENUMBER)
|
||||
private String phoneNumber;
|
||||
private String detpName;
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
public Long getDeptId() {
|
||||
return deptId;
|
||||
}
|
||||
public void setDeptId(Long deptId) {
|
||||
this.deptId = deptId;
|
||||
}
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
public String getPhoneNumber() {
|
||||
return phoneNumber;
|
||||
}
|
||||
public void setPhoneNumber(String phoneNumber) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
}
|
||||
public String getDetpName() {
|
||||
return detpName;
|
||||
}
|
||||
public void setDetpName(String detpName) {
|
||||
this.detpName = detpName;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CacheCallBackPojo [userId=" + userId + ", deptId=" + deptId + ", userName=" + userName
|
||||
+ ", phoneNumber=" + phoneNumber + ", detpName=" + detpName + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.cache.annotation.OrgCacheKey;
|
||||
import com.ruoyi.cache.annotation.OrgCacheTypeNum;
|
||||
import com.ruoyi.cache.annotation.OrgCacheValue;
|
||||
import com.ruoyi.cache.domain.CacheSysDept;
|
||||
import com.ruoyi.cache.domain.CacheSysUser;
|
||||
|
||||
public class CacheCallBackPojo2 {
|
||||
@OrgCacheKey(id = "user",type = OrgCacheTypeNum.CacheUserInfo)
|
||||
private Long userId;
|
||||
@OrgCacheValue(value = CacheSysUser.ANNOTAION_DEPT_ID)
|
||||
@OrgCacheKey(id = "dept",type = OrgCacheTypeNum.CacheDeptInfo)
|
||||
private Long deptId;
|
||||
@OrgCacheValue(value = CacheSysUser.ANNOTAION_USER_NAME)
|
||||
private String userName;
|
||||
@OrgCacheValue(value = CacheSysUser.ANNOTAION_PHONENUMBER)
|
||||
private String phoneNumber;
|
||||
@OrgCacheValue(id="dept",value = CacheSysDept.ANNOTAION_DEPT_NAME)
|
||||
private String detpName;
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
public Long getDeptId() {
|
||||
return deptId;
|
||||
}
|
||||
public void setDeptId(Long deptId) {
|
||||
this.deptId = deptId;
|
||||
}
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
public String getPhoneNumber() {
|
||||
return phoneNumber;
|
||||
}
|
||||
public void setPhoneNumber(String phoneNumber) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
}
|
||||
public String getDetpName() {
|
||||
return detpName;
|
||||
}
|
||||
public void setDetpName(String detpName) {
|
||||
this.detpName = detpName;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CacheCallBackPojo [userId=" + userId + ", deptId=" + deptId + ", userName=" + userName
|
||||
+ ", phoneNumber=" + phoneNumber + ", detpName=" + detpName + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import com.ruoyi.cache.service.CacheCallBack;
|
||||
import com.ruoyi.cache.service.IOrgCacheService;
|
||||
@SpringBootTest
|
||||
class CacheCallBackTest {
|
||||
|
||||
@Autowired
|
||||
private IOrgCacheService orgCacheService;
|
||||
@Test
|
||||
void testInvoke() {
|
||||
CacheCallBackPojo pojo=new CacheCallBackPojo();
|
||||
pojo.setUserId(1L);
|
||||
Lang.each(Lang.list(pojo), new CacheCallBack<>());
|
||||
assertNotNull(pojo.getUserName());
|
||||
System.out.println(pojo.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvoke2() {
|
||||
CacheCallBackPojo2 pojo=new CacheCallBackPojo2();
|
||||
pojo.setUserId(1L);
|
||||
pojo.setDeptId(103L);
|
||||
Lang.each(Lang.list(pojo), new CacheCallBack<>());
|
||||
assertNotNull(pojo.getUserName());
|
||||
System.out.println(pojo.toString());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.context.SecurityContextHolder;
|
||||
import com.ruoyi.system.domain.BulletinInfo;
|
||||
import com.ruoyi.system.service.IBulletinInfoService;
|
||||
@SpringBootTest
|
||||
class BulletinInfoServiceImplTest {
|
||||
|
||||
@Autowired
|
||||
private IBulletinInfoService bulletinInfoService;
|
||||
@BeforeEach
|
||||
void setUser() {
|
||||
SecurityContextHolder.set(SecurityConstants.DETAILS_USER_ID, 1);
|
||||
|
||||
}
|
||||
@Test
|
||||
void testSelectBulletinInfoList() {
|
||||
BulletinInfo bulletinInfo=new BulletinInfo();
|
||||
bulletinInfo.setSts("C");
|
||||
List<BulletinInfo> list=bulletinInfoService.selectBulletinInfoList(bulletinInfo);
|
||||
assertTrue(list.size()>0);
|
||||
System.out.println("aaaaaaaaaaaaaaaa:"+list.get(0).getCreateUserId()+"="+list.get(0).getCreateBy());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
# Tomcat
|
||||
server:
|
||||
port: 9201
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: ruoyi-system
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 192.168.0.17:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 192.168.0.17:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
Loading…
Reference in new issue