作者 RuoYi

优化参数&字典缓存操作

@@ -118,18 +118,19 @@ public class SysConfigController extends BaseController @@ -118,18 +118,19 @@ public class SysConfigController extends BaseController
118 @DeleteMapping("/{configIds}") 118 @DeleteMapping("/{configIds}")
119 public AjaxResult remove(@PathVariable Long[] configIds) 119 public AjaxResult remove(@PathVariable Long[] configIds)
120 { 120 {
121 - return toAjax(configService.deleteConfigByIds(configIds)); 121 + configService.deleteConfigByIds(configIds);
  122 + return success();
122 } 123 }
123 124
124 /** 125 /**
125 - * 清空缓存 126 + * 刷新参数缓存
126 */ 127 */
127 @PreAuthorize("@ss.hasPermi('system:config:remove')") 128 @PreAuthorize("@ss.hasPermi('system:config:remove')")
128 @Log(title = "参数管理", businessType = BusinessType.CLEAN) 129 @Log(title = "参数管理", businessType = BusinessType.CLEAN)
129 - @DeleteMapping("/clearCache")  
130 - public AjaxResult clearCache() 130 + @DeleteMapping("/refreshCache")
  131 + public AjaxResult refreshCache()
131 { 132 {
132 - configService.clearCache(); 133 + configService.resetConfigCache();
133 return AjaxResult.success(); 134 return AjaxResult.success();
134 } 135 }
135 } 136 }
@@ -115,6 +115,7 @@ public class SysDictDataController extends BaseController @@ -115,6 +115,7 @@ public class SysDictDataController extends BaseController
115 @DeleteMapping("/{dictCodes}") 115 @DeleteMapping("/{dictCodes}")
116 public AjaxResult remove(@PathVariable Long[] dictCodes) 116 public AjaxResult remove(@PathVariable Long[] dictCodes)
117 { 117 {
118 - return toAjax(dictDataService.deleteDictDataByIds(dictCodes)); 118 + dictDataService.deleteDictDataByIds(dictCodes);
  119 + return success();
119 } 120 }
120 } 121 }
@@ -104,18 +104,19 @@ public class SysDictTypeController extends BaseController @@ -104,18 +104,19 @@ public class SysDictTypeController extends BaseController
104 @DeleteMapping("/{dictIds}") 104 @DeleteMapping("/{dictIds}")
105 public AjaxResult remove(@PathVariable Long[] dictIds) 105 public AjaxResult remove(@PathVariable Long[] dictIds)
106 { 106 {
107 - return toAjax(dictTypeService.deleteDictTypeByIds(dictIds)); 107 + dictTypeService.deleteDictTypeByIds(dictIds);
  108 + return success();
108 } 109 }
109 110
110 /** 111 /**
111 - * 清空缓存 112 + * 刷新字典缓存
112 */ 113 */
113 @PreAuthorize("@ss.hasPermi('system:dict:remove')") 114 @PreAuthorize("@ss.hasPermi('system:dict:remove')")
114 @Log(title = "字典类型", businessType = BusinessType.CLEAN) 115 @Log(title = "字典类型", businessType = BusinessType.CLEAN)
115 - @DeleteMapping("/clearCache")  
116 - public AjaxResult clearCache() 116 + @DeleteMapping("/refreshCache")
  117 + public AjaxResult refreshCache()
117 { 118 {
118 - dictTypeService.clearCache(); 119 + dictTypeService.resetDictCache();
119 return AjaxResult.success(); 120 return AjaxResult.success();
120 } 121 }
121 122
@@ -152,6 +152,16 @@ public class DictUtils @@ -152,6 +152,16 @@ public class DictUtils
152 } 152 }
153 153
154 /** 154 /**
  155 + * 删除指定字典缓存
  156 + *
  157 + * @param key 字典键
  158 + */
  159 + public static void removeDictCache(String key)
  160 + {
  161 + SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key));
  162 + }
  163 +
  164 + /**
155 * 清空字典缓存 165 * 清空字典缓存
156 */ 166 */
157 public static void clearDictCache() 167 public static void clearDictCache()
@@ -56,12 +56,22 @@ public interface ISysConfigService @@ -56,12 +56,22 @@ public interface ISysConfigService
56 * @param configIds 需要删除的参数ID 56 * @param configIds 需要删除的参数ID
57 * @return 结果 57 * @return 结果
58 */ 58 */
59 - public int deleteConfigByIds(Long[] configIds); 59 + public void deleteConfigByIds(Long[] configIds);
60 60
61 /** 61 /**
62 - * 清空缓存数据 62 + * 加载参数缓存数据
63 */ 63 */
64 - public void clearCache(); 64 + public void loadingConfigCache();
  65 +
  66 + /**
  67 + * 清空参数缓存数据
  68 + */
  69 + public void clearConfigCache();
  70 +
  71 + /**
  72 + * 重置参数缓存数据
  73 + */
  74 + public void resetConfigCache();
65 75
66 /** 76 /**
67 * 校验参数键名是否唯一 77 * 校验参数键名是否唯一
@@ -41,7 +41,7 @@ public interface ISysDictDataService @@ -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 * 新增保存字典数据信息
@@ -56,12 +56,22 @@ public interface ISysDictTypeService @@ -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 * 新增保存字典类型信息
@@ -37,11 +37,7 @@ public class SysConfigServiceImpl implements ISysConfigService @@ -37,11 +37,7 @@ public class SysConfigServiceImpl implements ISysConfigService
37 @PostConstruct 37 @PostConstruct
38 public void init() 38 public void init()
39 { 39 {
40 - List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());  
41 - for (SysConfig config : configsList)  
42 - {  
43 - redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());  
44 - } 40 + loadingConfigCache();
45 } 41 }
46 42
47 /** 43 /**
@@ -137,7 +133,7 @@ public class SysConfigServiceImpl implements ISysConfigService @@ -137,7 +133,7 @@ public class SysConfigServiceImpl implements ISysConfigService
137 * @return 结果 133 * @return 结果
138 */ 134 */
139 @Override 135 @Override
140 - public int deleteConfigByIds(Long[] configIds) 136 + public void deleteConfigByIds(Long[] configIds)
141 { 137 {
142 for (Long configId : configIds) 138 for (Long configId : configIds)
143 { 139 {
@@ -146,27 +142,45 @@ public class SysConfigServiceImpl implements ISysConfigService @@ -146,27 +142,45 @@ public class SysConfigServiceImpl implements ISysConfigService
146 { 142 {
147 throw new CustomException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey())); 143 throw new CustomException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
148 } 144 }
  145 + configMapper.deleteConfigById(configId);
  146 + redisCache.deleteObject(getCacheKey(config.getConfigKey()));
  147 + }
149 } 148 }
150 - int count = configMapper.deleteConfigByIds(configIds);  
151 - if (count > 0) 149 +
  150 + /**
  151 + * 加载参数缓存数据
  152 + */
  153 + @Override
  154 + public void loadingConfigCache()
152 { 155 {
153 - Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");  
154 - redisCache.deleteObject(keys); 156 + List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
  157 + for (SysConfig config : configsList)
  158 + {
  159 + redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
155 } 160 }
156 - return count;  
157 } 161 }
158 162
159 /** 163 /**
160 - * 清空缓存数据 164 + * 清空参数缓存数据
161 */ 165 */
162 @Override 166 @Override
163 - public void clearCache() 167 + public void clearConfigCache()
164 { 168 {
165 Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*"); 169 Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
166 redisCache.deleteObject(keys); 170 redisCache.deleteObject(keys);
167 } 171 }
168 172
169 /** 173 /**
  174 + * 重置参数缓存数据
  175 + */
  176 + @Override
  177 + public void resetConfigCache()
  178 + {
  179 + clearConfigCache();
  180 + loadingConfigCache();
  181 + }
  182 +
  183 + /**
170 * 校验参数键名是否唯一 184 * 校验参数键名是否唯一
171 * 185 *
172 * @param config 参数配置信息 186 * @param config 参数配置信息
@@ -63,29 +63,31 @@ public class SysDictDataServiceImpl implements ISysDictDataService @@ -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,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 }
@@ -35,12 +35,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService @@ -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,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,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());
  129 + }
132 } 130 }
133 - int count = dictTypeMapper.deleteDictTypeByIds(dictIds);  
134 - if (count > 0) 131 +
  132 + /**
  133 + * 加载字典缓存数据
  134 + */
  135 + public void loadingDictCache()
