优化参数&字典缓存操作
This commit is contained in:
@ -50,6 +50,14 @@ public interface SysConfigMapper
|
||||
*/
|
||||
public int updateConfig(SysConfig config);
|
||||
|
||||
/**
|
||||
* 删除参数配置
|
||||
*
|
||||
* @param configId 参数主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteConfigById(Long configId);
|
||||
|
||||
/**
|
||||
* 批量删除参数配置
|
||||
*
|
||||
|
@ -56,12 +56,22 @@ public interface ISysConfigService
|
||||
* @param ids 需要删除的数据ID
|
||||
* @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 需要删除的数据
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDictDataByIds(String ids);
|
||||
public void deleteDictDataByIds(String ids);
|
||||
|
||||
/**
|
||||
* 新增保存字典数据信息
|
||||
|
@ -58,12 +58,22 @@ public interface ISysDictTypeService
|
||||
* @return 结果
|
||||
* @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
|
||||
public void init()
|
||||
{
|
||||
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
|
||||
for (SysConfig config : configsList)
|
||||
{
|
||||
CacheUtils.put(getCacheName(), getCacheKey(config.getConfigKey()), config.getConfigValue());
|
||||
}
|
||||
loadingConfigCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,7 +126,7 @@ public class SysConfigServiceImpl implements ISysConfigService
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteConfigByIds(String ids)
|
||||
public void deleteConfigByIds(String ids)
|
||||
{
|
||||
Long[] configIds = Convert.toLongArray(ids);
|
||||
for (Long configId : configIds)
|
||||
@ -140,25 +136,43 @@ public class SysConfigServiceImpl implements ISysConfigService
|
||||
{
|
||||
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
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置参数缓存数据
|
||||
*/
|
||||
@Override
|
||||
public void resetConfigCache()
|
||||
{
|
||||
clearConfigCache();
|
||||
loadingConfigCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验参数键名是否唯一
|
||||
*
|
||||
|
@ -64,14 +64,16 @@ public class SysDictDataServiceImpl implements ISysDictDataService
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDictDataByIds(String ids)
|
||||
public void deleteDictDataByIds(String ids)
|
||||
{
|
||||
int row = dictDataMapper.deleteDictDataByIds(Convert.toStrArray(ids));
|
||||
if (row > 0)
|
||||
Long[] dictCodes = Convert.toLongArray(ids);
|
||||
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 结果
|
||||
*/
|
||||
@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<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
|
||||
DictUtils.setDictCache(data.getDictType(), dictDatas);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
@ -98,12 +101,13 @@ public class SysDictDataServiceImpl implements ISysDictDataService
|
||||
* @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<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
|
||||
DictUtils.setDictCache(data.getDictType(), dictDatas);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
@ -38,12 +38,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
|
||||
@PostConstruct
|
||||
public void init()
|
||||
{
|
||||
List<SysDictType> dictTypeList = dictTypeMapper.selectDictTypeAll();
|
||||
for (SysDictType dictType : dictTypeList)
|
||||
{
|
||||
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType());
|
||||
DictUtils.setDictCache(dictType.getDictType(), dictDatas);
|
||||
}
|
||||
loadingDictCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,7 +118,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDictTypeByIds(String ids)
|
||||
public void deleteDictTypeByIds(String ids)
|
||||
{
|
||||
Long[] dictIds = Convert.toLongArray(ids);
|
||||
for (Long dictId : dictIds)
|
||||
@ -133,24 +128,41 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
|
||||
{
|
||||
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 clearCache()
|
||||
public void loadingDictCache()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置字典缓存数据
|
||||
*/
|
||||
public void resetDictCache()
|
||||
{
|
||||
clearDictCache();
|
||||
loadingDictCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增保存字典类型信息
|
||||
*
|
||||
@ -158,12 +170,12 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
|
||||
* @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;
|
||||
}
|
||||
@ -176,14 +188,15 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
|
||||
*/
|
||||
@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<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType());
|
||||
DictUtils.setDictCache(dict.getDictType(), dictDatas);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
Reference in New Issue
Block a user