mirror of https://gitee.com/stylefeng/roses
【8.3.3】【dict】【cache】更新对typeId+dictCode的缓存支持
parent
4e1bf45852
commit
2e59d68520
|
@ -22,9 +22,9 @@ public class DictFormatProcess extends BaseSimpleFieldFormatProcess {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object simpleItemFormat(Object businessId) {
|
public Object simpleItemFormat(Object businessId) {
|
||||||
Long orgId = Convert.toLong(businessId);
|
Long dictId = Convert.toLong(businessId);
|
||||||
DictApi bean = SpringUtil.getBean(DictApi.class);
|
DictApi bean = SpringUtil.getBean(DictApi.class);
|
||||||
return bean.getDictNameByDictId(orgId);
|
return bean.getDictNameByDictId(dictId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,9 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
||||||
@Resource(name = "dictInfoCache")
|
@Resource(name = "dictInfoCache")
|
||||||
private CacheOperatorApi<DictDetail> dictInfoCache;
|
private CacheOperatorApi<DictDetail> dictInfoCache;
|
||||||
|
|
||||||
|
@Resource(name = "dictNameMixedCache")
|
||||||
|
private CacheOperatorApi<String> dictNameMixedCache;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TreeDictInfo> getTreeDictList(DictRequest dictRequest) {
|
public List<TreeDictInfo> getTreeDictList(DictRequest dictRequest) {
|
||||||
|
|
||||||
|
@ -129,10 +132,21 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void del(DictRequest dictRequest) {
|
public void del(DictRequest dictRequest) {
|
||||||
this.removeById(dictRequest.getDictId());
|
|
||||||
|
|
||||||
// 删除字典缓存
|
// 获取字典id的详情
|
||||||
|
SysDict sysDict = this.getById(dictRequest.getDictId());
|
||||||
|
if (sysDict == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除字典id为key的缓存
|
||||||
this.dictInfoCache.remove(String.valueOf(dictRequest.getDictId()));
|
this.dictInfoCache.remove(String.valueOf(dictRequest.getDictId()));
|
||||||
|
|
||||||
|
// 删除字典类型id+字典编码为缓存key的缓存
|
||||||
|
this.dictNameMixedCache.remove(sysDict.getDictTypeId() + sysDict.getDictCode());
|
||||||
|
|
||||||
|
// 真实删除字典
|
||||||
|
this.removeById(dictRequest.getDictId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -142,6 +156,14 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
||||||
this.validateRepeat(dictRequest, true);
|
this.validateRepeat(dictRequest, true);
|
||||||
|
|
||||||
SysDict sysDict = this.querySysDict(dictRequest);
|
SysDict sysDict = this.querySysDict(dictRequest);
|
||||||
|
|
||||||
|
// 删除旧的字典的缓存,删除字典类型id+字典编码为缓存key的缓存
|
||||||
|
this.dictNameMixedCache.remove(sysDict.getDictTypeId() + sysDict.getDictCode());
|
||||||
|
|
||||||
|
// 删除字典名称缓存
|
||||||
|
this.dictInfoCache.remove(String.valueOf(sysDict.getDictId()));
|
||||||
|
|
||||||
|
// copy前端的属性
|
||||||
BeanUtil.copyProperties(dictRequest, sysDict);
|
BeanUtil.copyProperties(dictRequest, sysDict);
|
||||||
|
|
||||||
// 不能修改字典类型、编码和字典的上下级关系(上下级关系和顺序,通过更新字典树接口更方便)
|
// 不能修改字典类型、编码和字典的上下级关系(上下级关系和顺序,通过更新字典树接口更方便)
|
||||||
|
@ -153,9 +175,6 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
||||||
sysDict.setDictNamePinyin(pinYinApi.parseEveryPinyinFirstLetter(sysDict.getDictName()));
|
sysDict.setDictNamePinyin(pinYinApi.parseEveryPinyinFirstLetter(sysDict.getDictName()));
|
||||||
|
|
||||||
this.updateById(sysDict);
|
this.updateById(sysDict);
|
||||||
|
|
||||||
// 删除字典名称缓存
|
|
||||||
this.dictInfoCache.remove(String.valueOf(sysDict.getDictId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -185,14 +204,17 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
||||||
// 查询字典类型下的所有字典
|
// 查询字典类型下的所有字典
|
||||||
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
sysDictLambdaQueryWrapper.eq(SysDict::getDictTypeId, dictTypeId);
|
sysDictLambdaQueryWrapper.eq(SysDict::getDictTypeId, dictTypeId);
|
||||||
sysDictLambdaQueryWrapper.select(SysDict::getDictId);
|
sysDictLambdaQueryWrapper.select(SysDict::getDictId, SysDict::getDictTypeId, SysDict::getDictCode);
|
||||||
List<SysDict> list = this.list(sysDictLambdaQueryWrapper);
|
List<SysDict> list = this.list(sysDictLambdaQueryWrapper);
|
||||||
if (ObjectUtil.isEmpty(list)) {
|
if (ObjectUtil.isEmpty(list)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除所有字典的缓存
|
|
||||||
list.forEach(sysDict -> {
|
list.forEach(sysDict -> {
|
||||||
|
// 删除旧的字典的缓存,删除字典类型id+字典编码为缓存key的缓存
|
||||||
|
this.dictNameMixedCache.remove(sysDict.getDictTypeId() + sysDict.getDictCode());
|
||||||
|
|
||||||
|
// 删除字典名称缓存,key是字典id
|
||||||
this.dictInfoCache.remove(String.valueOf(sysDict.getDictId()));
|
this.dictInfoCache.remove(String.valueOf(sysDict.getDictId()));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -225,18 +247,35 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable(value = "dicts", key = "#dictTypeId+#dictCode", unless = "#result.length() == 0")
|
|
||||||
public String getDictName(Long dictTypeId, String dictCode) {
|
public String getDictName(Long dictTypeId, String dictCode) {
|
||||||
|
|
||||||
|
if (ObjectUtil.isEmpty(dictTypeId) || ObjectUtil.isEmpty(dictCode)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拼接缓存key
|
||||||
|
String cacheKey = dictTypeId + dictCode;
|
||||||
|
|
||||||
|
// 获取缓存中是否有值
|
||||||
|
String dictName = this.dictNameMixedCache.get(cacheKey);
|
||||||
|
if (dictName != null) {
|
||||||
|
return dictName;
|
||||||
|
}
|
||||||
|
|
||||||
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
sysDictLambdaQueryWrapper.eq(SysDict::getDictTypeId, dictTypeId);
|
sysDictLambdaQueryWrapper.eq(SysDict::getDictTypeId, dictTypeId);
|
||||||
sysDictLambdaQueryWrapper.eq(SysDict::getDictCode, dictCode);
|
sysDictLambdaQueryWrapper.eq(SysDict::getDictCode, dictCode);
|
||||||
sysDictLambdaQueryWrapper.select(SysDict::getDictName);
|
sysDictLambdaQueryWrapper.select(SysDict::getDictName);
|
||||||
SysDict sysDict = this.getOne(sysDictLambdaQueryWrapper, false);
|
SysDict sysDict = this.getOne(sysDictLambdaQueryWrapper, false);
|
||||||
if (ObjectUtil.isEmpty(sysDict)) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return sysDict.getDictName();
|
// 添加结果到缓存,然后再返回
|
||||||
|
if (ObjectUtil.isEmpty(sysDict)) {
|
||||||
|
this.dictNameMixedCache.put(cacheKey, StrUtil.EMPTY);
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
this.dictNameMixedCache.put(cacheKey, sysDict.getDictName());
|
||||||
|
return sysDict.getDictName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -304,10 +343,25 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteByDictId(Long dictId) {
|
public void deleteByDictId(Long dictId) {
|
||||||
this.removeById(dictId);
|
|
||||||
|
|
||||||
// 删除字典详情缓存
|
if (dictId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取字典详情
|
||||||
|
SysDict sysDict = this.getById(dictId);
|
||||||
|
if (sysDict == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除字典详情缓存,key是字典id
|
||||||
this.dictInfoCache.remove(dictId.toString());
|
this.dictInfoCache.remove(dictId.toString());
|
||||||
|
|
||||||
|
// 删除旧的字典的缓存,key是字典类型id+字典编码
|
||||||
|
this.dictNameMixedCache.remove(sysDict.getDictTypeId() + sysDict.getDictCode());
|
||||||
|
|
||||||
|
// 删除字典记录
|
||||||
|
this.removeById(dictId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -379,9 +433,6 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
||||||
|
|
||||||
// 更新字典
|
// 更新字典
|
||||||
this.edit(dictRequest);
|
this.edit(dictRequest);
|
||||||
|
|
||||||
// 删除字典详情缓存
|
|
||||||
this.dictInfoCache.remove(String.valueOf(dictRequest.getDictId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -561,12 +612,25 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void batchDelete(DictRequest dictRequest) {
|
public void batchDelete(DictRequest dictRequest) {
|
||||||
this.removeBatchByIds(dictRequest.getDictIdList());
|
|
||||||
|
|
||||||
// 循环删除缓存
|
// 获取这一批字典的详情
|
||||||
for (Long dictId : dictRequest.getDictIdList()) {
|
List<SysDict> dictList = this.listByIds(dictRequest.getDictIdList());
|
||||||
this.dictInfoCache.remove(dictId.toString());
|
if (ObjectUtil.isEmpty(dictList)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 删除这一批字典的缓存
|
||||||
|
for (SysDict sysDict : dictList) {
|
||||||
|
|
||||||
|
// 删除key为字典id的缓存
|
||||||
|
this.dictInfoCache.remove(sysDict.getDictId().toString());
|
||||||
|
|
||||||
|
// 删除旧的字典的缓存,key是字典类型id+字典编码
|
||||||
|
this.dictNameMixedCache.remove(sysDict.getDictTypeId() + sysDict.getDictCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除字典
|
||||||
|
this.removeBatchByIds(dictRequest.getDictIdList());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue