From af9cfb40a4c37579f21624c9f72ea4d9759095ff Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 27 May 2021 17:38:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=82=E6=95=B0&=E5=AD=97?= =?UTF-8?q?=E5=85=B8=E7=BC=93=E5=AD=98=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/SysConfigController.java | 11 ++-- .../system/SysDictDataController.java | 3 +- .../system/SysDictTypeController.java | 11 ++-- .../com/ruoyi/common/utils/DictUtils.java | 10 +++ .../system/service/ISysConfigService.java | 16 ++++- .../system/service/ISysDictDataService.java | 2 +- .../system/service/ISysDictTypeService.java | 16 ++++- .../service/impl/SysConfigServiceImpl.java | 44 ++++++++----- .../service/impl/SysDictDataServiceImpl.java | 29 +++++---- .../service/impl/SysDictTypeServiceImpl.java | 65 +++++++++++-------- ruoyi-ui/src/api/system/config.js | 6 +- ruoyi-ui/src/api/system/dict/type.js | 6 +- ruoyi-ui/src/views/system/config/index.vue | 14 ++-- ruoyi-ui/src/views/system/dict/index.vue | 14 ++-- 14 files changed, 155 insertions(+), 92 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java index 41b8209..8678fd6 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java @@ -118,18 +118,19 @@ public class SysConfigController extends BaseController @DeleteMapping("/{configIds}") public AjaxResult remove(@PathVariable Long[] configIds) { - return toAjax(configService.deleteConfigByIds(configIds)); + configService.deleteConfigByIds(configIds); + return success(); } /** - * 清空缓存 + * 刷新参数缓存 */ @PreAuthorize("@ss.hasPermi('system:config:remove')") @Log(title = "参数管理", businessType = BusinessType.CLEAN) - @DeleteMapping("/clearCache") - public AjaxResult clearCache() + @DeleteMapping("/refreshCache") + public AjaxResult refreshCache() { - configService.clearCache(); + configService.resetConfigCache(); return AjaxResult.success(); } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java index 8d0e870..c044d25 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java @@ -115,6 +115,7 @@ public class SysDictDataController extends BaseController @DeleteMapping("/{dictCodes}") public AjaxResult remove(@PathVariable Long[] dictCodes) { - return toAjax(dictDataService.deleteDictDataByIds(dictCodes)); + dictDataService.deleteDictDataByIds(dictCodes); + return success(); } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java index efde2d4..3185f41 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java @@ -104,18 +104,19 @@ public class SysDictTypeController extends BaseController @DeleteMapping("/{dictIds}") public AjaxResult remove(@PathVariable Long[] dictIds) { - return toAjax(dictTypeService.deleteDictTypeByIds(dictIds)); + dictTypeService.deleteDictTypeByIds(dictIds); + return success(); } /** - * 清空缓存 + * 刷新字典缓存 */ @PreAuthorize("@ss.hasPermi('system:dict:remove')") @Log(title = "字典类型", businessType = BusinessType.CLEAN) - @DeleteMapping("/clearCache") - public AjaxResult clearCache() + @DeleteMapping("/refreshCache") + public AjaxResult refreshCache() { - dictTypeService.clearCache(); + dictTypeService.resetDictCache(); return AjaxResult.success(); } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java index 0d3a23d..16e7fca 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java @@ -151,6 +151,16 @@ public class DictUtils return StringUtils.stripEnd(propertyString.toString(), separator); } + /** + * 删除指定字典缓存 + * + * @param key 字典键 + */ + public static void removeDictCache(String key) + { + SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key)); + } + /** * 清空字典缓存 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java index a937e83..6b6842f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java @@ -56,12 +56,22 @@ public interface ISysConfigService * @param configIds 需要删除的参数ID * @return 结果 */ - public int deleteConfigByIds(Long[] configIds); + public void deleteConfigByIds(Long[] configIds); /** - * 清空缓存数据 + * 加载参数缓存数据 */ - public void clearCache(); + public void loadingConfigCache(); + + /** + * 清空参数缓存数据 + */ + public void clearConfigCache(); + + /** + * 重置参数缓存数据 + */ + public void resetConfigCache(); /** * 校验参数键名是否唯一 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java index 5fe8956..63664cd 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java @@ -41,7 +41,7 @@ public interface ISysDictDataService * @param dictCodes 需要删除的字典数据ID * @return 结果 */ - public int deleteDictDataByIds(Long[] dictCodes); + public void deleteDictDataByIds(Long[] dictCodes); /** * 新增保存字典数据信息 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java index 3603d89..bbc0658 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java @@ -56,12 +56,22 @@ public interface ISysDictTypeService * @param dictIds 需要删除的字典ID * @return 结果 */ - public int deleteDictTypeByIds(Long[] dictIds); + public void deleteDictTypeByIds(Long[] dictIds); /** - * 清空缓存数据 + * 加载字典缓存数据 */ - public void clearCache(); + public void loadingDictCache(); + + /** + * 清空字典缓存数据 + */ + public void clearDictCache(); + + /** + * 重置字典缓存数据 + */ + public void resetDictCache(); /** * 新增保存字典类型信息 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 f1e2f29..41ef261 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 @@ -37,11 +37,7 @@ public class SysConfigServiceImpl implements ISysConfigService @PostConstruct public void init() { - List configsList = configMapper.selectConfigList(new SysConfig()); - for (SysConfig config : configsList) - { - redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); - } + loadingConfigCache(); } /** @@ -137,7 +133,7 @@ public class SysConfigServiceImpl implements ISysConfigService * @return 结果 */ @Override - public int deleteConfigByIds(Long[] configIds) + public void deleteConfigByIds(Long[] configIds) { for (Long configId : configIds) { @@ -146,26 +142,44 @@ public class SysConfigServiceImpl implements ISysConfigService { throw new CustomException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey())); } + configMapper.deleteConfigById(configId); + redisCache.deleteObject(getCacheKey(config.getConfigKey())); } - int count = configMapper.deleteConfigByIds(configIds); - if (count > 0) - { - Collection keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*"); - redisCache.deleteObject(keys); - } - return count; } /** - * 清空缓存数据 + * 加载参数缓存数据 */ @Override - public void clearCache() + public void loadingConfigCache() + { + List configsList = configMapper.selectConfigList(new SysConfig()); + for (SysConfig config : configsList) + { + redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + } + } + + /** + * 清空参数缓存数据 + */ + @Override + public void clearConfigCache() { Collection keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*"); redisCache.deleteObject(keys); } + /** + * 重置参数缓存数据 + */ + @Override + public void resetConfigCache() + { + clearConfigCache(); + loadingConfigCache(); + } + /** * 校验参数键名是否唯一 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java index 39d9505..5500f73 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java @@ -63,29 +63,31 @@ public class SysDictDataServiceImpl implements ISysDictDataService * @return 结果 */ @Override - public int deleteDictDataByIds(Long[] dictCodes) + public void deleteDictDataByIds(Long[] dictCodes) { - int row = dictDataMapper.deleteDictDataByIds(dictCodes); - if (row > 0) + for (Long dictCode : dictCodes) { - DictUtils.clearDictCache(); + SysDictData data = selectDictDataById(dictCode); + dictDataMapper.deleteDictDataById(dictCode); + List dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); + DictUtils.setDictCache(data.getDictType(), dictDatas); } - return row; } /** * 新增保存字典数据信息 * - * @param dictData 字典数据信息 + * @param data 字典数据信息 * @return 结果 */ @Override - public int insertDictData(SysDictData dictData) + public int insertDictData(SysDictData data) { - int row = dictDataMapper.insertDictData(dictData); + int row = dictDataMapper.insertDictData(data); if (row > 0) { - DictUtils.clearDictCache(); + List dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); + DictUtils.setDictCache(data.getDictType(), dictDatas); } return row; } @@ -93,16 +95,17 @@ public class SysDictDataServiceImpl implements ISysDictDataService /** * 修改保存字典数据信息 * - * @param dictData 字典数据信息 + * @param data 字典数据信息 * @return 结果 */ @Override - public int updateDictData(SysDictData dictData) + public int updateDictData(SysDictData data) { - int row = dictDataMapper.updateDictData(dictData); + int row = dictDataMapper.updateDictData(data); if (row > 0) { - DictUtils.clearDictCache(); + List dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); + DictUtils.setDictCache(data.getDictType(), dictDatas); } return row; } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java index 2db4341..d2daae4 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java @@ -35,12 +35,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService @PostConstruct public void init() { - List dictTypeList = dictTypeMapper.selectDictTypeAll(); - for (SysDictType dictType : dictTypeList) - { - List dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType()); - DictUtils.setDictCache(dictType.getDictType(), dictDatas); - } + loadingDictCache(); } /** @@ -120,7 +115,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService * @return 结果 */ @Override - public int deleteDictTypeByIds(Long[] dictIds) + public void deleteDictTypeByIds(Long[] dictIds) { for (Long dictId : dictIds) { @@ -129,37 +124,54 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService { throw new CustomException(String.format("%1$s已分配,不能删除", dictType.getDictName())); } + dictTypeMapper.deleteDictTypeById(dictId); + DictUtils.removeDictCache(dictType.getDictType()); } - int count = dictTypeMapper.deleteDictTypeByIds(dictIds); - if (count > 0) - { - DictUtils.clearDictCache(); - } - return count; } /** - * 清空缓存数据 + * 加载字典缓存数据 */ - @Override - public void clearCache() + public void loadingDictCache() + { + List dictTypeList = dictTypeMapper.selectDictTypeAll(); + for (SysDictType dictType : dictTypeList) + { + List dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType()); + DictUtils.setDictCache(dictType.getDictType(), dictDatas); + } + } + + /** + * 清空字典缓存数据 + */ + public void clearDictCache() { DictUtils.clearDictCache(); } + /** + * 重置字典缓存数据 + */ + public void resetDictCache() + { + clearDictCache(); + loadingDictCache(); + } + /** * 新增保存字典类型信息 * - * @param dictType 字典类型信息 + * @param dict 字典类型信息 * @return 结果 */ @Override - public int insertDictType(SysDictType dictType) + public int insertDictType(SysDictType dict) { - int row = dictTypeMapper.insertDictType(dictType); + int row = dictTypeMapper.insertDictType(dict); if (row > 0) { - DictUtils.clearDictCache(); + DictUtils.setDictCache(dict.getDictType(), null); } return row; } @@ -167,19 +179,20 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService /** * 修改保存字典类型信息 * - * @param dictType 字典类型信息 + * @param dict 字典类型信息 * @return 结果 */ @Override @Transactional - public int updateDictType(SysDictType dictType) + public int updateDictType(SysDictType dict) { - SysDictType oldDict = dictTypeMapper.selectDictTypeById(dictType.getDictId()); - dictDataMapper.updateDictDataType(oldDict.getDictType(), dictType.getDictType()); - int row = dictTypeMapper.updateDictType(dictType); + SysDictType oldDict = dictTypeMapper.selectDictTypeById(dict.getDictId()); + dictDataMapper.updateDictDataType(oldDict.getDictType(), dict.getDictType()); + int row = dictTypeMapper.updateDictType(dict); if (row > 0) { - DictUtils.clearDictCache(); + List dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType()); + DictUtils.setDictCache(dict.getDictType(), dictDatas); } return row; } diff --git a/ruoyi-ui/src/api/system/config.js b/ruoyi-ui/src/api/system/config.js index 2221540..f1f8727 100644 --- a/ruoyi-ui/src/api/system/config.js +++ b/ruoyi-ui/src/api/system/config.js @@ -51,10 +51,10 @@ export function delConfig(configId) { }) } -// 清理参数缓存 -export function clearCache() { +// 刷新参数缓存 +export function refreshCache() { return request({ - url: '/system/config/clearCache', + url: '/system/config/refreshCache', method: 'delete' }) } diff --git a/ruoyi-ui/src/api/system/dict/type.js b/ruoyi-ui/src/api/system/dict/type.js index d392f50..2c66bd5 100644 --- a/ruoyi-ui/src/api/system/dict/type.js +++ b/ruoyi-ui/src/api/system/dict/type.js @@ -43,10 +43,10 @@ export function delType(dictId) { }) } -// 清理参数缓存 -export function clearCache() { +// 刷新字典缓存 +export function refreshCache() { return request({ - url: '/system/dict/type/clearCache', + url: '/system/dict/type/refreshCache', method: 'delete' }) } diff --git a/ruoyi-ui/src/views/system/config/index.vue b/ruoyi-ui/src/views/system/config/index.vue index aff5089..d6275f5 100644 --- a/ruoyi-ui/src/views/system/config/index.vue +++ b/ruoyi-ui/src/views/system/config/index.vue @@ -99,9 +99,9 @@ plain icon="el-icon-refresh" size="mini" - @click="handleClearCache" + @click="handleRefreshCache" v-hasPermi="['system:config:remove']" - >清理缓存 + >刷新缓存 @@ -181,7 +181,7 @@