Browse Source

代码优化

zhaops 4 years atrás
parent
commit
33524fc762

+ 195 - 0
cdssman-service/src/main/java/com/diagbot/aggregate/CallIndicationAggregate.java

@@ -0,0 +1,195 @@
+package com.diagbot.aggregate;
+
+import com.diagbot.client.CdssCoreClient;
+import com.diagbot.dto.BillMsg;
+import com.diagbot.dto.IndicationDTO;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.entity.ResultRule;
+import com.diagbot.facade.MedSearchDataFacade;
+import com.diagbot.util.BeanUtil;
+import com.diagbot.util.FastJsonUtils;
+import com.diagbot.util.ListUtil;
+import com.diagbot.util.RespDTOUtil;
+import com.diagbot.vo.IndicationPushVO;
+import com.google.common.collect.Lists;
+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.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2021/3/23 14:55
+ */
+@Component
+@Slf4j
+public class CallIndicationAggregate {
+    @Autowired
+    CdssCoreClient cdssCoreClient;
+    @Autowired
+    MedSearchDataFacade medSearchDataFacade;
+
+    @DataProvider("callIndication")
+    public List<ResultRule> callIndication(
+            @DataConsumer("callIndicationThread1") List<ResultRule> resultlist1,
+            @DataConsumer("callIndicationThread2") List<ResultRule> resultlist2,
+            @DataConsumer("callIndicationThread3") List<ResultRule> resultlist3,
+            @DataConsumer("callIndicationThread4") List<ResultRule> resultlist4) {
+
+        List<ResultRule> retList = Lists.newLinkedList();
+        if (ListUtil.isNotEmpty(resultlist1)) {
+            retList.addAll(resultlist1);
+        }
+        if (ListUtil.isNotEmpty(resultlist2)) {
+            retList.addAll(resultlist2);
+        }
+        if (ListUtil.isNotEmpty(resultlist3)) {
+            retList.addAll(resultlist3);
+        }
+        if (ListUtil.isNotEmpty(resultlist4)) {
+            retList.addAll(resultlist4);
+        }
+        return retList;
+    }
+
+    @DataProvider("callIndicationThread1")
+    public List<ResultRule> callIndicationThread1(@InvokeParameter("threadList1") List<ResultRule> threadList1,
+                                                  @InvokeParameter("hospitalId") Long hospitalId) {
+        return callIndicationExe(threadList1, hospitalId);
+    }
+
+    @DataProvider("callIndicationThread2")
+    public List<ResultRule> callIndicationThread2(@InvokeParameter("threadList2") List<ResultRule> threadList2,
+                                                  @InvokeParameter("hospitalId") Long hospitalId) {
+        return callIndicationExe(threadList2, hospitalId);
+    }
+
+    @DataProvider("callIndicationThread3")
+    public List<ResultRule> callIndicationThread3(@InvokeParameter("threadList3") List<ResultRule> threadList3,
+                                                  @InvokeParameter("hospitalId") Long hospitalId) {
+        return callIndicationExe(threadList3, hospitalId);
+    }
+
+    @DataProvider("callIndicationThread4")
+    public List<ResultRule> callIndicationThread4(@InvokeParameter("threadList4") List<ResultRule> threadList4,
+                                                  @InvokeParameter("hospitalId") Long hospitalId) {
+        return callIndicationExe(threadList4, hospitalId);
+    }
+
+    /**
+     * 开单合理性远程调用接口
+     *
+     * @param list
+     * @param hospitalId
+     * @return
+     */
+    public List<ResultRule> callIndicationExe(List<ResultRule> list, Long hospitalId) {
+        List<ResultRule> retList = Lists.newLinkedList();
+        if (ListUtil.isEmpty(list)) {
+            return retList;
+        }
+        Map<Long, List<ResultRule>> ruleMap = list
+                .stream()
+                .collect(Collectors.groupingBy(ResultRule::getRuleOrderNo));
+        for (Map.Entry<Long, List<ResultRule>> entry : ruleMap.entrySet()) {
+
+            if (entry.getValue().get(0).getSuccess() != null
+                    && entry.getValue().get(0).getSuccess().equals(0)) {
+                retList.addAll(entry.getValue());
+                continue;
+            }
+
+            Integer ruleType = entry.getValue().get(0).getRuleType();
+            IndicationPushVO indicationPushVO = medSearchDataFacade.createBillVO(entry.getValue(), hospitalId);
+
+            //入参
+            entry.getValue().forEach(result -> {
+                result.setInputParams(FastJsonUtils.getBeanToJson(indicationPushVO));
+            });
+
+            RespDTO<IndicationDTO> respDTO = cdssCoreClient.indication(indicationPushVO);
+            if (RespDTOUtil.respIsOK(respDTO)) {
+                IndicationDTO data = respDTO.data;
+                //出参
+                entry.getValue().forEach(result -> {
+                    result.setOutputParams(FastJsonUtils.getBeanToJson(respDTO.data));
+                });
+                List<BillMsg> msgList = Lists.newLinkedList();
+                switch (ruleType) {
+                    case 1:
+                    case 6:
+                        msgList = data.getBillMsgList();
+                        break;
+                    case 2:
+                        msgList = data.getHighRiskList();
+                        break;
+                    case 3:
+                        msgList = data.getCriticalValList();
+                        break;
+                    case 4:
+                    case 5:
+                        msgList = data.getOtherList();
+                        break;
+                    default:
+                        break;
+                }
+
+                if (ListUtil.isEmpty(msgList)) {
+                    entry.getValue().forEach(result -> {
+                        result.setSuccess(0);
+                        result.setMessage("提醒信息未出现");
+                        retList.add(result);
+                    });
+                    continue;
+                }
+
+                Boolean success = false;
+                for (BillMsg msg : msgList) {
+                    if (!msg.getMsg().equals(entry.getValue().get(0).getExpectedOutput())) {
+                        continue;
+                    } else {
+                        success = true;
+                    }
+                    for (ResultRule result : entry.getValue()) {
+                        ResultRule saveResult = new ResultRule();
+                        BeanUtil.copyProperties(result, saveResult);
+                        saveResult.setOutput(msg.getMsg());
+                        if (saveResult.getOutput().equals(saveResult.getExpectedOutput())) {
+                            saveResult.setSuccess(1);
+                        } else {
+                            saveResult.setSuccess(0);
+                            saveResult.setMessage("提示内容与预期不符");
+                        }
+                        retList.add(saveResult);
+                    }
+                }
+                if (!success) {
+                    for (ResultRule result : entry.getValue()) {
+                        Integer count = 1;
+                        result.setSuccess(0);
+                        result.setMessage(result.getMessage() + "提示内容("
+                                + (count++) + "、"
+                                + msgList.stream().map(i -> i.getMsg()).collect(Collectors.joining(";" + (count++) + "、"))
+                                + ")与预期不符");
+                        retList.add(result);
+                    }
+                }
+            } else {
+                for (ResultRule result : entry.getValue()) {
+                    result.setInputParams(FastJsonUtils.getBeanToJson(indicationPushVO));
+                    result.setSuccess(0);
+                    result.setMessage("远程调用推理接口失败");
+                    retList.add(result);
+                }
+            }
+        }
+        return retList;
+    }
+}

