You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.7 KiB
66 lines
1.7 KiB
5 years ago
|
package com.ruoyi.common.utils;
|
||
|
|
||
|
import java.util.Collection;
|
||
|
import java.util.List;
|
||
4 years ago
|
|
||
5 years ago
|
import com.ruoyi.common.constant.Constants;
|
||
4 years ago
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
||
|
import com.ruoyi.common.core.redis.RedisCache;
|
||
5 years ago
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||
|
|
||
|
/**
|
||
|
* 字典工具类
|
||
|
*
|
||
|
* @author ruoyi
|
||
|
*/
|
||
|
public class DictUtils
|
||
|
{
|
||
|
/**
|
||
|
* 设置字典缓存
|
||
|
*
|
||
|
* @param key 参数键
|
||
|
* @param dictDatas 字典数据列表
|
||
|
*/
|
||
|
public static void setDictCache(String key, List<SysDictData> dictDatas)
|
||
|
{
|
||
|
SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dictDatas);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取字典缓存
|
||
|
*
|
||
|
* @param key 参数键
|
||
|
* @return dictDatas 字典数据列表
|
||
|
*/
|
||
|
public static List<SysDictData> getDictCache(String key)
|
||
|
{
|
||
|
Object cacheObj = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
|
||
|
if (StringUtils.isNotNull(cacheObj))
|
||
|
{
|
||
|
List<SysDictData> DictDatas = StringUtils.cast(cacheObj);
|
||
|
return DictDatas;
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 清空字典缓存
|
||
|
*/
|
||
|
public static void clearDictCache()
|
||
|
{
|
||
|
Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(Constants.SYS_DICT_KEY + "*");
|
||
|
SpringUtils.getBean(RedisCache.class).deleteObject(keys);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 设置cache key
|
||
|
*
|
||
|
* @param configKey 参数键
|
||
|
* @return 缓存键key
|
||
|
*/
|
||
|
public static String getCacheKey(String configKey)
|
||
|
{
|
||
|
return Constants.SYS_DICT_KEY + configKey;
|
||
|
}
|
||
|
}
|