From 07f3517b6f178efea6150429a3867468b718e3c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?=
<15040126243@163.com>
Date: Mon, 8 Aug 2022 18:20:29 +0800
Subject: [PATCH 01/14] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20=E7=94=A8?=
=?UTF-8?q?=E6=88=B7=E7=99=BB=E5=BD=95=E4=B8=8E=E7=9F=AD=E4=BF=A1=E7=99=BB?=
=?UTF-8?q?=E5=BD=95=20=E5=9B=BD=E9=99=85=E5=8C=96=E6=A0=BC=E5=BC=8F?=
=?UTF-8?q?=E4=B8=8D=E4=B8=80=E8=87=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ruoyi-admin/src/main/resources/i18n/messages.properties | 2 +-
ruoyi-admin/src/main/resources/i18n/messages_en_US.properties | 2 +-
ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties | 2 +-
.../main/java/com/ruoyi/system/service/SysLoginService.java | 4 +---
4 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/ruoyi-admin/src/main/resources/i18n/messages.properties b/ruoyi-admin/src/main/resources/i18n/messages.properties
index 7ddd6cd92..1645af347 100644
--- a/ruoyi-admin/src/main/resources/i18n/messages.properties
+++ b/ruoyi-admin/src/main/resources/i18n/messages.properties
@@ -41,5 +41,5 @@ repeat.submit.message=\u4E0D\u5141\u8BB8\u91CD\u590D\u63D0\u4EA4\uFF0C\u8BF7\u7A
rate.limiter.message=\u8BBF\u95EE\u8FC7\u4E8E\u9891\u7E41\uFF0C\u8BF7\u7A0D\u5019\u518D\u8BD5
sms.code.not.blank=\u77ED\u4FE1\u9A8C\u8BC1\u7801\u4E0D\u80FD\u4E3A\u7A7A
sms.code.retry.limit.count=\u77ED\u4FE1\u9A8C\u8BC1\u7801\u8F93\u5165\u9519\u8BEF{0}\u6B21
-sms.code.retry.limit.exceed=\u77ED\u4FE1\u9A8C\u8BC1\u7801\u9519\u8BEF\u6B21\u6570\u8FC7\u591A\uFF0C\u5E10\u6237\u9501\u5B9A{0}\u5206\u949F
+sms.code.retry.limit.exceed=\u77ED\u4FE1\u9A8C\u8BC1\u7801\u8F93\u5165\u9519\u8BEF{0}\u6B21\uFF0C\u5E10\u6237\u9501\u5B9A{0}\u5206\u949F
xcx.code.not.blank=\u5C0F\u7A0B\u5E8Fcode\u4E0D\u80FD\u4E3A\u7A7A
diff --git a/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties b/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties
index 7aae8ced3..92d8185d3 100644
--- a/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties
+++ b/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties
@@ -41,5 +41,5 @@ repeat.submit.message=Repeat submit is not allowed, please try again later
rate.limiter.message=Visit too frequently, please try again later
sms.code.not.blank=Sms code cannot be blank
sms.code.retry.limit.count=Sms code input error {0} times
-sms.code.retry.limit.exceed=Too many sms code errors, account locked for {0} minutes
+sms.code.retry.limit.exceed=Sms code input error {0} times, account locked for {0} minutes
xcx.code.not.blank=Mini program code cannot be blank
diff --git a/ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties b/ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties
index 7ddd6cd92..1645af347 100644
--- a/ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties
+++ b/ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties
@@ -41,5 +41,5 @@ repeat.submit.message=\u4E0D\u5141\u8BB8\u91CD\u590D\u63D0\u4EA4\uFF0C\u8BF7\u7A
rate.limiter.message=\u8BBF\u95EE\u8FC7\u4E8E\u9891\u7E41\uFF0C\u8BF7\u7A0D\u5019\u518D\u8BD5
sms.code.not.blank=\u77ED\u4FE1\u9A8C\u8BC1\u7801\u4E0D\u80FD\u4E3A\u7A7A
sms.code.retry.limit.count=\u77ED\u4FE1\u9A8C\u8BC1\u7801\u8F93\u5165\u9519\u8BEF{0}\u6B21
-sms.code.retry.limit.exceed=\u77ED\u4FE1\u9A8C\u8BC1\u7801\u9519\u8BEF\u6B21\u6570\u8FC7\u591A\uFF0C\u5E10\u6237\u9501\u5B9A{0}\u5206\u949F
+sms.code.retry.limit.exceed=\u77ED\u4FE1\u9A8C\u8BC1\u7801\u8F93\u5165\u9519\u8BEF{0}\u6B21\uFF0C\u5E10\u6237\u9501\u5B9A{0}\u5206\u949F
xcx.code.not.blank=\u5C0F\u7A0B\u5E8Fcode\u4E0D\u80FD\u4E3A\u7A7A
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java
index bf5413172..ea53635e7 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java
@@ -15,9 +15,7 @@ import com.ruoyi.common.core.service.LogininforService;
import com.ruoyi.common.enums.DeviceType;
import com.ruoyi.common.enums.LoginType;
import com.ruoyi.common.enums.UserStatus;
-import com.ruoyi.common.exception.user.CaptchaException;
-import com.ruoyi.common.exception.user.CaptchaExpireException;
-import com.ruoyi.common.exception.user.UserException;
+import com.ruoyi.common.exception.user.*;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MessageUtils;
From 5d367b7bf8a61e1a586db90f95706e7626926ce7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?=
<15040126243@163.com>
Date: Thu, 11 Aug 2022 12:40:21 +0800
Subject: [PATCH 02/14] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20getLoginId?=
=?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=E5=BF=85=E8=A6=81=E5=8F=82=E6=95=B0?=
=?UTF-8?q?=E7=A9=BA=E6=A0=A1=E9=AA=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/com/ruoyi/common/core/domain/model/LoginUser.java | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java
index 9f7186c48..c93b9efe1 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java
@@ -105,6 +105,12 @@ public class LoginUser implements Serializable {
* 获取登录id
*/
public String getLoginId() {
+ if (userType == null) {
+ throw new IllegalArgumentException("用户类型不能为空");
+ }
+ if (userId == null) {
+ throw new IllegalArgumentException("用户ID不能为空");
+ }
return userType + LoginHelper.JOIN_CODE + userId;
}
From 89c1e4f91de2a527ec825c76b0de5dd2fd42cc59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?=
<15040126243@163.com>
Date: Sat, 13 Aug 2022 11:30:33 +0800
Subject: [PATCH 03/14] =?UTF-8?q?update=20=E9=87=8D=E5=86=99=20spring-cach?=
=?UTF-8?q?e=20=E5=AE=9E=E7=8E=B0=20=E6=9B=B4=E4=BA=BA=E6=80=A7=E5=8C=96?=
=?UTF-8?q?=E7=9A=84=E6=93=8D=E4=BD=9C=20=E6=94=AF=E6=8C=81=E6=B3=A8?=
=?UTF-8?q?=E8=A7=A3=E6=8C=87=E5=AE=9Attl=E7=AD=89=E4=B8=80=E4=BA=9B?=
=?UTF-8?q?=E5=8F=82=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/main/resources/application.yml | 15 --
.../com/ruoyi/common/constant/CacheNames.java | 23 +++
.../demo/controller/RedisCacheController.java | 19 +-
.../ruoyi/framework/config/RedisConfig.java | 21 +-
.../config/properties/RedissonProperties.java | 37 +---
.../manager/PlusSpringCacheManager.java | 191 ++++++++++++++++++
6 files changed, 230 insertions(+), 76 deletions(-)
create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheNames.java
create mode 100644 ruoyi-framework/src/main/java/com/ruoyi/framework/manager/PlusSpringCacheManager.java
diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml
index 4c54de53d..aef309ee3 100644
--- a/ruoyi-admin/src/main/resources/application.yml
+++ b/ruoyi-admin/src/main/resources/application.yml
@@ -233,21 +233,6 @@ thread-pool:
# 线程池维护线程所允许的空闲时间
keepAliveSeconds: 300
---- # redisson 缓存配置
-redisson:
- cacheGroup:
- # 用例: @Cacheable(cacheNames="groupId", key="#XXX") 方可使用缓存组配置
- - groupId: redissonCacheMap
- # 组过期时间(脚本监控)
- ttl: 60000
- # 组最大空闲时间(脚本监控)
- maxIdleTime: 60000
- # 组最大长度
- maxSize: 0
- - groupId: testCache
- ttl: 1000
- maxIdleTime: 500
-
--- # 分布式锁 lock4j 全局配置
lock4j:
# 获取分布式锁超时时间,默认为 3000 毫秒
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheNames.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheNames.java
new file mode 100644
index 000000000..892de005d
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheNames.java
@@ -0,0 +1,23 @@
+package com.ruoyi.common.constant;
+
+/**
+ * 缓存组名称常量
+ *
+ * key 格式为 cacheNames#ttl#maxIdleTime#maxSize
+ *
+ * ttl 过期时间 如果设置为0则不过期 默认为0
+ * maxIdleTime 最大空闲时间 根据LRU算法清理空闲数据 如果设置为0则不检测 默认为0
+ * maxSize 组最大长度 根据LRU算法清理溢出数据 如果设置为0则无限长 默认为0
+ *
+ * 例子: test#60s、test#0#60s、test#0#1m#1000、test#1h#0#500
+ *
+ * @author Lion Li
+ */
+public interface CacheNames {
+
+ /**
+ * 演示案例
+ */
+ String DEMO_CACHE = "demo:cache#60s#10m#20";
+
+}
diff --git a/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisCacheController.java b/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisCacheController.java
index 2312aab0e..7342cba98 100644
--- a/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisCacheController.java
+++ b/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisCacheController.java
@@ -1,5 +1,6 @@
package com.ruoyi.demo.controller;
+import com.ruoyi.common.constant.CacheNames;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.redis.RedisUtils;
import lombok.RequiredArgsConstructor;
@@ -18,7 +19,7 @@ import java.time.Duration;
* @author Lion Li
*/
// 类级别 缓存统一配置
-//@CacheConfig(cacheNames = "redissonCacheMap")
+//@CacheConfig(cacheNames = CacheNames.DEMO_CACHE)
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/cache")
@@ -36,9 +37,9 @@ public class RedisCacheController {
* 重点说明: 缓存注解严谨与其他筛选数据功能一起使用
* 例如: 数据权限注解 会造成 缓存击穿 与 数据不一致问题
*
- * cacheNames 为配置文件内 groupId
+ * cacheNames 命名规则 查看 {@link CacheNames} 注释 支持多参数
*/
- @Cacheable(cacheNames = "redissonCacheMap", key = "#key", condition = "#key != null")
+ @Cacheable(cacheNames = "demo:cache#60s#10m#20", key = "#key", condition = "#key != null")
@GetMapping("/test1")
public R test1(String key, String value) {
return R.ok("操作成功", value);
@@ -48,11 +49,11 @@ public class RedisCacheController {
* 测试 @CachePut
*
* 加了@CachePut注解的方法,会把方法的返回值put到缓存里面缓存起来,供其它地方使用
- * 它「通常用在新增方法上」
+ * 它「通常用在新增或者实时更新方法上」
*
- * cacheNames 为 配置文件内 groupId
+ * cacheNames 命名规则 查看 {@link CacheNames} 注释 支持多参数
*/
- @CachePut(cacheNames = "redissonCacheMap", key = "#key", condition = "#key != null")
+ @CachePut(cacheNames = CacheNames.DEMO_CACHE, key = "#key", condition = "#key != null")
@GetMapping("/test2")
public R test2(String key, String value) {
return R.ok("操作成功", value);
@@ -62,11 +63,11 @@ public class RedisCacheController {
* 测试 @CacheEvict
*
* 使用了CacheEvict注解的方法,会清空指定缓存
- * 「一般用在更新或者删除的方法上」
+ * 「一般用在删除的方法上」
*
- * cacheNames 为 配置文件内 groupId
+ * cacheNames 命名规则 查看 {@link CacheNames} 注释 支持多参数
*/
- @CacheEvict(cacheNames = "redissonCacheMap", key = "#key", condition = "#key != null")
+ @CacheEvict(cacheNames = CacheNames.DEMO_CACHE, key = "#key", condition = "#key != null")
@GetMapping("/test3")
public R test3(String key, String value) {
return R.ok("操作成功", value);
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/RedisConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/RedisConfig.java
index c86952871..9a7938a4b 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/RedisConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/RedisConfig.java
@@ -4,11 +4,9 @@ import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.framework.config.properties.RedissonProperties;
import com.ruoyi.framework.handler.KeyPrefixHandler;
+import com.ruoyi.framework.manager.PlusSpringCacheManager;
import lombok.extern.slf4j.Slf4j;
-import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
-import org.redisson.spring.cache.CacheConfig;
-import org.redisson.spring.cache.RedissonSpringCacheManager;
import org.redisson.spring.starter.RedissonAutoConfigurationCustomizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -18,10 +16,6 @@ import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
/**
* redis配置
*
@@ -80,18 +74,11 @@ public class RedisConfig extends CachingConfigurerSupport {
}
/**
- * 整合spring-cache
+ * 自定义缓存管理器 整合spring-cache
*/
@Bean
- public CacheManager cacheManager(RedissonClient redissonClient) {
- List cacheGroup = redissonProperties.getCacheGroup();
- Map config = new HashMap<>();
- for (RedissonProperties.CacheGroup group : cacheGroup) {
- CacheConfig cacheConfig = new CacheConfig(group.getTtl(), group.getMaxIdleTime());
- cacheConfig.setMaxSize(group.getMaxSize());
- config.put(group.getGroupId(), cacheConfig);
- }
- return new RedissonSpringCacheManager(redissonClient, config, new JsonJacksonCodec(objectMapper));
+ public CacheManager cacheManager() {
+ return new PlusSpringCacheManager();
}
/**
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/RedissonProperties.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/RedissonProperties.java
index eab746c8b..b0bf285f3 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/RedissonProperties.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/RedissonProperties.java
@@ -7,8 +7,6 @@ import org.redisson.config.SubscriptionMode;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
-import java.util.List;
-
/**
* Redisson 配置属性
*
@@ -18,12 +16,12 @@ import java.util.List;
@Component
@ConfigurationProperties(prefix = "redisson")
public class RedissonProperties {
-
+
/**
* redis缓存key前缀
*/
private String keyPrefix;
-
+
/**
* 线程池数量,默认值 = 当前处理核数量 * 2
*/
@@ -44,11 +42,6 @@ public class RedissonProperties {
*/
private ClusterServersConfig clusterServersConfig;
- /**
- * 缓存组
- */
- private List cacheGroup;
-
@Data
@NoArgsConstructor
public static class SingleServerConfig {
@@ -141,30 +134,4 @@ public class RedissonProperties {
}
- @Data
- @NoArgsConstructor
- public static class CacheGroup {
-
- /**
- * 组id
- */
- private String groupId;
-
- /**
- * 组过期时间
- */
- private long ttl;
-
- /**
- * 组最大空闲时间
- */
- private long maxIdleTime;
-
- /**
- * 组最大长度
- */
- private int maxSize;
-
- }
-
}
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/manager/PlusSpringCacheManager.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/manager/PlusSpringCacheManager.java
new file mode 100644
index 000000000..d8bfce7c5
--- /dev/null
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/manager/PlusSpringCacheManager.java
@@ -0,0 +1,191 @@
+/**
+ * Copyright (c) 2013-2021 Nikita Koksharov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.ruoyi.framework.manager;
+
+import com.ruoyi.common.utils.redis.RedisUtils;
+import org.redisson.api.RMap;
+import org.redisson.api.RMapCache;
+import org.redisson.spring.cache.CacheConfig;
+import org.redisson.spring.cache.RedissonCache;
+import org.springframework.boot.convert.DurationStyle;
+import org.springframework.cache.Cache;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.transaction.TransactionAwareCacheDecorator;
+import org.springframework.util.StringUtils;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * A {@link org.springframework.cache.CacheManager} implementation
+ * backed by Redisson instance.
+ *
+ * 修改 RedissonSpringCacheManager 源码
+ * 重写 cacheName 处理方法 支持多参数
+ *
+ * @author Nikita Koksharov
+ *
+ */
+@SuppressWarnings("unchecked")
+public class PlusSpringCacheManager implements CacheManager {
+
+ private boolean dynamic = true;
+
+ private boolean allowNullValues = true;
+
+ private boolean transactionAware = true;
+
+ Map configMap = new ConcurrentHashMap<>();
+ ConcurrentMap instanceMap = new ConcurrentHashMap<>();
+
+ /**
+ * Creates CacheManager supplied by Redisson instance
+ */
+ public PlusSpringCacheManager() {
+ }
+
+
+ /**
+ * Defines possibility of storing {@code null} values.
+ *
+ * Default is true
+ *
+ * @param allowNullValues stores if true
+ */
+ public void setAllowNullValues(boolean allowNullValues) {
+ this.allowNullValues = allowNullValues;
+ }
+
+ /**
+ * Defines if cache aware of Spring-managed transactions.
+ * If {@code true} put/evict operations are executed only for successful transaction in after-commit phase.
+ *
+ * Default is false
+ *
+ * @param transactionAware cache is transaction aware if true
+ */
+ public void setTransactionAware(boolean transactionAware) {
+ this.transactionAware = transactionAware;
+ }
+
+ /**
+ * Defines 'fixed' cache names.
+ * A new cache instance will not be created in dynamic for non-defined names.
+ *
+ * `null` parameter setups dynamic mode
+ *
+ * @param names of caches
+ */
+ public void setCacheNames(Collection names) {
+ if (names != null) {
+ for (String name : names) {
+ getCache(name);
+ }
+ dynamic = false;
+ } else {
+ dynamic = true;
+ }
+ }
+
+ /**
+ * Set cache config mapped by cache name
+ *
+ * @param config object
+ */
+ public void setConfig(Map config) {
+ this.configMap = (Map) config;
+ }
+
+ protected CacheConfig createDefaultConfig() {
+ return new CacheConfig();
+ }
+
+ @Override
+ public Cache getCache(String name) {
+ Cache cache = instanceMap.get(name);
+ if (cache != null) {
+ return cache;
+ }
+ if (!dynamic) {
+ return cache;
+ }
+
+ CacheConfig config = configMap.get(name);
+ if (config == null) {
+ config = createDefaultConfig();
+ configMap.put(name, config);
+ }
+
+ // 重写 cacheName 支持多参数
+ String[] array = StringUtils.delimitedListToStringArray(name, "#");
+ name = array[0];
+ if (array.length > 1) {
+ config.setTTL(DurationStyle.detectAndParse(array[1]).toMillis());
+ }
+ if (array.length > 2) {
+ config.setMaxIdleTime(DurationStyle.detectAndParse(array[2]).toMillis());
+ }
+ if (array.length > 3) {
+ config.setMaxSize(Integer.parseInt(array[3]));
+ }
+
+ if (config.getMaxIdleTime() == 0 && config.getTTL() == 0 && config.getMaxSize() == 0) {
+ return createMap(name, config);
+ }
+
+ return createMapCache(name, config);
+ }
+
+ private Cache createMap(String name, CacheConfig config) {
+ RMap map = RedisUtils.getClient().getMap(name);
+
+ Cache cache = new RedissonCache(map, allowNullValues);
+ if (transactionAware) {
+ cache = new TransactionAwareCacheDecorator(cache);
+ }
+ Cache oldCache = instanceMap.putIfAbsent(name, cache);
+ if (oldCache != null) {
+ cache = oldCache;
+ }
+ return cache;
+ }
+
+ private Cache createMapCache(String name, CacheConfig config) {
+ RMapCache map = RedisUtils.getClient().getMapCache(name);
+
+ Cache cache = new RedissonCache(map, config, allowNullValues);
+ if (transactionAware) {
+ cache = new TransactionAwareCacheDecorator(cache);
+ }
+ Cache oldCache = instanceMap.putIfAbsent(name, cache);
+ if (oldCache != null) {
+ cache = oldCache;
+ } else {
+ map.setMaxSize(config.getMaxSize());
+ }
+ return cache;
+ }
+
+ @Override
+ public Collection getCacheNames() {
+ return Collections.unmodifiableSet(configMap.keySet());
+ }
+
+
+}
From 0936aaccea661743b37ac948b9bfec5093e1f93b Mon Sep 17 00:00:00 2001
From: MichelleChung <1242874891@qq.com>
Date: Sat, 13 Aug 2022 15:35:55 +0000
Subject: [PATCH 04/14] =?UTF-8?q?!215=20=E4=BD=BF=E7=94=A8Spring=20Cache?=
=?UTF-8?q?=E6=B3=A8=E8=A7=A3=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../system/SysConfigController.java | 6 +-
.../system/SysDictDataController.java | 6 +-
.../system/SysDictTypeController.java | 6 +-
.../com/ruoyi/common/constant/CacheNames.java | 15 +++++
.../ruoyi/common/utils/cache/CacheUtils.java | 60 +++++++++++++++++++
.../com/ruoyi/oss/factory/OssFactory.java | 6 +-
.../system/service/ISysConfigService.java | 6 +-
.../system/service/ISysDictDataService.java | 4 +-
.../system/service/ISysDictTypeService.java | 4 +-
.../service/impl/SysConfigServiceImpl.java | 51 ++++++----------
.../service/impl/SysDictDataServiceImpl.java | 34 ++++-------
.../service/impl/SysDictTypeServiceImpl.java | 47 ++++++---------
.../service/impl/SysOssConfigServiceImpl.java | 25 +++-----
13 files changed, 151 insertions(+), 119 deletions(-)
create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/cache/CacheUtils.java
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
index 0571bcf82..7010ba01c 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
@@ -82,7 +82,7 @@ public class SysConfigController extends BaseController {
if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) {
return R.fail("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
- return toAjax(configService.insertConfig(config));
+ return R.ok(configService.insertConfig(config));
}
/**
@@ -95,7 +95,7 @@ public class SysConfigController extends BaseController {
if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) {
return R.fail("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
- return toAjax(configService.updateConfig(config));
+ return R.ok(configService.updateConfig(config));
}
/**
@@ -105,7 +105,7 @@ public class SysConfigController extends BaseController {
@Log(title = "参数管理", businessType = BusinessType.UPDATE)
@PutMapping("/updateByKey")
public R updateByKey(@RequestBody SysConfig config) {
- return toAjax(configService.updateConfig(config));
+ return R.ok(configService.updateConfig(config));
}
/**
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java
index 22a501738..01613db8b 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java
@@ -86,7 +86,8 @@ public class SysDictDataController extends BaseController {
@Log(title = "字典数据", businessType = BusinessType.INSERT)
@PostMapping
public R add(@Validated @RequestBody SysDictData dict) {
- return toAjax(dictDataService.insertDictData(dict));
+ dictDataService.insertDictData(dict);
+ return R.ok();
}
/**
@@ -96,7 +97,8 @@ public class SysDictDataController extends BaseController {
@Log(title = "字典数据", businessType = BusinessType.UPDATE)
@PutMapping
public R edit(@Validated @RequestBody SysDictData dict) {
- return toAjax(dictDataService.updateDictData(dict));
+ dictDataService.updateDictData(dict);
+ return R.ok();
}
/**
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java
index fd1763405..86840b7a5 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java
@@ -72,7 +72,8 @@ public class SysDictTypeController extends BaseController {
if (UserConstants.NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict))) {
return R.fail("新增字典'" + dict.getDictName() + "'失败,字典类型已存在");
}
- return toAjax(dictTypeService.insertDictType(dict));
+ dictTypeService.insertDictType(dict);
+ return R.ok();
}
/**
@@ -85,7 +86,8 @@ public class SysDictTypeController extends BaseController {
if (UserConstants.NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict))) {
return R.fail("修改字典'" + dict.getDictName() + "'失败,字典类型已存在");
}
- return toAjax(dictTypeService.updateDictType(dict));
+ dictTypeService.updateDictType(dict);
+ return R.ok();
}
/**
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheNames.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheNames.java
index 892de005d..d36818bb9 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheNames.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheNames.java
@@ -20,4 +20,19 @@ public interface CacheNames {
*/
String DEMO_CACHE = "demo:cache#60s#10m#20";
+ /**
+ * 系统配置
+ */
+ String SYS_CONFIG = "sys_config";
+
+ /**
+ * 数据字典
+ */
+ String SYS_DICT = "sys_dict";
+
+ /**
+ * OSS配置
+ */
+ String SYS_OSS_CONFIG = "sys_oss_config";
+
}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/cache/CacheUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/cache/CacheUtils.java
new file mode 100644
index 000000000..6f77ae8b8
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/cache/CacheUtils.java
@@ -0,0 +1,60 @@
+package com.ruoyi.common.utils.cache;
+
+import com.ruoyi.common.utils.spring.SpringUtils;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.springframework.cache.CacheManager;
+
+/**
+ * 缓存操作工具类 {@link }
+ *
+ * @author Michelle.Chung
+ * @date 2022/8/13
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+@SuppressWarnings(value = {"unchecked", "rawtypes"})
+public class CacheUtils {
+
+ private static final CacheManager CACHE_MANAGER = SpringUtils.getBean(CacheManager.class);
+
+ /**
+ * 获取缓存值
+ *
+ * @param cacheNames 缓存组名称
+ * @param key 缓存key
+ */
+ public static Object get(String cacheNames, Object key) {
+ return CACHE_MANAGER.getCache(cacheNames).get(key).get();
+ }
+
+ /**
+ * 保存缓存值
+ *
+ * @param cacheNames 缓存组名称
+ * @param key 缓存key
+ * @param value 缓存值
+ */
+ public static void put(String cacheNames, Object key, Object value) {
+ CACHE_MANAGER.getCache(cacheNames).put(key, value);
+ }
+
+ /**
+ * 删除缓存值
+ *
+ * @param cacheNames 缓存组名称
+ * @param key 缓存key
+ */
+ public static void evict(String cacheNames, Object key) {
+ CACHE_MANAGER.getCache(cacheNames).evict(key);
+ }
+
+ /**
+ * 清空缓存值
+ *
+ * @param cacheNames 缓存组名称
+ */
+ public static void clear(String cacheNames) {
+ CACHE_MANAGER.getCache(cacheNames).clear();
+ }
+
+}
diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java
index 7065c4a4a..68c37365b 100644
--- a/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java
+++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java
@@ -1,7 +1,9 @@
package com.ruoyi.oss.factory;
+import com.ruoyi.common.constant.CacheNames;
import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.cache.CacheUtils;
import com.ruoyi.common.utils.redis.RedisUtils;
import com.ruoyi.oss.constant.OssConstant;
import com.ruoyi.oss.core.OssClient;
@@ -42,7 +44,7 @@ public class OssFactory {
*/
public static OssClient instance() {
// 获取redis 默认类型
- String configKey = RedisUtils.getCacheObject(OssConstant.CACHE_CONFIG_KEY);
+ String configKey = (String) CacheUtils.get(CacheNames.SYS_OSS_CONFIG, OssConstant.OSS_CONFIG_KEY);
if (StringUtils.isEmpty(configKey)) {
throw new OssException("文件存储服务类型无法找到!");
}
@@ -62,7 +64,7 @@ public class OssFactory {
}
private static void refresh(String configKey) {
- Object json = RedisUtils.getCacheObject(OssConstant.SYS_OSS_KEY + configKey);
+ Object json = CacheUtils.get(CacheNames.SYS_OSS_CONFIG, configKey);
OssProperties properties = JsonUtils.parseObject(json.toString(), OssProperties.class);
if (properties == null) {
throw new OssException("系统异常, '" + configKey + "'配置信息不存在!");
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java
index f957b5b25..adcb5d3f7 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java
@@ -53,7 +53,7 @@ public interface ISysConfigService {
* @param config 参数配置信息
* @return 结果
*/
- int insertConfig(SysConfig config);
+ String insertConfig(SysConfig config);
/**
* 修改参数配置
@@ -61,7 +61,7 @@ public interface ISysConfigService {
* @param config 参数配置信息
* @return 结果
*/
- int updateConfig(SysConfig config);
+ String updateConfig(SysConfig config);
/**
* 批量删除参数信息
@@ -93,6 +93,4 @@ public interface ISysConfigService {
*/
String checkConfigKeyUnique(SysConfig config);
- SysConfig getOne(SysConfig config);
-
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java
index 504032ee1..3c5a04e65 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java
@@ -54,7 +54,7 @@ public interface ISysDictDataService {
* @param dictData 字典数据信息
* @return 结果
*/
- int insertDictData(SysDictData dictData);
+ List insertDictData(SysDictData dictData);
/**
* 修改保存字典数据信息
@@ -62,5 +62,5 @@ public interface ISysDictDataService {
* @param dictData 字典数据信息
* @return 结果
*/
- int updateDictData(SysDictData dictData);
+ List updateDictData(SysDictData dictData);
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java
index 5966e08c0..1bad68089 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java
@@ -84,7 +84,7 @@ public interface ISysDictTypeService {
* @param dictType 字典类型信息
* @return 结果
*/
- int insertDictType(SysDictType dictType);
+ List insertDictType(SysDictType dictType);
/**
* 修改保存字典类型信息
@@ -92,7 +92,7 @@ public interface ISysDictTypeService {
* @param dictType 字典类型信息
* @return 结果
*/
- int updateDictType(SysDictType dictType);
+ List updateDictType(SysDictType dictType);
/**
* 校验字典类型称是否唯一
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
index 010c3beb2..6f0ebdca4 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
@@ -5,22 +5,23 @@ import cn.hutool.core.util.ObjectUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.ruoyi.common.constant.CacheConstants;
+import com.ruoyi.common.constant.CacheNames;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.service.ConfigService;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.redis.RedisUtils;
+import com.ruoyi.common.utils.cache.CacheUtils;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.system.service.ISysConfigService;
import lombok.RequiredArgsConstructor;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -66,16 +67,12 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
* @param configKey 参数key
* @return 参数键值
*/
+ @Cacheable(cacheNames = CacheNames.SYS_CONFIG, key = "#configKey")
@Override
public String selectConfigByKey(String configKey) {
- String configValue = RedisUtils.getCacheObject(getCacheKey(configKey));
- if (StringUtils.isNotEmpty(configValue)) {
- return configValue;
- }
SysConfig retConfig = baseMapper.selectOne(new LambdaQueryWrapper()
.eq(SysConfig::getConfigKey, configKey));
if (ObjectUtil.isNotNull(retConfig)) {
- RedisUtils.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
return retConfig.getConfigValue();
}
return StringUtils.EMPTY;
@@ -119,13 +116,14 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
* @param config 参数配置信息
* @return 结果
*/
+ @CachePut(cacheNames = CacheNames.SYS_CONFIG, key = "#config.configKey")
@Override
- public int insertConfig(SysConfig config) {
+ public String insertConfig(SysConfig config) {
int row = baseMapper.insert(config);
if (row > 0) {
- RedisUtils.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
+ return config.getConfigValue();
}
- return row;
+ throw new ServiceException("操作失败");
}
/**
@@ -134,8 +132,9 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
* @param config 参数配置信息
* @return 结果
*/
+ @CachePut(cacheNames = CacheNames.SYS_CONFIG, key = "#config.configKey")
@Override
- public int updateConfig(SysConfig config) {
+ public String updateConfig(SysConfig config) {
int row = 0;
if (config.getConfigId() != null) {
row = baseMapper.updateById(config);
@@ -144,9 +143,9 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
.eq(SysConfig::getConfigKey, config.getConfigKey()));
}
if (row > 0) {
- RedisUtils.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
+ return config.getConfigValue();
}
- return row;
+ throw new ServiceException("操作失败");
}
/**
@@ -161,7 +160,7 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
if (StringUtils.equals(UserConstants.YES, config.getConfigType())) {
throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
}
- RedisUtils.deleteObject(getCacheKey(config.getConfigKey()));
+ CacheUtils.evict(CacheNames.SYS_CONFIG, config.getConfigKey());
}
baseMapper.deleteBatchIds(Arrays.asList(configIds));
}
@@ -172,9 +171,8 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
@Override
public void loadingConfigCache() {
List configsList = selectConfigList(new SysConfig());
- for (SysConfig config : configsList) {
- RedisUtils.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
- }
+ configsList.forEach(config ->
+ CacheUtils.put(CacheNames.SYS_CONFIG, config.getConfigKey(), config.getConfigValue()));
}
/**
@@ -182,8 +180,7 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
*/
@Override
public void clearConfigCache() {
- Collection keys = RedisUtils.keys(CacheConstants.SYS_CONFIG_KEY + "*");
- RedisUtils.deleteObject(keys);
+ CacheUtils.clear(CacheNames.SYS_CONFIG);
}
/**
@@ -211,11 +208,6 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
return UserConstants.UNIQUE;
}
- @Override
- public SysConfig getOne(SysConfig config) {
- return baseMapper.selectOne(new LambdaQueryWrapper<>(config));
- }
-
/**
* 根据参数 key 获取参数值
*
@@ -227,13 +219,4 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
return selectConfigByKey(configKey);
}
- /**
- * 设置cache key
- *
- * @param configKey 参数键
- * @return 缓存键key
- */
- private String getCacheKey(String configKey) {
- return CacheConstants.SYS_CONFIG_KEY + configKey;
- }
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java
index 71a83052a..c003f4744 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java
@@ -2,15 +2,17 @@ package com.ruoyi.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.ruoyi.common.constant.CacheConstants;
+import com.ruoyi.common.constant.CacheNames;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.redis.RedisUtils;
+import com.ruoyi.common.utils.cache.CacheUtils;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.service.ISysDictDataService;
import lombok.RequiredArgsConstructor;
+import org.springframework.cache.annotation.CachePut;
import org.springframework.stereotype.Service;
import java.util.List;
@@ -89,8 +91,7 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
for (Long dictCode : dictCodes) {
SysDictData data = selectDictDataById(dictCode);
baseMapper.deleteById(dictCode);
- List dictDatas = baseMapper.selectDictDataByType(data.getDictType());
- RedisUtils.setCacheObject(getCacheKey(data.getDictType()), dictDatas);
+ CacheUtils.evict(CacheNames.SYS_DICT, data.getDictType());
}
}
@@ -100,14 +101,14 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
* @param data 字典数据信息
* @return 结果
*/
+ @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#data.dictType")
@Override
- public int insertDictData(SysDictData data) {
+ public List insertDictData(SysDictData data) {
int row = baseMapper.insert(data);
if (row > 0) {
- List dictDatas = baseMapper.selectDictDataByType(data.getDictType());
- RedisUtils.setCacheObject(getCacheKey(data.getDictType()), dictDatas);
+ return baseMapper.selectDictDataByType(data.getDictType());
}
- return row;
+ throw new ServiceException("操作失败");
}
/**
@@ -116,23 +117,14 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
* @param data 字典数据信息
* @return 结果
*/
+ @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#data.dictType")
@Override
- public int updateDictData(SysDictData data) {
+ public List updateDictData(SysDictData data) {
int row = baseMapper.updateById(data);
if (row > 0) {
- List dictDatas = baseMapper.selectDictDataByType(data.getDictType());
- RedisUtils.setCacheObject(getCacheKey(data.getDictType()), dictDatas);
+ return baseMapper.selectDictDataByType(data.getDictType());
}
- return row;
+ throw new ServiceException("操作失败");
}
- /**
- * 设置cache key
- *
- * @param configKey 参数键
- * @return 缓存键key
- */
- String getCacheKey(String configKey) {
- return CacheConstants.SYS_DICT_KEY + configKey;
- }
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
index 04e4f4ecf..b65bcc536 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
@@ -5,7 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.ruoyi.common.constant.CacheConstants;
+import com.ruoyi.common.constant.CacheNames;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.entity.SysDictData;
@@ -15,11 +15,13 @@ import com.ruoyi.common.core.service.DictService;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StreamUtils;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.redis.RedisUtils;
+import com.ruoyi.common.utils.cache.CacheUtils;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.mapper.SysDictTypeMapper;
import com.ruoyi.system.service.ISysDictTypeService;
import lombok.RequiredArgsConstructor;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -83,17 +85,13 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
* @param dictType 字典类型
* @return 字典数据集合信息
*/
+ @Cacheable(cacheNames = CacheNames.SYS_DICT, key = "#dictType")
@Override
public List selectDictDataByType(String dictType) {
- List dictDatas = RedisUtils.getCacheObject(getCacheKey(dictType));
+ List dictDatas = dictDataMapper.selectDictDataByType(dictType);
if (CollUtil.isNotEmpty(dictDatas)) {
return dictDatas;
}
- dictDatas = dictDataMapper.selectDictDataByType(dictType);
- if (CollUtil.isNotEmpty(dictDatas)) {
- RedisUtils.setCacheObject(getCacheKey(dictType), dictDatas);
- return dictDatas;
- }
return null;
}
@@ -132,7 +130,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
.eq(SysDictData::getDictType, dictType.getDictType()))) {
throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
}
- RedisUtils.deleteObject(getCacheKey(dictType.getDictType()));
+ CacheUtils.evict(CacheNames.SYS_DICT, dictType.getDictType());
}
baseMapper.deleteBatchIds(Arrays.asList(dictIds));
}
@@ -146,9 +144,8 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
new LambdaQueryWrapper().eq(SysDictData::getStatus, UserConstants.DICT_NORMAL));
Map> dictDataMap = StreamUtils.groupByKey(dictDataList, SysDictData::getDictType);
dictDataMap.forEach((k,v) -> {
- String dictKey = getCacheKey(k);
List dictList = StreamUtils.sorted(v, Comparator.comparing(SysDictData::getDictSort));
- RedisUtils.setCacheObject(dictKey, dictList);
+ CacheUtils.put(CacheNames.SYS_DICT, k, dictList);
});
}
@@ -157,8 +154,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
*/
@Override
public void clearDictCache() {
- Collection keys = RedisUtils.keys(CacheConstants.SYS_DICT_KEY + "*");
- RedisUtils.deleteObject(keys);
+ CacheUtils.clear(CacheNames.SYS_DICT);
}
/**
@@ -176,13 +172,14 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
* @param dict 字典类型信息
* @return 结果
*/
+ @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#dict.dictType")
@Override
- public int insertDictType(SysDictType dict) {
+ public List insertDictType(SysDictType dict) {
int row = baseMapper.insert(dict);
if (row > 0) {
- RedisUtils.setCacheObject(getCacheKey(dict.getDictType()), null);
+ return new ArrayList<>();
}
- return row;
+ throw new ServiceException("操作失败");
}
/**
@@ -191,19 +188,20 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
* @param dict 字典类型信息
* @return 结果
*/
+ @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#dict.dictType")
@Override
@Transactional(rollbackFor = Exception.class)
- public int updateDictType(SysDictType dict) {
+ public List updateDictType(SysDictType dict) {
SysDictType oldDict = baseMapper.selectById(dict.getDictId());
dictDataMapper.update(null, new LambdaUpdateWrapper()
.set(SysDictData::getDictType, dict.getDictType())
.eq(SysDictData::getDictType, oldDict.getDictType()));
int row = baseMapper.updateById(dict);
if (row > 0) {
- List dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType());
- RedisUtils.setCacheObject(getCacheKey(dict.getDictType()), dictDatas);
+ CacheUtils.evict(CacheNames.SYS_DICT, oldDict.getDictType());
+ return dictDataMapper.selectDictDataByType(dict.getDictType());
}
- return row;
+ throw new ServiceException("操作失败");
}
/**
@@ -287,13 +285,4 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
return StringUtils.stripEnd(propertyString.toString(), separator);
}
- /**
- * 设置cache key
- *
- * @param configKey 参数键
- * @return 缓存键key
- */
- String getCacheKey(String configKey) {
- return CacheConstants.SYS_DICT_KEY + configKey;
- }
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssConfigServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssConfigServiceImpl.java
index 1ec3f9f51..1f9cece23 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssConfigServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssConfigServiceImpl.java
@@ -7,12 +7,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.constant.CacheNames;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.cache.CacheUtils;
import com.ruoyi.common.utils.redis.RedisUtils;
import com.ruoyi.oss.constant.OssConstant;
import com.ruoyi.oss.factory.OssFactory;
@@ -53,7 +55,7 @@ public class SysOssConfigServiceImpl implements ISysOssConfigService {
for (SysOssConfig config : list) {
String configKey = config.getConfigKey();
if ("0".equals(config.getStatus())) {
- RedisUtils.setCacheObject(OssConstant.CACHE_CONFIG_KEY, configKey);
+ CacheUtils.put(CacheNames.SYS_OSS_CONFIG, OssConstant.OSS_CONFIG_KEY, configKey);
}
setConfigCache(true, config);
}
@@ -126,9 +128,8 @@ public class SysOssConfigServiceImpl implements ISysOssConfigService {
}
boolean flag = baseMapper.deleteBatchIds(ids) > 0;
if (flag) {
- list.forEach(sysOssConfig -> {
- RedisUtils.deleteObject(getCacheKey(sysOssConfig.getConfigKey()));
- });
+ list.forEach(sysOssConfig ->
+ CacheUtils.evict(CacheNames.SYS_OSS_CONFIG, sysOssConfig.getConfigKey()));
}
return flag;
}
@@ -158,21 +159,11 @@ public class SysOssConfigServiceImpl implements ISysOssConfigService {
.set(SysOssConfig::getStatus, "1"));
row += baseMapper.updateById(sysOssConfig);
if (row > 0) {
- RedisUtils.setCacheObject(OssConstant.CACHE_CONFIG_KEY, sysOssConfig.getConfigKey());
+ CacheUtils.put(CacheNames.SYS_OSS_CONFIG, OssConstant.OSS_CONFIG_KEY, sysOssConfig.getConfigKey());
}
return row;
}
- /**
- * 设置cache key
- *
- * @param configKey 参数键
- * @return 缓存键key
- */
- private String getCacheKey(String configKey) {
- return OssConstant.SYS_OSS_KEY + configKey;
- }
-
/**
* 如果操作成功 则更新缓存
*
@@ -182,9 +173,7 @@ public class SysOssConfigServiceImpl implements ISysOssConfigService {
*/
private boolean setConfigCache(boolean flag, SysOssConfig config) {
if (flag) {
- RedisUtils.setCacheObject(
- getCacheKey(config.getConfigKey()),
- JsonUtils.toJsonString(config));
+ CacheUtils.put(CacheNames.SYS_OSS_CONFIG, config.getConfigKey(), JsonUtils.toJsonString(config));
RedisUtils.publish(OssConstant.CACHE_CONFIG_KEY, config.getConfigKey(), msg -> {
log.info("发布刷新OSS配置 => " + msg);
});
From 56d209cd20ccae3165eedfc5105089175c611db2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?=
<15040126243@163.com>
Date: Sat, 13 Aug 2022 23:53:04 +0800
Subject: [PATCH 05/14] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20BaseMapperPlus?=
=?UTF-8?q?=20=E6=96=B9=E6=B3=95=E5=91=BD=E4=BB=A4=E4=B8=8D=E4=B8=80?=
=?UTF-8?q?=E8=87=B4=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../main/java/com/ruoyi/common/core/mapper/BaseMapperPlus.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/mapper/BaseMapperPlus.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/mapper/BaseMapperPlus.java
index 1ff35792f..862887d16 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/mapper/BaseMapperPlus.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/mapper/BaseMapperPlus.java
@@ -149,7 +149,7 @@ public interface BaseMapperPlus extends BaseMapper {
return BeanCopyUtils.copy(obj, voClass);
}
- default List selectVoById(Collection extends Serializable> idList) {
+ default List selectVoBatchIds(Collection extends Serializable> idList) {
return selectVoBatchIds(idList, this.currentVoClass());
}
From f9a9431958e58903d97a86cd08497165ae77beaf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?=
<15040126243@163.com>
Date: Sun, 14 Aug 2022 01:49:05 +0800
Subject: [PATCH 06/14] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20pr215=20?=
=?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../controller/system/SysOssController.java | 2 +-
.../com/ruoyi/common/constant/CacheNames.java | 10 ++++++++
.../utils/{cache => redis}/CacheUtils.java | 23 +++++++++++++++----
.../com/ruoyi/oss/constant/OssConstant.java | 14 ++---------
.../com/ruoyi/oss/factory/OssFactory.java | 12 +++++-----
.../ruoyi/system/service/ISysOssService.java | 2 +-
.../service/impl/SysConfigServiceImpl.java | 2 +-
.../service/impl/SysDictDataServiceImpl.java | 2 +-
.../service/impl/SysDictTypeServiceImpl.java | 2 +-
.../service/impl/SysOssConfigServiceImpl.java | 8 +++----
.../service/impl/SysOssServiceImpl.java | 19 +++++++--------
11 files changed, 54 insertions(+), 42 deletions(-)
rename ruoyi-common/src/main/java/com/ruoyi/common/utils/{cache => redis}/CacheUtils.java (65%)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java
index f3c3cd9d7..d15a13d35 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java
@@ -96,7 +96,7 @@ public class SysOssController extends BaseController {
@SaCheckPermission("system:oss:download")
@GetMapping("/download/{ossId}")
public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException {
- SysOss sysOss = iSysOssService.getById(ossId);
+ SysOssVo sysOss = iSysOssService.getById(ossId);
if (ObjectUtil.isNull(sysOss)) {
throw new ServiceException("文件数据不存在!");
}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheNames.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheNames.java
index d36818bb9..591ca2546 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheNames.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheNames.java
@@ -30,9 +30,19 @@ public interface CacheNames {
*/
String SYS_DICT = "sys_dict";
+ /**
+ * OSS内容
+ */
+ String SYS_OSS = "sys_oss#30d";
+
/**
* OSS配置
*/
String SYS_OSS_CONFIG = "sys_oss_config";
+ /**
+ * 在线用户
+ */
+ String ONLINE_TOKEN = "online_tokens";
+
}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/cache/CacheUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/CacheUtils.java
similarity index 65%
rename from ruoyi-common/src/main/java/com/ruoyi/common/utils/cache/CacheUtils.java
rename to ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/CacheUtils.java
index 6f77ae8b8..9e0b09b07 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/cache/CacheUtils.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/CacheUtils.java
@@ -1,10 +1,14 @@
-package com.ruoyi.common.utils.cache;
+package com.ruoyi.common.utils.redis;
import com.ruoyi.common.utils.spring.SpringUtils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.redisson.api.RMap;
+import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
+import java.util.Set;
+
/**
* 缓存操作工具类 {@link }
*
@@ -12,19 +16,30 @@ import org.springframework.cache.CacheManager;
* @date 2022/8/13
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-@SuppressWarnings(value = {"unchecked", "rawtypes"})
+@SuppressWarnings(value = {"unchecked"})
public class CacheUtils {
private static final CacheManager CACHE_MANAGER = SpringUtils.getBean(CacheManager.class);
+ /**
+ * 获取缓存组内所有的KEY
+ *
+ * @param cacheNames 缓存组名称
+ */
+ public static Set keys(String cacheNames) {
+ RMap rmap = (RMap) CACHE_MANAGER.getCache(cacheNames).getNativeCache();
+ return rmap.keySet();
+ }
+
/**
* 获取缓存值
*
* @param cacheNames 缓存组名称
* @param key 缓存key
*/
- public static Object get(String cacheNames, Object key) {
- return CACHE_MANAGER.getCache(cacheNames).get(key).get();
+ public static T get(String cacheNames, Object key) {
+ Cache.ValueWrapper wrapper = CACHE_MANAGER.getCache(cacheNames).get(key);
+ return wrapper != null ? (T) wrapper.get() : null;
}
/**
diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/constant/OssConstant.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/constant/OssConstant.java
index 1d1a77708..0f9a0528c 100644
--- a/ruoyi-oss/src/main/java/com/ruoyi/oss/constant/OssConstant.java
+++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/constant/OssConstant.java
@@ -11,19 +11,9 @@ import java.util.List;
public interface OssConstant {
/**
- * OSS模块KEY
+ * 默认配置KEY
*/
- String SYS_OSS_KEY = "sys_oss:";
-
- /**
- * 对象存储配置KEY
- */
- String OSS_CONFIG_KEY = "OssConfig";
-
- /**
- * 缓存配置KEY
- */
- String CACHE_CONFIG_KEY = SYS_OSS_KEY + OSS_CONFIG_KEY;
+ String DEFAULT_CONFIG_KEY = "sys_oss:default_config";
/**
* 预览列表资源开关Key
diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java
index 68c37365b..c3312d730 100644
--- a/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java
+++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java
@@ -3,7 +3,7 @@ package com.ruoyi.oss.factory;
import com.ruoyi.common.constant.CacheNames;
import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.cache.CacheUtils;
+import com.ruoyi.common.utils.redis.CacheUtils;
import com.ruoyi.common.utils.redis.RedisUtils;
import com.ruoyi.oss.constant.OssConstant;
import com.ruoyi.oss.core.OssClient;
@@ -29,7 +29,7 @@ public class OssFactory {
*/
public static void init() {
log.info("初始化OSS工厂");
- RedisUtils.subscribe(OssConstant.CACHE_CONFIG_KEY, String.class, configKey -> {
+ RedisUtils.subscribe(OssConstant.DEFAULT_CONFIG_KEY, String.class, configKey -> {
OssClient client = getClient(configKey);
// 未初始化不处理
if (client != null) {
@@ -44,7 +44,7 @@ public class OssFactory {
*/
public static OssClient instance() {
// 获取redis 默认类型
- String configKey = (String) CacheUtils.get(CacheNames.SYS_OSS_CONFIG, OssConstant.OSS_CONFIG_KEY);
+ String configKey = RedisUtils.getCacheObject(OssConstant.DEFAULT_CONFIG_KEY);
if (StringUtils.isEmpty(configKey)) {
throw new OssException("文件存储服务类型无法找到!");
}
@@ -64,11 +64,11 @@ public class OssFactory {
}
private static void refresh(String configKey) {
- Object json = CacheUtils.get(CacheNames.SYS_OSS_CONFIG, configKey);
- OssProperties properties = JsonUtils.parseObject(json.toString(), OssProperties.class);
- if (properties == null) {
+ String json = CacheUtils.get(CacheNames.SYS_OSS_CONFIG, configKey);
+ if (json == null) {
throw new OssException("系统异常, '" + configKey + "'配置信息不存在!");
}
+ OssProperties properties = JsonUtils.parseObject(json, OssProperties.class);
CLIENT_CACHE.put(configKey, new OssClient(configKey, properties));
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysOssService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysOssService.java
index c55e5bc12..f02ea3d98 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysOssService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysOssService.java
@@ -21,7 +21,7 @@ public interface ISysOssService {
List listByIds(Collection ossIds);
- SysOss getById(Long ossId);
+ SysOssVo getById(Long ossId);
SysOss upload(MultipartFile file);
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
index 6f0ebdca4..da0ee394f 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
@@ -12,7 +12,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.service.ConfigService;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.cache.CacheUtils;
+import com.ruoyi.common.utils.redis.CacheUtils;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.system.service.ISysConfigService;
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java
index c003f4744..6b80cf482 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java
@@ -8,7 +8,7 @@ import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.cache.CacheUtils;
+import com.ruoyi.common.utils.redis.CacheUtils;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.service.ISysDictDataService;
import lombok.RequiredArgsConstructor;
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
index b65bcc536..00e88b8a3 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
@@ -15,7 +15,7 @@ import com.ruoyi.common.core.service.DictService;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StreamUtils;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.cache.CacheUtils;
+import com.ruoyi.common.utils.redis.CacheUtils;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.mapper.SysDictTypeMapper;
import com.ruoyi.system.service.ISysDictTypeService;
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssConfigServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssConfigServiceImpl.java
index 1f9cece23..8ceff7cb5 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssConfigServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssConfigServiceImpl.java
@@ -14,7 +14,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.cache.CacheUtils;
+import com.ruoyi.common.utils.redis.CacheUtils;
import com.ruoyi.common.utils.redis.RedisUtils;
import com.ruoyi.oss.constant.OssConstant;
import com.ruoyi.oss.factory.OssFactory;
@@ -55,7 +55,7 @@ public class SysOssConfigServiceImpl implements ISysOssConfigService {
for (SysOssConfig config : list) {
String configKey = config.getConfigKey();
if ("0".equals(config.getStatus())) {
- CacheUtils.put(CacheNames.SYS_OSS_CONFIG, OssConstant.OSS_CONFIG_KEY, configKey);
+ RedisUtils.setCacheObject(OssConstant.DEFAULT_CONFIG_KEY, configKey);
}
setConfigCache(true, config);
}
@@ -159,7 +159,7 @@ public class SysOssConfigServiceImpl implements ISysOssConfigService {
.set(SysOssConfig::getStatus, "1"));
row += baseMapper.updateById(sysOssConfig);
if (row > 0) {
- CacheUtils.put(CacheNames.SYS_OSS_CONFIG, OssConstant.OSS_CONFIG_KEY, sysOssConfig.getConfigKey());
+ RedisUtils.setCacheObject(OssConstant.DEFAULT_CONFIG_KEY, sysOssConfig.getConfigKey());
}
return row;
}
@@ -174,7 +174,7 @@ public class SysOssConfigServiceImpl implements ISysOssConfigService {
private boolean setConfigCache(boolean flag, SysOssConfig config) {
if (flag) {
CacheUtils.put(CacheNames.SYS_OSS_CONFIG, config.getConfigKey(), JsonUtils.toJsonString(config));
- RedisUtils.publish(OssConstant.CACHE_CONFIG_KEY, config.getConfigKey(), msg -> {
+ RedisUtils.publish(OssConstant.DEFAULT_CONFIG_KEY, config.getConfigKey(), msg -> {
log.info("发布刷新OSS配置 => " + msg);
});
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java
index 03a6cfca8..514e68efb 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java
@@ -4,12 +4,11 @@ import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.constant.CacheNames;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.redis.RedisUtils;
-import com.ruoyi.oss.constant.OssConstant;
import com.ruoyi.oss.core.OssClient;
import com.ruoyi.oss.entity.UploadResult;
import com.ruoyi.oss.factory.OssFactory;
@@ -19,11 +18,11 @@ import com.ruoyi.system.domain.vo.SysOssVo;
import com.ruoyi.system.mapper.SysOssMapper;
import com.ruoyi.system.service.ISysOssService;
import lombok.RequiredArgsConstructor;
+import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
-import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -51,13 +50,10 @@ public class SysOssServiceImpl implements ISysOssService {
public List listByIds(Collection ossIds) {
List list = new ArrayList<>();
for (Long id : ossIds) {
- String key = OssConstant.SYS_OSS_KEY + id;
- SysOssVo vo = RedisUtils.getCacheObject(key);
- if (ObjectUtil.isNull(vo)) {
- vo = baseMapper.selectVoById(id);
- RedisUtils.setCacheObject(key, vo, Duration.ofDays(30));
+ SysOssVo vo = getById(id);
+ if (ObjectUtil.isNotNull(vo)) {
+ list.add(vo);
}
- list.add(vo);
}
return list;
}
@@ -76,9 +72,10 @@ public class SysOssServiceImpl implements ISysOssService {
return lqw;
}
+ @Cacheable(cacheNames = CacheNames.SYS_OSS, key = "#ossId")
@Override
- public SysOss getById(Long ossId) {
- return baseMapper.selectById(ossId);
+ public SysOssVo getById(Long ossId) {
+ return baseMapper.selectVoById(ossId);
}
@Override
From 8837119aad5ca91747fc198fcca51090c3ca7cf6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?=
<15040126243@163.com>
Date: Sun, 14 Aug 2022 01:50:00 +0800
Subject: [PATCH 07/14] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E5=9C=A8?=
=?UTF-8?q?=E7=BA=BF=E7=94=A8=E6=88=B7=E5=8A=9F=E8=83=BD=20=E4=BD=BF?=
=?UTF-8?q?=E7=94=A8=20spring-cache=20=E7=AE=A1=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../monitor/SysUserOnlineController.java | 8 +++++---
.../listener/UserActionListener.java | 19 +++++++++++--------
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnlineController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnlineController.java
index 41c267d39..a8ad8efff 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnlineController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnlineController.java
@@ -6,6 +6,7 @@ import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.CacheConstants;
+import com.ruoyi.common.constant.CacheNames;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.dto.UserOnlineDTO;
@@ -13,7 +14,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StreamUtils;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.redis.RedisUtils;
+import com.ruoyi.common.utils.redis.CacheUtils;
import com.ruoyi.system.domain.SysUserOnline;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
@@ -46,11 +47,12 @@ public class SysUserOnlineController extends BaseController {
List userOnlineDTOList = new ArrayList<>();
for (String key : keys) {
String token = key.replace(CacheConstants.LOGIN_TOKEN_KEY, "");
- // 如果已经过期则踢下线
+ // 如果已经过期则跳过
if (StpUtil.stpLogic.getTokenActivityTimeoutByToken(token) < 0) {
continue;
}
- userOnlineDTOList.add(RedisUtils.getCacheObject(CacheConstants.ONLINE_TOKEN_KEY + token));
+ UserOnlineDTO dto = CacheUtils.get(CacheNames.ONLINE_TOKEN, token);
+ userOnlineDTOList.add(dto);
}
if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) {
userOnlineDTOList = StreamUtils.filter(userOnlineDTOList, userOnline ->
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/listener/UserActionListener.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/listener/UserActionListener.java
index 1e3c22c35..d6268eb8a 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/listener/UserActionListener.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/listener/UserActionListener.java
@@ -5,20 +5,18 @@ import cn.dev33.satoken.listener.SaTokenListener;
import cn.dev33.satoken.stp.SaLoginModel;
import cn.hutool.http.useragent.UserAgent;
import cn.hutool.http.useragent.UserAgentUtil;
-import com.ruoyi.common.constant.CacheConstants;
+import com.ruoyi.common.constant.CacheNames;
import com.ruoyi.common.core.domain.dto.UserOnlineDTO;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.UserType;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.common.utils.ServletUtils;
+import com.ruoyi.common.utils.redis.CacheUtils;
import com.ruoyi.common.utils.ip.AddressUtils;
-import com.ruoyi.common.utils.redis.RedisUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
-import java.time.Duration;
-
/**
* 用户行为 侦听器的实现
*
@@ -50,7 +48,12 @@ public class UserActionListener implements SaTokenListener {
dto.setTokenId(tokenValue);
dto.setUserName(user.getUsername());
dto.setDeptName(user.getDeptName());
- RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto, Duration.ofSeconds(tokenConfig.getTimeout()));
+ String cacheNames = CacheNames.ONLINE_TOKEN;
+ if (tokenConfig.getTimeout() > 0) {
+ // 增加 ttl 过期时间 单位秒
+ cacheNames = CacheNames.ONLINE_TOKEN + "#" + tokenConfig.getTimeout() + "s";
+ }
+ CacheUtils.put(cacheNames, tokenValue, dto);
log.info("user doLogin, userId:{}, token:{}", loginId, tokenValue);
} else if (userType == UserType.APP_USER) {
// app端 自行根据业务编写
@@ -62,7 +65,7 @@ public class UserActionListener implements SaTokenListener {
*/
@Override
public void doLogout(String loginType, Object loginId, String tokenValue) {
- RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
+ CacheUtils.evict(CacheNames.ONLINE_TOKEN, tokenValue);
log.info("user doLogout, userId:{}, token:{}", loginId, tokenValue);
}
@@ -71,7 +74,7 @@ public class UserActionListener implements SaTokenListener {
*/
@Override
public void doKickout(String loginType, Object loginId, String tokenValue) {
- RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
+ CacheUtils.evict(CacheNames.ONLINE_TOKEN, tokenValue);
log.info("user doLogoutByLoginId, userId:{}, token:{}", loginId, tokenValue);
}
@@ -80,7 +83,7 @@ public class UserActionListener implements SaTokenListener {
*/
@Override
public void doReplaced(String loginType, Object loginId, String tokenValue) {
- RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
+ CacheUtils.evict(CacheNames.ONLINE_TOKEN, tokenValue);
log.info("user doReplaced, userId:{}, token:{}", loginId, tokenValue);
}
From d351c59b38f772fb4fcfcb1a16b3fe40098da4f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?=
<15040126243@163.com>
Date: Sun, 14 Aug 2022 01:50:32 +0800
Subject: [PATCH 08/14] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E7=BC=93?=
=?UTF-8?q?=E5=AD=98=E5=88=97=E8=A1=A8=E7=AE=A1=E7=90=86=20=E9=80=82?=
=?UTF-8?q?=E9=85=8D=20spring-cache=20=E7=BC=93=E5=AD=98=E7=9A=84=E6=95=B0?=
=?UTF-8?q?=E6=8D=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../controller/monitor/CacheController.java | 49 ++++++--
ruoyi-ui/src/api/monitor/cache.js | 114 +++++++++---------
ruoyi-ui/src/views/monitor/cache/list.vue | 2 +-
3 files changed, 96 insertions(+), 69 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java
index b42248ed4..5490837be 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/CacheController.java
@@ -1,12 +1,14 @@
package com.ruoyi.web.controller.monitor;
import cn.dev33.satoken.annotation.SaCheckPermission;
+import cn.hutool.core.collection.CollUtil;
import com.ruoyi.common.constant.CacheConstants;
+import com.ruoyi.common.constant.CacheNames;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.redis.CacheUtils;
import com.ruoyi.common.utils.redis.RedisUtils;
-import com.ruoyi.oss.constant.OssConstant;
import com.ruoyi.system.domain.SysCache;
import lombok.RequiredArgsConstructor;
import org.redisson.spring.data.connection.RedissonConnectionFactory;
@@ -14,6 +16,7 @@ import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.web.bind.annotation.*;
import java.util.*;
+import java.util.stream.Collectors;
/**
* 缓存监控
@@ -31,13 +34,13 @@ public class CacheController {
static {
CACHES.add(new SysCache(CacheConstants.LOGIN_TOKEN_KEY, "用户信息"));
- CACHES.add(new SysCache(CacheConstants.ONLINE_TOKEN_KEY, "在线用户"));
- CACHES.add(new SysCache(CacheConstants.SYS_CONFIG_KEY, "配置信息"));
- CACHES.add(new SysCache(CacheConstants.SYS_DICT_KEY, "数据字典"));
+ CACHES.add(new SysCache(CacheNames.ONLINE_TOKEN, "在线用户"));
+ CACHES.add(new SysCache(CacheNames.SYS_CONFIG, "配置信息"));
+ CACHES.add(new SysCache(CacheNames.SYS_DICT, "数据字典"));
CACHES.add(new SysCache(CacheConstants.CAPTCHA_CODE_KEY, "验证码"));
CACHES.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "防重提交"));
CACHES.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "限流处理"));
- CACHES.add(new SysCache(OssConstant.SYS_OSS_KEY, "OSS配置"));
+ CACHES.add(new SysCache(CacheNames.SYS_OSS_CONFIG, "OSS配置"));
CACHES.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "密码错误次数"));
}
@@ -87,7 +90,15 @@ public class CacheController {
@SaCheckPermission("monitor:cache:list")
@GetMapping("/getKeys/{cacheName}")
public R> getCacheKeys(@PathVariable String cacheName) {
- Collection cacheKeys = RedisUtils.keys(cacheName + "*");
+ Collection cacheKeys = new HashSet<>(0);
+ if (isCacheNames(cacheName)) {
+ Set keys = CacheUtils.keys(cacheName);
+ if (CollUtil.isNotEmpty(keys)) {
+ cacheKeys = keys.stream().map(Object::toString).collect(Collectors.toList());
+ }
+ } else {
+ cacheKeys = RedisUtils.keys(cacheName + "*");
+ }
return R.ok(cacheKeys);
}
@@ -100,7 +111,12 @@ public class CacheController {
@SaCheckPermission("monitor:cache:list")
@GetMapping("/getValue/{cacheName}/{cacheKey}")
public R getCacheValue(@PathVariable String cacheName, @PathVariable String cacheKey) {
- Object cacheValue = RedisUtils.getCacheObject(cacheKey);
+ Object cacheValue;
+ if (isCacheNames(cacheName)) {
+ cacheValue = CacheUtils.get(cacheName, cacheKey);
+ } else {
+ cacheValue = RedisUtils.getCacheObject(cacheKey);
+ }
SysCache sysCache = new SysCache(cacheName, cacheKey, JsonUtils.toJsonString(cacheValue));
return R.ok(sysCache);
}
@@ -113,7 +129,11 @@ public class CacheController {
@SaCheckPermission("monitor:cache:list")
@DeleteMapping("/clearCacheName/{cacheName}")
public R clearCacheName(@PathVariable String cacheName) {
- RedisUtils.deleteKeys(cacheName + "*");
+ if (isCacheNames(cacheName)) {
+ CacheUtils.clear(cacheName);
+ } else {
+ RedisUtils.deleteKeys(cacheName + "*");
+ }
return R.ok();
}
@@ -123,9 +143,13 @@ public class CacheController {
* @param cacheKey key名
*/
@SaCheckPermission("monitor:cache:list")
- @DeleteMapping("/clearCacheKey/{cacheKey}")
- public R clearCacheKey(@PathVariable String cacheKey) {
- RedisUtils.deleteObject(cacheKey);
+ @DeleteMapping("/clearCacheKey/{cacheName}/{cacheKey}")
+ public R clearCacheKey(@PathVariable String cacheName, @PathVariable String cacheKey) {
+ if (isCacheNames(cacheName)) {
+ CacheUtils.evict(cacheName, cacheKey);
+ } else {
+ RedisUtils.deleteObject(cacheKey);
+ }
return R.ok();
}
@@ -139,4 +163,7 @@ public class CacheController {
return R.ok();
}
+ private boolean isCacheNames(String cacheName) {
+ return !StringUtils.contains(cacheName, ":");
+ }
}
diff --git a/ruoyi-ui/src/api/monitor/cache.js b/ruoyi-ui/src/api/monitor/cache.js
index e1f2c878c..5cf051780 100644
--- a/ruoyi-ui/src/api/monitor/cache.js
+++ b/ruoyi-ui/src/api/monitor/cache.js
@@ -1,57 +1,57 @@
-import request from '@/utils/request'
-
-// 查询缓存详细
-export function getCache() {
- return request({
- url: '/monitor/cache',
- method: 'get'
- })
-}
-
-// 查询缓存名称列表
-export function listCacheName() {
- return request({
- url: '/monitor/cache/getNames',
- method: 'get'
- })
-}
-
-// 查询缓存键名列表
-export function listCacheKey(cacheName) {
- return request({
- url: '/monitor/cache/getKeys/' + cacheName,
- method: 'get'
- })
-}
-
-// 查询缓存内容
-export function getCacheValue(cacheName, cacheKey) {
- return request({
- url: '/monitor/cache/getValue/' + cacheName + '/' + cacheKey,
- method: 'get'
- })
-}
-
-// 清理指定名称缓存
-export function clearCacheName(cacheName) {
- return request({
- url: '/monitor/cache/clearCacheName/' + cacheName,
- method: 'delete'
- })
-}
-
-// 清理指定键名缓存
-export function clearCacheKey(cacheKey) {
- return request({
- url: '/monitor/cache/clearCacheKey/' + cacheKey,
- method: 'delete'
- })
-}
-
-// 清理全部缓存
-export function clearCacheAll() {
- return request({
- url: '/monitor/cache/clearCacheAll',
- method: 'delete'
- })
-}
+import request from '@/utils/request'
+
+// 查询缓存详细
+export function getCache() {
+ return request({
+ url: '/monitor/cache',
+ method: 'get'
+ })
+}
+
+// 查询缓存名称列表
+export function listCacheName() {
+ return request({
+ url: '/monitor/cache/getNames',
+ method: 'get'
+ })
+}
+
+// 查询缓存键名列表
+export function listCacheKey(cacheName) {
+ return request({
+ url: '/monitor/cache/getKeys/' + cacheName,
+ method: 'get'
+ })
+}
+
+// 查询缓存内容
+export function getCacheValue(cacheName, cacheKey) {
+ return request({
+ url: '/monitor/cache/getValue/' + cacheName + '/' + cacheKey,
+ method: 'get'
+ })
+}
+
+// 清理指定名称缓存
+export function clearCacheName(cacheName) {
+ return request({
+ url: '/monitor/cache/clearCacheName/' + cacheName,
+ method: 'delete'
+ })
+}
+
+// 清理指定键名缓存
+export function clearCacheKey(cacheName, cacheKey) {
+ return request({
+ url: '/monitor/cache/clearCacheKey/'+ cacheName + "/" + cacheKey,
+ method: 'delete'
+ })
+}
+
+// 清理全部缓存
+export function clearCacheAll() {
+ return request({
+ url: '/monitor/cache/clearCacheAll',
+ method: 'delete'
+ })
+}
diff --git a/ruoyi-ui/src/views/monitor/cache/list.vue b/ruoyi-ui/src/views/monitor/cache/list.vue
index a1e795522..94307ab6a 100644
--- a/ruoyi-ui/src/views/monitor/cache/list.vue
+++ b/ruoyi-ui/src/views/monitor/cache/list.vue
@@ -211,7 +211,7 @@ export default {
},
/** 清理指定键名缓存 */
handleClearCacheKey(cacheKey) {
- clearCacheKey(cacheKey).then(response => {
+ clearCacheKey(this.nowCacheName, cacheKey).then(response => {
this.$modal.msgSuccess("清理缓存键名[" + cacheKey + "]成功");
this.getCacheKeys();
});
From 9f2fe90e5019e563dee0a88a970e8abcdb1f38a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?=
<15040126243@163.com>
Date: Mon, 15 Aug 2022 10:55:43 +0800
Subject: [PATCH 09/14] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E4=B8=9A?=
=?UTF-8?q?=E5=8A=A1=E7=BC=93=E5=AD=98=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ruoyi/web/controller/system/SysConfigController.java | 9 ++++++---
.../system/service/impl/SysDictTypeServiceImpl.java | 1 +
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
index 7010ba01c..c1b3acd86 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
@@ -82,7 +82,8 @@ public class SysConfigController extends BaseController {
if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) {
return R.fail("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
- return R.ok(configService.insertConfig(config));
+ configService.insertConfig(config);
+ return R.ok();
}
/**
@@ -95,7 +96,8 @@ public class SysConfigController extends BaseController {
if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) {
return R.fail("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
- return R.ok(configService.updateConfig(config));
+ configService.updateConfig(config);
+ return R.ok();
}
/**
@@ -105,7 +107,8 @@ public class SysConfigController extends BaseController {
@Log(title = "参数管理", businessType = BusinessType.UPDATE)
@PutMapping("/updateByKey")
public R updateByKey(@RequestBody SysConfig config) {
- return R.ok(configService.updateConfig(config));
+ configService.updateConfig(config);
+ return R.ok();
}
/**
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
index 00e88b8a3..2d589e5b3 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
@@ -112,6 +112,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
* @param dictType 字典类型
* @return 字典类型
*/
+ @Cacheable(cacheNames = CacheNames.SYS_DICT, key = "#dictType")
@Override
public SysDictType selectDictTypeByType(String dictType) {
return baseMapper.selectById(new LambdaQueryWrapper().eq(SysDictType::getDictType, dictType));
From 0fa007006227c2c6d136fa2c0de269c65c1b45e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?=
<15040126243@163.com>
Date: Tue, 16 Aug 2022 16:30:56 +0800
Subject: [PATCH 10/14] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20=E7=9F=AD?=
=?UTF-8?q?=E4=BF=A1=E5=8A=9F=E8=83=BD=E6=98=AF=E5=90=A6=E5=90=AF=E7=94=A8?=
=?UTF-8?q?=E5=88=A4=E6=96=AD=E4=B8=8D=E7=94=9F=E6=95=88BUG?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/ruoyi/web/controller/common/CaptchaController.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java
index 2680c01e6..60c632a92 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java
@@ -54,8 +54,8 @@ public class CaptchaController {
@GetMapping("/captchaSms")
public R smsCaptcha(@NotBlank(message = "{user.phonenumber.not.blank}")
String phonenumber) {
- if (smsProperties.getEnabled()) {
- R.fail("当前系统没有开启短信功能!");
+ if (!smsProperties.getEnabled()) {
+ return R.fail("当前系统没有开启短信功能!");
}
String key = CacheConstants.CAPTCHA_CODE_KEY + phonenumber;
String code = RandomUtil.randomNumbers(4);
From 7d57725490a4afc4024cd1a2219a242ac5822917 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?=
<15040126243@163.com>
Date: Tue, 16 Aug 2022 18:06:33 +0800
Subject: [PATCH 11/14] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20xxljob=20prod?=
=?UTF-8?q?=20=E7=8E=AF=E5=A2=83=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=20?=
=?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93ip=E6=BC=8F=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ruoyi-xxl-job-admin/src/main/resources/application-prod.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ruoyi-extend/ruoyi-xxl-job-admin/src/main/resources/application-prod.yml b/ruoyi-extend/ruoyi-xxl-job-admin/src/main/resources/application-prod.yml
index cd4057b33..d4193d0be 100644
--- a/ruoyi-extend/ruoyi-xxl-job-admin/src/main/resources/application-prod.yml
+++ b/ruoyi-extend/ruoyi-xxl-job-admin/src/main/resources/application-prod.yml
@@ -14,7 +14,7 @@ spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
- url: jdbc:mysql://172.30.0.36:3306/ry-vue?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
+ url: jdbc:mysql://127.0.0.1:3306/ry-vue?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
username: root
password: root
hikari:
From 34997ef3e11db962fa00ca365c717f519566a188 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?=
<15040126243@163.com>
Date: Tue, 16 Aug 2022 22:11:55 +0800
Subject: [PATCH 12/14] =?UTF-8?q?add=20=E6=96=B0=E5=A2=9E=20=E8=8E=B7?=
=?UTF-8?q?=E5=8F=96oss=E5=AF=B9=E8=B1=A1=E5=85=83=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E6=96=B9=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../main/java/com/ruoyi/oss/core/OssClient.java | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/core/OssClient.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/core/OssClient.java
index 2b3910c55..cc79a6bb9 100644
--- a/ruoyi-oss/src/main/java/com/ruoyi/oss/core/OssClient.java
+++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/core/OssClient.java
@@ -10,10 +10,7 @@ import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
-import com.amazonaws.services.s3.model.CannedAccessControlList;
-import com.amazonaws.services.s3.model.CreateBucketRequest;
-import com.amazonaws.services.s3.model.ObjectMetadata;
-import com.amazonaws.services.s3.model.PutObjectRequest;
+import com.amazonaws.services.s3.model.*;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.oss.constant.OssConstant;
@@ -121,6 +118,16 @@ public class OssClient {
return upload(inputStream, getPath(properties.getPrefix(), suffix), contentType);
}
+ /**
+ * 获取文件元数据
+ *
+ * @param path 完整文件路径
+ */
+ public ObjectMetadata getObjectMetadata(String path) {
+ S3Object object = client.getObject(properties.getBucketName(), path);
+ return object.getObjectMetadata();
+ }
+
public String getUrl() {
String domain = properties.getDomain();
String endpoint = properties.getEndpoint();
From 0c58ba50570dd4b07132351917d88d203a6719e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?=
<15040126243@163.com>
Date: Wed, 17 Aug 2022 17:44:42 +0800
Subject: [PATCH 13/14] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20=E9=83=A8?=
=?UTF-8?q?=E7=BD=B2=E8=84=9A=E6=9C=AC=20cp=20=E5=91=BD=E4=BB=A4=E7=BC=BA?=
=?UTF-8?q?=E5=B0=91=E5=8F=82=E6=95=B0=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
script/docker/deploy.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/script/docker/deploy.sh b/script/docker/deploy.sh
index a4b053ccb..8c756f342 100644
--- a/script/docker/deploy.sh
+++ b/script/docker/deploy.sh
@@ -29,12 +29,12 @@ mount(){
#挂载 nginx 配置文件
if test ! -f "/docker/nginx/" ;then
mkdir -p /docker/nginx/
- cp nginx/* /docker/nginx/
+ cp -r nginx/* /docker/nginx/
fi
#挂载 redis 配置文件
if test ! -f "/docker/redis/" ;then
mkdir -p /docker/redis/
- cp redis/* /docker/redis/
+ cp -r redis/* /docker/redis/
fi
chmod -R 777 /docker
}
From d1681dc18c786ff97b24b0849d453e896af7b8fc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?=
<15040126243@163.com>
Date: Wed, 17 Aug 2022 18:19:48 +0800
Subject: [PATCH 14/14] =?UTF-8?q?=F0=9F=91=80=20=E5=8F=91=E5=B8=83=204.3.0?=
=?UTF-8?q?-beta2=20=E5=85=AC=E6=B5=8B=E7=89=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
pom.xml | 4 ++--
ruoyi-admin/pom.xml | 2 +-
ruoyi-common/pom.xml | 2 +-
ruoyi-demo/pom.xml | 2 +-
ruoyi-extend/pom.xml | 2 +-
ruoyi-extend/ruoyi-monitor-admin/pom.xml | 2 +-
ruoyi-extend/ruoyi-xxl-job-admin/pom.xml | 2 +-
ruoyi-framework/pom.xml | 2 +-
ruoyi-generator/pom.xml | 2 +-
ruoyi-job/pom.xml | 2 +-
ruoyi-oss/pom.xml | 2 +-
ruoyi-sms/pom.xml | 2 +-
ruoyi-system/pom.xml | 2 +-
ruoyi-ui/package.json | 2 +-
ruoyi-ui/src/views/index.vue | 2 +-
script/docker/docker-compose.yml | 8 ++++----
17 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/README.md b/README.md
index bbd5977db..6b05e91cb 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
[](https://gitee.com/JavaLionLi/RuoYi-Vue-Plus/blob/master/LICENSE)
[](https://www.jetbrains.com/?from=RuoYi-Vue-Plus)
-[](https://gitee.com/JavaLionLi/RuoYi-Vue-Plus)
+[](https://gitee.com/JavaLionLi/RuoYi-Vue-Plus)
[]()
[]()
[]()
diff --git a/pom.xml b/pom.xml
index b29214a6e..bd179ca7a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,14 +6,14 @@
com.ruoyi
ruoyi-vue-plus
- 4.3.0-beta1
+ 4.3.0-beta2
RuoYi-Vue-Plus
https://gitee.com/JavaLionLi/RuoYi-Vue-Plus
RuoYi-Vue-Plus后台管理系统
- 4.3.0-beta1
+ 4.3.0-beta2
2.7.2
UTF-8
UTF-8
diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml
index fbb5c444a..9c3ba1506 100644
--- a/ruoyi-admin/pom.xml
+++ b/ruoyi-admin/pom.xml
@@ -5,7 +5,7 @@
ruoyi-vue-plus
com.ruoyi
- 4.3.0-beta1
+ 4.3.0-beta2
4.0.0
jar
diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml
index 9c49dbbd1..bf946925e 100644
--- a/ruoyi-common/pom.xml
+++ b/ruoyi-common/pom.xml
@@ -5,7 +5,7 @@
ruoyi-vue-plus
com.ruoyi
- 4.3.0-beta1
+ 4.3.0-beta2
4.0.0
diff --git a/ruoyi-demo/pom.xml b/ruoyi-demo/pom.xml
index 4e7c00d4b..d221f70f4 100644
--- a/ruoyi-demo/pom.xml
+++ b/ruoyi-demo/pom.xml
@@ -5,7 +5,7 @@
ruoyi-vue-plus
com.ruoyi
- 4.3.0-beta1
+ 4.3.0-beta2
4.0.0
diff --git a/ruoyi-extend/pom.xml b/ruoyi-extend/pom.xml
index bbc64243b..aea86a664 100644
--- a/ruoyi-extend/pom.xml
+++ b/ruoyi-extend/pom.xml
@@ -5,7 +5,7 @@
ruoyi-vue-plus
com.ruoyi
- 4.3.0-beta1
+ 4.3.0-beta2
4.0.0
ruoyi-extend
diff --git a/ruoyi-extend/ruoyi-monitor-admin/pom.xml b/ruoyi-extend/ruoyi-monitor-admin/pom.xml
index 6ff537ae0..2893a2960 100644
--- a/ruoyi-extend/ruoyi-monitor-admin/pom.xml
+++ b/ruoyi-extend/ruoyi-monitor-admin/pom.xml
@@ -5,7 +5,7 @@
ruoyi-extend
com.ruoyi
- 4.3.0-beta1
+ 4.3.0-beta2
4.0.0
jar
diff --git a/ruoyi-extend/ruoyi-xxl-job-admin/pom.xml b/ruoyi-extend/ruoyi-xxl-job-admin/pom.xml
index 0e55bb1fc..d0a867373 100644
--- a/ruoyi-extend/ruoyi-xxl-job-admin/pom.xml
+++ b/ruoyi-extend/ruoyi-xxl-job-admin/pom.xml
@@ -4,7 +4,7 @@
ruoyi-extend
com.ruoyi
- 4.3.0-beta1
+ 4.3.0-beta2
ruoyi-xxl-job-admin
jar
diff --git a/ruoyi-framework/pom.xml b/ruoyi-framework/pom.xml
index 18ee83b03..e28511c00 100644
--- a/ruoyi-framework/pom.xml
+++ b/ruoyi-framework/pom.xml
@@ -5,7 +5,7 @@
ruoyi-vue-plus
com.ruoyi
- 4.3.0-beta1
+ 4.3.0-beta2
4.0.0
diff --git a/ruoyi-generator/pom.xml b/ruoyi-generator/pom.xml
index 8566adc08..ef7f43ee8 100644
--- a/ruoyi-generator/pom.xml
+++ b/ruoyi-generator/pom.xml
@@ -5,7 +5,7 @@
ruoyi-vue-plus
com.ruoyi
- 4.3.0-beta1
+ 4.3.0-beta2
4.0.0
diff --git a/ruoyi-job/pom.xml b/ruoyi-job/pom.xml
index 7675ee749..37b4e71ec 100644
--- a/ruoyi-job/pom.xml
+++ b/ruoyi-job/pom.xml
@@ -5,7 +5,7 @@
ruoyi-vue-plus
com.ruoyi
- 4.3.0-beta1
+ 4.3.0-beta2
4.0.0
jar
diff --git a/ruoyi-oss/pom.xml b/ruoyi-oss/pom.xml
index d2c2a7919..ed8a3899e 100644
--- a/ruoyi-oss/pom.xml
+++ b/ruoyi-oss/pom.xml
@@ -5,7 +5,7 @@
ruoyi-vue-plus
com.ruoyi
- 4.3.0-beta1
+ 4.3.0-beta2
4.0.0
diff --git a/ruoyi-sms/pom.xml b/ruoyi-sms/pom.xml
index 101b2a8cd..50e82b020 100644
--- a/ruoyi-sms/pom.xml
+++ b/ruoyi-sms/pom.xml
@@ -5,7 +5,7 @@
ruoyi-vue-plus
com.ruoyi
- 4.3.0-beta1
+ 4.3.0-beta2
4.0.0
diff --git a/ruoyi-system/pom.xml b/ruoyi-system/pom.xml
index 280b14101..481825d93 100644
--- a/ruoyi-system/pom.xml
+++ b/ruoyi-system/pom.xml
@@ -5,7 +5,7 @@
ruoyi-vue-plus
com.ruoyi
- 4.3.0-beta1
+ 4.3.0-beta2
4.0.0
diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json
index 51cf5eba0..64840dc23 100644
--- a/ruoyi-ui/package.json
+++ b/ruoyi-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "ruoyi-vue-plus",
- "version": "4.3.0-beta1",
+ "version": "4.3.0-beta2",
"description": "RuoYi-Vue-Plus后台管理系统",
"author": "LionLi",
"license": "MIT",
diff --git a/ruoyi-ui/src/views/index.vue b/ruoyi-ui/src/views/index.vue
index 5d115085d..ba0fa778a 100644
--- a/ruoyi-ui/src/views/index.vue
+++ b/ruoyi-ui/src/views/index.vue
@@ -114,7 +114,7 @@ export default {
data() {
return {
// 版本号
- version: "4.3.0-beta1",
+ version: "4.3.0-beta2",
};
},
methods: {
diff --git a/script/docker/docker-compose.yml b/script/docker/docker-compose.yml
index b9a26746e..57a735926 100644
--- a/script/docker/docker-compose.yml
+++ b/script/docker/docker-compose.yml
@@ -99,7 +99,7 @@ services:
network_mode: "host"
ruoyi-server1:
- image: ruoyi/ruoyi-server:4.3.0-beta1
+ image: ruoyi/ruoyi-server:4.3.0-beta2
container_name: ruoyi-server1
environment:
# 时区上海
@@ -112,7 +112,7 @@ services:
network_mode: "host"
ruoyi-server2:
- image: "ruoyi/ruoyi-server:4.3.0-beta1"
+ image: "ruoyi/ruoyi-server:4.3.0-beta2"
container_name: ruoyi-server2
environment:
# 时区上海
@@ -125,7 +125,7 @@ services:
network_mode: "host"
ruoyi-monitor-admin:
- image: ruoyi/ruoyi-monitor-admin:4.3.0-beta1
+ image: ruoyi/ruoyi-monitor-admin:4.3.0-beta2
container_name: ruoyi-monitor-admin
environment:
# 时区上海
@@ -137,7 +137,7 @@ services:
network_mode: "host"
ruoyi-xxl-job-admin:
- image: ruoyi/ruoyi-xxl-job-admin:4.3.0-beta1
+ image: ruoyi/ruoyi-xxl-job-admin:4.3.0-beta2
container_name: ruoyi-xxl-job-admin
environment:
# 时区上海