优化参数&字典缓存操作

pull/274/head^2
RuoYi 2021-05-26 19:52:01 +08:00
parent fe204ad7c5
commit 387a3f838d
14 changed files with 154 additions and 78 deletions

View File

@ -129,19 +129,20 @@ public class SysConfigController extends BaseController
@ResponseBody @ResponseBody
public AjaxResult remove(String ids) public AjaxResult remove(String ids)
{ {
return toAjax(configService.deleteConfigByIds(ids)); configService.deleteConfigByIds(ids);
return success();
} }
/** /**
* *
*/ */
@RequiresPermissions("system:config:remove") @RequiresPermissions("system:config:remove")
@Log(title = "参数管理", businessType = BusinessType.CLEAN) @Log(title = "参数管理", businessType = BusinessType.CLEAN)
@GetMapping("/clearCache") @GetMapping("/refreshCache")
@ResponseBody @ResponseBody
public AjaxResult clearCache() public AjaxResult refreshCache()
{ {
configService.clearCache(); configService.resetConfigCache();
return success(); return success();
} }

View File

@ -115,6 +115,7 @@ public class SysDictDataController extends BaseController
@ResponseBody @ResponseBody
public AjaxResult remove(String ids) public AjaxResult remove(String ids)
{ {
return toAjax(dictDataService.deleteDictDataByIds(ids)); dictDataService.deleteDictDataByIds(ids);
return success();
} }
} }

View File

@ -125,19 +125,20 @@ public class SysDictTypeController extends BaseController
@ResponseBody @ResponseBody
public AjaxResult remove(String ids) public AjaxResult remove(String ids)
{ {
return toAjax(dictTypeService.deleteDictTypeByIds(ids)); dictTypeService.deleteDictTypeByIds(ids);
return success();
} }
/** /**
* *
*/ */
@RequiresPermissions("system:dict:remove") @RequiresPermissions("system:dict:remove")
@Log(title = "字典类型", businessType = BusinessType.CLEAN) @Log(title = "字典类型", businessType = BusinessType.CLEAN)
@GetMapping("/clearCache") @GetMapping("/refreshCache")
@ResponseBody @ResponseBody
public AjaxResult clearCache() public AjaxResult refreshCache()
{ {
dictTypeService.clearCache(); dictTypeService.resetDictCache();
return success(); return success();
} }

View File

@ -50,8 +50,8 @@
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:config:export"> <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:config:export">
<i class="fa fa-download"></i> 导出 <i class="fa fa-download"></i> 导出
</a> </a>
<a class="btn btn-danger" onclick="clearCache()" shiro:hasPermission="system:config:remove"> <a class="btn btn-danger" onclick="refreshCache()" shiro:hasPermission="system:config:remove">
<i class="fa fa-refresh"></i> 清理缓存 <i class="fa fa-refresh"></i> 刷新缓存
</a> </a>
</div> </div>
<div class="col-sm-12 select-table table-striped"> <div class="col-sm-12 select-table table-striped">
@ -135,9 +135,9 @@
$.table.init(options); $.table.init(options);
}); });
/** 清理参数缓存 */ /** 刷新参数缓存 */
function clearCache() { function refreshCache() {
$.operate.get(prefix + "/clearCache"); $.operate.get(prefix + "/refreshCache");
} }
</script> </script>
</body> </body>

View File

@ -50,8 +50,8 @@
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:dict:export"> <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:dict:export">
<i class="fa fa-download"></i> 导出 <i class="fa fa-download"></i> 导出
</a> </a>
<a class="btn btn-danger" onclick="clearCache()" shiro:hasPermission="system:dict:remove"> <a class="btn btn-danger" onclick="refreshCache()" shiro:hasPermission="system:dict:remove">
<i class="fa fa-refresh"></i> 清理缓存 <i class="fa fa-refresh"></i> 刷新缓存
</a> </a>
</div> </div>
@ -139,9 +139,9 @@
$.modal.openTab("字典数据", url); $.modal.openTab("字典数据", url);
} }
/** 清理字典缓存 */ /** 刷新字典缓存 */
function clearCache() { function refreshCache() {
$.operate.get(prefix + "/clearCache"); $.operate.get(prefix + "/refreshCache");
} }
</script> </script>
</body> </body>

View File

