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;
|
2025-08-18 18:20:58 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2025-08-09 22:28:44 +08:00
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
public class ComOptionUtils {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-08-18 18:20:58 +08:00
|
|
|
|
* 设置参数缓存
|
|
|
|
|
|
* 缓存格式:com_opt:HISOPT:SP_INTER com_opt:yq:xxdh
|
|
|
|
|
|
* @param yq 仪器
|
|
|
|
|
|
* @param xxdh 项目代码
|
|
|
|
|
|
* @param comOpt 参数数据
|
2025-08-09 22:28:44 +08:00
|
|
|
|
*/
|
2025-08-18 18:20:58 +08:00
|
|
|
|
public static void setOptCache(String yq,String xxdh, ComOpt comOpt) {
|
2025-08-09 22:28:44 +08:00
|
|
|
|
//先清除该key的所有缓存,然后再重新设置该key的缓存
|
2025-08-18 18:20:58 +08:00
|
|
|
|
String key = yq+":"+xxdh;
|
2025-08-09 22:28:44 +08:00
|
|
|
|
SpringUtils.getBean(RedisCache.class).deleteObject(key);
|
2025-08-18 18:20:58 +08:00
|
|
|
|
SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), comOpt);
|
2025-08-09 22:28:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
/**
|
2025-08-18 18:20:58 +08:00
|
|
|
|
* 清空参数缓存
|
2025-08-09 22:28:44 +08:00
|
|
|
|
*/
|
|
|
|
|
|
public static void clearOptCache() {
|
2025-08-18 18:20:58 +08:00
|
|
|
|
Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.COM_OPT_KEY + "*");
|
2025-08-09 22:28:44 +08:00
|
|
|
|
SpringUtils.getBean(RedisCache.class).deleteObject(keys);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
2025-08-18 18:20:58 +08:00
|
|
|
|
* 获取参数缓存
|
|
|
|
|
|
* 根据现在的参数,获取到的数据应该只有一条
|
|
|
|
|
|
* @param yq 仪器
|
|
|
|
|
|
* @param xxdh 项目代码
|
|
|
|
|
|
* @return ComOpt 参数数据
|
2025-08-09 22:28:44 +08:00
|
|
|
|
*/
|
2025-08-18 18:20:58 +08:00
|
|
|
|
public static ComOpt getOptCache(String yq,String xxdh) {
|
|
|
|
|
|
String key = yq+":"+xxdh;
|
|
|
|
|
|
Object cacheObject = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
|
|
|
|
|
|
if (StringUtils.isNotNull(cacheObject)) {
|
|
|
|
|
|
return (ComOpt) cacheObject;
|
2025-08-09 22:28:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 设置cache key
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param configKey 参数键
|
|
|
|
|
|
* @return 缓存键key
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String getCacheKey(String configKey) {
|
|
|
|
|
|
return CacheConstants.COM_OPT_KEY + configKey;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|