update 优化根据字典类型查询信息增加一级缓存

This commit is contained in:
AprilWind 2025-02-26 09:54:20 +08:00
parent 319a89e320
commit 71180584da
2 changed files with 9 additions and 0 deletions

View File

@ -30,6 +30,11 @@ public interface CacheNames {
*/ */
String SYS_DICT = "sys_dict"; String SYS_DICT = "sys_dict";
/**
* 数据字典类型
*/
String SYS_DICT_TYPE = "sys_dict_type";
/** /**
* 租户 * 租户
*/ */

View File

@ -124,6 +124,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
* @param dictType 字典类型 * @param dictType 字典类型
* @return 字典类型 * @return 字典类型
*/ */
@Cacheable(cacheNames = CacheNames.SYS_DICT_TYPE, key = "#dictType")
@Override @Override
public SysDictTypeVo selectDictTypeByType(String dictType) { public SysDictTypeVo selectDictTypeByType(String dictType) {
return baseMapper.selectVoOne(new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getDictType, dictType)); return baseMapper.selectVoOne(new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getDictType, dictType));
@ -143,6 +144,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName())); throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
} }
CacheUtils.evict(CacheNames.SYS_DICT, dictType.getDictType()); CacheUtils.evict(CacheNames.SYS_DICT, dictType.getDictType());
CacheUtils.evict(CacheNames.SYS_DICT_TYPE, dictType.getDictType());
} }
baseMapper.deleteByIds(Arrays.asList(dictIds)); baseMapper.deleteByIds(Arrays.asList(dictIds));
} }
@ -153,6 +155,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
@Override @Override
public void resetDictCache() { public void resetDictCache() {
CacheUtils.clear(CacheNames.SYS_DICT); CacheUtils.clear(CacheNames.SYS_DICT);
CacheUtils.clear(CacheNames.SYS_DICT_TYPE);
} }
/** /**
@ -191,6 +194,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
int row = baseMapper.updateById(dict); int row = baseMapper.updateById(dict);
if (row > 0) { if (row > 0) {
CacheUtils.evict(CacheNames.SYS_DICT, oldDict.getDictType()); CacheUtils.evict(CacheNames.SYS_DICT, oldDict.getDictType());
CacheUtils.evict(CacheNames.SYS_DICT_TYPE, oldDict.getDictType());
return dictDataMapper.selectDictDataByType(dict.getDictType()); return dictDataMapper.selectDictDataByType(dict.getDictType());
} }
throw new ServiceException("操作失败"); throw new ServiceException("操作失败");