mirror of https://gitee.com/y_project/RuoYi.git
优化参数&字典缓存操作
parent
fe204ad7c5
commit
387a3f838d
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空字典缓存
|
* 清空字典缓存
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除参数配置
|
* 批量删除参数配置
|
||||||
*
|
*
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验参数键名是否唯一
|
* 校验参数键名是否唯一
|
||||||
|
|
|
@ -41,7 +41,7 @@ public interface ISysDictDataService
|
||||||
* @param ids 需要删除的数据
|
* @param ids 需要删除的数据
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteDictDataByIds(String ids);
|
public void deleteDictDataByIds(String ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增保存字典数据信息
|
* 新增保存字典数据信息
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增保存字典类型信息
|
* 新增保存字典类型信息
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验参数键名是否唯一
|
* 校验参数键名是否唯一
|
||||||
*
|
*
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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=")">
|
||||||
|
|
Loading…
Reference in New Issue