Parcourir la source

缓存处理,考虑到分进程处理,需要后台加参数自动加载缓存

0027005599 il y a 1 an
Parent
commit
e99410688b

+ 14 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/ruleengine/FactorEnchangeFactory.java

@@ -33,6 +33,9 @@ import org.jeecg.modules.medical.service.IFactorCondRelaService;
 import org.jeecg.modules.medical.service.IMidIncidentAuditDetailService;
 import org.jeecg.modules.medical.service.IMidIncidentAuditService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
@@ -78,19 +81,29 @@ public class FactorEnchangeFactory {
     SqlUtil sqlUtil;
     @Autowired
     RedisTemplate redisTemplate;
+    @Value("${cache.auto:false}")
+    private Boolean cacheAutoInit;
 
     public static Map<Integer, EventAttr> enchanceAttrMap = new HashMap<>();
 
     public static Map<Integer, List<FactorCondRela>> factorCondRelaMap = new HashMap<>();
 
-//    @PostConstruct
+
     public void init() {
+        log.info("进入初始化FactorEnchangeFactory");
         List<EventAttr> eventAttrList = eventAttrService.lambdaQuery().eq(EventAttr::getDelFlag, CommonConstant.DEL_FLAG_0).list();
         enchanceAttrMap = eventAttrList.stream().collect(Collectors.toMap(EventAttr::getId, v -> v, (v1, v2) -> v1));
         List<FactorCondRela> factorCondRelaList = factorCondRelaService.lambdaQuery().orderByAsc(FactorCondRela::getSeqNum).list();
         factorCondRelaMap = factorCondRelaList.stream().collect(Collectors.groupingBy(FactorCondRela::getFactorEnhanceId));
     }
 
+    @PostConstruct
+    public void initAuto() {
+        if(cacheAutoInit) {
+            init();
+        }
+    }
+
     public boolean runFactorEnchange(Integer medicalInfoRuleInfoId, MedicalInsRuleInfo medicalInsRuleInfo, Object audit, Map<String, Object> localMap, List<RuleFactorRela> ruleFactorRelaList, List<FactorEnchance> factorEnchanceList, List<Map<String, Object>> itemList) {
         Map<Integer, FactorEnchance> factorEnchanceMap = factorEnchanceList.stream().collect(Collectors.toMap(FactorEnchance::getId, v -> v, (v1, v2) -> v1));
         boolean result = false;

+ 61 - 27
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/ruleengine/RuleEngine.java

@@ -58,6 +58,11 @@ import org.jeecg.modules.medical.service.IRuleFactorRelaService;
 import org.jeecg.modules.medical.service.ITreatmentItemsService;
 import org.jeecg.modules.message.websocket.WebSocket;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Profile;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
@@ -128,15 +133,20 @@ public class RuleEngine {
     IMedicalInsuranceDrugsService medicalInsuranceDrugsService;
     @Autowired
     IDiagnoseItemsService diagnoseItemsService;
+    @Value("${cache.auto:false}")
+    private Boolean cacheAutoInit;
 
     public static ThreadLocal<MidIncidentWarningVO> midIncidentWarningVOThreadLocal = new ThreadLocal<>();
 
     public static Map<String, List<RuleAttr>> interfRuleAttrList = new HashMap<>();
     public static List<Integer> advanceWaringRuleIdList = new ArrayList<>();
     public static Map<String, Set<Integer>> itemCodeAndRuleIdMap = new HashMap<>();
+    public static Map<Integer, List<RuleFactorRela>> ruleIdAndFatorEnchanceIdMap = new HashMap<>();
+    public static Map<Integer, List<FactorEnchance>> allEnchanceTypeMap = new HashMap<>();
+
 
-//    @PostConstruct
     public void initMedicalInsRule() {
+        log.info("进入初始化RuleEngine");
         List<MedicalInsRuleInfo> medicalInsRuleInfoList = medicalInsRuleInfoService.lambdaQuery().eq(MedicalInsRuleInfo::getState, Constant.EFF_STATE).list();
         if (!CollectionUtil.isNotEmpty(medicalInsRuleInfoList)) {
             log.error("规则配置表没有有效的规则");
@@ -152,10 +162,7 @@ public class RuleEngine {
             medicalMap.put(medicalInsRuleInfo.getId(), medicalInsRuleInfo);
             if (Constant.TREATMEN_TYPE_ADVANCE_WARNING.equals(medicalInsRuleInfo.getCallScenario())) {
                 advanceWaringRuleIdList.add(medicalInsRuleInfo.getId());
-            } else
-//                if (Constant.TREATMEN_TYPE_MID_INCIDENT_WARNING.equals(medicalInsRuleInfo.getCallScenario())
-//                    || Constant.TREATMEN_TYPE_MID_EX_POST_SUPERVISION.equals(medicalInsRuleInfo.getCallScenario()))
-            {
+            } else {
                 midMedicalInsRuleInfoList.add(medicalInsRuleInfo);
             }
         }
@@ -163,6 +170,26 @@ public class RuleEngine {
         genItemCodeAndRuleIdMap(midMedicalInsRuleInfoList);
         List<RuleAttr> ruleAttrList = ruleAttrService.list();
         interfRuleAttrList = ruleAttrList.stream().collect(Collectors.groupingBy(RuleAttr::getInterfName));
+        initFactor();
+    }
+
+    @PostConstruct
+    public void initMedicalInsRuleAuto() {
+        if(cacheAutoInit) {
+            initMedicalInsRule();
+        }
+    }
+
+    public void initFactor(){
+        LambdaQueryWrapper<RuleFactorRela> query = new LambdaQueryWrapper<RuleFactorRela>();
+        query.eq(RuleFactorRela::getDelFlag, CommonConstant.DEL_FLAG_0);
+//        query.in(RuleFactorRela::getMedicalInsRuleInfoId, medicalInsRuleInfoIdList);
+        query.orderByAsc(RuleFactorRela::getSeqNum);
+        List<RuleFactorRela> ruleFactorRelaList = ruleFactorRelaService.list(query);
+        ruleIdAndFatorEnchanceIdMap = ruleFactorRelaList.stream().collect(Collectors.groupingBy(RuleFactorRela::getMedicalInsRuleInfoId));
+        Set<Integer> factorEnchangeIdList = ruleFactorRelaList.stream().map(RuleFactorRela::getFactorEnhanceId).collect(Collectors.toSet());
+        List<FactorEnchance> factorEnchanceList = factorEnchanceService.listByIds(factorEnchangeIdList);
+        allEnchanceTypeMap = factorEnchanceList.stream().collect(Collectors.groupingBy(FactorEnchance::getFactorCatalog));
 
     }
 
@@ -274,7 +301,7 @@ public class RuleEngine {
         try {
             List<Integer> ruleIdList = medicalInsRuleInfoList.stream().map(MedicalInsRuleInfo::getId).collect(Collectors.toList());
             List<MedicalInsRuleProject> medicalInsRuleProjectList = medicalInsRuleProjectService.lambdaQuery().in(MedicalInsRuleProject::getMedicalInsRuleInfoId, ruleIdList).list();
-            if(CollectionUtil.isEmpty(medicalInsRuleProjectList)){
+            if (CollectionUtil.isEmpty(medicalInsRuleProjectList)) {
                 return;
             }
             Map<Integer, List<MedicalInsRuleProject>> ruleIdAndMap = medicalInsRuleProjectList.stream().collect(Collectors.groupingBy(MedicalInsRuleProject::getMedicalInsRuleInfoId));
@@ -937,17 +964,20 @@ public class RuleEngine {
             log.error("未有对应的规则,接口数据:{}", paramMap);
             return;
         }
-        LambdaQueryWrapper<RuleFactorRela> query = new LambdaQueryWrapper<RuleFactorRela>();
-        query.eq(RuleFactorRela::getDelFlag, CommonConstant.DEL_FLAG_0);
-        query.in(RuleFactorRela::getMedicalInsRuleInfoId, medicalInsRuleInfoIdList);
-        query.orderByAsc(RuleFactorRela::getSeqNum);
-        List<RuleFactorRela> ruleFactorRelaList = ruleFactorRelaService.list(query);
-
-        if (CollectionUtil.isNotEmpty(ruleFactorRelaList)) {
-            Map<Integer, List<RuleFactorRela>> ruleIdAndFatorEnchanceIdMap = ruleFactorRelaList.stream().collect(Collectors.groupingBy(RuleFactorRela::getMedicalInsRuleInfoId));
-            Set<Integer> factorEnchangeIdList = ruleFactorRelaList.stream().map(RuleFactorRela::getFactorEnhanceId).collect(Collectors.toSet());
-            List<FactorEnchance> factorEnchanceList = factorEnchanceService.listByIds(factorEnchangeIdList);
-            Map<Integer, List<FactorEnchance>> enchanceTypeMap = factorEnchanceList.stream().collect(Collectors.groupingBy(FactorEnchance::getFactorCatalog));
+//        LambdaQueryWrapper<RuleFactorRela> query = new LambdaQueryWrapper<RuleFactorRela>();
+//        query.eq(RuleFactorRela::getDelFlag, CommonConstant.DEL_FLAG_0);
+//        query.in(RuleFactorRela::getMedicalInsRuleInfoId, medicalInsRuleInfoIdList);
+//        query.orderByAsc(RuleFactorRela::getSeqNum);
+//        List<RuleFactorRela> ruleFactorRelaList = ruleFactorRelaService.list(query);
+        Map<Integer, List<FactorEnchance>> enchanceTypeMap = new HashMap<>();
+        for(Integer medicalRuleINfoId : medicalInsRuleInfoIdList){
+            enchanceTypeMap.put(medicalRuleINfoId, allEnchanceTypeMap.get(medicalRuleINfoId));
+        }
+        if (CollectionUtil.isNotEmpty(enchanceTypeMap)) {
+//            Map<Integer, List<RuleFactorRela>> ruleIdAndFatorEnchanceIdMap = ruleFactorRelaList.stream().collect(Collectors.groupingBy(RuleFactorRela::getMedicalInsRuleInfoId));
+//            Set<Integer> factorEnchangeIdList = ruleFactorRelaList.stream().map(RuleFactorRela::getFactorEnhanceId).collect(Collectors.toSet());
+//            List<FactorEnchance> factorEnchanceList = factorEnchanceService.listByIds(factorEnchangeIdList);
+//            Map<Integer, List<FactorEnchance>> enchanceTypeMap = factorEnchanceList.stream().collect(Collectors.groupingBy(FactorEnchance::getFactorCatalog));
             for (Integer medicalRuleInsInfoId : enchanceTypeMap.keySet()) {
                 String auditDetailKeyStr = paramMap.get(Constant.MEDICAL_PROJECT_NAME_KEY) + "_" + medicalRuleInsInfoId;
                 if (auditDetailSet.contains(auditDetailKeyStr)) {
@@ -982,17 +1012,21 @@ public class RuleEngine {
             log.error("未有对应的规则,接口数据:{}", paramMap);
             return false;
         }
-        LambdaQueryWrapper<RuleFactorRela> query = new LambdaQueryWrapper<RuleFactorRela>();
-        query.eq(RuleFactorRela::getDelFlag, CommonConstant.DEL_FLAG_0);
-        query.in(RuleFactorRela::getMedicalInsRuleInfoId, medicalInsRuleInfoIdList);
-        query.orderByAsc(RuleFactorRela::getSeqNum);
-        List<RuleFactorRela> ruleFactorRelaList = ruleFactorRelaService.list(query);
+//        LambdaQueryWrapper<RuleFactorRela> query = new LambdaQueryWrapper<RuleFactorRela>();
+//        query.eq(RuleFactorRela::getDelFlag, CommonConstant.DEL_FLAG_0);
+//        query.in(RuleFactorRela::getMedicalInsRuleInfoId, medicalInsRuleInfoIdList);
+//        query.orderByAsc(RuleFactorRela::getSeqNum);
+//        List<RuleFactorRela> ruleFactorRelaList = ruleFactorRelaService.list(query);
+        Map<Integer, List<FactorEnchance>> enchanceTypeMap = new HashMap<>();
+        for(Integer medicalRuleINfoId : medicalInsRuleInfoIdList){
+            enchanceTypeMap.put(medicalRuleINfoId, allEnchanceTypeMap.get(medicalRuleINfoId));
+        }
         boolean auditFlag = false;
-        if (CollectionUtil.isNotEmpty(ruleFactorRelaList)) {
-            Map<Integer, List<RuleFactorRela>> ruleIdAndFatorEnchanceIdMap = ruleFactorRelaList.stream().collect(Collectors.groupingBy(RuleFactorRela::getMedicalInsRuleInfoId));
-            Set<Integer> factorEnchangeIdList = ruleFactorRelaList.stream().map(RuleFactorRela::getFactorEnhanceId).collect(Collectors.toSet());
-            List<FactorEnchance> factorEnchanceList = factorEnchanceService.listByIds(factorEnchangeIdList);
-            Map<Integer, List<FactorEnchance>> enchanceTypeMap = factorEnchanceList.stream().collect(Collectors.groupingBy(FactorEnchance::getFactorCatalog));
+        if (CollectionUtil.isNotEmpty(enchanceTypeMap)) {
+//            Map<Integer, List<RuleFactorRela>> ruleIdAndFatorEnchanceIdMap = ruleFactorRelaList.stream().collect(Collectors.groupingBy(RuleFactorRela::getMedicalInsRuleInfoId));
+//            Set<Integer> factorEnchangeIdList = ruleFactorRelaList.stream().map(RuleFactorRela::getFactorEnhanceId).collect(Collectors.toSet());
+//            List<FactorEnchance> factorEnchanceList = factorEnchanceService.listByIds(factorEnchangeIdList);
+//            Map<Integer, List<FactorEnchance>> enchanceTypeMap = factorEnchanceList.stream().collect(Collectors.groupingBy(FactorEnchance::getFactorCatalog));
             for (Integer medicalRuleInsInfoId : enchanceTypeMap.keySet()) {
                 String auditDetailKeyStr = paramMap.get(Constant.MEDICAL_PROJECT_NAME_KEY) + "_" + medicalRuleInsInfoId;
                 if (auditDetailSet.contains(auditDetailKeyStr)) {

+ 1 - 1
jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml

@@ -160,7 +160,7 @@ mybatis-plus:
       table-underline: true
   configuration:
     # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
     # 返回类型为Map,显示null对应的字段
     call-setters-on-nulls: true
 #jeecg专用配置