ソースを参照

优化参数&字典缓存操作

RuoYi 4 年 前
コミット
67feb9947e

+ 6 - 5
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysConfigController.java

@@ -117,18 +117,19 @@ public class SysConfigController extends BaseController
117
     @DeleteMapping("/{configIds}")
117
     @DeleteMapping("/{configIds}")
118
     public AjaxResult remove(@PathVariable Long[] configIds)
118
     public AjaxResult remove(@PathVariable Long[] configIds)
119
     {
119
     {
120
-        return toAjax(configService.deleteConfigByIds(configIds));
120
+        configService.deleteConfigByIds(configIds);
121
+        return success();
121
     }
122
     }
122
 
123
 
123
     /**
124
     /**
124
-     * 清空缓存
125
+     * 刷新参数缓存
125
      */
126
      */
126
     @PreAuthorize(hasPermi = "system:config:remove")
127
     @PreAuthorize(hasPermi = "system:config:remove")
127
     @Log(title = "参数管理", businessType = BusinessType.CLEAN)
128
     @Log(title = "参数管理", businessType = BusinessType.CLEAN)
128
-    @DeleteMapping("/clearCache")
129
-    public AjaxResult clearCache()
129
+    @DeleteMapping("/refreshCache")
130
+    public AjaxResult refreshCache()
130
     {
131
     {
131
-        configService.clearCache();
132
+        configService.resetConfigCache();
132
         return AjaxResult.success();
133
         return AjaxResult.success();
133
     }
134
     }
134
 }
135
 }

+ 2 - 1
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDictDataController.java

@@ -117,6 +117,7 @@ public class SysDictDataController extends BaseController
117
     @DeleteMapping("/{dictCodes}")
117
     @DeleteMapping("/{dictCodes}")
118
     public AjaxResult remove(@PathVariable Long[] dictCodes)
118
     public AjaxResult remove(@PathVariable Long[] dictCodes)
119
     {
119
     {
120
-        return toAjax(dictDataService.deleteDictDataByIds(dictCodes));
120
+        dictDataService.deleteDictDataByIds(dictCodes);
121
+        return success();
121
     }
122
     }
122
 }
123
 }

+ 6 - 5
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDictTypeController.java

@@ -106,18 +106,19 @@ public class SysDictTypeController extends BaseController
106
     @DeleteMapping("/{dictIds}")
106
     @DeleteMapping("/{dictIds}")
107
     public AjaxResult remove(@PathVariable Long[] dictIds)
107
     public AjaxResult remove(@PathVariable Long[] dictIds)
108
     {
108
     {
109
-        return toAjax(dictTypeService.deleteDictTypeByIds(dictIds));
109
+        dictTypeService.deleteDictTypeByIds(dictIds);
110
+        return success();
110
     }
111
     }
111
 
112
 
112
     /**
113
     /**
113
-     * 清空缓存
114
+     * 刷新字典缓存
114
      */
115
      */
115
     @PreAuthorize(hasPermi = "system:dict:remove")
116
     @PreAuthorize(hasPermi = "system:dict:remove")
116
     @Log(title = "字典类型", businessType = BusinessType.CLEAN)
117
     @Log(title = "字典类型", businessType = BusinessType.CLEAN)
117
-    @DeleteMapping("/clearCache")
118
-    public AjaxResult clearCache()
118
+    @DeleteMapping("/refreshCache")
119
+    public AjaxResult refreshCache()
119
     {
120
     {
120
-        dictTypeService.clearCache();
121
+        dictTypeService.resetDictCache();
121
         return AjaxResult.success();
122
         return AjaxResult.success();
122
     }
123
     }
123
 
124
 

+ 13 - 3
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java

@@ -57,12 +57,22 @@ public interface ISysConfigService
57
      * @param configIds 需要删除的参数ID
57
      * @param configIds 需要删除的参数ID
58
      * @return 结果
58
      * @return 结果
59
      */
59
      */
60
-    public int deleteConfigByIds(Long[] configIds);
60
+    public void deleteConfigByIds(Long[] configIds);
61
 
61
 
62
     /**
62
     /**
63
-     * 清空缓存数据
63
+     * 加载参数缓存数据
64
      */
64
      */
65
-    public void clearCache();
65
+    public void loadingConfigCache();
66
+
67
+    /**
68
+     * 清空参数缓存数据
69
+     */
70
+    public void clearConfigCache();
71
+
72
+    /**
73
+     * 重置参数缓存数据
74
+     */
75
+    public void resetConfigCache();
66
 
