Merge remote-tracking branch 'origin/dev' into 4.X
This commit is contained in:
commit
67e20711d4
@ -4,7 +4,7 @@
|
||||
[](https://gitee.com/JavaLionLi/RuoYi-Vue-Plus/blob/master/LICENSE)
|
||||
[](https://www.jetbrains.com/?from=RuoYi-Vue-Plus)
|
||||
<br>
|
||||
[](https://gitee.com/JavaLionLi/RuoYi-Vue-Plus)
|
||||
[](https://gitee.com/JavaLionLi/RuoYi-Vue-Plus)
|
||||
[]()
|
||||
[]()
|
||||
[]()
|
||||
|
4
pom.xml
4
pom.xml
@ -6,14 +6,14 @@
|
||||
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-vue-plus</artifactId>
|
||||
<version>4.3.0-beta1</version>
|
||||
<version>4.3.0-beta2</version>
|
||||
|
||||
<name>RuoYi-Vue-Plus</name>
|
||||
<url>https://gitee.com/JavaLionLi/RuoYi-Vue-Plus</url>
|
||||
<description>RuoYi-Vue-Plus后台管理系统</description>
|
||||
|
||||
<properties>
|
||||
<ruoyi-vue-plus.version>4.3.0-beta1</ruoyi-vue-plus.version>
|
||||
<ruoyi-vue-plus.version>4.3.0-beta2</ruoyi-vue-plus.version>
|
||||
<spring-boot.version>2.7.2</spring-boot.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ruoyi-vue-plus</artifactId>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<version>4.3.0-beta1</version>
|
||||
<version>4.3.0-beta2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
@ -54,8 +54,8 @@ public class CaptchaController {
|
||||
@GetMapping("/captchaSms")
|
||||
public R<Void> 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);
|
||||
|
@ -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<Collection<String>> getCacheKeys(@PathVariable String cacheName) {
|
||||
Collection<String> cacheKeys = RedisUtils.keys(cacheName + "*");
|
||||
Collection<String> cacheKeys = new HashSet<>(0);
|
||||
if (isCacheNames(cacheName)) {
|
||||
Set<Object> 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<SysCache> 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<Void> 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<Void> clearCacheKey(@PathVariable String cacheKey) {
|
||||
RedisUtils.deleteObject(cacheKey);
|
||||
@DeleteMapping("/clearCacheKey/{cacheName}/{cacheKey}")
|
||||
public R<Void> 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, ":");
|
||||
}
|
||||
}
|
||||
|
@ -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<UserOnlineDTO> 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 ->
|
||||
|
@ -82,7 +82,8 @@ public class SysConfigController extends BaseController {
|
||||
if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) {
|
||||
return R.fail("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
|
||||
}
|
||||
return toAjax(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 toAjax(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<Void> updateByKey(@RequestBody SysConfig config) {
|
||||
return toAjax(configService.updateConfig(config));
|
||||
configService.updateConfig(config);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,7 +86,8 @@ public class SysDictDataController extends BaseController {
|
||||
@Log(title = "字典数据", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public R<Void> 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<Void> edit(@Validated @RequestBody SysDictData dict) {
|
||||
return toAjax(dictDataService.updateDictData(dict));
|
||||
dictDataService.updateDictData(dict);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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("文件数据不存在!");
|
||||
}
|
||||
|
@ -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 毫秒
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ruoyi-vue-plus</artifactId>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<version>4.3.0-beta1</version>
|
||||
<version>4.3.0-beta2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -0,0 +1,48 @@
|
||||
package com.ruoyi.common.constant;
|
||||
|
||||
/**
|
||||
* 缓存组名称常量
|
||||
* <p>
|
||||
* key 格式为 cacheNames#ttl#maxIdleTime#maxSize
|
||||
* <p>
|
||||
* ttl 过期时间 如果设置为0则不过期 默认为0
|
||||
* maxIdleTime 最大空闲时间 根据LRU算法清理空闲数据 如果设置为0则不检测 默认为0
|
||||
* maxSize 组最大长度 根据LRU算法清理溢出数据 如果设置为0则无限长 默认为0
|
||||
* <p>
|
||||
* 例子: 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";
|
||||
|
||||
/**
|
||||
* 系统配置
|
||||
*/
|
||||
String SYS_CONFIG = "sys_config";
|
||||
|
||||
/**
|
||||
* 数据字典
|
||||
*/
|
||||
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";
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
||||
return BeanCopyUtils.copy(obj, voClass);
|
||||
}
|
||||
|
||||
default List<V> selectVoById(Collection<? extends Serializable> idList) {
|
||||
default List<V> selectVoBatchIds(Collection<? extends Serializable> idList) {
|
||||
return selectVoBatchIds(idList, this.currentVoClass());
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,75 @@
|
||||
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 }
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
* @date 2022/8/13
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings(value = {"unchecked"})
|
||||
public class CacheUtils {
|
||||
|
||||
private static final CacheManager CACHE_MANAGER = SpringUtils.getBean(CacheManager.class);
|
||||
|
||||
/**
|
||||
* 获取缓存组内所有的KEY
|
||||
*
|
||||
* @param cacheNames 缓存组名称
|
||||
*/
|
||||
public static Set<Object> keys(String cacheNames) {
|
||||
RMap<Object, Object> rmap = (RMap<Object, Object>) CACHE_MANAGER.getCache(cacheNames).getNativeCache();
|
||||
return rmap.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存值
|
||||
*
|
||||
* @param cacheNames 缓存组名称
|
||||
* @param key 缓存key
|
||||
*/
|
||||
public static <T> T get(String cacheNames, Object key) {
|
||||
Cache.ValueWrapper wrapper = CACHE_MANAGER.getCache(cacheNames).get(key);
|
||||
return wrapper != null ? (T) wrapper.get() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存缓存值
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ruoyi-vue-plus</artifactId>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<version>4.3.0-beta1</version>
|
||||
<version>4.3.0-beta2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -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 {
|
||||
* 重点说明: 缓存注解严谨与其他筛选数据功能一起使用
|
||||
* 例如: 数据权限注解 会造成 缓存击穿 与 数据不一致问题
|
||||
* <p>
|
||||
* 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<String> test1(String key, String value) {
|
||||
return R.ok("操作成功", value);
|
||||
@ -48,11 +49,11 @@ public class RedisCacheController {
|
||||
* 测试 @CachePut
|
||||
* <p>
|
||||
* 加了@CachePut注解的方法,会把方法的返回值put到缓存里面缓存起来,供其它地方使用
|
||||
* 它「通常用在新增方法上」
|
||||
* 它「通常用在新增或者实时更新方法上」
|
||||
* <p>
|
||||
* 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<String> test2(String key, String value) {
|
||||
return R.ok("操作成功", value);
|
||||
@ -62,11 +63,11 @@ public class RedisCacheController {
|
||||
* 测试 @CacheEvict
|
||||
* <p>
|
||||
* 使用了CacheEvict注解的方法,会清空指定缓存
|
||||
* 「一般用在更新或者删除的方法上」
|
||||
* 「一般用在删除的方法上」
|
||||
* <p>
|
||||
* 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<String> test3(String key, String value) {
|
||||
return R.ok("操作成功", value);
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ruoyi-vue-plus</artifactId>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<version>4.3.0-beta1</version>
|
||||
<version>4.3.0-beta2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>ruoyi-extend</artifactId>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ruoyi-extend</artifactId>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<version>4.3.0-beta1</version>
|
||||
<version>4.3.0-beta2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ruoyi-extend</artifactId>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<version>4.3.0-beta1</version>
|
||||
<version>4.3.0-beta2</version>
|
||||
</parent>
|
||||
<artifactId>ruoyi-xxl-job-admin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
@ -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:
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ruoyi-vue-plus</artifactId>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<version>4.3.0-beta1</version>
|
||||
<version>4.3.0-beta2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -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<RedissonProperties.CacheGroup> cacheGroup = redissonProperties.getCacheGroup();
|
||||
Map<String, CacheConfig> 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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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> 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* 修改 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<String, CacheConfig> configMap = new ConcurrentHashMap<>();
|
||||
ConcurrentMap<String, Cache> instanceMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Creates CacheManager supplied by Redisson instance
|
||||
*/
|
||||
public PlusSpringCacheManager() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defines possibility of storing {@code null} values.
|
||||
* <p>
|
||||
* Default is <code>true</code>
|
||||
*
|
||||
* @param allowNullValues stores if <code>true</code>
|
||||
*/
|
||||
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.
|
||||
* <p>
|
||||
* Default is <code>false</code>
|
||||
*
|
||||
* @param transactionAware cache is transaction aware if <code>true</code>
|
||||
*/
|
||||
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.
|
||||
* <p>
|
||||
* `null` parameter setups dynamic mode
|
||||
*
|
||||
* @param names of caches
|
||||
*/
|
||||
public void setCacheNames(Collection<String> 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<String, ? extends CacheConfig> config) {
|
||||
this.configMap = (Map<String, CacheConfig>) 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<Object, Object> 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<Object, Object> 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<String> getCacheNames() {
|
||||
return Collections.unmodifiableSet(configMap.keySet());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ruoyi-vue-plus</artifactId>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<version>4.3.0-beta1</version>
|
||||
<version>4.3.0-beta2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ruoyi-vue-plus</artifactId>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<version>4.3.0-beta1</version>
|
||||
<version>4.3.0-beta2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ruoyi-vue-plus</artifactId>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<version>4.3.0-beta1</version>
|
||||
<version>4.3.0-beta2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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.redis.CacheUtils;
|
||||
import com.ruoyi.common.utils.redis.RedisUtils;
|
||||
import com.ruoyi.oss.constant.OssConstant;
|
||||
import com.ruoyi.oss.core.OssClient;
|
||||
@ -27,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) {
|
||||
@ -42,7 +44,7 @@ public class OssFactory {
|
||||
*/
|
||||
public static OssClient instance() {
|
||||
// 获取redis 默认类型
|
||||
String configKey = RedisUtils.getCacheObject(OssConstant.CACHE_CONFIG_KEY);
|
||||
String configKey = RedisUtils.getCacheObject(OssConstant.DEFAULT_CONFIG_KEY);
|
||||
if (StringUtils.isEmpty(configKey)) {
|
||||
throw new OssException("文件存储服务类型无法找到!");
|
||||
}
|
||||
@ -62,11 +64,11 @@ public class OssFactory {
|
||||
}
|
||||
|
||||
private static void refresh(String configKey) {
|
||||
Object json = RedisUtils.getCacheObject(OssConstant.SYS_OSS_KEY + 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));
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ruoyi-vue-plus</artifactId>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<version>4.3.0-beta1</version>
|
||||
<version>4.3.0-beta2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ruoyi-vue-plus</artifactId>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<version>4.3.0-beta1</version>
|
||||
<version>4.3.0-beta2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public interface ISysDictDataService {
|
||||
* @param dictData 字典数据信息
|
||||
* @return 结果
|
||||
*/
|
||||
int insertDictData(SysDictData dictData);
|
||||
List<SysDictData> insertDictData(SysDictData dictData);
|
||||
|
||||
/**
|
||||
* 修改保存字典数据信息
|
||||
@ -62,5 +62,5 @@ public interface ISysDictDataService {
|
||||
* @param dictData 字典数据信息
|
||||
* @return 结果
|
||||
*/
|
||||
int updateDictData(SysDictData dictData);
|
||||
List<SysDictData> updateDictData(SysDictData dictData);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public interface ISysDictTypeService {
|
||||
* @param dictType 字典类型信息
|
||||
* @return 结果
|
||||
*/
|
||||
int insertDictType(SysDictType dictType);
|
||||
List<SysDictData> insertDictType(SysDictType dictType);
|
||||
|
||||
/**
|
||||
* 修改保存字典类型信息
|
||||
@ -92,7 +92,7 @@ public interface ISysDictTypeService {
|
||||
* @param dictType 字典类型信息
|
||||
* @return 结果
|
||||
*/
|
||||
int updateDictType(SysDictType dictType);
|
||||
List<SysDictData> updateDictType(SysDictType dictType);
|
||||
|
||||
/**
|
||||
* 校验字典类型称是否唯一
|
||||
|
@ -21,7 +21,7 @@ public interface ISysOssService {
|
||||
|
||||
List<SysOssVo> listByIds(Collection<Long> ossIds);
|
||||
|
||||
SysOss getById(Long ossId);
|
||||
SysOssVo getById(Long ossId);
|
||||
|
||||
SysOss upload(MultipartFile file);
|
||||
|
||||
|
@ -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.redis.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<SysConfig>()
|
||||
.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<SysConfig> 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<String> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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.redis.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<SysDictData> 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<SysDictData> insertDictData(SysDictData data) {
|
||||
int row = baseMapper.insert(data);
|
||||
if (row > 0) {
|
||||
List<SysDictData> 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<SysDictData> updateDictData(SysDictData data) {
|
||||
int row = baseMapper.updateById(data);
|
||||
if (row > 0) {
|
||||
List<SysDictData> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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.redis.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<SysDictData> selectDictDataByType(String dictType) {
|
||||
List<SysDictData> dictDatas = RedisUtils.getCacheObject(getCacheKey(dictType));
|
||||
List<SysDictData> 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;
|
||||
}
|
||||
|
||||
@ -114,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<SysDictType>().eq(SysDictType::getDictType, dictType));
|
||||
@ -132,7 +131,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 +145,8 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getStatus, UserConstants.DICT_NORMAL));
|
||||
Map<String, List<SysDictData>> dictDataMap = StreamUtils.groupByKey(dictDataList, SysDictData::getDictType);
|
||||
dictDataMap.forEach((k,v) -> {
|
||||
String dictKey = getCacheKey(k);
|
||||
List<SysDictData> dictList = StreamUtils.sorted(v, Comparator.comparing(SysDictData::getDictSort));
|
||||
RedisUtils.setCacheObject(dictKey, dictList);
|
||||
CacheUtils.put(CacheNames.SYS_DICT, k, dictList);
|
||||
});
|
||||
}
|
||||
|
||||
@ -157,8 +155,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
*/
|
||||
@Override
|
||||
public void clearDictCache() {
|
||||
Collection<String> keys = RedisUtils.keys(CacheConstants.SYS_DICT_KEY + "*");
|
||||
RedisUtils.deleteObject(keys);
|
||||
CacheUtils.clear(CacheNames.SYS_DICT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,13 +173,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<SysDictData> 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 +189,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<SysDictData> updateDictType(SysDictType dict) {
|
||||
SysDictType oldDict = baseMapper.selectById(dict.getDictId());
|
||||
dictDataMapper.update(null, new LambdaUpdateWrapper<SysDictData>()
|
||||
.set(SysDictData::getDictType, dict.getDictType())
|
||||
.eq(SysDictData::getDictType, oldDict.getDictType()));
|
||||
int row = baseMapper.updateById(dict);
|
||||
if (row > 0) {
|
||||
List<SysDictData> 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 +286,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;
|
||||
}
|
||||
}
|
||||
|
@ -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.redis.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);
|
||||
RedisUtils.setCacheObject(OssConstant.DEFAULT_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());
|
||||
RedisUtils.setCacheObject(OssConstant.DEFAULT_CONFIG_KEY, sysOssConfig.getConfigKey());
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置cache key
|
||||
*
|
||||
* @param configKey 参数键
|
||||
* @return 缓存键key
|
||||
*/
|
||||
private String getCacheKey(String configKey) {
|
||||
return OssConstant.SYS_OSS_KEY + configKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果操作成功 则更新缓存
|
||||
*
|
||||
@ -182,10 +173,8 @@ public class SysOssConfigServiceImpl implements ISysOssConfigService {
|
||||
*/
|
||||
private boolean setConfigCache(boolean flag, SysOssConfig config) {
|
||||
if (flag) {
|
||||
RedisUtils.setCacheObject(
|
||||
getCacheKey(config.getConfigKey()),
|
||||
JsonUtils.toJsonString(config));
|
||||
RedisUtils.publish(OssConstant.CACHE_CONFIG_KEY, config.getConfigKey(), msg -> {
|
||||
CacheUtils.put(CacheNames.SYS_OSS_CONFIG, config.getConfigKey(), JsonUtils.toJsonString(config));
|
||||
RedisUtils.publish(OssConstant.DEFAULT_CONFIG_KEY, config.getConfigKey(), msg -> {
|
||||
log.info("发布刷新OSS配置 => " + msg);
|
||||
});
|
||||
}
|
||||
|
@ -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<SysOssVo> listByIds(Collection<Long> ossIds) {
|
||||
List<SysOssVo> 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
|
||||
|
@ -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",
|
||||
|
@ -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'
|
||||
})
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
// 版本号
|
||||
version: "4.3.0-beta1",
|
||||
version: "4.3.0-beta2",
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
|
2
ruoyi-ui/src/views/monitor/cache/list.vue
vendored
2
ruoyi-ui/src/views/monitor/cache/list.vue
vendored
@ -211,7 +211,7 @@ export default {
|
||||
},
|
||||
/** 清理指定键名缓存 */
|
||||
handleClearCacheKey(cacheKey) {
|
||||
clearCacheKey(cacheKey).then(response => {
|
||||
clearCacheKey(this.nowCacheName, cacheKey).then(response => {
|
||||
this.$modal.msgSuccess("清理缓存键名[" + cacheKey + "]成功");
|
||||
this.getCacheKeys();
|
||||
});
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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:
|
||||
# 时区上海
|
||||
|
Loading…
x
Reference in New Issue
Block a user