update 所有业务适配 RedisUtils 新工具
| | |
| | | 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; |
| | |
| | | */ |
| | | @RestController |
| | | public class CaptchaController { |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | @Autowired |
| | | private CaptchaProperties captchaProperties; |
| | |
| | | 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); |
| | |
| | | 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; |
| | |
| | | @Autowired |
| | | private ISysUserOnlineService userOnlineService; |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:online:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(String ipaddr, String userName) |
| | | { |
| | | Collection<String> keys = redisCache.keys(Constants.LOGIN_TOKEN_KEY + "*"); |
| | | Collection<String> keys = RedisUtils.keys(Constants.LOGIN_TOKEN_KEY + "*"); |
| | | List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>(); |
| | | 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())) |
| | |
| | | @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(); |
| | | } |
| | | } |
| | |
| | | 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; |
| | |
| | | |
| | | private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(true); |
| | | |
| | | private RedisCache redisCache; |
| | | |
| | | private String id; |
| | | |
| | | public MybatisPlusRedisCache(final String id) { |
| | |
| | | |
| | | @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(); |
| | |
| | | |
| | | @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; |
| | | } |
| | |
| | | @Override |
| | | public void clear() { |
| | | log.debug("清空缓存"); |
| | | if (redisCache == null) { |
| | | redisCache = SpringUtil.getBean(RedisCache.class); |
| | | } |
| | | Collection<String> keys = redisCache.keys("*:" + this.id + "*"); |
| | | Collection<String> keys = RedisUtils.keys("*:" + this.id + "*"); |
| | | if (!CollectionUtils.isEmpty(keys)) { |
| | | redisCache.deleteObject(keys); |
| | | RedisUtils.deleteObject(keys); |
| | | } |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | */ |
| | | public static void setDictCache(String key, List<SysDictData> dictDatas) |
| | | { |
| | | SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dictDatas); |
| | | RedisUtils.setCacheObject(getCacheKey(key), dictDatas); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static List<SysDictData> getDictCache(String key) |
| | | { |
| | | Object cacheObj = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key)); |
| | | Object cacheObj = RedisUtils.getCacheObject(getCacheKey(key)); |
| | | if (StringUtils.isNotNull(cacheObj)) |
| | | { |
| | | List<SysDictData> dictDatas = (List<SysDictData>)cacheObj; |
| | |
| | | */ |
| | | public static void removeDictCache(String key) |
| | | { |
| | | SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key)); |
| | | RedisUtils.deleteObject(getCacheKey(key)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static void clearDictCache() |
| | | { |
| | | Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(Constants.SYS_DICT_KEY + "*"); |
| | | SpringUtils.getBean(RedisCache.class).deleteObject(keys); |
| | | Collection<String> keys = RedisUtils.keys(Constants.SYS_DICT_KEY + "*"); |
| | | RedisUtils.deleteObject(keys); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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; |
| | |
| | | @RequestMapping("/demo/redis/pubsub") |
| | | public class RedisPubSubController { |
| | | |
| | | private final RedisCache redisCache; |
| | | |
| | | @ApiOperation("发布消息") |
| | | @GetMapping("/pub") |
| | | public AjaxResult<Void> pub(String key, String value){ |
| | | redisCache.publish(key, value, consumer -> { |
| | | RedisUtils.publish(key, value, consumer -> { |
| | | System.out.println("发布通道 => " + key + ", 发送值 => " + value); |
| | | }); |
| | | return AjaxResult.success("操作成功"); |
| | |
| | | @ApiOperation("订阅消息") |
| | | @GetMapping("/sub") |
| | | public AjaxResult<Void> sub(String key){ |
| | | redisCache.subscribe(key, String.class, msg -> { |
| | | RedisUtils.subscribe(key, String.class, msg -> { |
| | | System.out.println("订阅通道 => " + key + ", 接收值 => " + msg); |
| | | }); |
| | | return AjaxResult.success("操作成功"); |
| | |
| | | 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; |
| | |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Slf4j |
| | | @Configuration |
| | | @EnableCaching |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | |
| | | 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; |
| | |
| | | |
| | | private final TokenProperties tokenProperties; |
| | | private final RepeatSubmitProperties repeatSubmitProperties; |
| | | private final RedisCache redisCache; |
| | | |
| | | |
| | | @SuppressWarnings("unchecked") |
| | |
| | | // 唯一标识(指定key + 消息头) |
| | | String cacheRepeatKey = Constants.REPEAT_SUBMIT_KEY + submitKey; |
| | | |
| | | Object sessionObj = redisCache.getCacheObject(cacheRepeatKey); |
| | | Object sessionObj = RedisUtils.getCacheObject(cacheRepeatKey); |
| | | if (sessionObj != null) { |
| | | Map<String, Object> sessionMap = (Map<String, Object>) sessionObj; |
| | | if (sessionMap.containsKey(url)) { |
| | |
| | | } |
| | | Map<String, Object> cacheMap = new HashMap<String, Object>(); |
| | | cacheMap.put(url, nowDataMap); |
| | | redisCache.setCacheObject(cacheRepeatKey, cacheMap, Convert.toInt(intervalTime), TimeUnit.MILLISECONDS); |
| | | RedisUtils.setCacheObject(cacheRepeatKey, cacheMap, Convert.toInt(intervalTime), TimeUnit.MILLISECONDS); |
| | | return false; |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | |
| | | @Resource |
| | | private AuthenticationManager authenticationManager; |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | @Autowired |
| | | private ISysUserService userService; |
| | |
| | | */ |
| | | 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(); |
| | |
| | | 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; |
| | |
| | | |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | @Autowired |
| | | private AsyncService asyncService; |
| | |
| | | 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(); |
| | |
| | | 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; |
| | |
| | | private static final Long MILLIS_MINUTE_TEN = 20 * 60 * 1000L; |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | @Autowired |
| | | private TokenProperties tokenProperties; |
| | | |
| | | /** |
| | |
| | | // 解析对应的权限以及用户信息 |
| | | 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) { |
| | | |
| | |
| | | public void delLoginUser(String token) { |
| | | if (StringUtils.isNotEmpty(token)) { |
| | | String userKey = getTokenKey(token); |
| | | redisCache.deleteObject(userKey); |
| | | RedisUtils.deleteObject(userKey); |
| | | } |
| | | } |
| | | |
| | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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; |
| | |
| | | @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); |
| | | }); |
| | |
| | | */ |
| | | 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("文件存储服务类型无法找到!"); |
| | | } |
| | |
| | | } |
| | | |
| | | 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 + "'配置信息不存在!"); |
| | |
| | | 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; |
| | |
| | | */ |
| | | @Service |
| | | public class SysConfigServiceImpl extends ServicePlusImpl<SysConfigMapper, SysConfig, SysConfig> implements ISysConfigService { |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | /** |
| | | * 项目启动时,初始化参数到缓存 |
| | |
| | | */ |
| | | @Override |
| | | public String selectConfigByKey(String configKey) { |
| | | String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey))); |
| | | String configValue = Convert.toStr(RedisUtils.getCacheObject(getCacheKey(configKey))); |
| | | if (StringUtils.isNotEmpty(configValue)) { |
| | | return configValue; |
| | | } |
| | | SysConfig retConfig = baseMapper.selectOne(new LambdaQueryWrapper<SysConfig>() |
| | | .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; |
| | |
| | | public int insertConfig(SysConfig config) { |
| | | int row = baseMapper.insert(config); |
| | | if (row > 0) { |
| | | redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); |
| | | RedisUtils.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); |
| | | } |
| | | return row; |
| | | } |
| | |
| | | public int updateConfig(SysConfig config) { |
| | | int row = baseMapper.updateById(config); |
| | | if (row > 0) { |
| | | redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); |
| | | RedisUtils.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); |
| | | } |
| | | return row; |
| | | } |
| | |
| | | if (StringUtils.equals(UserConstants.YES, config.getConfigType())) { |
| | | throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey())); |
| | | } |
| | | redisCache.deleteObject(getCacheKey(config.getConfigKey())); |
| | | RedisUtils.deleteObject(getCacheKey(config.getConfigKey())); |
| | | } |
| | | baseMapper.deleteBatchIds(Arrays.asList(configIds)); |
| | | } |
| | |
| | | public void loadingConfigCache() { |
| | | List<SysConfig> configsList = selectConfigList(new SysConfig()); |
| | | for (SysConfig config : configsList) { |
| | | redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); |
| | | RedisUtils.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void clearConfigCache() { |
| | | Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*"); |
| | | redisCache.deleteObject(keys); |
| | | Collection<String> keys = RedisUtils.keys(Constants.SYS_CONFIG_KEY + "*"); |
| | | RedisUtils.deleteObject(keys); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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; |
| | |
| | | @Service |
| | | public class SysOssConfigServiceImpl extends ServicePlusImpl<SysOssConfigMapper, SysOssConfig, SysOssConfigVo> implements ISysOssConfigService { |
| | | |
| | | private final RedisCache redisCache; |
| | | |
| | | /** |
| | | * 项目启动时,初始化参数到缓存,加载配置类 |
| | | */ |
| | |
| | | for (SysOssConfig config : list) { |
| | | String configKey = config.getConfigKey(); |
| | | if ("0".equals(config.getStatus())) { |
| | | redisCache.setCacheObject(CloudConstant.CACHE_CONFIG_KEY, configKey); |
| | | RedisUtils.setCacheObject(CloudConstant.CACHE_CONFIG_KEY, configKey); |
| | | } |
| | | setConfigCache(true, config); |
| | | } |
| | |
| | | if (flag) { |
| | | for (Long configId : ids) { |
| | | SysOssConfig config = getById(configId); |
| | | redisCache.deleteObject(getCacheKey(config.getConfigKey())); |
| | | RedisUtils.deleteObject(getCacheKey(config.getConfigKey())); |
| | | } |
| | | } |
| | | return flag; |
| | |
| | | .set(SysOssConfig::getStatus, "1")); |
| | | row += baseMapper.updateById(sysOssConfig); |
| | | if (row > 0) { |
| | | redisCache.setCacheObject(CloudConstant.CACHE_CONFIG_KEY, sysOssConfig.getConfigKey()); |
| | | RedisUtils.setCacheObject(CloudConstant.CACHE_CONFIG_KEY, sysOssConfig.getConfigKey()); |
| | | } |
| | | return row; |
| | | } |
| | |
| | | */ |
| | | private boolean setConfigCache(boolean flag, SysOssConfig config) { |
| | | if (flag) { |
| | | redisCache.setCacheObject( |
| | | RedisUtils.setCacheObject( |
| | | getCacheKey(config.getConfigKey()), |
| | | JsonUtils.toJsonString(config)); |
| | | redisCache.publish(CloudConstant.CACHE_CONFIG_KEY, config.getConfigKey(), msg -> { |
| | | RedisUtils.publish(CloudConstant.CACHE_CONFIG_KEY, config.getConfigKey(), msg -> { |
| | | log.info("发布刷新OSS配置 => " + msg); |
| | | }); |
| | | } |