76
 
67
     /**
77
     /**
68
      * 校验参数键名是否唯一
78
      * 校验参数键名是否唯一

+ 1 - 1
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java

@@ -41,7 +41,7 @@ public interface ISysDictDataService
41
      * @param dictCodes 需要删除的字典数据ID
41
      * @param dictCodes 需要删除的字典数据ID
42
      * @return 结果
42
      * @return 结果
43
      */
43
      */
44
-    public int deleteDictDataByIds(Long[] dictCodes);
44
+    public void deleteDictDataByIds(Long[] dictCodes);
45
 
45
 
46
     /**
46
     /**
47
      * 新增保存字典数据信息
47
      * 新增保存字典数据信息

+ 13 - 3
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java

@@ -56,12 +56,22 @@ public interface ISysDictTypeService
56
      * @param dictIds 需要删除的字典ID
56
      * @param dictIds 需要删除的字典ID
57
      * @return 结果
57
      * @return 结果
58
      */
58
      */
59
-    public int deleteDictTypeByIds(Long[] dictIds);
59
+    public void deleteDictTypeByIds(Long[] dictIds);
60
 
60
 
61
     /**
61
     /**
62
-     * 清空缓存数据
62
+     * 加载字典缓存数据
63
      */
63
      */
64
-    public void clearCache();
64
+    public void loadingDictCache();
65
+
66
+    /**
67
+     * 清空字典缓存数据
68
+     */
69
+    public void clearDictCache();
70
+
71
+    /**
72
+     * 重置字典缓存数据
73
+     */
74
+    public void resetDictCache();
65
 
75
 
66
     /**
76
     /**
67
      * 新增保存字典类型信息
77
      * 新增保存字典类型信息

+ 27 - 13
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java

@@ -35,11 +35,7 @@ public class SysConfigServiceImpl implements ISysConfigService
35
     @PostConstruct
35
     @PostConstruct
36
     public void init()
36
     public void init()
37
     {
37
     {
38
-        List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
39
-        for (SysConfig config : configsList)
40
-        {
41
-            redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
42
-        }
38
+        loadingConfigCache();
43
     }
39
     }
44
 
40
 
45
     /**
41
     /**
@@ -134,7 +130,7 @@ public class SysConfigServiceImpl implements ISysConfigService
134
      * @return 结果
130
      * @return 结果
135
      */
131
      */
136
     @Override
132
     @Override
137
-    public int deleteConfigByIds(Long[] configIds)
133
+    public void deleteConfigByIds(Long[] configIds)
138
     {
134
     {
139
         for (Long configId : configIds)
135
         for (Long configId : configIds)
140
         {
136
         {
@@ -143,27 +139,45 @@ public class SysConfigServiceImpl implements ISysConfigService
143
             {
139
             {
144
                 throw new CustomException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
140
                 throw new CustomException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
145
             }
141
             }
142
+            configMapper.deleteConfigById(configId);
143
+            redisService.deleteObject(getCacheKey(config.getConfigKey()));
146
         }
144
         }
147
-        int count = configMapper.deleteConfigByIds(configIds);
148
-        if (count > 0)
145
+    }
146
+
147
+    /**
148
+     * 加载参数缓存数据
149
+     */
150
+    @Override
151
+    public void loadingConfigCache()
152
+    {
153
+        List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
154
+        for (SysConfig config : configsList)
149
         {
155
         {
150
-            Collection<String> keys = redisService.keys(Constants.SYS_CONFIG_KEY + "*");
151
-            redisService.deleteObject(keys);
156
+            redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
152
         }
157
         }
153
-        return count;
154
     }
158
     }
155
 
159
 
156
     /**
160
     /**
157
-     * 清空缓存数据
161
+     * 清空参数缓存数据
158
      */
162
      */
159
     @Override
163
     @Override
160
-    public void clearCache()
164
+    public void clearConfigCache()
161
     {
165
     {
162
         Collection<String> keys = redisService.keys(Constants.SYS_CONFIG_KEY + "*");
166
         Collection<String> keys = redisService.keys(Constants.SYS_CONFIG_KEY + "*");
163
         redisService.deleteObject(keys);
167
         redisService.deleteObject(keys);
164
     }
168
     }
165
 
169
 
