|
@@ -1,11 +1,16 @@
|
|
|
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;
|
|
|
+import com.diagbot.vo.RuleBaseQueryVO;
|
|
|
import com.diagbot.dto.RuleConditionDTO;
|
|
|
import com.diagbot.dto.RuleConditionInitDTO;
|
|
|
import com.diagbot.dto.RuleDTO;
|
|
|
+import com.diagbot.dto.RuleIdDTO;
|
|
|
import com.diagbot.dto.RuleInitDTO;
|
|
|
+import com.diagbot.entity.KlRuleSearch;
|
|
|
import com.diagbot.enums.BaseTypeEnum;
|
|
|
import com.diagbot.enums.LexiconEnum;
|
|
|
import com.diagbot.enums.RedisEnum;
|
|
@@ -13,21 +18,26 @@ 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;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description:
|
|
@@ -41,16 +51,23 @@ public class RuleAggregate {
|
|
|
private KlRuleFacade klRuleFacade;
|
|
|
@Autowired
|
|
|
private RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("klRuleSearchServiceImpl")
|
|
|
+ private KlRuleSearchService klRuleSearchService;
|
|
|
|
|
|
@DataProvider("getAllRules")
|
|
|
- public Map<String, RuleDTO> getAllRules(
|
|
|
+ public AllRulesDTO getAllRules(
|
|
|
@DataConsumer("getRuleInit") Map<String, List<RuleInitDTO>> ruleInits,
|
|
|
@DataConsumer("getRuleConditionInit") Map<Integer, Map<String, List<RuleConditionInitDTO>>> ruleConditionInits,
|
|
|
@DataConsumer("getRuleBaseInit") Map<Integer, List<RuleBaseInitDTO>> ruleBaseInits) {
|
|
|
try {
|
|
|
- Map<String, RuleDTO> res = new HashMap();
|
|
|
+ //有效规则Map
|
|
|
+ Map<String, RuleDTO> ruleDTOMap = new HashMap();
|
|
|
//药物过敏源
|
|
|
Map<String, Integer> drugAllergen = new HashMap<>();
|
|
|
+ //规则搜索有效的规则ID
|
|
|
+ HashSet<Long> ruleIdSet = new HashSet<>();
|
|
|
+ List<KlRuleSearch> klRuleSearchList = new ArrayList<>();
|
|
|
//结果判空第一层规则类型
|
|
|
if (MapUtils.isNotEmpty(ruleInits)) {
|
|
|
for (String ruleKey : ruleInits.keySet()) {
|
|
@@ -74,6 +91,7 @@ public class RuleAggregate {
|
|
|
for (String ruleGroup : map.keySet()) {
|
|
|
RuleConditionDTO ruleConditionDTO = new RuleConditionDTO();
|
|
|
ruleConditionDTO.setHasSubCond(ruleInitDTO.getHasSubCond());
|
|
|
+ ruleConditionDTO.setDescription(ruleInitDTO.getDescription());
|
|
|
ruleConditionDTO.setRuleGroup(ruleGroup);
|
|
|
//结果判空第三层条件明细
|
|
|
if (ListUtil.isNotEmpty(map.get(ruleGroup))) {
|
|
@@ -98,6 +116,7 @@ public class RuleAggregate {
|
|
|
RuleConditionDTO ruleConditionDTO1 = new RuleConditionDTO();
|
|
|
ruleConditionDTO1.setHasSubCond(ruleConditionDTO.getHasSubCond());
|
|
|
ruleConditionDTO1.setRuleGroup(ruleConditionDTO.getRuleGroup());
|
|
|
+ ruleConditionDTO1.setDescription(ruleConditionDTO.getDescription());
|
|
|
ruleConditionDTO1.setMsg(ruleConditionDTO.getMsg());
|
|
|
ruleConditionDTO1.getRuleBaseDTOList().addAll(ruleBaseDTOList);
|
|
|
if (!ruleConditionMap.containsKey(ruleConditionDTO1.toString())) {
|
|
@@ -115,6 +134,13 @@ public class RuleAggregate {
|
|
|
}
|
|
|
}
|
|
|
ruleConditionMap.put(ruleConditionDTO1.toString(), 1);
|
|
|
+ //规则搜索有效的规则ID
|
|
|
+ if (!ruleIdSet.contains(ruleInitDTO.getRuleId())) {
|
|
|
+ ruleIdSet.add(ruleInitDTO.getRuleId());
|
|
|
+ KlRuleSearch klRuleSearch = new KlRuleSearch();
|
|
|
+ klRuleSearch.setId(ruleInitDTO.getRuleId());
|
|
|
+ klRuleSearchList.add(klRuleSearch);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -123,6 +149,7 @@ public class RuleAggregate {
|
|
|
} else {
|
|
|
RuleConditionDTO ruleConditionDTO = new RuleConditionDTO();
|
|
|
ruleConditionDTO.setHasSubCond(ruleInitDTO.getHasSubCond());
|
|
|
+ ruleConditionDTO.setDescription(ruleInitDTO.getDescription());
|
|
|
ruleConditionDTO.setMsg(ruleInitDTO.getMsg());
|
|
|
//无条件
|
|
|
ruleConditionDTO.setRuleGroup(ruleInitDTO.getRuleId() + "-1");
|
|
@@ -130,17 +157,25 @@ public class RuleAggregate {
|
|
|
if (!ruleConditionMap.containsKey(ruleConditionDTO.toString())) {
|
|
|
ruleDTO.getRuleConditionDTOList().add(ruleConditionDTO);
|
|
|
ruleConditionMap.put(ruleConditionDTO.toString(), 1);
|
|
|
+ //规则搜索有效的规则ID
|
|
|
+ if (!ruleIdSet.contains(ruleInitDTO.getRuleId())) {
|
|
|
+ ruleIdSet.add(ruleInitDTO.getRuleId());
|
|
|
+ KlRuleSearch klRuleSearch = new KlRuleSearch();
|
|
|
+ klRuleSearch.setId(ruleInitDTO.getRuleId());
|
|
|
+ klRuleSearchList.add(klRuleSearch);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- res.put(RedisEnum.allRule.getName() + ruleDTO.getLibType() + "_" + ruleDTO.getLibName() + "_" + ruleDTO.getRuleType(), ruleDTO);
|
|
|
- }
|
|
|
- //直接加载缓存
|
|
|
- if (MapUtils.isNotEmpty(drugAllergen)) {
|
|
|
- redisUtil.set(RedisEnum.drugAllergen.getName(), drugAllergen);
|
|
|
+ ruleDTOMap.put(RedisEnum.allRule.getName() + ruleDTO.getLibType() + "_" + ruleDTO.getLibName() + "_" + ruleDTO.getRuleType(), ruleDTO);
|
|
|
}
|
|
|
}
|
|
|
- return res;
|
|
|
+ //出参设置
|
|
|
+ AllRulesDTO allRulesDTO = new AllRulesDTO();
|
|
|
+ allRulesDTO.setRuleDTOMap(ruleDTOMap);
|
|
|
+ allRulesDTO.setDrugAllergen(drugAllergen);
|
|
|
+ allRulesDTO.setKlRuleSearchList(klRuleSearchList);
|
|
|
+ return allRulesDTO;
|
|
|
} catch (Exception e) {
|
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "全部规则加载出错:" + e.getMessage());
|
|
|
}
|
|
@@ -167,18 +202,18 @@ public class RuleAggregate {
|
|
|
// }
|
|
|
|
|
|
@DataProvider("getRuleConditionInit")
|
|
|
- public Map<Integer, Map<String, List<RuleConditionInitDTO>>> getRuleConditionInit() {
|
|
|
+ public Map<Long, Map<String, List<RuleConditionInitDTO>>> getRuleConditionInit() {
|
|
|
List<RuleConditionInitDTO> list = klRuleFacade.getRuleConditionInitDTO();
|
|
|
- Map<Integer, List<RuleConditionInitDTO>> map = EntityUtil.makeEntityListMap(list, "ruleId");
|
|
|
- Map<Integer, Map<String, List<RuleConditionInitDTO>>> res = new HashMap<>();
|
|
|
- for (Integer ruleId : map.keySet()) {
|
|
|
+ Map<Long, List<RuleConditionInitDTO>> map = EntityUtil.makeEntityListMap(list, "ruleId");
|
|
|
+ Map<Long, Map<String, List<RuleConditionInitDTO>>> res = new HashMap<>();
|
|
|
+ for (Long ruleId : map.keySet()) {
|
|
|
res.put(ruleId, EntityUtil.makeEntityListMap(map.get(ruleId), "ruleGroup"));
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
@DataProvider("getRuleBaseInit")
|
|
|
- public Map<Integer, List<RuleBaseInitDTO>> getRuleBaseInit(
|
|
|
+ public Map<Long, List<RuleBaseInitDTO>> getRuleBaseInit(
|
|
|
@DataConsumer("getRuleBaseInitNotHaveClass") List<RuleBaseInitDTO> ruleBaseNotHaveClass,
|
|
|
@DataConsumer("getRuleBaseInitHaveClass") List<RuleBaseInitDTO> ruleBaseHaveClass) {
|
|
|
List<RuleBaseInitDTO> list = new ArrayList<>();
|
|
@@ -246,6 +281,70 @@ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @DataProvider("getAllRuleIds")
|
|
|
+ public List<Long> setAllRules(
|
|
|
+ @InvokeParameter("ruleBaseQueryVO") RuleBaseQueryVO ruleBaseQueryVO,
|
|
|
+ @DataConsumer("getRuleNotHaveClass") List<RuleIdDTO> notHaveClassRuleIds,
|
|
|
+ @DataConsumer("getRuleHaveClass") List<RuleIdDTO> haveClassRuleIds) {
|
|
|
+ List<Long> ruleIds = new ArrayList<>();
|
|
|
+ if (ListUtil.isNotEmpty(notHaveClassRuleIds)){
|
|
|
+ ruleIds.addAll(notHaveClassRuleIds.stream().map(RuleIdDTO::getRuleId).distinct().collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ if (ListUtil.isNotEmpty(haveClassRuleIds)){
|
|
|
+ ruleIds.addAll(haveClassRuleIds.stream().map(RuleIdDTO::getRuleId).distinct().collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ if (ListUtil.isEmpty(ruleIds)){
|
|
|
+ ruleIds.add(-1000L);
|
|
|
+ }
|
|
|
+ return ruleIds;
|
|
|
+ }
|
|
|
+ @DataProvider("getRuleNotHaveClass")
|
|
|
+ public List<RuleIdDTO> getRuleNotHaveClass( @InvokeParameter("ruleBaseQueryVO") RuleBaseQueryVO ruleBaseQueryVO){
|
|
|
+ return klRuleFacade.getRuleNotHaveClass(ruleBaseQueryVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @DataProvider("getRuleHaveClass")
|
|
|
+ public List<RuleIdDTO> getRuleHaveClass( @InvokeParameter("ruleBaseQueryVO") RuleBaseQueryVO ruleBaseQueryVO){
|
|
|
+ return klRuleFacade.getRuleHaveClass(ruleBaseQueryVO);
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
List<List<RuleBaseDTO>> ruleBaseList = new ArrayList<>();
|
|
|
List<RuleBaseDTO> ruleBaseDTOListA = new ArrayList<>();
|