54 lines
1.4 KiB
Java
54 lines
1.4 KiB
Java
|
|
package com.czlis.common.utils;
|
|||
|
|
|
|||
|
|
import com.alibaba.fastjson2.JSONArray;
|
|||
|
|
import com.czlis.common.constant.CacheConstants;
|
|||
|
|
import com.czlis.common.core.domain.entity.ComDict;
|
|||
|
|
import com.czlis.common.core.redis.RedisCache;
|
|||
|
|
import com.czlis.common.utils.spring.SpringUtils;
|
|||
|
|
|
|||
|
|
import java.util.List;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* lis字典工具类
|
|||
|
|
*/
|
|||
|
|
public class ComDictUtils {
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 设置字典缓存
|
|||
|
|
*
|
|||
|
|
* @param key 参数键
|
|||
|
|
* @param dictDatas 字典数据列表
|
|||
|
|
*/
|
|||
|
|
public static void setDictCache(String key, List<ComDict> dictDatas) {
|
|||
|
|
//先清除该key的所有缓存,然后再重新设置该key的缓存
|
|||
|
|
SpringUtils.getBean(RedisCache.class).deleteObject(key);
|
|||
|
|
SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dictDatas);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取字典缓存
|
|||
|
|
*
|
|||
|
|
* @param key 参数键
|
|||
|
|
* @return dictDatas 字典数据列表
|
|||
|
|
*/
|
|||
|
|
public static List<ComDict> getDictCache(String key) {
|
|||
|
|
JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
|
|||
|
|
if (StringUtils.isNotNull(arrayCache)) {
|
|||
|
|
return arrayCache.toList(ComDict.class);
|
|||
|
|
}
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 设置cache key
|
|||
|
|
*
|
|||
|
|
* @param configKey 参数键
|
|||
|
|
* @return 缓存键key
|
|||
|
|
*/
|
|||
|
|
public static String getCacheKey(String configKey) {
|
|||
|
|
return CacheConstants.COM_DICT_KEY + configKey;
|
|||
|
|
}
|
|||
|
|
}
|