|
@@ -5,7 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.ruoyi.common.constant.CacheConstants;
|
|
|
+import com.ruoyi.common.constant.CacheNames;
|
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
|
import com.ruoyi.common.core.domain.PageQuery;
|
|
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
@@ -15,11 +15,13 @@ import com.ruoyi.common.core.service.DictService;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.StreamUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
-import com.ruoyi.common.utils.redis.RedisUtils;
|
|
|
+import com.ruoyi.common.utils.cache.CacheUtils;
|
|
|
import com.ruoyi.system.mapper.SysDictDataMapper;
|
|
|
import com.ruoyi.system.mapper.SysDictTypeMapper;
|
|
|
import com.ruoyi.system.service.ISysDictTypeService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.cache.annotation.CachePut;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -83,17 +85,13 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
|
|
* @param dictType 字典类型
|
|
|
* @return 字典数据集合信息
|
|
|
*/
|
|
|
+ @Cacheable(cacheNames = CacheNames.SYS_DICT, key = "#dictType")
|
|
|
@Override
|
|
|
public List<SysDictData> selectDictDataByType(String dictType) {
|
|
|
- List<SysDictData> dictDatas = RedisUtils.getCacheObject(getCacheKey(dictType));
|
|
|
+ List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType);
|
|
|
if (CollUtil.isNotEmpty(dictDatas)) {
|
|
|
return dictDatas;
|
|
|
}
|
|
|
- dictDatas = dictDataMapper.selectDictDataByType(dictType);
|
|
|
- if (CollUtil.isNotEmpty(dictDatas)) {
|
|
|
- RedisUtils.setCacheObject(getCacheKey(dictType), dictDatas);
|
|
|
- return dictDatas;
|
|
|
- }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -132,7 +130,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
|
|
.eq(SysDictData::getDictType, dictType.getDictType()))) {
|
|
|
throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
|
|
|
}
|
|
|
- RedisUtils.deleteObject(getCacheKey(dictType.getDictType()));
|
|
|
+ CacheUtils.evict(CacheNames.SYS_DICT, dictType.getDictType());
|
|
|
}
|
|
|
baseMapper.deleteBatchIds(Arrays.asList(dictIds));
|
|
|
}
|
|
@@ -146,9 +144,8 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
|
|
new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getStatus, UserConstants.DICT_NORMAL));
|
|
|
Map<String, List<SysDictData>> dictDataMap = StreamUtils.groupByKey(dictDataList, SysDictData::getDictType);
|
|
|
dictDataMap.forEach((k,v) -> {
|
|
|
- String dictKey = getCacheKey(k);
|
|
|
List<SysDictData> dictList = StreamUtils.sorted(v, Comparator.comparing(SysDictData::getDictSort));
|
|
|
- RedisUtils.setCacheObject(dictKey, dictList);
|
|
|
+ CacheUtils.put(CacheNames.SYS_DICT, k, dictList);
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -157,8 +154,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
|
|
*/
|
|
|
@Override
|
|
|
public void clearDictCache() {
|
|
|
- Collection<String> keys = RedisUtils.keys(CacheConstants.SYS_DICT_KEY + "*");
|
|
|
- RedisUtils.deleteObject(keys);
|
|
|
+ CacheUtils.clear(CacheNames.SYS_DICT);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -176,13 +172,14 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
|
|
* @param dict 字典类型信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
+ @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#dict.dictType")
|
|
|
@Override
|
|
|
- public int insertDictType(SysDictType dict) {
|
|
|
+ public List<SysDictData> insertDictType(SysDictType dict) {
|
|
|
int row = baseMapper.insert(dict);
|
|
|
if (row > 0) {
|
|
|
- RedisUtils.setCacheObject(getCacheKey(dict.getDictType()), null);
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
|
- return row;
|
|
|
+ throw new ServiceException("操作失败");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -191,19 +188,20 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
|
|
* @param dict 字典类型信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
+ @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#dict.dictType")
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public int updateDictType(SysDictType dict) {
|
|
|
+ public List<SysDictData> updateDictType(SysDictType dict) {
|
|
|
SysDictType oldDict = baseMapper.selectById(dict.getDictId());
|
|
|
dictDataMapper.update(null, new LambdaUpdateWrapper<SysDictData>()
|
|
|
.set(SysDictData::getDictType, dict.getDictType())
|
|
|
.eq(SysDictData::getDictType, oldDict.getDictType()));
|
|
|
int row = baseMapper.updateById(dict);
|
|
|
if (row > 0) {
|
|
|
- List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType());
|
|
|
- RedisUtils.setCacheObject(getCacheKey(dict.getDictType()), dictDatas);
|
|
|
+ CacheUtils.evict(CacheNames.SYS_DICT, oldDict.getDictType());
|
|
|
+ return dictDataMapper.selectDictDataByType(dict.getDictType());
|
|
|
}
|
|
|
- return row;
|
|
|
+ throw new ServiceException("操作失败");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -287,13 +285,4 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
|
|
return StringUtils.stripEnd(propertyString.toString(), separator);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 设置cache key
|
|
|
- *
|
|
|
- * @param configKey 参数键
|
|
|
- * @return 缓存键key
|
|
|
- */
|
|
|
- String getCacheKey(String configKey) {
|
|
|
- return CacheConstants.SYS_DICT_KEY + configKey;
|
|
|
- }
|
|
|
}
|