mirror of https://github.com/elunez/eladmin
Merge remote-tracking branch 'origin/master' into master
commit
23ce1fceab
|
@ -105,4 +105,4 @@
|
|||
项目的发展离不开你的支持,请作者喝杯咖啡吧☕ [Donate](https://eladmin.vip/donation/)
|
||||
|
||||
#### 反馈交流
|
||||
- QQ交流群:一群:<strike>891137268</strike> 、二群:<strike>947578238</strike>、三群:659622532
|
||||
- QQ交流群:一群:<strike>891137268</strike> 、二群:<strike>947578238</strike>、三群:659622532
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
package me.zhengjie.utils;
|
||||
|
||||
/**
|
||||
* 实际上缓存中的记录的Key为 PROJECT + xxx_KEY + :: + ID|NAME + : + 数据
|
||||
* <p>
|
||||
* 即最终保存的key为 eladmin-user::id:1
|
||||
*
|
||||
* @author: liaojinlong
|
||||
* @date: 2020/6/11 15:49
|
||||
* @apiNote: 关于缓存的Key集合
|
||||
|
@ -23,36 +27,97 @@ package me.zhengjie.utils;
|
|||
public interface CacheKey {
|
||||
|
||||
/**
|
||||
* 用户
|
||||
* 项目名称
|
||||
*/
|
||||
String USER_ID = "user::id:";
|
||||
String PROJECT = "eladmin-";
|
||||
/**
|
||||
* 数据
|
||||
* 用户部分
|
||||
*/
|
||||
String DATA_USER = "data::user:";
|
||||
String USER_KEY = "user";
|
||||
/**
|
||||
* 菜单
|
||||
* 目录部分
|
||||
*/
|
||||
String MENU_ID = "menu::id:";
|
||||
String MENU_USER = "menu::user:";
|
||||
String MENU_KEY = "menu";
|
||||
/**
|
||||
* 角色授权
|
||||
* 角色部分
|
||||
*/
|
||||
String ROLE_AUTH = "role::auth:";
|
||||
String ROLE_KEY = "role";
|
||||
/**
|
||||
* 角色信息
|
||||
* 部门部分
|
||||
*/
|
||||
String ROLE_ID = "role::id:";
|
||||
/**
|
||||
* 部门
|
||||
*/
|
||||
String DEPT_ID = "dept::id:";
|
||||
String DEPT_KEY = "dept";
|
||||
/**
|
||||
* 岗位
|
||||
*/
|
||||
String JOB_ID = "job::id:";
|
||||
String JOB_KEY = "job";
|
||||
/**
|
||||
* 数据部分
|
||||
*/
|
||||
String DATA_KEY = "data";
|
||||
/**
|
||||
* 鉴权部分
|
||||
*/
|
||||
String AUTH_KEY = "auth";
|
||||
/**
|
||||
* 数据字典
|
||||
*/
|
||||
String DICT_NAME = "dict::name:";
|
||||
String DICT_KEY = "dict";
|
||||
/**
|
||||
* 支付宝
|
||||
*/
|
||||
String ALI_PAY = "aliPay";
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
String EMAIL = "email";
|
||||
/**
|
||||
* 七牛云
|
||||
*/
|
||||
String QI_NIU = "qiNiu";
|
||||
/**
|
||||
* 通用ID部分
|
||||
*/
|
||||
String ID = "id";
|
||||
/**
|
||||
* 通用名称部分
|
||||
*/
|
||||
String NAME = "name";
|
||||
/**
|
||||
* 配置
|
||||
*/
|
||||
String CONFIG = "config";
|
||||
|
||||
/**
|
||||
* 依据传入的 key 拼接为 PROJECT + xx_KEY
|
||||
* 例如 baiKe-user
|
||||
*
|
||||
* @param key xx_KEY
|
||||
* @return /
|
||||
*/
|
||||
static String projectAndKey(String key) {
|
||||
return String.format(
|
||||
"%1$s%2$s",
|
||||
PROJECT,
|
||||
key
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 一般用于手动操作Redis时,拼接存入的Key
|
||||
* <p>
|
||||
* 依据传入的 key 和 target 拼接为 PROJECT + xx_KEY + target::
|
||||
* <p>
|
||||
* 例如 返回 baiKe-user::id:,后面自行拼接区分的标识,例如ID值
|
||||
*
|
||||
* @param key xx_KEY
|
||||
* @param target target
|
||||
* @return PROJECT-key::target:
|
||||
*/
|
||||
static String keyAndTarget(String key, String target) {
|
||||
return String.format(
|
||||
"%1$s::%2$s:",
|
||||
projectAndKey(key),
|
||||
target
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.wf.captcha.*;
|
|||
import com.wf.captcha.base.Captcha;
|
||||
import lombok.Data;
|
||||
import me.zhengjie.exception.BadConfigurationException;
|
||||
import me.zhengjie.utils.CacheKey;
|
||||
import me.zhengjie.utils.StringUtils;
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
|
@ -39,7 +40,7 @@ public class LoginProperties {
|
|||
|
||||
private LoginCode loginCode;
|
||||
|
||||
public static final String cacheKey = "USER-LOGIN-DATA";
|
||||
public static final String cacheKey = CacheKey.PROJECT + "USER-LOGIN-DATA";
|
||||
|
||||
public boolean isSingleLogin() {
|
||||
return singleLogin;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package me.zhengjie.modules.security.config.bean;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.utils.CacheKey;
|
||||
|
||||
/**
|
||||
* Jwt参数配置
|
||||
|
@ -66,6 +67,14 @@ public class SecurityProperties {
|
|||
*/
|
||||
private Long renew;
|
||||
|
||||
public void setOnlineKey(String onlineKey) {
|
||||
this.onlineKey = CacheKey.PROJECT + onlineKey;
|
||||
}
|
||||
|
||||
public void setCodeKey(String codeKey) {
|
||||
this.codeKey = CacheKey.PROJECT + codeKey;
|
||||
}
|
||||
|
||||
public String getTokenStartWith() {
|
||||
return tokenStartWith + " ";
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import me.zhengjie.modules.system.service.DeptService;
|
|||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDto;
|
||||
import me.zhengjie.modules.system.service.dto.UserDto;
|
||||
import me.zhengjie.utils.CacheKey;
|
||||
import me.zhengjie.utils.enums.DataScopeEnum;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
@ -36,7 +37,7 @@ import java.util.*;
|
|||
**/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@CacheConfig(cacheNames = "data")
|
||||
@CacheConfig(cacheNames = CacheKey.PROJECT + CacheKey.DATA_KEY)
|
||||
public class DataServiceImpl implements DataService {
|
||||
|
||||
private final RoleService roleService;
|
||||
|
@ -48,7 +49,7 @@ public class DataServiceImpl implements DataService {
|
|||
* @return /
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(key = "'user:' + #p0.id")
|
||||
@Cacheable(key = "'" + CacheKey.USER_KEY + ":' + #user.id")
|
||||
public List<Long> getDeptIds(UserDto user) {
|
||||
// 用于存储部门id
|
||||
Set<Long> deptIds = new HashSet<>();
|
||||
|
|
|
@ -47,7 +47,7 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@CacheConfig(cacheNames = "dept")
|
||||
@CacheConfig(cacheNames = CacheKey.PROJECT + CacheKey.DEPT_KEY)
|
||||
public class DeptServiceImpl implements DeptService {
|
||||
|
||||
private final DeptRepository deptRepository;
|
||||
|
@ -88,7 +88,7 @@ public class DeptServiceImpl implements DeptService {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(key = "'id:' + #p0")
|
||||
@Cacheable(key = "'" + CacheKey.ID + ":' + #id")
|
||||
public DeptDto findById(Long id) {
|
||||
Dept dept = deptRepository.findById(id).orElseGet(Dept::new);
|
||||
ValidationUtil.isNull(dept.getId(),"Dept","id",id);
|
||||
|
@ -277,7 +277,7 @@ public class DeptServiceImpl implements DeptService {
|
|||
public void delCaches(Long id){
|
||||
List<User> users = userRepository.findByRoleDeptId(id);
|
||||
// 删除数据权限
|
||||
redisUtils.delByKeys(CacheKey.DATA_USER, users.stream().map(User::getId).collect(Collectors.toSet()));
|
||||
redisUtils.del(CacheKey.DEPT_ID + id);
|
||||
redisUtils.delByKeys(CacheKey.keyAndTarget(CacheKey.DATA_KEY, CacheKey.USER_KEY), users.stream().map(User::getId).collect(Collectors.toSet()));
|
||||
redisUtils.del(CacheKey.keyAndTarget(CacheKey.DEPT_KEY, CacheKey.ID) + id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue