Browse Source

设置有效规则和数据改成多线程

gaodm 3 years ago
parent
commit
4fa094068b

+ 46 - 2
src/main/java/com/diagbot/aggregate/RuleAggregate.java

@@ -1,5 +1,6 @@
 package com.diagbot.aggregate;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.diagbot.dto.AllRulesDTO;
 import com.diagbot.dto.RuleBaseDTO;
 import com.diagbot.dto.RuleBaseInitDTO;
@@ -15,15 +16,18 @@ import com.diagbot.enums.RuleTypeEnum;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
 import com.diagbot.facade.KlRuleFacade;
+import com.diagbot.service.KlRuleSearchService;
 import com.diagbot.util.BeanUtil;
 import com.diagbot.util.EntityUtil;
 import com.diagbot.util.ListUtil;
 import com.diagbot.util.RedisUtil;
 import io.github.lvyahui8.spring.annotation.DataConsumer;
 import io.github.lvyahui8.spring.annotation.DataProvider;
+import io.github.lvyahui8.spring.annotation.InvokeParameter;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
@@ -44,6 +48,9 @@ public class RuleAggregate {
     private KlRuleFacade klRuleFacade;
     @Autowired
     private RedisUtil redisUtil;
+    @Autowired
+    @Qualifier("klRuleSearchServiceImpl")
+    private KlRuleSearchService klRuleSearchService;
 
     @DataProvider("getAllRules")
     public AllRulesDTO getAllRules(
@@ -125,7 +132,7 @@ public class RuleAggregate {
                                                 }
                                                 ruleConditionMap.put(ruleConditionDTO1.toString(), 1);
                                                 //规则搜索有效的规则ID
-                                                if (!ruleIdSet.contains(ruleInitDTO.getRuleId())){
+                                                if (!ruleIdSet.contains(ruleInitDTO.getRuleId())) {
                                                     ruleIdSet.add(ruleInitDTO.getRuleId());
                                                     KlRuleSearch klRuleSearch = new KlRuleSearch();
                                                     klRuleSearch.setId(ruleInitDTO.getRuleId());
@@ -148,7 +155,7 @@ public class RuleAggregate {
                                 ruleDTO.getRuleConditionDTOList().add(ruleConditionDTO);
                                 ruleConditionMap.put(ruleConditionDTO.toString(), 1);
                                 //规则搜索有效的规则ID
-                                if (!ruleIdSet.contains(ruleInitDTO.getRuleId())){
+                                if (!ruleIdSet.contains(ruleInitDTO.getRuleId())) {
                                     ruleIdSet.add(ruleInitDTO.getRuleId());
                                     KlRuleSearch klRuleSearch = new KlRuleSearch();
                                     klRuleSearch.setId(ruleInitDTO.getRuleId());
@@ -271,6 +278,43 @@ public class RuleAggregate {
         }
     }
 
+    @DataProvider("setAllRules")
+    public Boolean setAllRules(
+            @InvokeParameter("allRulesDTO") AllRulesDTO allRulesDTO,
+            @DataConsumer("setRuleDTOMap") Boolean resRuleDTOMap,
+            @DataConsumer("setDrugAllergen") Boolean resDrugAllergen,
+            @DataConsumer("setKlRuleSearchList") Boolean resKlRuleSearchList) {
+        return true;
+    }
+
+    @DataProvider("setRuleDTOMap")
+    public Boolean setRuleDTOMap(@InvokeParameter("allRulesDTO") AllRulesDTO allRulesDTO) {
+        //加载有效规则Map
+        if (MapUtils.isNotEmpty(allRulesDTO.getRuleDTOMap())) {
+            redisUtil.multiSet(allRulesDTO.getRuleDTOMap());
+        }
+        return true;
+    }
+
+    @DataProvider("setDrugAllergen")
+    public Boolean setDrugAllergen(@InvokeParameter("allRulesDTO") AllRulesDTO allRulesDTO) {
+        //加载药物过敏源缓存
+        if (MapUtils.isNotEmpty(allRulesDTO.getDrugAllergen())) {
+            redisUtil.set(RedisEnum.drugAllergen.getName(), allRulesDTO.getDrugAllergen());
+        }
+        return true;
+    }
+
+    @DataProvider("setKlRuleSearchList")
+    public Boolean setKlRuleSearchList(@InvokeParameter("allRulesDTO") AllRulesDTO allRulesDTO) {
+        //存储有效规则Id
+        klRuleSearchService.remove(new QueryWrapper<>());
+        if (ListUtil.isNotEmpty(allRulesDTO.getKlRuleSearchList())) {
+            klRuleSearchService.saveBatch(allRulesDTO.getKlRuleSearchList());
+        }
+        return true;
+    }
+
     public static void main(String[] args) {
         List<List<RuleBaseDTO>> ruleBaseList = new ArrayList<>();
         List<RuleBaseDTO> ruleBaseDTOListA = new ArrayList<>();

+ 5 - 18
src/main/java/com/diagbot/facade/NeoFacade.java

@@ -20,7 +20,6 @@ import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
 import com.diagbot.model.entity.PD;
 import com.diagbot.service.KlDiseaseCorrespondingService;
-import com.diagbot.service.KlRuleSearchService;
 import com.diagbot.service.SymptomFeatureService;
 import com.diagbot.service.TranHospitalFilterService;
 import com.diagbot.util.ListUtil;
@@ -39,7 +38,6 @@ import io.github.lvyahui8.spring.facade.DataFacade;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
@@ -80,9 +78,6 @@ public class NeoFacade {
     private KlDiagnoseBaseFacade klDiagnoseBaseFacade;
     @Autowired
     private KlRegulationBaseFacade klRegulationBaseFacade;
-    @Autowired
-    @Qualifier("klRuleSearchServiceImpl")
-    private KlRuleSearchService klRuleSearchService;
 
     /**
      * 返回药品缓存信息
@@ -497,21 +492,13 @@ public class NeoFacade {
         //            redisTemplate.opsForValue().multiSet(map);
         //        }
         try {
+            //取得所有需要设置的规则
             Map<String, Object> invokeParams = new HashMap<>();
             AllRulesDTO allRulesDTO = DataFacade.get("getAllRules", invokeParams, AllRulesDTO.class);
-            //加载有效规则Map
-            if (MapUtils.isNotEmpty(allRulesDTO.getRuleDTOMap())) {
-                redisUtil.multiSet(allRulesDTO.getRuleDTOMap());
-            }
-            //加载药物过敏源缓存
-            if (MapUtils.isNotEmpty(allRulesDTO.getDrugAllergen())) {
-                redisUtil.set(RedisEnum.drugAllergen.getName(), allRulesDTO.getDrugAllergen());
-            }
-            //存储有效规则Id
-            klRuleSearchService.remove(new QueryWrapper<>());
-            if (ListUtil.isNotEmpty(allRulesDTO.getKlRuleSearchList())) {
-                klRuleSearchService.saveBatch(allRulesDTO.getKlRuleSearchList());
-            }
+            //设置的所有规则
+            Map<String, Object> invokeParamsSet = new HashMap<>();
+            invokeParamsSet.put("allRulesDTO", allRulesDTO);
+            Boolean res = DataFacade.get("setAllRules", invokeParamsSet, Boolean.class);
         } catch (Exception e) {
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "获取所有规则失败" + e.getMessage());
         }