@ -150,6 +150,16 @@ public class DictUtils
return StringUtils.stripEnd(propertyString.toString(), separator); return StringUtils.stripEnd(propertyString.toString(), separator);
} }
/**
*
*
* @param key
*/
public static void removeDictCache(String key)
{
CacheUtils.remove(getCacheName(), getCacheKey(key));
}
/** /**
* *
*/ */

View File

@ -50,6 +50,14 @@ public interface SysConfigMapper
*/ */
public int updateConfig(SysConfig config); public int updateConfig(SysConfig config);
/**
*
*
* @param configId
* @return
*/
public int deleteConfigById(Long configId);
/** /**
* *
* *

View File

@ -56,12 +56,22 @@ public interface ISysConfigService
* @param ids ID * @param ids ID
* @return * @return
*/ */
public int deleteConfigByIds(String ids); public void deleteConfigByIds(String ids);
/** /**
* *
*/ */
public void clearCache(); public void loadingConfigCache();
/**
*
*/
public void clearConfigCache();
/**
*
*/
public void resetConfigCache();
/** /**
* *

View File

@ -41,7 +41,7 @@ public interface ISysDictDataService
* @param ids * @param ids
* @return * @return
*/ */
public int deleteDictDataByIds(String ids); public void deleteDictDataByIds(String ids);
/** /**
* *

View File

@ -58,12 +58,22 @@ public interface ISysDictTypeService
* @return * @return
* @throws Exception * @throws Exception
*/ */
public int deleteDictTypeByIds(String ids); public void deleteDictTypeByIds(String ids);
/** /**
* *
*/ */
public void clearCache(); public void loadingDictCache();
/**
*
*/
public void clearDictCache();
/**
*
*/
public void resetDictCache();
/** /**
* *

View File

@ -31,11 +31,7 @@ public class SysConfigServiceImpl implements ISysConfigService
@PostConstruct @PostConstruct
public void init() public void init()
{ {
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig()); loadingConfigCache();
for (SysConfig config : configsList)
{
CacheUtils.put(getCacheName(), getCacheKey(config.getConfigKey()), config.getConfigValue());
}
} }
/** /**
@ -130,7 +126,7 @@ public class SysConfigServiceImpl implements ISysConfigService
* @return * @return
*/ */
@Override @Override
public int deleteConfigByIds(String ids) public void deleteConfigByIds(String ids)
{ {
Long[] configIds = Convert.toLongArray(ids); Long[] configIds = Convert.toLongArray(ids);
for (Long configId : configIds) for (Long configId : configIds)
@ -140,25 +136,43 @@ public class SysConfigServiceImpl implements ISysConfigService
{ {
throw new BusinessException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey())); throw new BusinessException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
} }
configMapper.deleteConfigById(configId);
CacheUtils.remove(getCacheName(), getCacheKey(config.getConfigKey()));
} }
int count = configMapper.deleteConfigByIds(Convert.toStrArray(ids));
if (count > 0)
{
CacheUtils.removeAll(getCacheName());
}
return count;
} }
/** /**
* *
*/ */
@Override @Override
public void clearCache() public void loadingConfigCache()
{
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
for (SysConfig config : configsList)
{
CacheUtils.put(getCacheName(), getCacheKey(config.getConfigKey()), config.getConfigValue());
}
}
/**
*
*/
@Override
public void clearConfigCache()
{ {
CacheUtils.removeAll(getCacheName()); CacheUtils.removeAll(getCacheName());
} }
/**
*
*/
@Override
public void resetConfigCache()
{
clearConfigCache();
loadingConfigCache();
}
/** /**
* *
* *

View File

@ -64,14 +64,16 @@ public class SysDictDataServiceImpl implements ISysDictDataService
* @return * @return
*/ */
@Override @Override
public int deleteDictDataByIds(String ids) public void deleteDictDataByIds(String ids)
{ {
int row = dictDataMapper.deleteDictDataByIds(Convert.toStrArray(ids)); Long[] dictCodes = Convert.toLongArray(ids);
if (row > 0) for (Long dictCode : dictCodes)
{ {
DictUtils.clearDictCache(); SysDictData data = selectDictDataById(dictCode);
dictDataMapper.deleteDictDataById(dictCode);
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
DictUtils.setDictCache(data.getDictType(), dictDatas);
} }
return row;
} }
/** /**
@ -81,12 +83,13 @@ public class SysDictDataServiceImpl implements ISysDictDataService
* @return * @return
*/ */
@Override @Override
public int insertDictData(SysDictData dictData) public int insertDictData(SysDictData data)
{ {
int row = dictDataMapper.insertDictData(dictData); int row = dictDataMapper.insertDictData(data);
if (row > 0) if (row > 0)
{ {
DictUtils.clearDictCache(); List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
DictUtils.setDictCache(data.getDictType(), dictDatas);
} }
return row; return row;
} }
@ -98,12 +101,13 @@ public class SysDictDataServiceImpl implements ISysDictDataService
* @return * @return
*/ */
@Override @Override
public int updateDictData(SysDictData dictData) public int updateDictData(SysDictData data)
{ {
int row = dictDataMapper.updateDictData(dictData); int row = dictDataMapper.updateDictData(data);
if (row > 0) if (row > 0)
{ {
DictUtils.clearDictCache(); List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
DictUtils.setDictCache(data.getDictType(), dictDatas);
} }
return row; return row;
} }

View File

@ -38,12 +38,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
@PostConstruct @PostConstruct
public void init() public void init()
{ {
List<SysDictType> dictTypeList = dictTypeMapper.selectDictTypeAll(); loadingDictCache();
for (SysDictType dictType : dictTypeList)
{
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType());
DictUtils.setDictCache(dictType.getDictType(), dictDatas);
}
} }
/** /**
@ -123,7 +118,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
* @return * @return
*/ */
@Override @Override
public int deleteDictTypeByIds(String ids) public void deleteDictTypeByIds(String ids)
{ {
Long[] dictIds = Convert.toLongArray(ids); Long[] dictIds = Convert.toLongArray(ids);
for (Long dictId : dictIds) for (Long dictId : dictIds)
@ -133,24 +128,41 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
{ {
throw new BusinessException(String.format("%1$s已分配,不能删除", dictType.getDictName())); throw new BusinessException(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 loadingDictCache()
public void clearCache() {
List<SysDictType> dictTypeList = dictTypeMapper.selectDictTypeAll();
for (SysDictType dict : dictTypeList)
{
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType());
DictUtils.setDictCache(dict.getDictType(), dictDatas);
}
}
/**
*
*/
public void clearDictCache()
{ {
DictUtils.clearDictCache(); DictUtils.clearDictCache();
} }
/**
*
*/
public void resetDictCache()
{
clearDictCache();
loadingDictCache();
}
/** /**
* *
* *
@ -158,12 +170,12 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
* @return * @return
*/ */
@Override @Override
public int insertDictType(SysDictType dictType) public int insertDictType(SysDictType dict)
{ {
int row = dictTypeMapper.insertDictType(dictType); int row = dictTypeMapper.insertDictType(dict);
if (row > 0) if (row > 0)
{ {
DictUtils.clearDictCache(); DictUtils.setDictCache(dict.getDictType(), null);
} }
return row; return row;
} }
@ -176,14 +188,15 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
*/ */
@Override @Override
@Transactional @Transactional
public int updateDictType(SysDictType dictType) public int updateDictType(SysDictType dict)
{ {
SysDictType oldDict = dictTypeMapper.selectDictTypeById(dictType.getDictId()); SysDictType oldDict = dictTypeMapper.selectDictTypeById(dict.getDictId());
dictDataMapper.updateDictDataType(oldDict.getDictType(), dictType.getDictType()); dictDataMapper.updateDictDataType(oldDict.getDictType(), dict.getDictType());
int row = dictTypeMapper.updateDictType(dictType); int row = dictTypeMapper.updateDictType(dict);
if (row > 0) if (row > 0)
{ {
DictUtils.clearDictCache(); List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType());
DictUtils.setDictCache(dict.getDictType(), dictDatas);
} }
return row; return row;
} }

View File

@ -98,6 +98,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where config_id = #{configId} where config_id = #{configId}
</update> </update>
<delete id="deleteConfigById" parameterType="Long">
delete from sys_config where config_id = #{configId}
</delete>
<delete id="deleteConfigByIds" parameterType="String"> <delete id="deleteConfigByIds" parameterType="String">
delete from sys_config where config_id in delete from sys_config where config_id in
<foreach item="configId" collection="array" open="(" separator="," close=")"> <foreach item="configId" collection="array" open="(" separator="," close=")">