diff --git a/README.md b/README.md
index 62eb60cd..76340cff 100644
--- a/README.md
+++ b/README.md
@@ -105,4 +105,4 @@
项目的发展离不开你的支持,请作者喝杯咖啡吧☕ [Donate](https://eladmin.vip/donation/)
#### 反馈交流
-- QQ交流群:一群:891137268 、二群:947578238、三群:659622532
\ No newline at end of file
+- QQ交流群:一群:891137268 、二群:947578238、三群:659622532
diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java b/eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java
index 7485713f..2ade6e94 100644
--- a/eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java
+++ b/eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java
@@ -16,6 +16,10 @@
package me.zhengjie.utils;
/**
+ * 实际上缓存中的记录的Key为 PROJECT + xxx_KEY + :: + ID|NAME + : + 数据
+ *
+ * 即最终保存的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 + *
+ * 依据传入的 key 和 target 拼接为 PROJECT + xx_KEY + target:: + *
+ * 例如 返回 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
+ );
+ }
}
diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java
index 164c0073..a2b1886f 100644
--- a/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java
+++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java
@@ -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;
diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/SecurityProperties.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/SecurityProperties.java
index 16ec3cf0..e051d0af 100644
--- a/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/SecurityProperties.java
+++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/SecurityProperties.java
@@ -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 + " ";
}
diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DataServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DataServiceImpl.java
index 88f208e6..1f6319d9 100644
--- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DataServiceImpl.java
+++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DataServiceImpl.java
@@ -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