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 f4e97c8b0..b6f8a5087 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 @@ -6,8 +6,8 @@ import cn.hutool.core.convert.Convert; import cn.hutool.core.util.IdUtil; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.enums.CaptchaType; +import com.ruoyi.common.utils.RedisUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.reflect.ReflectUtils; import com.ruoyi.common.utils.spring.SpringUtils; @@ -29,9 +29,6 @@ import java.util.concurrent.TimeUnit; @RestController public class CaptchaController { - @Autowired - private RedisCache redisCache; - @Autowired private CaptchaProperties captchaProperties; @@ -61,7 +58,7 @@ public class CaptchaController { captcha.setGenerator(codeGenerator); captcha.createCode(); String code = isMath ? getCodeResult(captcha.getCode()) : captcha.getCode(); - redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); + RedisUtils.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); ajax.put("uuid", uuid); ajax.put("img", captcha.getImageBase64()); return AjaxResult.success(ajax); 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 f1442cc71..9c836093f 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,9 +6,9 @@ import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.page.TableDataInfo; -import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.PageUtils; +import com.ruoyi.common.utils.RedisUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.domain.SysUserOnline; import com.ruoyi.system.service.ISysUserOnlineService; @@ -33,18 +33,15 @@ public class SysUserOnlineController extends BaseController @Autowired private ISysUserOnlineService userOnlineService; - @Autowired - private RedisCache redisCache; - @PreAuthorize("@ss.hasPermi('monitor:online:list')") @GetMapping("/list") public TableDataInfo list(String ipaddr, String userName) { - Collection keys = redisCache.keys(Constants.LOGIN_TOKEN_KEY + "*"); + Collection keys = RedisUtils.keys(Constants.LOGIN_TOKEN_KEY + "*"); List userOnlineList = new ArrayList(); for (String key : keys) { - LoginUser user = redisCache.getCacheObject(key); + LoginUser user = RedisUtils.getCacheObject(key); if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) { if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) @@ -84,7 +81,7 @@ public class SysUserOnlineController extends BaseController @DeleteMapping("/{tokenId}") public AjaxResult forceLogout(@PathVariable String tokenId) { - redisCache.deleteObject(Constants.LOGIN_TOKEN_KEY + tokenId); + RedisUtils.deleteObject(Constants.LOGIN_TOKEN_KEY + tokenId); return AjaxResult.success(); } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/cache/MybatisPlusRedisCache.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/cache/MybatisPlusRedisCache.java index 633a0b5ab..51b9ec38e 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/cache/MybatisPlusRedisCache.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/cache/MybatisPlusRedisCache.java @@ -1,7 +1,7 @@ package com.ruoyi.common.core.mybatisplus.cache; import cn.hutool.extra.spring.SpringUtil; -import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.utils.RedisUtils; import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.cache.Cache; import org.springframework.data.redis.connection.RedisServerCommands; @@ -25,8 +25,6 @@ public class MybatisPlusRedisCache implements Cache { private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(true); - private RedisCache redisCache; - private String id; public MybatisPlusRedisCache(final String id) { @@ -43,23 +41,16 @@ public class MybatisPlusRedisCache implements Cache { @Override public void putObject(Object key, Object value) { - if (redisCache == null) { - redisCache = SpringUtil.getBean(RedisCache.class); - } if (value != null) { - redisCache.setCacheObject(key.toString(), value); + RedisUtils.setCacheObject(key.toString(), value); } } @Override public Object getObject(Object key) { - if (redisCache == null) { - //由于启动期间注入失败,只能运行期间注入,这段代码可以删除 - redisCache = SpringUtil.getBean(RedisCache.class); - } try { if (key != null) { - return redisCache.getCacheObject(key.toString()); + return RedisUtils.getCacheObject(key.toString()); } } catch (Exception e) { e.printStackTrace(); @@ -70,11 +61,8 @@ public class MybatisPlusRedisCache implements Cache { @Override public Object removeObject(Object key) { - if (redisCache == null) { - redisCache = SpringUtil.getBean(RedisCache.class); - } if (key != null) { - redisCache.deleteObject(key.toString()); + RedisUtils.deleteObject(key.toString()); } return null; } @@ -82,12 +70,9 @@ public class MybatisPlusRedisCache implements Cache { @Override public void clear() { log.debug("清空缓存"); - if (redisCache == null) { - redisCache = SpringUtil.getBean(RedisCache.class); - } - Collection keys = redisCache.keys("*:" + this.id + "*"); + Collection keys = RedisUtils.keys("*:" + this.id + "*"); if (!CollectionUtils.isEmpty(keys)) { - redisCache.deleteObject(keys); + RedisUtils.deleteObject(keys); } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java index 64ac8efdc..39e71a66a 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java @@ -3,8 +3,6 @@ package com.ruoyi.common.utils; import cn.hutool.core.collection.CollUtil; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.entity.SysDictData; -import com.ruoyi.common.core.redis.RedisCache; -import com.ruoyi.common.utils.spring.SpringUtils; import java.util.Collection; import java.util.List; @@ -29,7 +27,7 @@ public class DictUtils */ public static void setDictCache(String key, List dictDatas) { - SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dictDatas); + RedisUtils.setCacheObject(getCacheKey(key), dictDatas); } /** @@ -40,7 +38,7 @@ public class DictUtils */ public static List getDictCache(String key) { - Object cacheObj = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key)); + Object cacheObj = RedisUtils.getCacheObject(getCacheKey(key)); if (StringUtils.isNotNull(cacheObj)) { List dictDatas = (List)cacheObj; @@ -160,7 +158,7 @@ public class DictUtils */ public static void removeDictCache(String key) { - SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key)); + RedisUtils.deleteObject(getCacheKey(key)); } /** @@ -168,8 +166,8 @@ public class DictUtils */ public static void clearDictCache() { - Collection keys = SpringUtils.getBean(RedisCache.class).keys(Constants.SYS_DICT_KEY + "*"); - SpringUtils.getBean(RedisCache.class).deleteObject(keys); + Collection keys = RedisUtils.keys(Constants.SYS_DICT_KEY + "*"); + RedisUtils.deleteObject(keys); } /** diff --git a/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisPubSubController.java b/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisPubSubController.java index d49d6ee82..810b307dc 100644 --- a/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisPubSubController.java +++ b/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisPubSubController.java @@ -1,7 +1,7 @@ package com.ruoyi.demo.controller; import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.utils.RedisUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -21,12 +21,10 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("/demo/redis/pubsub") public class RedisPubSubController { - private final RedisCache redisCache; - @ApiOperation("发布消息") @GetMapping("/pub") public AjaxResult pub(String key, String value){ - redisCache.publish(key, value, consumer -> { + RedisUtils.publish(key, value, consumer -> { System.out.println("发布通道 => " + key + ", 发送值 => " + value); }); return AjaxResult.success("操作成功"); @@ -35,7 +33,7 @@ public class RedisPubSubController { @ApiOperation("订阅消息") @GetMapping("/sub") public AjaxResult sub(String key){ - redisCache.subscribe(key, String.class, msg -> { + RedisUtils.subscribe(key, String.class, msg -> { System.out.println("订阅通道 => " + key + ", 接收值 => " + msg); }); return AjaxResult.success("操作成功"); 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 d66d86bf6..867cd40b5 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 @@ -3,6 +3,7 @@ package com.ruoyi.framework.config; import cn.hutool.core.util.StrUtil; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.config.properties.RedissonProperties; +import lombok.extern.slf4j.Slf4j; import org.redisson.Redisson; import org.redisson.api.RedissonClient; import org.redisson.codec.JsonJacksonCodec; @@ -29,6 +30,7 @@ import java.util.Map; * * @author Lion Li */ +@Slf4j @Configuration @EnableCaching public class RedisConfig extends CachingConfigurerSupport { @@ -73,7 +75,9 @@ public class RedisConfig extends CachingConfigurerSupport { .setConnectionMinimumIdleSize(singleServerConfig.getConnectionMinimumIdleSize()) .setConnectionPoolSize(singleServerConfig.getConnectionPoolSize()) .setDnsMonitoringInterval(singleServerConfig.getDnsMonitoringInterval()); - return Redisson.create(config); + RedissonClient redissonClient = Redisson.create(config); + log.info("初始化 redis 配置"); + return redissonClient; } /** diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java index d9b3464e4..b2256c935 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java @@ -4,9 +4,9 @@ import cn.hutool.core.convert.Convert; import cn.hutool.core.io.IoUtil; import com.ruoyi.common.annotation.RepeatSubmit; import com.ruoyi.common.constant.Constants; -import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.filter.RepeatedlyRequestWrapper; import com.ruoyi.common.utils.JsonUtils; +import com.ruoyi.common.utils.RedisUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.config.properties.RepeatSubmitProperties; import com.ruoyi.framework.config.properties.TokenProperties; @@ -38,7 +38,6 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor { private final TokenProperties tokenProperties; private final RepeatSubmitProperties repeatSubmitProperties; - private final RedisCache redisCache; @SuppressWarnings("unchecked") @@ -79,7 +78,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor { // 唯一标识(指定key + 消息头) String cacheRepeatKey = Constants.REPEAT_SUBMIT_KEY + submitKey; - Object sessionObj = redisCache.getCacheObject(cacheRepeatKey); + Object sessionObj = RedisUtils.getCacheObject(cacheRepeatKey); if (sessionObj != null) { Map sessionMap = (Map) sessionObj; if (sessionMap.containsKey(url)) { @@ -91,7 +90,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor { } Map cacheMap = new HashMap(); cacheMap.put(url, nowDataMap); - redisCache.setCacheObject(cacheRepeatKey, cacheMap, Convert.toInt(intervalTime), TimeUnit.MILLISECONDS); + RedisUtils.setCacheObject(cacheRepeatKey, cacheMap, Convert.toInt(intervalTime), TimeUnit.MILLISECONDS); return false; } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index e3e8e71f5..7df8c26d5 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -3,13 +3,13 @@ package com.ruoyi.framework.web.service; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; -import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.user.CaptchaException; import com.ruoyi.common.exception.user.CaptchaExpireException; import com.ruoyi.common.exception.user.UserPasswordNotMatchException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.MessageUtils; +import com.ruoyi.common.utils.RedisUtils; import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.service.ISysUserService; @@ -37,9 +37,6 @@ public class SysLoginService @Resource private AuthenticationManager authenticationManager; - @Autowired - private RedisCache redisCache; - @Autowired private ISysUserService userService; @@ -105,8 +102,8 @@ public class SysLoginService */ public void validateCaptcha(String username, String code, String uuid, HttpServletRequest request) { String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; - String captcha = redisCache.getCacheObject(verifyKey); - redisCache.deleteObject(verifyKey); + String captcha = RedisUtils.getCacheObject(verifyKey); + RedisUtils.deleteObject(verifyKey); if (captcha == null) { asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"), request); throw new CaptchaExpireException(); diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java index 48d40af8a..149392f21 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java @@ -4,13 +4,9 @@ import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.RegisterBody; -import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.exception.user.CaptchaException; import com.ruoyi.common.exception.user.CaptchaExpireException; -import com.ruoyi.common.utils.MessageUtils; -import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.ServletUtils; -import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.*; import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.service.ISysUserService; import org.springframework.beans.factory.annotation.Autowired; @@ -30,9 +26,6 @@ public class SysRegisterService @Autowired private ISysConfigService configService; - @Autowired - private RedisCache redisCache; - @Autowired private AsyncService asyncService; @@ -103,8 +96,8 @@ public class SysRegisterService public void validateCaptcha(String username, String code, String uuid) { String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; - String captcha = redisCache.getCacheObject(verifyKey); - redisCache.deleteObject(verifyKey); + String captcha = RedisUtils.getCacheObject(verifyKey); + RedisUtils.deleteObject(verifyKey); if (captcha == null) { throw new CaptchaExpireException(); diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java index 3414e372f..cb8878e86 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java @@ -5,7 +5,7 @@ import cn.hutool.http.useragent.UserAgent; import cn.hutool.http.useragent.UserAgentUtil; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.model.LoginUser; -import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.utils.RedisUtils; import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.ip.AddressUtils; @@ -35,9 +35,6 @@ public class TokenService { private static final Long MILLIS_MINUTE_TEN = 20 * 60 * 1000L; - @Autowired - private RedisCache redisCache; - @Autowired private TokenProperties tokenProperties; @@ -55,7 +52,7 @@ public class TokenService { // 解析对应的权限以及用户信息 String uuid = (String) claims.get(Constants.LOGIN_USER_KEY); String userKey = getTokenKey(uuid); - LoginUser user = redisCache.getCacheObject(userKey); + LoginUser user = RedisUtils.getCacheObject(userKey); return user; } catch (Exception e) { @@ -79,7 +76,7 @@ public class TokenService { public void delLoginUser(String token) { if (StringUtils.isNotEmpty(token)) { String userKey = getTokenKey(token); - redisCache.deleteObject(userKey); + RedisUtils.deleteObject(userKey); } } @@ -124,7 +121,7 @@ public class TokenService { loginUser.setExpireTime(loginUser.getLoginTime() + tokenProperties.getExpireTime() * MILLIS_MINUTE); // 根据uuid将loginUser缓存 String userKey = getTokenKey(loginUser.getToken()); - redisCache.setCacheObject(userKey, loginUser, tokenProperties.getExpireTime(), TimeUnit.MINUTES); + RedisUtils.setCacheObject(userKey, loginUser, tokenProperties.getExpireTime(), TimeUnit.MINUTES); } /** 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 7a22c5088..ecb269dd7 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,11 +1,10 @@ package com.ruoyi.oss.factory; import cn.hutool.core.convert.Convert; -import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.utils.JsonUtils; +import com.ruoyi.common.utils.RedisUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.reflect.ReflectUtils; -import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.oss.constant.CloudConstant; import com.ruoyi.oss.enumd.CloudServiceEnumd; import com.ruoyi.oss.exception.OssException; @@ -25,11 +24,8 @@ import java.util.concurrent.ConcurrentHashMap; @Slf4j public class OssFactory { - private static RedisCache redisCache; - static { - OssFactory.redisCache = SpringUtils.getBean(RedisCache.class); - redisCache.subscribe(CloudConstant.CACHE_CONFIG_KEY, String.class, msg -> { + RedisUtils.subscribe(CloudConstant.CACHE_CONFIG_KEY, String.class, msg -> { refreshService(msg); log.info("订阅刷新OSS配置 => " + msg); }); @@ -45,7 +41,7 @@ public class OssFactory { */ public static ICloudStorageStrategy instance() { // 获取redis 默认类型 - String type = Convert.toStr(redisCache.getCacheObject(CloudConstant.CACHE_CONFIG_KEY)); + String type = Convert.toStr(RedisUtils.getCacheObject(CloudConstant.CACHE_CONFIG_KEY)); if (StringUtils.isEmpty(type)) { throw new OssException("文件存储服务类型无法找到!"); } @@ -65,7 +61,7 @@ public class OssFactory { } private static void refreshService(String type) { - Object json = redisCache.getCacheObject(CloudConstant.SYS_OSS_KEY + type); + Object json = RedisUtils.getCacheObject(CloudConstant.SYS_OSS_KEY + type); CloudStorageProperties properties = JsonUtils.parseObject(json.toString(), CloudStorageProperties.class); if (properties == null) { throw new OssException("系统异常, '" + type + "'配置信息不存在!"); 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 6cc895848..7aba69d89 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 @@ -1,21 +1,20 @@ package com.ruoyi.system.service.impl; import cn.hutool.core.convert.Convert; -import com.ruoyi.common.utils.StringUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ruoyi.common.annotation.DataSource; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; import com.ruoyi.common.core.page.TableDataInfo; -import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.enums.DataSourceType; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.PageUtils; +import com.ruoyi.common.utils.RedisUtils; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.domain.SysConfig; import com.ruoyi.system.mapper.SysConfigMapper; import com.ruoyi.system.service.ISysConfigService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; @@ -32,9 +31,6 @@ import java.util.Map; @Service public class SysConfigServiceImpl extends ServicePlusImpl implements ISysConfigService { - @Autowired - private RedisCache redisCache; - /** * 项目启动时,初始化参数到缓存 */ @@ -79,14 +75,14 @@ public class SysConfigServiceImpl extends ServicePlusImpl() .eq(SysConfig::getConfigKey, configKey)); if (StringUtils.isNotNull(retConfig)) { - redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue()); + RedisUtils.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue()); return retConfig.getConfigValue(); } return StringUtils.EMPTY; @@ -138,7 +134,7 @@ public class SysConfigServiceImpl extends ServicePlusImpl 0) { - redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + RedisUtils.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); } return row; } @@ -153,7 +149,7 @@ public class SysConfigServiceImpl extends ServicePlusImpl 0) { - redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + RedisUtils.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); } return row; } @@ -171,7 +167,7 @@ public class SysConfigServiceImpl extends ServicePlusImpl configsList = selectConfigList(new SysConfig()); for (SysConfig config : configsList) { - redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + RedisUtils.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); } } @@ -192,8 +188,8 @@ public class SysConfigServiceImpl extends ServicePlusImpl keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*"); - redisCache.deleteObject(keys); + Collection keys = RedisUtils.keys(Constants.SYS_CONFIG_KEY + "*"); + RedisUtils.deleteObject(keys); } /** 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 b3a92c09a..e80252539 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 @@ -9,10 +9,10 @@ import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; import com.ruoyi.common.core.page.PagePlus; import com.ruoyi.common.core.page.TableDataInfo; -import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.JsonUtils; import com.ruoyi.common.utils.PageUtils; +import com.ruoyi.common.utils.RedisUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.oss.constant.CloudConstant; import com.ruoyi.system.domain.SysOssConfig; @@ -42,8 +42,6 @@ import java.util.List; @Service public class SysOssConfigServiceImpl extends ServicePlusImpl implements ISysOssConfigService { - private final RedisCache redisCache; - /** * 项目启动时,初始化参数到缓存,加载配置类 */ @@ -53,7 +51,7 @@ public class SysOssConfigServiceImpl extends ServicePlusImpl 0) { - redisCache.setCacheObject(CloudConstant.CACHE_CONFIG_KEY, sysOssConfig.getConfigKey()); + RedisUtils.setCacheObject(CloudConstant.CACHE_CONFIG_KEY, sysOssConfig.getConfigKey()); } return row; } @@ -168,10 +166,10 @@ public class SysOssConfigServiceImpl extends ServicePlusImpl { + RedisUtils.publish(CloudConstant.CACHE_CONFIG_KEY, config.getConfigKey(), msg -> { log.info("发布刷新OSS配置 => " + msg); }); }