+ 40 - 101
cdssman-service/src/main/java/com/diagbot/aggregate/RuleTestAggregate.java

@@ -1,26 +1,20 @@
 package com.diagbot.aggregate;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.diagbot.client.CdssCoreClient;
-import com.diagbot.dto.BillMsg;
-import com.diagbot.dto.IndicationDTO;
-import com.diagbot.dto.RespDTO;
 import com.diagbot.entity.ResultInfo;
 import com.diagbot.entity.ResultRule;
 import com.diagbot.enums.IsDeleteEnum;
+import com.diagbot.exception.CommonErrorCode;
+import com.diagbot.exception.CommonException;
 import com.diagbot.facade.MedRuleConvertFacade;
-import com.diagbot.facade.MedSearchDataFacade;
 import com.diagbot.facade.RunningInfoFacade;
 import com.diagbot.service.ResultInfoService;
 import com.diagbot.service.ResultRuleService;
-import com.diagbot.util.BeanUtil;
-import com.diagbot.util.FastJsonUtils;
 import com.diagbot.util.ListUtil;
-import com.diagbot.util.RespDTOUtil;
-import com.diagbot.vo.IndicationPushVO;
 import com.diagbot.vo.RuleTestVO;
 import com.diagbot.vo.RunningInfoVO;
 import com.google.common.collect.Lists;
+import io.github.lvyahui8.spring.aggregate.facade.DataBeanAggregateQueryFacade;
 import io.github.lvyahui8.spring.annotation.DataConsumer;
 import io.github.lvyahui8.spring.annotation.DataProvider;
 import io.github.lvyahui8.spring.annotation.InvokeParameter;
@@ -31,6 +25,7 @@ import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -43,8 +38,6 @@ import java.util.stream.Collectors;
 @Component
 @Slf4j
 public class RuleTestAggregate {
-    @Autowired
-    private CdssCoreClient cdssCoreClient;
     @Autowired
     @Qualifier("resultRuleServiceImpl")
     private ResultRuleService resultRuleService;
@@ -56,7 +49,7 @@ public class RuleTestAggregate {
     @Autowired
     private MedRuleConvertFacade medRuleConvertFacade;
     @Autowired
-    private MedSearchDataFacade medSearchDataFacade;
+    private DataBeanAggregateQueryFacade dataBeanAggregateQueryFacade;
 
     @DataProvider("ruleTest")
     public Boolean ruleTest(
@@ -231,7 +224,6 @@ public class RuleTestAggregate {
         return true;
     }
 
-
     /**
      * 开单合理性远程调用接口
      *
@@ -244,101 +236,48 @@ public class RuleTestAggregate {
         if (ListUtil.isEmpty(list)) {
             return retList;
         }
+
         Map<Long, List<ResultRule>> ruleMap = list
                 .stream()
                 .collect(Collectors.groupingBy(ResultRule::getRuleOrderNo));
-        for (Map.Entry<Long, List<ResultRule>> entry : ruleMap.entrySet()) {
-
-            if (entry.getValue().get(0).getSuccess() != null
-                    && entry.getValue().get(0).getSuccess().equals(0)) {
-                retList.addAll(entry.getValue());
-                continue;
-            }
-
-            Integer ruleType = entry.getValue().get(0).getRuleType();
-            IndicationPushVO indicationPushVO = medSearchDataFacade.createBillVO(entry.getValue(),hospitalId);
-
-            //入参
-            entry.getValue().forEach(result -> {
-                result.setInputParams(FastJsonUtils.getBeanToJson(indicationPushVO));
-            });
-
-            RespDTO<IndicationDTO> respDTO = cdssCoreClient.indication(indicationPushVO);
-            if (RespDTOUtil.respIsOK(respDTO)) {
-                IndicationDTO data = respDTO.data;
-                //出参
-                entry.getValue().forEach(result -> {
-                    result.setOutputParams(FastJsonUtils.getBeanToJson(respDTO.data));
-                });
-                List<BillMsg> msgList = Lists.newLinkedList();
-                switch (ruleType) {
-                    case 1:
-                    case 6:
-                        msgList = data.getBillMsgList();
-                        break;
-                    case 2:
-                        msgList = data.getHighRiskList();
-                        break;
-                    case 3:
-                        msgList = data.getCriticalValList();
-                        break;
-                    case 4:
-                    case 5:
-                        msgList = data.getOtherList();
-                        break;
-                    default:
-                        break;
-                }
-
-                if (ListUtil.isEmpty(msgList)) {
-                    entry.getValue().forEach(result -> {
-                        result.setSuccess(0);
-                        result.setMessage("提醒信息未出现");
-                        retList.add(result);
-                    });
-                    continue;
-                }
 
-                Boolean success = false;
-                for (BillMsg msg : msgList) {
-                    if (!msg.getMsg().equals(entry.getValue().get(0).getExpectedOutput())) {
-                        continue;
-                    } else {
-                        success = true;
-                    }
-                    for (ResultRule result : entry.getValue()) {
-                        ResultRule saveResult = new ResultRule();
-                        BeanUtil.copyProperties(result, saveResult);
-                        saveResult.setOutput(msg.getMsg());
-                        if (saveResult.getOutput().equals(saveResult.getExpectedOutput())) {
-                            saveResult.setSuccess(1);
-                        } else {
-                            saveResult.setSuccess(0);
-                            saveResult.setMessage("提示内容与预期不符");
-                        }
-                        retList.add(saveResult);
-                    }
-                }
-                if (!success) {
-                    for (ResultRule result : entry.getValue()) {
-                        Integer count = 1;
-                        result.setSuccess(0);
-                        result.setMessage(result.getMessage() + "提示内容("
-                                + (count++) + "、"
-                                + msgList.stream().map(i -> i.getMsg()).collect(Collectors.joining(";" + (count++) + "、"))
-                                + ")与预期不符");
-                        retList.add(result);
-                    }
-                }
-            } else {
-                for (ResultRule result : entry.getValue()) {
-                    result.setInputParams(FastJsonUtils.getBeanToJson(indicationPushVO));
-                    result.setSuccess(0);
-                    result.setMessage("远程调用推理接口失败");
-                    retList.add(result);
+        List<ResultRule> threadList1 = Lists.newLinkedList();
+        List<ResultRule> threadList2 = Lists.newLinkedList();
+        List<ResultRule> threadList3 = Lists.newLinkedList();
+        List<ResultRule> threadList4 = Lists.newLinkedList();
+
+        if (ruleMap.size() >= 100) {
+            Integer averageNum = ruleMap.size() / 4;
+            Integer count = 0;
+            for (Map.Entry<Long, List<ResultRule>> entry : ruleMap.entrySet()) {
+                count++;
+                if (count < averageNum) {
+                    threadList1.addAll(entry.getValue());
+                } else if (count >= averageNum && count < averageNum * 2) {
+                    threadList2.addAll(entry.getValue());
+                } else if (count >= averageNum * 2 && count < averageNum * 3) {
+                    threadList3.addAll(entry.getValue());
+                } else if (count >= averageNum * 3) {
+                    threadList4.addAll(entry.getValue());
                 }
             }
+        } else {
+            threadList1.addAll(list);
+        }
+
+        try {
+            Map<String, Object> invokeParams = new HashMap<>();
+            invokeParams.put("threadList1", threadList1);
+            invokeParams.put("threadList2", threadList2);
+            invokeParams.put("threadList3", threadList3);
+            invokeParams.put("threadList4", threadList4);
+            invokeParams.put("hospitalId", hospitalId);
+            retList
+                    = dataBeanAggregateQueryFacade.get("callIndication", invokeParams, List.class);
+        } catch (Exception e) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR);
         }
+
         return retList;
     }