166
     /**
170
     /**
171
+     * 重置参数缓存数据
172
+     */
173
+    @Override
174
+    public void resetConfigCache()
175
+    {
176
+        clearConfigCache();
177
+        loadingConfigCache();
178
+    }
179
+
180
+    /**
167
      * 校验参数键名是否唯一
181
      * 校验参数键名是否唯一
168
      * 
182
      * 
169
      * @param config 参数配置信息
183
      * @param config 参数配置信息

+ 16 - 13
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java

@@ -63,29 +63,31 @@ public class SysDictDataServiceImpl implements ISysDictDataService
63
      * @return 结果
63
      * @return 结果
64
      */
64
      */
65
     @Override
65
     @Override
66
-    public int deleteDictDataByIds(Long[] dictCodes)
66
+    public void deleteDictDataByIds(Long[] dictCodes)
67
     {
67
     {
68
-        int row = dictDataMapper.deleteDictDataByIds(dictCodes);
69
-        if (row > 0)
68
+        for (Long dictCode : dictCodes)
70
         {
69
         {
71
-            DictUtils.clearDictCache();
70
+            SysDictData data = selectDictDataById(dictCode);
71
+            dictDataMapper.deleteDictDataById(dictCode);
72
+            List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
73
+            DictUtils.setDictCache(data.getDictType(), dictDatas);
72
         }
74
         }
73
-        return row;
74
     }
75
     }
75
 
76
 
76
     /**
77
     /**
77
      * 新增保存字典数据信息
78
      * 新增保存字典数据信息
78
      * 
79
      * 
79
-     * @param dictData 字典数据信息
80
+     * @param data 字典数据信息
80
      * @return 结果
81
      * @return 结果
81
      */
82
      */
82
     @Override
83
     @Override
83
-    public int insertDictData(SysDictData dictData)
84
+    public int insertDictData(SysDictData data)
84
     {
85
     {
85
-        int row = dictDataMapper.insertDictData(dictData);
86
+        int row = dictDataMapper.insertDictData(data);
86
         if (row > 0)
87
         if (row > 0)
87
         {
88
         {
88
-            DictUtils.clearDictCache();
89
+            List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
90
+            DictUtils.setDictCache(data.getDictType(), dictDatas);
89
         }
91
         }
90
         return row;
92
         return row;
91
     }
93
     }
@@ -93,16 +95,17 @@ public class SysDictDataServiceImpl implements ISysDictDataService
93
     /**
95
     /**
94
      * 修改保存字典数据信息
96
      * 修改保存字典数据信息
95
      * 
97
      * 
96
-     * @param dictData 字典数据信息
98
+     * @param data 字典数据信息
97
      * @return 结果
99
      * @return 结果
98
      */
100
      */
99
     @Override
101
     @Override
100
-    public int updateDictData(SysDictData dictData)
102
+    public int updateDictData(SysDictData data)
101
     {
103
     {
102
-        int row = dictDataMapper.updateDictData(dictData);
104
+        int row = dictDataMapper.updateDictData(data);
103
         if (row > 0)
105
         if (row > 0)
104
         {
106
         {
105
-            DictUtils.clearDictCache();
107
+            List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
108
+            DictUtils.setDictCache(data.getDictType(), dictDatas);
106
         }
109
         }
107
         return row;
110
         return row;
108
     }
111
     }

+ 37 - 24
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java

@@ -35,12 +35,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
35
     @PostConstruct
35
     @PostConstruct
36
     public void init()
36
     public void init()
37
     {
37
     {
38
-        List<SysDictType> dictTypeList = dictTypeMapper.selectDictTypeAll();
39
-        for (SysDictType dictType : dictTypeList)
40
-        {
41
-            List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType());
42
-            DictUtils.setDictCache(dictType.getDictType(), dictDatas);
43
-        }
38
+        loadingDictCache();
44
     }
39
     }
45
 
40
 
46
     /**
41
     /**
@@ -120,7 +115,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
120
      * @return 结果
115
      * @return 结果
121
      */
116
      */
122
     @Override
117
     @Override
123
-    public int deleteDictTypeByIds(Long[] dictIds)
118
+    public void deleteDictTypeByIds(Long[] dictIds)
124
     {
119
     {
125
         for (Long dictId : dictIds)
120
         for (Long dictId : dictIds)
126
         {
121
         {
@@ -129,37 +124,54 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
129
             {
124
             {
130
                 throw new CustomException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
125
                 throw new CustomException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
131
             }
126
             }
127
+            dictTypeMapper.deleteDictTypeById(dictId);
128
+            DictUtils.removeDictCache(dictType.getDictType());
132
         }
129
         }
133
-        int count = dictTypeMapper.deleteDictTypeByIds(dictIds);
134
-        if (count > 0)
130
+    }
131
+
132
+    /**
133
+     * 加载字典缓存数据
134
+     */
135
+    public void loadingDictCache()
136
+    {
137
+        List<SysDictType> dictTypeList = dictTypeMapper.selectDictTypeAll();
138
+        for (SysDictType dictType : dictTypeList)
135
         {
139
         {
136
-            DictUtils.clearDictCache();
140
+            List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType());
141
+            DictUtils.setDictCache(dictType.getDictType(), dictDatas);
137
         }
142
         }
138
-        return count;
139
     }
143
     }
140
 
144
 
141
     /**
145
     /**
142
-     * 清空缓存数据
146
+     * 清空字典缓存数据
143
      */
147
      */
144
-    @Override
145
-    public void clearCache()
148
+    public void clearDictCache()
146
     {
149
     {
147
         DictUtils.clearDictCache();
150
         DictUtils.clearDictCache();
148
     }
151
     }
149
 
152
 
150
     /**
153
     /**
154
+     * 重置字典缓存数据
155
+     */
156
+    public void resetDictCache()
157
+    {
158
+        clearDictCache();
159
+        loadingDictCache();
160
+    }
161
+
162
+    /**
151
      * 新增保存字典类型信息
163
      * 新增保存字典类型信息
152
      * 
164
      * 
153
-     * @param dictType 字典类型信息
165
+     * @param dict 字典类型信息
154
      * @return 结果
166
      * @return 结果
155
      */
167
      */
156
     @Override
168
     @Override
157
-    public int insertDictType(SysDictType dictType)
169
+    public int insertDictType(SysDictType dict)
158
     {
170
     {
159
-        int row = dictTypeMapper.insertDictType(dictType);
171
+        int row = dictTypeMapper.insertDictType(dict);
160
         if (row > 0)
172
         if (row > 0)
161
         {
173
         {
162
-            DictUtils.clearDictCache();
174
+            DictUtils.setDictCache(dict.getDictType(), null);
163
         }
175
         }
164
         return row;
176
         return row;
165
     }
177
     }
@@ -167,19 +179,20 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
167
     /**
179
     /**
168
      * 修改保存字典类型信息
180
      * 修改保存字典类型信息
169
      * 
181
      * 
170
-     * @param dictType 字典类型信息
182
+     * @param dict 字典类型信息
171
      * @return 结果
183
      * @return 结果
172
      */
184
      */
173
     @Override
185
     @Override
174
     @Transactional
186
     @Transactional
175
-    public int updateDictType(SysDictType dictType)
187
+    public int updateDictType(SysDictType dict)
176
     {
188
     {
177
-        SysDictType oldDict = dictTypeMapper.selectDictTypeById(dictType.getDictId());
178
-        dictDataMapper.updateDictDataType(oldDict.getDictType(), dictType.getDictType());
179
-        int row = dictTypeMapper.updateDictType(dictType);
189
+        SysDictType oldDict = dictTypeMapper.selectDictTypeById(dict.getDictId());
190
+        dictDataMapper.updateDictDataType(oldDict.getDictType(), dict.getDictType());
191
+        int row = dictTypeMapper.updateDictType(dict);
180
         if (row > 0)
192
         if (row > 0)
181
         {
193
         {
182
-            DictUtils.clearDictCache();
194
+            List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType());
195
+            DictUtils.setDictCache(dict.getDictType(), dictDatas);
183
         }
196
         }
184
         return row;
197
         return row;
185
     }
198
     }

+ 10 - 0
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/utils/DictUtils.java

@@ -44,6 +44,16 @@ public class DictUtils
44
     }
44
     }
45
 
45
 
46
     /**
46
     /**
47
+     * 删除指定字典缓存
48
+     * 
49
+     * @param key 字典键
50
+     */
51
+    public static void removeDictCache(String key)
52
+    {
53
+        SpringUtils.getBean(RedisService.class).deleteObject(getCacheKey(key));
54
+    }
55
+
56
+    /**
47
      * 清空字典缓存
57
      * 清空字典缓存
48
      */
58
      */
49
     public static void clearDictCache()
59
     public static void clearDictCache()

+ 3 - 3
ruoyi-ui/src/api/system/config.js

@@ -51,10 +51,10 @@ export function delConfig(configId) {
51
   })
51
   })
52
 }
52
 }
53
 
53
 