135 { 136 {
136 - DictUtils.clearDictCache(); 137 + List<SysDictType> dictTypeList = dictTypeMapper.selectDictTypeAll();
  138 + for (SysDictType dictType : dictTypeList)
  139 + {
  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,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 }
@@ -51,10 +51,10 @@ export function delConfig(configId) { @@ -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 }
@@ -43,10 +43,10 @@ export function delType(dictId) { @@ -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 }
@@ -99,9 +99,9 @@ @@ -99,9 +99,9 @@
99 plain 99 plain
100 icon="el-icon-refresh" 100 icon="el-icon-refresh"
101 size="mini" 101 size="mini"
102 - @click="handleClearCache" 102 + @click="handleRefreshCache"
103 v-hasPermi="['system:config:remove']" 103 v-hasPermi="['system:config:remove']"
104 - >清理缓存</el-button> 104 + >刷新缓存</el-button>
105 </el-col> 105 </el-col>
106 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> 106 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
107 </el-row> 107 </el-row>
@@ -181,7 +181,7 @@ @@ -181,7 +181,7 @@
181 </template> 181 </template>
182 182
183 <script> 183 <script>
184 -import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig, clearCache } from "@/api/system/config"; 184 +import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig, refreshCache } from "@/api/system/config";
185 185
186 export default { 186 export default {
187 name: "Config", 187 name: "Config",
@@ -355,10 +355,10 @@ export default { @@ -355,10 +355,10 @@ export default {
355 this.exportLoading = false; 355 this.exportLoading = false;
356 }) 356 })
357 }, 357 },
358 - /** 清理缓存按钮操作 */  
359 - handleClearCache() {  
360 - clearCache().then(response => {  
361 - this.msgSuccess("清理成功"); 358 + /** 刷新缓存按钮操作 */
  359 + handleRefreshCache() {
  360 + refreshCache().then(() => {
  361 + this.msgSuccess("刷新成功");
362 }); 362 });
363 } 363 }
364 } 364 }
@@ -105,9 +105,9 @@ @@ -105,9 +105,9 @@
105 plain 105 plain
106 icon="el-icon-refresh" 106 icon="el-icon-refresh"
107 size="mini" 107 size="mini"
108 - @click="handleClearCache" 108 + @click="handleRefreshCache"
109 v-hasPermi="['system:dict:remove']" 109 v-hasPermi="['system:dict:remove']"
110 - >清理缓存</el-button> 110 + >刷新缓存</el-button>
111 </el-col> 111 </el-col>
112 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> 112 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
113 </el-row> 113 </el-row>
@@ -189,7 +189,7 @@ @@ -189,7 +189,7 @@
189 </template> 189 </template>
190 190
191 <script> 191 <script>
192 -import { listType, getType, delType, addType, updateType, exportType, clearCache } from "@/api/system/dict/type"; 192 +import { listType, getType, delType, addType, updateType, exportType, refreshCache } from "@/api/system/dict/type";
193 193
194 export default { 194 export default {
195 name: "Dict", 195 name: "Dict",
@@ -359,10 +359,10 @@ export default { @@ -359,10 +359,10 @@ export default {
359 this.exportLoading = false; 359 this.exportLoading = false;
360 }) 360 })
361 }, 361 },
362 - /** 清理缓存按钮操作 */  
363 - handleClearCache() {  
364 - clearCache().then(response => {  
365 - this.msgSuccess("清理成功"); 362 + /** 刷新缓存按钮操作 */
  363 + handleRefreshCache() {
  364 + refreshCache().then(() => {
  365 + this.msgSuccess("刷新成功");
366 }); 366 });
367 } 367 }
368 } 368 }