mirror of https://gitee.com/stylefeng/roses
【8.3.3】【dict】【cache】字典类型修改,清空字典缓存
parent
dd8cf5780d
commit
a03d64b2ca
|
@ -127,4 +127,20 @@ public interface DictService extends IService<SysDict>, DictApi {
|
||||||
*/
|
*/
|
||||||
String getPinyin(String name);
|
String getPinyin(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空字典id对应的所有缓存
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2025/1/10 18:16
|
||||||
|
*/
|
||||||
|
void deleteDictIdCaches(Long dictId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空字典对应的所有缓存
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2025/1/10 18:17
|
||||||
|
*/
|
||||||
|
void deleteDictIdCaches(SysDict sysDict);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
||||||
LambdaQueryWrapper<SysDict> wrapper = this.createWrapper(dictRequest);
|
LambdaQueryWrapper<SysDict> wrapper = this.createWrapper(dictRequest);
|
||||||
|
|
||||||
// 只查询有用字段
|
// 只查询有用字段
|
||||||
wrapper.select(SysDict::getDictName, SysDict::getDictCode, SysDict::getDictSort, SysDict::getDictId, SysDict::getDictParentId);
|
wrapper.select(SysDict::getDictId, SysDict::getDictTypeId, SysDict::getDictName, SysDict::getDictCode, SysDict::getDictSort, SysDict::getDictParentId);
|
||||||
|
|
||||||
return this.list(wrapper);
|
return this.list(wrapper);
|
||||||
}
|
}
|
||||||
|
@ -498,6 +498,59 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
||||||
this.removeBatchByIds(dictRequest.getDictIdList());
|
this.removeBatchByIds(dictRequest.getDictIdList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除字典id对应的缓存,目前有3种缓存
|
||||||
|
* <p>
|
||||||
|
* 第一种:key是字典id
|
||||||
|
* 第二种:key是字典类型id + 字典编码
|
||||||
|
* 第三种:key是字典类型编码 + 字典编码
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2025/1/10 18:02
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteDictIdCaches(Long dictId) {
|
||||||
|
if (dictId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取字典id的详情
|
||||||
|
SysDict sysDict = this.getById(dictId);
|
||||||
|
if (sysDict == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.deleteDictIdCaches(sysDict);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除字典id对应的缓存,目前有3种缓存
|
||||||
|
* <p>
|
||||||
|
* 第一种:key是字典id
|
||||||
|
* 第二种:key是字典类型id + 字典编码
|
||||||
|
* 第三种:key是字典类型编码 + 字典编码
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2025/1/10 18:02
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteDictIdCaches(SysDict sysDict) {
|
||||||
|
if (sysDict == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除字典id为key的缓存
|
||||||
|
this.dictInfoCache.remove(String.valueOf(sysDict.getDictId()));
|
||||||
|
|
||||||
|
// 删除字典类型id+字典编码为缓存key的缓存
|
||||||
|
this.dictNameMixedCache.remove(sysDict.getDictTypeId() + sysDict.getDictCode());
|
||||||
|
|
||||||
|
// 获取字典类型对应的字典编码
|
||||||
|
SysDictType sysDictType = dictTypeService.getById(sysDict.getDictTypeId());
|
||||||
|
if (sysDictType != null) {
|
||||||
|
this.dictNameMixedCache.remove(sysDictType.getDictTypeCode() + sysDict.getDictCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取详细信息
|
* 获取详细信息
|
||||||
*
|
*
|
||||||
|
@ -613,55 +666,4 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除字典id对应的缓存,目前有3种缓存
|
|
||||||
* <p>
|
|
||||||
* 第一种:key是字典id
|
|
||||||
* 第二种:key是字典类型id + 字典编码
|
|
||||||
* 第三种:key是字典类型编码 + 字典编码
|
|
||||||
*
|
|
||||||
* @author fengshuonan
|
|
||||||
* @since 2025/1/10 18:02
|
|
||||||
*/
|
|
||||||
private void deleteDictIdCaches(Long dictId) {
|
|
||||||
if (dictId == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取字典id的详情
|
|
||||||
SysDict sysDict = this.getById(dictId);
|
|
||||||
if (sysDict == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.deleteDictIdCaches(sysDict);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除字典id对应的缓存,目前有3种缓存
|
|
||||||
* <p>
|
|
||||||
* 第一种:key是字典id
|
|
||||||
* 第二种:key是字典类型id + 字典编码
|
|
||||||
* 第三种:key是字典类型编码 + 字典编码
|
|
||||||
*
|
|
||||||
* @author fengshuonan
|
|
||||||
* @since 2025/1/10 18:02
|
|
||||||
*/
|
|
||||||
private void deleteDictIdCaches(SysDict sysDict) {
|
|
||||||
if (sysDict == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除字典id为key的缓存
|
|
||||||
this.dictInfoCache.remove(String.valueOf(sysDict.getDictId()));
|
|
||||||
|
|
||||||
// 删除字典类型id+字典编码为缓存key的缓存
|
|
||||||
this.dictNameMixedCache.remove(sysDict.getDictTypeId() + sysDict.getDictCode());
|
|
||||||
|
|
||||||
// 获取字典类型对应的字典编码
|
|
||||||
SysDictType sysDictType = dictTypeService.getById(sysDict.getDictTypeId());
|
|
||||||
if (sysDictType != null) {
|
|
||||||
this.dictNameMixedCache.remove(sysDictType.getDictTypeCode() + sysDict.getDictCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,10 @@ import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||||
import cn.stylefeng.roses.kernel.dict.api.enums.DictTypeClassEnum;
|
import cn.stylefeng.roses.kernel.dict.api.enums.DictTypeClassEnum;
|
||||||
import cn.stylefeng.roses.kernel.dict.api.exception.DictException;
|
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.exception.enums.DictExceptionEnum;
|
||||||
|
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
|
||||||
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
|
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
|
||||||
import cn.stylefeng.roses.kernel.dict.modular.mapper.DictTypeMapper;
|
import cn.stylefeng.roses.kernel.dict.modular.mapper.DictTypeMapper;
|
||||||
|
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictRequest;
|
||||||
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictTypeRequest;
|
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictTypeRequest;
|
||||||
import cn.stylefeng.roses.kernel.dict.modular.service.DictService;
|
import cn.stylefeng.roses.kernel.dict.modular.service.DictService;
|
||||||
import cn.stylefeng.roses.kernel.dict.modular.service.DictTypeService;
|
import cn.stylefeng.roses.kernel.dict.modular.service.DictTypeService;
|
||||||
|
@ -85,6 +87,9 @@ public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, SysDictType
|
||||||
|
|
||||||
// 删除字典类型下的所有字典
|
// 删除字典类型下的所有字典
|
||||||
dictService.removeByDictTypeId(dictTypeRequest.getDictTypeId());
|
dictService.removeByDictTypeId(dictTypeRequest.getDictTypeId());
|
||||||
|
|
||||||
|
// 删除字典相关缓存
|
||||||
|
this.deleteDictCaches(dictTypeRequest.getDictTypeId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,8 +98,13 @@ public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, SysDictType
|
||||||
// 如果是系统级字典,只允许管理员操作
|
// 如果是系统级字典,只允许管理员操作
|
||||||
validateSystemTypeClassOperate(dictTypeRequest);
|
validateSystemTypeClassOperate(dictTypeRequest);
|
||||||
|
|
||||||
// 更新数据
|
// 获取旧的字典类型信息
|
||||||
SysDictType sysDictType = this.querySysDictType(dictTypeRequest);
|
SysDictType sysDictType = this.querySysDictType(dictTypeRequest);
|
||||||
|
|
||||||
|
// 删除旧的字典类型的缓存
|
||||||
|
this.deleteDictCaches(dictTypeRequest.getDictTypeId());
|
||||||
|
|
||||||
|
// 修改属性
|
||||||
BeanUtil.copyProperties(dictTypeRequest, sysDictType);
|
BeanUtil.copyProperties(dictTypeRequest, sysDictType);
|
||||||
|
|
||||||
// 字典类型编码不能修改
|
// 字典类型编码不能修改
|
||||||
|
@ -189,4 +199,26 @@ public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, SysDictType
|
||||||
return queryWrapper;
|
return queryWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除针对字典类型下的所有字典的缓存
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2025/1/10 18:12
|
||||||
|
*/
|
||||||
|
private void deleteDictCaches(Long dictTypeId) {
|
||||||
|
if (dictTypeId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取字典类型下的所有字典
|
||||||
|
DictRequest dictRequest = new DictRequest();
|
||||||
|
dictRequest.setDictTypeId(dictTypeId);
|
||||||
|
List<SysDict> list = dictService.findList(dictRequest);
|
||||||
|
|
||||||
|
// 删除掉这些字典的所有缓存
|
||||||
|
for (SysDict sysDict : list) {
|
||||||
|
this.dictService.deleteDictIdCaches(sysDict);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue