package com.gkhy.hazmat.common.utils;
|
|
import cn.hutool.extra.spring.SpringUtil;
|
import com.gkhy.hazmat.common.constant.CacheConstant;
|
import com.gkhy.hazmat.common.domain.entity.SysDictData;
|
|
import java.util.Collection;
|
import java.util.List;
|
|
/**
|
* 字典工具类
|
*/
|
public class DictUtils {
|
/**
|
* 获取字典缓存
|
*
|
* @param key 参数键
|
* @return dictDatas 字典数据列表
|
*/
|
public static List<SysDictData> getDictCache(String key){
|
List<SysDictData> sysDictDataList= (List<SysDictData>) SpringUtil.getBean(RedisUtils.class).get(getCacheKey(key));
|
return sysDictDataList;
|
}
|
|
|
public static String getCacheKey(String configKey){
|
return CacheConstant.SYS_DICT_KEY + configKey;
|
}
|
|
/**
|
* 设置字典缓存
|
*
|
* @param key 参数键
|
* @param dictDatas 字典数据列表
|
*/
|
public static void setDictCache(String key, List<SysDictData> dictDatas)
|
{
|
SpringUtil.getBean(RedisUtils.class).set(getCacheKey(key), dictDatas);
|
}
|
|
/**
|
* 删除指定字典缓存
|
*
|
* @param key 字典键
|
*/
|
public static void removeDictCache(String key)
|
{
|
SpringUtil.getBean(RedisUtils.class).del(getCacheKey(key));
|
}
|
|
/**
|
* 清空字典缓存
|
*/
|
public static void clearDictCache()
|
{
|
Collection<String> keys = SpringUtil.getBean(RedisUtils.class).keys(CacheConstant.SYS_DICT_KEY + "*");
|
SpringUtil.getBean(RedisUtils.class).del(keys);
|
}
|
|
}
|