From eb9f3d37725c5df391f390c00cdeefa2d9a1d29b Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期二, 12 七月 2022 18:04:49 +0800 Subject: [PATCH] 修改验证码开关变量名 --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java | 72 +++++++++++++++++++++++++++-------- 1 files changed, 55 insertions(+), 17 deletions(-) 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 1c113fa..bc390ad 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 @@ -6,11 +6,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.common.annotation.DataSource; -import com.ruoyi.common.constant.Constants; +import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.enums.DataSourceType; +import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.domain.SysConfig; import com.ruoyi.system.mapper.SysConfigMapper; @@ -36,11 +37,7 @@ @PostConstruct public void init() { - List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig()); - for (SysConfig config : configsList) - { - redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); - } + loadingConfigCache(); } /** @@ -81,6 +78,22 @@ return retConfig.getConfigValue(); } return StringUtils.EMPTY; + } + + /** + * 获取验证码开关 + * + * @return true开启,false关闭 + */ + @Override + public boolean selectCaptchaEnabled() + { + String captchaEnabled = selectConfigByKey("sys.account.captchaEnabled"); + if (StringUtils.isEmpty(captchaEnabled)) + { + return true; + } + return Convert.toBool(captchaEnabled); } /** @@ -133,28 +146,53 @@ * 批量删除参数信息 * * @param configIds 需要删除的参数ID - * @return 结果 */ @Override - public int deleteConfigByIds(Long[] configIds) + public void deleteConfigByIds(Long[] configIds) { - int count = configMapper.deleteConfigByIds(configIds); - if (count > 0) + for (Long configId : configIds) { - Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*"); - redisCache.deleteObject(keys); + SysConfig config = selectConfigById(configId); + if (StringUtils.equals(UserConstants.YES, config.getConfigType())) + { + throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey())); + } + configMapper.deleteConfigById(configId); + redisCache.deleteObject(getCacheKey(config.getConfigKey())); } - return count; } /** - * 清空缓存数据 + * 加载参数缓存数据 */ @Override - public void clearCache() + public void loadingConfigCache() { - Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*"); + List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig()); + for (SysConfig config : configsList) + { + redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + } + } + + /** + * 清空参数缓存数据 + */ + @Override + public void clearConfigCache() + { + Collection<String> keys = redisCache.keys(CacheConstants.SYS_CONFIG_KEY + "*"); redisCache.deleteObject(keys); + } + + /** + * 重置参数缓存数据 + */ + @Override + public void resetConfigCache() + { + clearConfigCache(); + loadingConfigCache(); } /** @@ -183,6 +221,6 @@ */ private String getCacheKey(String configKey) { - return Constants.SYS_CONFIG_KEY + configKey; + return CacheConstants.SYS_CONFIG_KEY + configKey; } } -- Gitblit v1.9.2