| | |
| | | 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.UserConstants; |
| | | import com.ruoyi.common.core.domain.PageQuery; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.core.constant.CacheNames; |
| | | import com.ruoyi.common.core.constant.UserConstants; |
| | | import com.ruoyi.common.mybatis.core.page.PageQuery; |
| | | import com.ruoyi.common.mybatis.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.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.redis.utils.CacheUtils; |
| | | import com.ruoyi.common.core.utils.SpringUtils; |
| | | 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; |
| | | |
| | |
| | | * @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; |
| | |
| | | * @return true开启,false关闭 |
| | | */ |
| | | @Override |
| | | public boolean selectCaptchaOnOff() { |
| | | String captchaOnOff = selectConfigByKey("sys.account.captchaOnOff"); |
| | | if (StringUtils.isEmpty(captchaOnOff)) { |
| | | public boolean selectCaptchaEnabled() { |
| | | String captchaEnabled = SpringUtils.getAopProxy(this).selectConfigByKey("sys.account.captchaEnabled"); |
| | | if (StringUtils.isEmpty(captchaEnabled)) { |
| | | return true; |
| | | } |
| | | return Convert.toBool(captchaOnOff); |
| | | return Convert.toBool(captchaEnabled); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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("操作失败"); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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) { |
| | | SysConfig temp = baseMapper.selectById(config.getConfigId()); |
| | | if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey())) { |
| | | CacheUtils.evict(CacheNames.SYS_CONFIG, temp.getConfigKey()); |
| | | } |
| | | row = baseMapper.updateById(config); |
| | | } else { |
| | | row = baseMapper.update(config, new LambdaQueryWrapper<SysConfig>() |
| | | .eq(SysConfig::getConfigKey, config.getConfigKey())); |
| | | } |
| | | if (row > 0) { |
| | | RedisUtils.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); |
| | | return config.getConfigValue(); |
| | | } |
| | | return row; |
| | | throw new ServiceException("操作失败"); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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)); |
| | | } |
| | |
| | | @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())); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void clearConfigCache() { |
| | | Collection<String> keys = RedisUtils.keys(CacheConstants.SYS_CONFIG_KEY + "*"); |
| | | RedisUtils.deleteObject(keys); |
| | | CacheUtils.clear(CacheNames.SYS_CONFIG); |
| | | } |
| | | |
| | | /** |
| | |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | |
| | | @Override |
| | | public SysConfig getOne(SysConfig config) { |
| | | return baseMapper.selectOne(new LambdaQueryWrapper<>(config)); |
| | | } |
| | | |
| | | /** |
| | | * 根据参数 key 获取参数值 |
| | | * |
| | |
| | | */ |
| | | @Override |
| | | public String getConfigValue(String configKey) { |
| | | return selectConfigByKey(configKey); |
| | | return SpringUtils.getAopProxy(this).selectConfigByKey(configKey); |
| | | } |
| | | |
| | | /** |
| | | * 设置cache key |
| | | * |
| | | * @param configKey 参数键 |
| | | * @return 缓存键key |
| | | */ |
| | | private String getCacheKey(String configKey) { |
| | | return CacheConstants.SYS_CONFIG_KEY + configKey; |
| | | } |
| | | } |