From ed19109e80a10fd4def53bae13a59f8a917c8fa1 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: 星期三, 28 九月 2022 16:49:21 +0800
Subject: [PATCH] 导入更新用户数据前校验数据权限

---
 src/main/java/com/ruoyi/project/system/service/impl/SysConfigServiceImpl.java |   71 +++++++++++++++++++++++++----------
 1 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/ruoyi/project/system/service/impl/SysConfigServiceImpl.java b/src/main/java/com/ruoyi/project/system/service/impl/SysConfigServiceImpl.java
index 1ee1de6..2c217d2 100644
--- a/src/main/java/com/ruoyi/project/system/service/impl/SysConfigServiceImpl.java
+++ b/src/main/java/com/ruoyi/project/system/service/impl/SysConfigServiceImpl.java
@@ -5,10 +5,10 @@
 import javax.annotation.PostConstruct;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.constant.CacheConstants;
 import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.text.Convert;
-import com.ruoyi.common.exception.CustomException;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.framework.redis.RedisCache;
 import com.ruoyi.project.system.domain.SysConfig;
@@ -35,11 +35,7 @@
     @PostConstruct
     public void init()
     {
-        List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
-        for (SysConfig config : configsList)
-        {
-            redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
-        }
+        loadingConfigCache();
     }
 
     /**
@@ -79,6 +75,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);
     }
 
     /**
@@ -131,36 +143,53 @@
      * 鎵归噺鍒犻櫎鍙傛暟淇℃伅
      * 
      * @param configIds 闇�瑕佸垹闄ょ殑鍙傛暟ID
-     * @return 缁撴灉
      */
     @Override
-    public int deleteConfigByIds(Long[] configIds)
+    public void deleteConfigByIds(Long[] configIds)
     {
         for (Long configId : configIds)
         {
             SysConfig config = selectConfigById(configId);
             if (StringUtils.equals(UserConstants.YES, config.getConfigType()))
             {
-                throw new CustomException(String.format("鍐呯疆鍙傛暟銆�%1$s銆戜笉鑳藉垹闄� ", config.getConfigKey()));
+                throw new ServiceException(String.format("鍐呯疆鍙傛暟銆�%1$s銆戜笉鑳藉垹闄� ", config.getConfigKey()));
             }
+            configMapper.deleteConfigById(configId);
+            redisCache.deleteObject(getCacheKey(config.getConfigKey()));
         }
-        int count = configMapper.deleteConfigByIds(configIds);
-        if (count > 0)
-        {
-            Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
-            redisCache.deleteObject(keys);
-        }
-        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();
     }
 
     /**
@@ -189,6 +218,6 @@
      */
     private String getCacheKey(String configKey)
     {
-        return Constants.SYS_CONFIG_KEY + configKey;
+        return CacheConstants.SYS_CONFIG_KEY + configKey;
     }
 }

--
Gitblit v1.9.3