Browse Source

优化代码

zhoutg 4 years ago
parent
commit
0bcb501a58

+ 23 - 17
src/main/java/com/diagbot/facade/KlRegularConfigFacade.java

@@ -13,10 +13,12 @@ import com.diagbot.exception.CommonException;
 import com.diagbot.model.entity.AllergyMedicine;
 import com.diagbot.model.label.PastLabel;
 import com.diagbot.service.impl.KlRegularConfigServiceImpl;
+import com.diagbot.util.EntityUtil;
 import com.diagbot.util.ListUtil;
+import com.diagbot.util.StringUtil;
 import com.diagbot.vo.IndicationPushVO;
-import com.diagbot.vo.RegularConfigDataVO;
 import com.diagbot.vo.RegularConfigSaveVO;
+import com.google.common.collect.Lists;
 import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
@@ -32,13 +34,11 @@ import java.util.regex.Pattern;
 @Component
 public class KlRegularConfigFacade extends KlRegularConfigServiceImpl {
 
-    public List<RegularValueDTO> getRegularConfigDatas(RegularConfigDataVO regularConfigDataVO) {
+    public List<RegularValueDTO> getRegularConfigDatas(String text, List<KlRegularConfig> regularConfigs) {
         List<RegularValueDTO> listData = new ArrayList<>();
-        QueryWrapper<KlRegularConfig> regularQuery = new QueryWrapper<>();
-        regularQuery.eq("is_deleted", IsDeleteEnum.N.getKey())
-                .eq(regularConfigDataVO.getRulesCode() != null, "rules_code", regularConfigDataVO.getRulesCode())
-                .eq(regularConfigDataVO.getRulesTepy() != null, "rules_tepy", regularConfigDataVO.getRulesTepy());
-        List<KlRegularConfig> regularConfigs = list(regularQuery);
+        if (StringUtil.isBlank(text)) {
+            return Lists.newArrayList();
+        }
         if (ListUtil.isNotEmpty(regularConfigs)) {
             for (KlRegularConfig data : regularConfigs) {
                 String pattern = "";
@@ -52,7 +52,7 @@ public class KlRegularConfigFacade extends KlRegularConfigServiceImpl {
                 // 创建 Pattern 对象
                 Pattern r = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
                 // 现在创建 matcher 对象
-                Matcher m = r.matcher(regularConfigDataVO.getText());
+                Matcher m = r.matcher(text);
                 int trueMin = 0;
                 while (m.find()) {
                     //System.out.println(m.group());
@@ -77,7 +77,7 @@ public class KlRegularConfigFacade extends KlRegularConfigServiceImpl {
                 if (data.getRulesTepy().equals(RegularConfigEnum.allergy.getKey())) {
                     Pattern rMax = Pattern.compile(patternMax, Pattern.CASE_INSENSITIVE);
                     // 现在创建 matcher 对象
-                    Matcher mMax = rMax.matcher(regularConfigDataVO.getText());
+                    Matcher mMax = rMax.matcher(text);
                     while (mMax.find()) {
                         if (data.getRulesTepy().equals(RegularConfigEnum.allergy.getKey())) {
                             trueMax++;
@@ -108,9 +108,16 @@ public class KlRegularConfigFacade extends KlRegularConfigServiceImpl {
     public WordCrfDTO getRegularConfigs(WordCrfDTO wordCrfDTO, IndicationPushVO indicationPushVO) {
         String allergyStr = indicationPushVO.getAllergy();
         String symptom = wordCrfDTO.getSymptom();//现病史
-        RegularConfigDataVO regularConfigData = new RegularConfigDataVO();
-        regularConfigData.setText(symptom);
-        List<RegularValueDTO> regularConfigDatas = getRegularConfigDatas(regularConfigData);
+        String pasts = wordCrfDTO.getPasts();//既往史
+        if (StringUtil.isBlank(symptom) && StringUtil.isBlank(pasts)) {
+            return wordCrfDTO;
+        }
+
+        // 现病史化验和过敏史
+        QueryWrapper<KlRegularConfig> regularQuery = new QueryWrapper<>();
+        regularQuery.eq("is_deleted", IsDeleteEnum.N.getKey());
+        List<KlRegularConfig> regularConfigs = list(regularQuery);
+        List<RegularValueDTO> regularConfigDatas = getRegularConfigDatas(symptom, regularConfigs);
         List<Lis> lisData = wordCrfDTO.getLis();
         PastLabel pastLabel = wordCrfDTO.getPastLabel();//获取过敏史数据
         List<AllergyMedicine> allergies = pastLabel.getAllergyMedicines();
@@ -133,11 +140,10 @@ public class KlRegularConfigFacade extends KlRegularConfigServiceImpl {
                 }
             }
         }
-        String pasts = wordCrfDTO.getPasts();//既往史
-        RegularConfigDataVO regularConfigPasts = new RegularConfigDataVO();
-        regularConfigData.setText(pasts);
-        regularConfigData.setRulesTepy(RegularConfigEnum.allergy.getKey());
-        List<RegularValueDTO> regularConfigPastss = getRegularConfigDatas(regularConfigData);
+
+        // 既往史过敏史
+        List<RegularValueDTO> regularConfigPastss = getRegularConfigDatas(pasts,
+                EntityUtil.makeEntityListMap(regularConfigs, "rulesTepy").get(RegularConfigEnum.allergy.getKey()));
         if (ListUtil.isNotEmpty(regularConfigPastss)) {
             for (RegularValueDTO dataPasts : regularConfigPastss) {
                 AllergyMedicine allergy = new AllergyMedicine();

+ 11 - 1
src/main/java/com/diagbot/web/KlRegularConfigController.java

@@ -1,8 +1,11 @@
 package com.diagbot.web;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.diagbot.dto.RegularValueDTO;
 import com.diagbot.dto.RespDTO;
+import com.diagbot.entity.KlRegularConfig;
+import com.diagbot.enums.IsDeleteEnum;
 import com.diagbot.facade.KlRegularConfigFacade;
 import com.diagbot.vo.RegularConfigDataVO;
 import com.diagbot.vo.RegularConfigSaveVO;
@@ -35,11 +38,18 @@ public class KlRegularConfigController {
     @Autowired
     KlRegularConfigFacade klRegularConfigFacade;
 
+
     @ApiOperation(value = "从文本中取出化验相应正则数据",
             notes = "从文本中取出化验相应正则数据")
     @PostMapping("/getRegularConfigData")
     public RespDTO<List<RegularValueDTO>> getRegularConfigData(@Valid @RequestBody RegularConfigDataVO regularConfigDataVO) {
-        List<RegularValueDTO> data = klRegularConfigFacade.getRegularConfigDatas(regularConfigDataVO);
+        // 现病史化验和过敏史
+        QueryWrapper<KlRegularConfig> regularQuery = new QueryWrapper<>();
+        regularQuery.eq("is_deleted", IsDeleteEnum.N.getKey())
+        .eq(regularConfigDataVO.getRulesCode() != null, "rules_code", regularConfigDataVO.getRulesCode())
+                .eq(regularConfigDataVO.getRulesTepy() != null, "rules_tepy", regularConfigDataVO.getRulesTepy());
+        List<KlRegularConfig> regularConfigs = klRegularConfigFacade.list(regularQuery);
+        List<RegularValueDTO> data = klRegularConfigFacade.getRegularConfigDatas(regularConfigDataVO.getText(), regularConfigs);
         return RespDTO.onSuc(data);
     }