Browse Source

长兴模板添加

rengb 5 years ago
parent
commit
c231330fed

+ 4 - 1
kernel/src/main/java/com/lantone/qc/kernel/analysis/QCAnalysis.java

@@ -5,6 +5,7 @@ import com.lantone.qc.kernel.client.CRFServiceClient;
 import com.lantone.qc.kernel.client.SimilarityServiceClient;
 import com.lantone.qc.kernel.structure.ai.AIAnalyze;
 import com.lantone.qc.kernel.util.CatalogueUtil;
+import com.lantone.qc.kernel.util.RedisUtil;
 import com.lantone.qc.pub.exception.AIException;
 import com.lantone.qc.pub.exception.CatalogueException;
 import com.lantone.qc.pub.model.InputInfo;
@@ -26,11 +27,13 @@ import java.util.Map;
 public class QCAnalysis {
     @Autowired
     CRFServiceClient crfServiceClient;
-
+    @Autowired
+    private RedisUtil redisUtil;
     @Autowired
     SimilarityServiceClient similarityServiceClient;
 
     public OutputInfo anlysis(QueryVo queryVo) throws AIException, CatalogueException, Exception {
+        redisUtil.getHospitalIdThreadLocal().set(queryVo.getHospitalId());
         OutputInfo outputInfo = new OutputInfo();
         InputInfo inputInfo = TransDispatch.trans(queryVo);
         inputInfo.setInputCatalogueMap(queryVo.getInputCatalogueMap());

+ 139 - 106
kernel/src/main/java/com/lantone/qc/kernel/util/CacheUtil.java

@@ -1,27 +1,23 @@
 package com.lantone.qc.kernel.util;
 
-
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import com.lantone.qc.nlp.participle.cfg.Configuration;
 import com.lantone.qc.nlp.participle.cfg.DefaultConfig;
 import com.lantone.qc.pub.util.FastJsonUtils;
-import com.lantone.qc.pub.util.FileUtil;
+import com.lantone.qc.pub.util.StringUtil;
 import com.lantone.qc.trans.comsis.ModuleMappingUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
 import org.springframework.stereotype.Component;
-import org.springframework.util.ResourceUtils;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -37,43 +33,51 @@ import java.util.Set;
  * @Author : 楼辉荣
  * @Date: 2020-03-11 11:42
  */
+@Slf4j
 @Component
 public class CacheUtil implements ApplicationRunner {
-    Logger logger = LoggerFactory.getLogger(DefaultConfig.class);
+    private Configuration configuration = new DefaultConfig();
     @Autowired
     private RedisUtil redisUtil;
-
     @Value("${qc.hospital_id}")
-    private String hospitalId;
+    private String hospitalIds;
 
     public void run(ApplicationArguments var1) {
-        try {
-            this.loadModuleMappingInfo();//加载页面模板映射信息
-            this.putConceptDiagPropertyMap();//疾病相关信息放入缓存 包括疾病是否是慢病、传染病、常见症状、同义词
-            this.putHospitalDiagMap();//医院疾病信息
-            this.putHospitalDiagHuaZMap();//医院华卓映射
-            this.putLantoneDiagHuaZMap();//朗通华卓映射
-            this.putClinicBodyPartMap();//症状需要部位描述词典放入redis缓存
-            this.putHospitalDoctorInfoMap();//症状需要部位描述词典放入redis缓存
-        } catch (Exception e) {
-            logger.error("缓存文件读取错误。。。");
+        if (StringUtil.isBlank(hospitalIds)) {
+            return;
         }
+        for (String i : hospitalIds.split(",")) {
+            if (StringUtil.isBlank(i)) {
+                continue;
+            }
+            redisUtil.getHospitalCache().put(i, Maps.newHashMap());
+            this.loadModuleMappingInfo(i);//加载页面模板映射信息
+            this.putConceptDiagPropertyMap(i);//疾病相关信息放入缓存 包括疾病是否是慢病、传染病、常见症状、同义词
+            this.putHospitalDiagMap(i);//医院疾病信息
+            this.putHospitalDiagHuaZMap(i);//医院华卓映射
+            this.putLantoneDiagHuaZMap(i);//朗通华卓映射
+            this.putClinicBodyPartMap(i);//症状需要部位描述词典放入redis缓存
+            this.putHospitalDoctorInfoMap(i);//症状需要部位描述词典放入redis缓存
+        }
+        log.info("缓存加载完成!");
     }
 
     /**
      * 加载页面模板映射信息
+     *
+     * @param hospitalId
      */
-    private void loadModuleMappingInfo() {
+    private void loadModuleMappingInfo(String hospitalId) {
         List<String> xmlDataTypeHospitalIds = Lists.newArrayList("1", "3");
         try {
             InputStream stream = getClass().getClassLoader().getResourceAsStream("cache/" + hospitalId + "/module_mapping.json");
-            File targetFile = new File("module_mapping.json");
+            File targetFile = new File("cache/" + hospitalId + "/module_mapping.json");
             FileUtils.copyInputStreamToFile(stream, targetFile);
             String mappingMsg = FileUtils.readFileToString(targetFile);
-//            logger.error("模板数据:"+mappingMsg);
+            //            logger.error("模板数据:"+mappingMsg);
 
-//            String path = ResourceUtils.getURL("classpath:").getPath() + "cache/" + hospitalId + "/module_mapping.json";
-//            String mappingMsg = FileUtil.fileRead(path);
+            //            String path = ResourceUtils.getURL("classpath:").getPath() + "cache/" + hospitalId + "/module_mapping.json";
+            //            String mappingMsg = FileUtil.fileRead(path);
             if (xmlDataTypeHospitalIds.contains(hospitalId)) {
                 Map<String, Long> mapKeysModuleInfoIdMap = (Map) FastJsonUtils.getJsonToMap(mappingMsg);
                 Map<Set<String>, String> xmlDataTypeModuleInfo = Maps.newHashMap();
@@ -88,131 +92,160 @@ public class CacheUtil implements ApplicationRunner {
                     });
                     xmlDataTypeModuleInfo.put(Sets.newLinkedHashSet(list), entry.getValue() + "");
                 }
-//                mapKeysModuleInfoIdMap.keySet().forEach(mapKeys -> {
-//                    xmlDataTypeModuleInfo.put(Sets.newLinkedHashSet(Arrays.asList(mapKeys.split(","))), mapKeysModuleInfoIdMap.get(mapKeys) + "");
-//                });
-                ModuleMappingUtil.xmlDataTypeModuleInfo = xmlDataTypeModuleInfo;
+                //                mapKeysModuleInfoIdMap.keySet().forEach(mapKeys -> {
+                //                    xmlDataTypeModuleInfo.put(Sets.newLinkedHashSet(Arrays.asList(mapKeys.split(","))), mapKeysModuleInfoIdMap.get(mapKeys) + "");
+                //                });
+                ModuleMappingUtil.xmlDataTypeModuleInfo.put(hospitalId, xmlDataTypeModuleInfo);
             }
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
         }
     }
 
     /**
      * 疾病相关信息放入缓存
      * 包括疾病是否是慢病、传染病、常见症状、同义词
+     *
+     * @param hospitalId
      */
-    public void putConceptDiagPropertyMap() throws Exception {
-        Configuration configuration = new DefaultConfig();
-        List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/concept_diag_properties.dict");
-
-        Map<String, Map<String, Object>> diagMap = new HashMap<>();
-        for (String line : lines) {
-            String[] line_arr = line.split("\\|", -1);
-            if (line_arr.length == 5) {
-                List<String> synonymsList = new ArrayList<>();
-                List<String> symptomsList = new ArrayList<>();
-                if (StringUtils.isNotEmpty(line_arr[3])) {
-                    line_arr[3] = line_arr[3].trim();
-                    synonymsList = java.util.Arrays.asList(line_arr[3].split(","));
-                }
-                if (StringUtils.isNotEmpty(line_arr[4])) {
-                    line_arr[4] = line_arr[4].trim();
-                    symptomsList = java.util.Arrays.asList(line_arr[4].split(","));
+    public void putConceptDiagPropertyMap(String hospitalId) {
+        try {
+            List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/concept_diag_properties.dict");
+
+            Map<String, Map<String, Object>> diagMap = new HashMap<>();
+            for (String line : lines) {
+                String[] line_arr = line.split("\\|", -1);
+                if (line_arr.length == 5) {
+                    List<String> synonymsList = new ArrayList<>();
+                    List<String> symptomsList = new ArrayList<>();
+                    if (StringUtils.isNotEmpty(line_arr[3])) {
+                        line_arr[3] = line_arr[3].trim();
+                        synonymsList = java.util.Arrays.asList(line_arr[3].split(","));
+                    }
+                    if (StringUtils.isNotEmpty(line_arr[4])) {
+                        line_arr[4] = line_arr[4].trim();
+                        symptomsList = java.util.Arrays.asList(line_arr[4].split(","));
+                    }
+                    Map<String, Object> map = new HashMap<>();
+                    map.put("infectious", line_arr[2].trim());
+                    map.put("chronic", line_arr[1].trim());
+                    map.put("synonyms", synonymsList);
+                    map.put("symptoms", symptomsList);
+                    diagMap.put(line_arr[0], map);
                 }
-                Map<String, Object> map = new HashMap<>();
-                map.put("infectious", line_arr[2].trim());
-                map.put("chronic", line_arr[1].trim());
-                map.put("synonyms", synonymsList);
-                map.put("symptoms", symptomsList);
-                diagMap.put(line_arr[0], map);
             }
+            redisUtil.setValByHospitalId(hospitalId, KernelConstants.CONCEPT_DIAG_PROPERTY_MAP, diagMap);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
         }
-        redisUtil.setJsonStringValue(KernelConstants.CONCEPT_DIAG_PROPERTY_MAP, diagMap);
     }
 
     /**
      * 医院医生信息
      *
-     * @throws Exception
+     * @param hospitalId
      */
-    public void putHospitalDoctorInfoMap() throws Exception {
-        Configuration configuration = new DefaultConfig();
-        List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_doctor_info.dict");
-
-        Map<String, Map<String, Object>> hospitalDoctorMap = new HashMap<>();
-        for (String line : lines) {
-            String[] line_arr = line.split("\\|", -1);
-            if (line_arr.length == 4) {
-                Map<String, Object> map = new HashMap<>();
-                map.put("doctorName", line_arr[0]);
-                map.put("deptName", line_arr[1]);
-                map.put("professor", line_arr[2]);
-                map.put("occup", line_arr[3]);
-                hospitalDoctorMap.put(line_arr[0], map);
+    public void putHospitalDoctorInfoMap(String hospitalId) {
+        try {
+            List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_doctor_info.dict");
+
+            Map<String, Map<String, Object>> hospitalDoctorMap = new HashMap<>();
+            for (String line : lines) {
+                String[] line_arr = line.split("\\|", -1);
+                if (line_arr.length == 4) {
+                    Map<String, Object> map = new HashMap<>();
+                    map.put("doctorName", line_arr[0]);
+                    map.put("deptName", line_arr[1]);
+                    map.put("professor", line_arr[2]);
+                    map.put("occup", line_arr[3]);
+                    hospitalDoctorMap.put(line_arr[0], map);
+                }
             }
+            redisUtil.setValByHospitalId(hospitalId, KernelConstants.HOSPITAL_DOCTOR_MAP, hospitalDoctorMap);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
         }
-        redisUtil.setJsonStringValue(KernelConstants.HOSPITAL_DOCTOR_MAP, hospitalDoctorMap);
     }
 
     /**
      * 医院疾病信息放入redis缓存
+     *
+     * @param hospitalId
      */
-    public void putHospitalDiagMap() throws Exception {
-        Configuration configuration = new DefaultConfig();
-        List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_diag_info.dict");
-        Map<String, Map<String, String>> hospitalDiagMap = new HashMap<>();
-        for (String line : lines) {
-            Map<String, String> detail = new HashMap<>();
-            detail.put("name", line.trim());
-            detail.put("icd10", "A001");
-            hospitalDiagMap.put(line, detail);
+    public void putHospitalDiagMap(String hospitalId) {
+        try {
+            List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_diag_info.dict");
+            Map<String, Map<String, String>> hospitalDiagMap = new HashMap<>();
+            for (String line : lines) {
+                Map<String, String> detail = new HashMap<>();
+                detail.put("name", line.trim());
+                detail.put("icd10", "A001");
+                hospitalDiagMap.put(line, detail);
+            }
+            redisUtil.setValByHospitalId(hospitalId, KernelConstants.HOSPITAL_DIAG_MAP, hospitalDiagMap);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
         }
-        redisUtil.setJsonStringValue(KernelConstants.HOSPITAL_DIAG_MAP, hospitalDiagMap);
     }
 
     /**
      * 医院和华卓映射疾病信息放入redis缓存
+     *
+     * @param hospitalId
      */
-    public void putHospitalDiagHuaZMap() throws Exception {
-        Configuration configuration = new DefaultConfig();
-        List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_diag_info.dict");
-        Map<String, Map<String, String>> hospitalDiagMap = new HashMap<>();
-        for (String line : lines) {
-            Map<String, String> detail = new HashMap<>();
-            detail.put("name", line.trim());
-            detail.put("icd10", "A001");
-            hospitalDiagMap.put(line, detail);
+    public void putHospitalDiagHuaZMap(String hospitalId) {
+        try {
+            List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_diag_info.dict");
+            Map<String, Map<String, String>> hospitalDiagMap = new HashMap<>();
+            for (String line : lines) {
+                Map<String, String> detail = new HashMap<>();
+                detail.put("name", line.trim());
+                detail.put("icd10", "A001");
+                hospitalDiagMap.put(line, detail);
+            }
+            redisUtil.setValByHospitalId(hospitalId, KernelConstants.HOSPITAL_DIAG_HUAZ_MAP, hospitalDiagMap);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
         }
-        redisUtil.setJsonStringValue(KernelConstants.HOSPITAL_DIAG_HUAZ_MAP, hospitalDiagMap);
     }
 
     /**
      * 医院和华卓映射疾病信息放入redis缓存
+     *
+     * @param hospitalId
      */
-    public void putLantoneDiagHuaZMap() throws Exception {
-        Configuration configuration = new DefaultConfig();
-        List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_diag_info.dict");
-        Map<String, Map<String, String>> hospitalDiagMap = new HashMap<>();
-        for (String line : lines) {
-            Map<String, String> detail = new HashMap<>();
-            detail.put("name", line.trim());
-            detail.put("icd10", "A001");
-            hospitalDiagMap.put(line, detail);
+    public void putLantoneDiagHuaZMap(String hospitalId) {
+        try {
+            List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/hospital_diag_info.dict");
+            Map<String, Map<String, String>> hospitalDiagMap = new HashMap<>();
+            for (String line : lines) {
+                Map<String, String> detail = new HashMap<>();
+                detail.put("name", line.trim());
+                detail.put("icd10", "A001");
+                hospitalDiagMap.put(line, detail);
+            }
+            redisUtil.setValByHospitalId(hospitalId, KernelConstants.LANTONE_DIAG_HUAZ_MAP, hospitalDiagMap);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
         }
-        redisUtil.setJsonStringValue(KernelConstants.LANTONE_DIAG_HUAZ_MAP, hospitalDiagMap);
     }
 
     /**
      * 症状需要部位描述词典放入redis缓存
+     *
+     * @param hospitalId
      */
-    public void putClinicBodyPartMap() throws Exception {
-        Configuration configuration = new DefaultConfig();
-        List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/concept_clinic_bodypart_properties.dict");
-        List<String> clinicBodyPartList = new ArrayList<>();
-        for (String line : lines) {
-            clinicBodyPartList.add(line);
+    public void putClinicBodyPartMap(String hospitalId) {
+        try {
+            List<String> lines = configuration.readTargetFileContents("cache/" + hospitalId + "/concept_clinic_bodypart_properties.dict");
+            List<String> clinicBodyPartList = new ArrayList<>();
+            for (String line : lines) {
+                clinicBodyPartList.add(line);
+            }
+            redisUtil.setValByHospitalId(hospitalId, KernelConstants.CONCEPT_CLINIC_BODYPART_PROPERTIES_LIST, clinicBodyPartList);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
         }
-        redisUtil.setJsonStringValue(KernelConstants.CONCEPT_CLINIC_BODYPART_PROPERTIES_LIST, clinicBodyPartList);
     }
+
 }

+ 25 - 586
kernel/src/main/java/com/lantone/qc/kernel/util/RedisUtil.java

@@ -1,16 +1,10 @@
 package com.lantone.qc.kernel.util;
 
-import com.lantone.qc.pub.util.FastJsonUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
+import com.google.common.collect.Maps;
+import com.lantone.qc.pub.util.StringUtil;
 import org.springframework.stereotype.Component;
-import org.springframework.util.CollectionUtils;
 
-import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
 
 /**
  * @Description:
@@ -19,600 +13,45 @@ import java.util.concurrent.TimeUnit;
  */
 @Component
 public final class RedisUtil {
+    private final Map<String, Map<String, Object>> hospitalCache = Maps.newHashMap();
+    private final ThreadLocal<String> hospitalIdThreadLocal = new ThreadLocal<>();
 
-    @Autowired
-    private RedisTemplate<String, Object> redisTemplate;
-
-    public static Map<String, Object> static_map = new HashMap<>();
-
-    // =============================common============================
-
-    /**
-     * 指定缓存失效时间
-     *
-     * @param key  键
-     * @param time 时间(秒)
-     * @return
-     */
-    private boolean expire(String key, long time) {
-        try {
-            if (time > 0) {
-                redisTemplate.expire(key, time, TimeUnit.SECONDS);
-            }
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    /**
-     * 根据key 获取过期时间
-     *
-     * @param key 键 不能为null
-     * @return 时间(秒) 返回0代表为永久有效
-     */
-    private long getExpire(String key) {
-        return redisTemplate.getExpire(key, TimeUnit.SECONDS);
-    }
-
-    /**
-     * 判断key是否存在
-     *
-     * @param key 键
-     * @return true 存在 false不存在
-     */
-    private boolean hasKey(String key) {
-        try {
-            return redisTemplate.hasKey(key);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    /**
-     * 删除缓存
-     *
-     * @param key 可以传一个值 或多个
-     */
-    @SuppressWarnings("unchecked")
-    private void del(String... key) {
-        if (key != null && key.length > 0) {
-            if (key.length == 1) {
-                redisTemplate.delete(key[0]);
-            } else {
-                redisTemplate.delete(CollectionUtils.arrayToList(key));
-            }
-        }
-    }
-
-    // ============================String=============================
-
-    /**
-     * 普通缓存获取
-     *
-     * @param key 键
-     * @return 值
-     */
-    public Object get(String key) {
-        return key == null ? null : redisTemplate.opsForValue().get(key);
-    }
-
-    /**
-     * 普通缓存放入
-     *
-     * @param key   键
-     * @param value 值
-     * @return true成功 false失败
-     */
-    public boolean set(String key, Object value) {
-        try {
-            redisTemplate.opsForValue().set(key, value);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-
-    }
-
-    /**
-     * 普通缓存放入并设置时间
-     *
-     * @param key   键
-     * @param value 值
-     * @param time  时间(秒) time要大于0 如果time小于等于0 将设置无限期
-     * @return true成功 false 失败
-     */
-    public boolean set(String key, Object value, long time) {
-        try {
-            if (time > 0) {
-                redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
-            } else {
-                set(key, value);
-            }
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    /**
-     * 递增
-     *
-     * @param key   键
-     * @param delta 要增加几(大于0)
-     * @return
-     */
-    private long incr(String key, long delta) {
-        if (delta < 0) {
-            throw new RuntimeException("递增因子必须大于0");
-        }
-        return redisTemplate.opsForValue().increment(key, delta);
-    }
-
-    /**
-     * 递减
-     *
-     * @param key   键
-     * @param delta 要减少几(小于0)
-     * @return
-     */
-    private long decr(String key, long delta) {
-        if (delta < 0) {
-            throw new RuntimeException("递减因子必须大于0");
-        }
-        return redisTemplate.opsForValue().increment(key, -delta);
-    }
-
-    // ================================Map=================================
-
-    /**
-     * HashGet
-     *
-     * @param key  键 不能为null
-     * @param item 项 不能为null
-     * @return 值
-     */
-    private Object hget(String key, String item) {
-        return redisTemplate.opsForHash().get(key, item);
-    }
-
-    /**
-     * 获取hashKey对应的所有键值
-     *
-     * @param key 键
-     * @return 对应的多个键值
-     */
-    private Map<Object, Object> hmget(String key) {
-        return redisTemplate.opsForHash().entries(key);
-    }
-
-    /**
-     * HashSet
-     *
-     * @param key 键
-     * @param map 对应多个键值
-     * @return true 成功 false 失败
-     */
-    private boolean hmset(String key, Map<String, Object> map) {
-        try {
-            redisTemplate.opsForHash().putAll(key, map);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    /**
-     * HashSet 并设置时间
-     *
-     * @param key  键
-     * @param map  对应多个键值
-     * @param time 时间(秒)
-     * @return true成功 false失败
-     */
-    private boolean hmset(String key, Map<String, Object> map, long time) {
-        try {
-            redisTemplate.opsForHash().putAll(key, map);
-            if (time > 0) {
-                expire(key, time);
-            }
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    /**
-     * 向一张hash表中放入数据,如果不存在将创建
-     *
-     * @param key   键
-     * @param item  项
-     * @param value 值
-     * @return true 成功 false失败
-     */
-    private boolean hset(String key, String item, Object value) {
-        try {
-            redisTemplate.opsForHash().put(key, item, value);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    /**
-     * 向一张hash表中放入数据,如果不存在将创建
-     *
-     * @param key   键
-     * @param item  项
-     * @param value 值
-     * @param time  时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
-     * @return true 成功 false失败
-     */
-    private boolean hset(String key, String item, Object value, long time) {
-        try {
-            redisTemplate.opsForHash().put(key, item, value);
-            if (time > 0) {
-                expire(key, time);
-            }
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    /**
-     * 删除hash表中的值
-     *
-     * @param key  键 不能为null
-     * @param item 项 可以使多个 不能为null
-     */
-    private void hdel(String key, Object... item) {
-        redisTemplate.opsForHash().delete(key, item);
-    }
-
-    /**
-     * 判断hash表中是否有该项的值
-     *
-     * @param key  键 不能为null
-     * @param item 项 不能为null
-     * @return true 存在 false不存在
-     */
-    private boolean hHasKey(String key, String item) {
-        return redisTemplate.opsForHash().hasKey(key, item);
-    }
-
-    /**
-     * hash递增 如果不存在,就会创建一个 并把新增后的值返回
-     *
-     * @param key  键
-     * @param item 项
-     * @param by   要增加几(大于0)
-     * @return
-     */
-    private double hincr(String key, String item, double by) {
-        return redisTemplate.opsForHash().increment(key, item, by);
-    }
-
-    /**
-     * hash递减
-     *
-     * @param key  键
-     * @param item 项
-     * @param by   要减少记(小于0)
-     * @return
-     */
-    private double hdecr(String key, String item, double by) {
-        return redisTemplate.opsForHash().increment(key, item, -by);
-    }
-
-    // ============================set=============================
-
-    /**
-     * 根据key获取Set中的所有值
-     *
-     * @param key 键
-     * @return
-     */
-    private Set<Object> sGet(String key) {
-        try {
-            return redisTemplate.opsForSet().members(key);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
-    }
-
-    /**
-     * 根据value从一个set中查询,是否存在
-     *
-     * @param key   键
-     * @param value 值
-     * @return true 存在 false不存在
-     */
-    private boolean sHasKey(String key, Object value) {
-        try {
-            return redisTemplate.opsForSet().isMember(key, value);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    /**
-     * 将数据放入set缓存
-     *
-     * @param key    键
-     * @param values 值 可以是多个
-     * @return 成功个数
-     */
-    private long sSet(String key, Object... values) {
-        try {
-            return redisTemplate.opsForSet().add(key, values);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return 0;
-        }
-    }
-
-    /**
-     * 将set数据放入缓存
-     *
-     * @param key    键
-     * @param time   时间(秒)
-     * @param values 值 可以是多个
-     * @return 成功个数
-     */
-    private long sSetAndTime(String key, long time, Object... values) {
-        try {
-            Long count = redisTemplate.opsForSet().add(key, values);
-            if (time > 0) {
-                expire(key, time);
-            }
-            return count;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return 0;
-        }
-    }
-
-    /**
-     * 获取set缓存的长度
-     *
-     * @param key 键
-     * @return
-     */
-    private long sGetSetSize(String key) {
-        try {
-            return redisTemplate.opsForSet().size(key);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return 0;
-        }
-    }
-
-    /**
-     * 移除值为value的
-     *
-     * @param key    键
-     * @param values 值 可以是多个
-     * @return 移除的个数
-     */
-    private long setRemove(String key, Object... values) {
-        try {
-            Long count = redisTemplate.opsForSet().remove(key, values);
-            return count;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return 0;
-        }
+    public <T> T getJsonStringValue(String key) {
+        return getValByHospitalId(hospitalIdThreadLocal.get(), key);
     }
-    // ===============================list=================================
 
-    /**
-     * 获取list缓存的内容
-     *
-     * @param key   键
-     * @param start 开始
-     * @param end   结束 0 到 -1代表所有值
-     * @return
-     */
-    private List<Object> lGet(String key, long start, long end) {
-        try {
-            return redisTemplate.opsForList().range(key, start, end);
-        } catch (Exception e) {
-            e.printStackTrace();
+    public <T> T getValByHospitalId(String hospitalId, String key) {
+        if (StringUtil.isBlank(hospitalId)) {
             return null;
         }
-    }
-
-    /**
-     * 获取list缓存的长度
-     *
-     * @param key 键
-     * @return
-     */
-    private long lGetListSize(String key) {
-        try {
-            return redisTemplate.opsForList().size(key);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return 0;
-        }
-    }
-
-    /**
-     * 通过索引 获取list中的值
-     *
-     * @param key   键
-     * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
-     * @return
-     */
-    private Object lGetIndex(String key, long index) {
-        try {
-            return redisTemplate.opsForList().index(key, index);
-        } catch (Exception e) {
-            e.printStackTrace();
+        Map<String, Object> map = hospitalCache.get(hospitalId);
+        if (map == null) {
             return null;
         }
+        return (T) map.get(key);
     }
 
-    /**
-     * 将list放入缓存
-     *
-     * @param key   键
-     * @param value 值
-     * @return
-     */
-    private boolean lSet(String key, Object value) {
-        try {
-            redisTemplate.opsForList().rightPush(key, value);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    /**
-     * 将list放入缓存
-     *
-     * @param key   键
-     * @param value 值
-     * @param time  时间(秒)
-     * @return
-     */
-    private boolean lSet(String key, Object value, long time) {
-        try {
-            redisTemplate.opsForList().rightPush(key, value);
-            if (time > 0) {
-                expire(key, time);
-            }
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    /**
-     * 将list放入缓存
-     *
-     * @param key   键
-     * @param value 值
-     * @return
-     */
-    private boolean lSet(String key, List<Object> value) {
-        try {
-            redisTemplate.opsForList().rightPushAll(key, value);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    /**
-     * 将list放入缓存
-     *
-     * @param key   键
-     * @param value 值
-     * @param time  时间(秒)
-     * @return
-     */
-    private boolean lSet(String key, List<Object> value, long time) {
-        try {
-            redisTemplate.opsForList().rightPushAll(key, value);
-            if (time > 0) {
-                expire(key, time);
-            }
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
+    public <T> void setJsonStringValue(String key, Object value) {
+        setValByHospitalId(hospitalIdThreadLocal.get(), key, value);
     }
 
-    /**
-     * 根据索引修改list中的某条数据
-     *
-     * @param key   键
-     * @param index 索引
-     * @param value 值
-     * @return
-     */
-    private boolean lUpdateIndex(String key, long index, Object value) {
-        try {
-            redisTemplate.opsForList().set(key, index, value);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
+    public <T> void setValByHospitalId(String hospitalId, String key, Object value) {
+        if (StringUtil.isBlank(hospitalId)) {
+            return;
         }
-    }
-
-    /**
-     * 移除N个值为value
-     *
-     * @param key   键
-     * @param count 移除多少个
-     * @param value 值
-     * @return 移除的个数
-     */
-    private long lRemove(String key, long count, Object value) {
-        try {
-            Long remove = redisTemplate.opsForList().remove(key, count, value);
-            return remove;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return 0;
+        Map<String, Object> map = hospitalCache.get(hospitalId);
+        if (map == null) {
+            return;
         }
+        map.put(key, value);
     }
 
-    /**
-     * 获取---value为json字符串
-     *
-     * @param key
-     * @param <T>
-     * @return
-     */
-    public <T> T getJsonStringValue(String key) {
-        try {
-//            Object valObj = get(key);
-//            if (valObj != null && valObj.getClass().getName().indexOf("String") > -1) {
-//                return (T) FastJsonUtils.getJsonToBean(valObj.toString(), Object.class);
-//            }
-//            return null;
-            return (T)static_map.get(key);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
+    public ThreadLocal<String> getHospitalIdThreadLocal() {
+        return hospitalIdThreadLocal;
     }
 
-    /**
-     * 插入---value为json字符串
-     *
-     * @param key
-     * @param value
-     */
-    public <T> void setJsonStringValue(String key, Object value) {
-        try {
-            static_map.put(key, value);
-//            set(key, FastJsonUtils.getBeanToJson(value));
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
+    public Map<String, Map<String, Object>> getHospitalCache() {
+        return hospitalCache;
     }
 
-
-}
-
+}

+ 1 - 1
kernel/src/main/resources/application.yml

@@ -25,7 +25,7 @@ spring:
         max-idle: 8
 
 qc:
-  hospital_id: 3
+  hospital_id: 1,3
 
 CRF:
   url: http://192.168.2.234:3456/api/mr_info_ex/entity_predict

File diff suppressed because it is too large
+ 1 - 0
kernel/src/main/resources/cache/1/module_mapping.json


+ 2 - 0
public/src/main/java/com/lantone/qc/pub/model/vo/QueryVo.java

@@ -23,4 +23,6 @@ public class QueryVo extends TokenVO {
 
     private String cid;
 
+    private String hospitalId;
+
 }

+ 2 - 0
trans/src/main/java/com/lantone/qc/trans/TransDispatch.java

@@ -2,6 +2,7 @@ package com.lantone.qc.trans;
 
 import com.lantone.qc.pub.model.InputInfo;
 import com.lantone.qc.pub.model.vo.QueryVo;
+import com.lantone.qc.trans.comsis.ModuleMappingUtil;
 import lombok.extern.slf4j.Slf4j;
 
 /**
@@ -14,6 +15,7 @@ public class TransDispatch {
 
     public static InputInfo trans(QueryVo queryVo) {
         try {
+            ModuleMappingUtil.hospitalIdThreadLocal.set(queryVo.getHospitalId());
             String classPath = "com.lantone.qc.trans."
                     + queryVo.getCid()
                     + "."

+ 5 - 10
trans/src/main/java/com/lantone/qc/trans/comsis/ModuleMappingUtil.java

@@ -17,10 +17,12 @@ import java.util.Set;
  */
 public class ModuleMappingUtil {
 
-    public static Map<Set<String>, String> xmlDataTypeModuleInfo = Maps.newLinkedHashMap();
+    public static final Map<String, Map<Set<String>, String>> xmlDataTypeModuleInfo = Maps.newHashMap();
+    public static final ThreadLocal<String> hospitalIdThreadLocal = new ThreadLocal<>();
 
     public static String getXmlDataTypeModuleId(Map<String, String> sourceMap) {
-        if (MapUtils.isEmpty(sourceMap)) {
+        if (MapUtils.isEmpty(sourceMap)
+                || MapUtils.isEmpty(xmlDataTypeModuleInfo.get(hospitalIdThreadLocal.get()))) {
             return null;
         }
         Set<String> set = sourceMap.keySet();
@@ -32,14 +34,7 @@ public class ModuleMappingUtil {
             }
         });
         set = Sets.newLinkedHashSet(list);
-        //                if (set.size() == 335) {
-        //                    System.out.println(" ");
-        //                    for (Map.Entry<Set<String>, String> entry : xmlDataTypeModuleInfo.entrySet()) {
-        //                        System.out.println(StringUtils.join(entry.getKey(), ","));
-        //                    }
-        //                    System.out.println(StringUtils.join(set, ","));
-        //                }
-        return xmlDataTypeModuleInfo.get(set);
+        return xmlDataTypeModuleInfo.get(hospitalIdThreadLocal.get()).get(set);
     }
 
 }