|
@@ -0,0 +1,110 @@
|
|
|
+package com.diagbot.aggregate;
|
|
|
+
|
|
|
+import com.diagbot.dto.RuleBaseDTO;
|
|
|
+import com.diagbot.dto.RuleBaseInitDTO;
|
|
|
+import com.diagbot.dto.RuleConditionDTO;
|
|
|
+import com.diagbot.dto.RuleConditionInitDTO;
|
|
|
+import com.diagbot.dto.RuleDTO;
|
|
|
+import com.diagbot.dto.RuleInitDTO;
|
|
|
+import com.diagbot.enums.RedisEnum;
|
|
|
+import com.diagbot.facade.KlRuleFacade;
|
|
|
+import com.diagbot.util.BeanUtil;
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import io.github.lvyahui8.spring.annotation.DataConsumer;
|
|
|
+import io.github.lvyahui8.spring.annotation.DataProvider;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections.MapUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @author: gaodm
|
|
|
+ * @time: 2021/5/31 17:14
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class RuleAggregate {
|
|
|
+ @Autowired
|
|
|
+ private KlRuleFacade klRuleFacade;
|
|
|
+
|
|
|
+ @DataProvider("getAllRules")
|
|
|
+ public Map<String, RuleDTO> getAllRules(
|
|
|
+ @DataConsumer("getRuleInit") Map<String, List<RuleInitDTO>> ruleInits,
|
|
|
+ @DataConsumer("getRuleConditionInit") Map<Integer, Map<String, List<RuleConditionInitDTO>>> ruleConditionInits,
|
|
|
+ @DataConsumer("getRuleBaseInit") Map<Integer, RuleBaseInitDTO> ruleBaseInits) {
|
|
|
+ Map<String, RuleDTO> res = new HashMap();
|
|
|
+ //结果判空第一层规则类型
|
|
|
+ if (MapUtils.isNotEmpty(ruleInits)) {
|
|
|
+ for (String ruleKey : ruleInits.keySet()) {
|
|
|
+ RuleInitDTO ruleInitZeroDTO = ruleInits.get(ruleKey).get(0);
|
|
|
+ RuleDTO ruleDTO = new RuleDTO();
|
|
|
+ ruleDTO.setLibName(ruleInitZeroDTO.getLibName());
|
|
|
+ ruleDTO.setLibType(ruleInitZeroDTO.getLibType());
|
|
|
+ ruleDTO.setRuleType(ruleInitZeroDTO.getRuleType());
|
|
|
+ for (RuleInitDTO ruleInitDTO : ruleInits.get(ruleKey)) {
|
|
|
+ if (ruleInitDTO.getHasSubCond().equals(1)) {
|
|
|
+ Map<String, List<RuleConditionInitDTO>> map = ruleConditionInits.get(ruleInitDTO.getRuleId());
|
|
|
+ //结果判空第二层条件组别
|
|
|
+ if (MapUtils.isNotEmpty(map)) {
|
|
|
+ for (String key : map.keySet()) {
|
|
|
+ RuleConditionDTO ruleConditionDTO = new RuleConditionDTO();
|
|
|
+ ruleConditionDTO.setHasSubCond(ruleInitDTO.getHasSubCond());
|
|
|
+ ruleConditionDTO.setMsg(ruleInitDTO.getMsg());
|
|
|
+ ruleConditionDTO.setRuleGroup(key);
|
|
|
+ //结果判空第三层条件明细
|
|
|
+ if (ListUtil.isNotEmpty(map.get(key))) {
|
|
|
+ for (RuleConditionInitDTO ruleConditionInitDTO : map.get(key)) {
|
|
|
+ RuleBaseDTO ruleBaseDTO = new RuleBaseDTO();
|
|
|
+ BeanUtil.copyProperties(ruleBaseInits.get(ruleConditionInitDTO.getRuleBaseId()), ruleBaseDTO);
|
|
|
+ ruleConditionDTO.getRuleBaseDTOList().add(ruleBaseDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ruleDTO.getRuleConditionDTOList().add(ruleConditionDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ RuleConditionDTO ruleConditionDTO = new RuleConditionDTO();
|
|
|
+ ruleConditionDTO.setHasSubCond(ruleInitDTO.getHasSubCond());
|
|
|
+ ruleConditionDTO.setMsg(ruleInitDTO.getMsg());
|
|
|
+ //无条件
|
|
|
+ ruleConditionDTO.setRuleGroup(ruleInitDTO.getRuleId() + "-1");
|
|
|
+ ruleConditionDTO.getRuleBaseDTOList().add(new RuleBaseDTO());
|
|
|
+ ruleDTO.getRuleConditionDTOList().add(ruleConditionDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res.put(RedisEnum.allRule.getName() + ruleDTO.getLibType() + "_" + ruleDTO.getLibName() + "_" + ruleDTO.getRuleType(), ruleDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @DataProvider("getRuleInit")
|
|
|
+ public Map<String, List<RuleInitDTO>> getRuleInit() {
|
|
|
+ List<RuleInitDTO> list = klRuleFacade.getRuleInitDTO();
|
|
|
+ return EntityUtil.makeEntityListMap(list, "conceptGroup");
|
|
|
+ }
|
|
|
+
|
|
|
+ @DataProvider("getRuleConditionInit")
|
|
|
+ public Map<Integer, 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 key : map.keySet()) {
|
|
|
+ res.put(key, EntityUtil.makeEntityListMap(map.get(key), "ruleGroup"));
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @DataProvider("getRuleBaseInit")
|
|
|
+ public Map<Integer, RuleBaseInitDTO> getRuleBaseInit() {
|
|
|
+ List<RuleBaseInitDTO> list = klRuleFacade.getRuleBaseInitDTO();
|
|
|
+ return EntityUtil.makeEntityMap(list, "ruleBaseId");
|
|
|
+ }
|
|
|
+}
|