2025-08-09 22:28:44 +08:00
|
|
|
|
package com.czlis.common.utils;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
|
|
|
import com.czlis.common.constant.CacheConstants;
|
|
|
|
|
|
import com.czlis.common.core.domain.entity.lis.ComOpt;
|
|
|
|
|
|
import com.czlis.common.core.redis.RedisCache;
|
|
|
|
|
|
import com.czlis.common.utils.spring.SpringUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
public class ComOptionUtils {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 设置字典缓存
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param key 参数键
|
2025-08-12 18:18:24 +08:00
|
|
|
|
* @param optDatas 字典数据列表
|
2025-08-09 22:28:44 +08:00
|
|
|
|
*/
|
|
|
|
|
|
public static void setOptCache(String key, List<ComOpt> optDatas) {
|
|
|
|
|
|
//先清除该key的所有缓存,然后再重新设置该key的缓存
|
|
|
|
|
|
SpringUtils.getBean(RedisCache.class).deleteObject(key);
|
|
|
|
|
|
SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), optDatas);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 清空字典缓存
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static void clearOptCache() {
|
|
|
|
|
|
Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys("com_opt:" + "*");
|
|
|
|
|
|
SpringUtils.getBean(RedisCache.class).deleteObject(keys);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取字典缓存
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param key 参数键
|
|
|
|
|
|
* @return dictDatas 字典数据列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static List<ComOpt> getOptCache(String key) {
|
|
|
|
|
|
JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
|
|
|
|
|
|
if (StringUtils.isNotNull(arrayCache)) {
|
|
|
|
|
|
return arrayCache.toList(ComOpt.class);
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 设置cache key
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param configKey 参数键
|
|
|
|
|
|
* @return 缓存键key
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String getCacheKey(String configKey) {
|
|
|
|
|
|
return CacheConstants.COM_OPT_KEY + configKey;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|