refactor(dict):优化字典缓存清理逻辑- 移除 SYS_DICT_TYPE_WITH_DEFAULT_TENANTID 缓存常量- 使用 GlobalConstants.GLOBAL_DICT_KEY 替代旧缓存键- 更新 insertDictType与 updateDictType 方法的缓存注解
- 在删除和重置缓存时同步清理全局字典缓存- 统一缓存更新操作,同时更新 SYS_DICT 和全局缓存
This commit is contained in:
parent
462ccbb250
commit
b2a9624aac
@ -35,11 +35,6 @@ public interface CacheNames {
|
||||
*/
|
||||
String SYS_DICT_TYPE = "sys_dict_type";
|
||||
|
||||
/**
|
||||
* 数据字典类型
|
||||
*/
|
||||
String SYS_DICT_TYPE_WITH_DEFAULT_TENANTID= "sys_dict_type_with_default_tenantid";
|
||||
|
||||
/**
|
||||
* 租户
|
||||
*/
|
||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.dromara.common.core.constant.CacheNames;
|
||||
import org.dromara.common.core.constant.GlobalConstants;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.ObjectUtils;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
@ -100,6 +101,7 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
|
||||
SysDictData data = baseMapper.selectById(dictCode);
|
||||
baseMapper.deleteById(dictCode);
|
||||
CacheUtils.evict(CacheNames.SYS_DICT, data.getDictType());
|
||||
CacheUtils.evict(GlobalConstants.GLOBAL_DICT_KEY, data.getDictType());
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +111,7 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
|
||||
* @param bo 字典数据信息
|
||||
* @return 结果
|
||||
*/
|
||||
@CachePut(cacheNames = CacheNames.SYS_DICT, key = "#bo.dictType")
|
||||
@CachePut(cacheNames = {CacheNames.SYS_DICT, GlobalConstants.GLOBAL_DICT_KEY}, key = "#bo.dictType")
|
||||
@Override
|
||||
public List<SysDictDataVo> insertDictData(SysDictDataBo bo) {
|
||||
SysDictData data = MapstructUtils.convert(bo, SysDictData.class);
|
||||
@ -126,7 +128,7 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
|
||||
* @param bo 字典数据信息
|
||||
* @return 结果
|
||||
*/
|
||||
@CachePut(cacheNames = CacheNames.SYS_DICT, key = "#bo.dictType")
|
||||
@CachePut(cacheNames = {CacheNames.SYS_DICT, GlobalConstants.GLOBAL_DICT_KEY}, key = "#bo.dictType")
|
||||
@Override
|
||||
public List<SysDictDataVo> updateDictData(SysDictDataBo bo) {
|
||||
SysDictData data = MapstructUtils.convert(bo, SysDictData.class);
|
||||
|
@ -160,7 +160,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
}
|
||||
CacheUtils.evict(CacheNames.SYS_DICT, dictType.getDictType());
|
||||
CacheUtils.evict(CacheNames.SYS_DICT_TYPE, dictType.getDictType());
|
||||
CacheUtils.evict(CacheNames.SYS_DICT_TYPE_WITH_DEFAULT_TENANTID, dictType.getDictType());
|
||||
CacheUtils.evict(GlobalConstants.GLOBAL_DICT_KEY, dictType.getDictType());
|
||||
}
|
||||
baseMapper.deleteByIds(Arrays.asList(dictIds));
|
||||
}
|
||||
@ -172,7 +172,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
public void resetDictCache() {
|
||||
CacheUtils.clear(CacheNames.SYS_DICT);
|
||||
CacheUtils.clear(CacheNames.SYS_DICT_TYPE);
|
||||
CacheUtils.clear(CacheNames.SYS_DICT_TYPE_WITH_DEFAULT_TENANTID);
|
||||
CacheUtils.clear(GlobalConstants.GLOBAL_DICT_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,7 +181,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
* @param bo 字典类型信息
|
||||
* @return 结果
|
||||
*/
|
||||
@CachePut(cacheNames = CacheNames.SYS_DICT, key = "#bo.dictType")
|
||||
@CachePut(cacheNames = {CacheNames.SYS_DICT, GlobalConstants.GLOBAL_DICT_KEY}, key = "#bo.dictType")
|
||||
@Override
|
||||
public List<SysDictDataVo> insertDictType(SysDictTypeBo bo) {
|
||||
SysDictType dict = MapstructUtils.convert(bo, SysDictType.class);
|
||||
@ -199,7 +199,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
* @param bo 字典类型信息
|
||||
* @return 结果
|
||||
*/
|
||||
@CachePut(cacheNames = CacheNames.SYS_DICT, key = "#bo.dictType")
|
||||
@CachePut(cacheNames = {CacheNames.SYS_DICT, GlobalConstants.GLOBAL_DICT_KEY}, key = "#bo.dictType")
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<SysDictDataVo> updateDictType(SysDictTypeBo bo) {
|
||||
@ -212,7 +212,6 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
if (row > 0) {
|
||||
CacheUtils.evict(CacheNames.SYS_DICT, oldDict.getDictType());
|
||||
CacheUtils.evict(CacheNames.SYS_DICT_TYPE, oldDict.getDictType());
|
||||
CacheUtils.evict(CacheNames.SYS_DICT_TYPE_WITH_DEFAULT_TENANTID, oldDict.getDictType());
|
||||
return dictDataMapper.selectDictDataByType(dict.getDictType());
|
||||
}
|
||||
throw new ServiceException("操作失败");
|
||||
|
Loading…
x
Reference in New Issue
Block a user