package com.ruoyi.project.system.dict.utils;
|
|
import java.util.List;
|
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.utils.CacheUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.project.system.dict.domain.DictData;
|
|
/**
|
* 字典工具类
|
*
|
* @author ruoyi
|
*/
|
public class DictUtils
|
{
|
/**
|
* 设置字典缓存
|
*
|
* @param key 参数键
|
* @param dictDatas 字典数据列表
|
*/
|
public static void setDictCache(String key, List<DictData> dictDatas)
|
{
|
CacheUtils.put(getCacheName(), getCacheKey(key), dictDatas);
|
}
|
|
/**
|
* 获取字典缓存
|
*
|
* @param key 参数键
|
* @return dictDatas 字典数据列表
|
*/
|
public static List<DictData> getDictCache(String key)
|
{
|
Object cacheObj = CacheUtils.get(getCacheName(), getCacheKey(key));
|
if (StringUtils.isNotNull(cacheObj))
|
{
|
List<DictData> DictDatas = StringUtils.cast(cacheObj);
|
return DictDatas;
|
}
|
return null;
|
}
|
|
/**
|
* 清空字典缓存
|
*/
|
public static void clearDictCache()
|
{
|
CacheUtils.removeAll(getCacheName());
|
}
|
|
/**
|
* 获取cache name
|
*
|
* @return 缓存名
|
*/
|
public static String getCacheName()
|
{
|
return Constants.SYS_DICT_CACHE;
|
}
|
|
/**
|
* 设置cache key
|
*
|
* @param configKey 参数键
|
* @return 缓存键key
|
*/
|
public static String getCacheKey(String configKey)
|
{
|
return Constants.SYS_DICT_KEY + configKey;
|
}
|
}
|