【8.3.3】【dict】【cache】更新字典名称的缓存获取

dev-8.3.3
stylefeng 2025-01-10 15:41:14 +08:00
parent fb80b235ed
commit f0fbaa8513
2 changed files with 26 additions and 10 deletions

View File

@ -7,6 +7,8 @@ import cn.stylefeng.roses.kernel.rule.format.BaseSimpleFieldFormatProcess;
/**
* JSONid
* <p>
*
*
* @author fengshuonan
* @since 2023/5/4 21:20

View File

@ -28,6 +28,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.dict.api.exception.DictException;
import cn.stylefeng.roses.kernel.dict.api.exception.enums.DictExceptionEnum;
import cn.stylefeng.roses.kernel.dict.api.pojo.DictDetail;
@ -78,6 +79,9 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
@Resource
private DictTypeService dictTypeService;
@Resource(name = "dictInfoCache")
private CacheOperatorApi<DictDetail> dictInfoCache;
@Override
public List<TreeDictInfo> getTreeDictList(DictRequest dictRequest) {
@ -290,15 +294,28 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
return new DictDetail();
}
// 先从缓存获取字典详情
DictDetail dictDetail = dictInfoCache.get(dictId.toString());
if (dictDetail != null) {
return dictDetail;
}
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
sysDictLambdaQueryWrapper.eq(SysDict::getDictId, dictId);
sysDictLambdaQueryWrapper.select(SysDict::getDictName, SysDict::getDictCode, SysDict::getDictId, SysDict::getDictSort);
SysDict sysDict = this.getOne(sysDictLambdaQueryWrapper, false);
if (sysDict == null) {
// 加入结果到缓存
dictInfoCache.put(dictId.toString(), new DictDetail());
return new DictDetail();
} else {
return new DictDetail(sysDict.getDictId(), sysDict.getDictCode(), sysDict.getDictName(), sysDict.getDictSort());
// 加入结果到缓存中
DictDetail dictDetailTemp = new DictDetail(sysDict.getDictId(), sysDict.getDictCode(), sysDict.getDictName(), sysDict.getDictSort());
dictInfoCache.put(dictId.toString(), dictDetailTemp);
return dictDetailTemp;
}
}
@ -308,16 +325,13 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
return "";
}
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
sysDictLambdaQueryWrapper.eq(SysDict::getDictId, dictId);
sysDictLambdaQueryWrapper.select(SysDict::getDictName);
SysDict sysDict = this.getOne(sysDictLambdaQueryWrapper, false);
if (sysDict == null) {
// 走统一方法,可以从缓存查询
DictDetail dictDetail = this.getDictByDictId(dictId);
if (dictDetail == null) {
return "";
} else {
return sysDict.getDictName();
}
return dictDetail.getDictName();
}
@Override