Compare commits

..

2 Commits

Author SHA1 Message Date
jiangs
7aa126dbe5 Merge remote-tracking branch 'lis8.0/master' 2025-08-18 18:21:08 +08:00
jiangs
75434d41a1 参数缓存 2025-08-18 18:20:58 +08:00
2 changed files with 35 additions and 26 deletions

View File

@ -5,6 +5,7 @@ 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 org.springframework.beans.factory.annotation.Autowired;
import java.util.Collection;
import java.util.List;
@ -12,33 +13,37 @@ import java.util.List;
public class ComOptionUtils {
/**
* 设置字典缓存
*
* @param key 参数键
* @param optDatas 字典数据列表
* 设置参数缓存
* 缓存格式:com_opt:HISOPT:SP_INTER com_opt:yq:xxdh
* @param yq 仪器
* @param xxdh 项目代码
* @param comOpt 参数数据
*/
public static void setOptCache(String key, List<ComOpt> optDatas) {
public static void setOptCache(String yq,String xxdh, ComOpt comOpt) {
//先清除该key的所有缓存,然后再重新设置该key的缓存
String key = yq+":"+xxdh;
SpringUtils.getBean(RedisCache.class).deleteObject(key);
SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), optDatas);
SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), comOpt);
}
/**
* 清空字典缓存
* 清空参数缓存
*/
public static void clearOptCache() {
Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys("com_opt:" + "*");
Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.COM_OPT_KEY + "*");
SpringUtils.getBean(RedisCache.class).deleteObject(keys);
}
/**
* 获取字典缓存
*
* @param key 参数键
* @return dictDatas 字典数据列表
* 获取参数缓存
* 根据现在的参数,获取到的数据应该只有一条
* @param yq 仪器
* @param xxdh 项目代码
* @return ComOpt 参数数据
*/
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);
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;
}
return null;
}

View File

@ -129,14 +129,17 @@ public class CommonUtil {
return comDictMapper.getComDictIdByName(zdlb,zdmc);
}
public String getComOptValue(String yq,String xxdh){
List<ComOpt> comOptList =getOptCache(yq);
if(comOptList!=null){
for (ComOpt opt : comOptList) {
if (xxdh.equals(opt.getXxdh())) {
return opt.getXxqz();
}
}}
return comOptMapper.getComOptValue(yq,xxdh);
ComOpt comOpt =getOptCache(yq,xxdh);
if(comOpt != null) {
//获取到缓存,直接返回缓存中的数据
return comOpt.getXxqz();
}else{
//没有获取到缓存,则先从数据库中查询数据,然后再进行缓存
ComOpt comOpt1 = comOptMapper.getComOptOne(yq, xxdh);
ComOptionUtils.setOptCache(yq,xxdh,comOpt1);
return comOpt1.getXxqz();
}
}
public List<LabReqdetail> getLabReqdetailList(String sqh){
@ -146,8 +149,9 @@ public class CommonUtil {
private List<ComDict> getDictCache(String zdlb) {
return ComDictUtils.getDictCache(zdlb);
}
private List<ComOpt> getOptCache(String yq) {
return ComOptionUtils.getOptCache(yq);
private ComOpt getOptCache(String yq,String xxdh) {
return ComOptionUtils.getOptCache(yq,xxdh);
}
public Boolean getUserPower(String yq,String yhdh,int powerIdx){