Merge remote-tracking branch 'origin/master' into master

pull/725/head
Emil.Zhang 2022-09-22 19:57:22 +08:00
commit 23ce1fceab
6 changed files with 101 additions and 25 deletions

View File

@ -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

View File

@ -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
);
}
/**
* RedisKey
* <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
);
}
}

View File

@ -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;

View File

@ -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 + " ";
}

View File

@ -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<>();

View File

@ -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);
}
}