54
-// 清理参数缓存
55
-export function clearCache() {
54
+// 刷新参数缓存
55
+export function refreshCache() {
56
   return request({
56
   return request({
57
-    url: '/system/config/clearCache',
57
+    url: '/system/config/refreshCache',
58
     method: 'delete'
58
     method: 'delete'
59
   })
59
   })
60
 }
60
 }

+ 3 - 3
ruoyi-ui/src/api/system/dict/type.js

@@ -43,10 +43,10 @@ export function delType(dictId) {
43
   })
43
   })
44
 }
44
 }
45
 
45
 
46
-// 清理参数缓存
47
-export function clearCache() {
46
+// 刷新字典缓存
47
+export function refreshCache() {
48
   return request({
48
   return request({
49
-    url: '/system/dict/type/clearCache',
49
+    url: '/system/dict/type/refreshCache',
50
     method: 'delete'
50
     method: 'delete'
51
   })
51
   })
52
 }
52
 }

+ 7 - 7
ruoyi-ui/src/views/system/config/index.vue

@@ -98,9 +98,9 @@
98
           plain
98
           plain
99
           icon="el-icon-refresh"
99
           icon="el-icon-refresh"
100
           size="mini"
100
           size="mini"
101
-          @click="handleClearCache"
101
+          @click="handleRefreshCache"
102
           v-hasPermi="['system:config:remove']"
102
           v-hasPermi="['system:config:remove']"
103
-        >清理缓存</el-button>
103
+        >刷新缓存</el-button>
104
       </el-col>
104
       </el-col>
105
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
105
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
106
     </el-row>
106
     </el-row>
@@ -180,7 +180,7 @@
180
 </template>
180
 </template>
181
 
181
 
182
 <script>
182
 <script>
183
-import { listConfig, getConfig, delConfig, addConfig, updateConfig, clearCache } from "@/api/system/config";
183
+import { listConfig, getConfig, delConfig, addConfig, updateConfig, refreshCache } from "@/api/system/config";
184
 
184
 
185
 export default {
185
 export default {
186
   name: "Config",
186
   name: "Config",
@@ -343,10 +343,10 @@ export default {
343
         ...this.queryParams
343
         ...this.queryParams
344
       }, `config_${new Date().getTime()}.xlsx`)
344
       }, `config_${new Date().getTime()}.xlsx`)
345
     },
345
     },
346
-    /** 清理缓存按钮操作 */
347
-    handleClearCache() {
348
-      clearCache().then(response => {
349
-        this.msgSuccess("清理成功");
346
+    /** 刷新缓存按钮操作 */
347
+    handleRefreshCache() {
348
+      refreshCache().then(() => {
349
+        this.msgSuccess("刷新成功");
350
       });
350
       });
351
     }
351
     }
352
   }
352
   }

+ 7 - 7
ruoyi-ui/src/views/system/dict/index.vue

@@ -104,9 +104,9 @@
104
           plain
104
           plain
105
           icon="el-icon-refresh"
105
           icon="el-icon-refresh"
106
           size="mini"
106
           size="mini"
107
-          @click="handleClearCache"
107
+          @click="handleRefreshCache"
108
           v-hasPermi="['system:dict:remove']"
108
           v-hasPermi="['system:dict:remove']"
109
-        >清理缓存</el-button>
109
+        >刷新缓存</el-button>
110
       </el-col>
110
       </el-col>
111
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
111
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
112
     </el-row>
112
     </el-row>
@@ -188,7 +188,7 @@
188
 </template>
188
 </template>
189
 
189
 
190
 <script>
190
 <script>
191
-import { listType, getType, delType, addType, updateType, clearCache } from "@/api/system/dict/type";
191
+import { listType, getType, delType, addType, updateType, refreshCache } from "@/api/system/dict/type";
192
 
192
 
193
 export default {
193
 export default {
194
   name: "Dict",
194
   name: "Dict",
@@ -347,10 +347,10 @@ export default {
347
         ...this.queryParams
347
         ...this.queryParams
348
       }, `type_${new Date().getTime()}.xlsx`)
348
       }, `type_${new Date().getTime()}.xlsx`)
349
     },
349
     },
350
-    /** 清理缓存按钮操作 */
351
-    handleClearCache() {
352
-      clearCache().then(response => {
353
-        this.msgSuccess("清理成功");
350
+    /** 刷新缓存按钮操作 */
351
+    handleRefreshCache() {
352
+      refreshCache().then(() => {
353
+        this.msgSuccess("刷新成功");
354
       });
354
       });
355
     }
355
     }
356
   }
356
   }