|
@@ -1,14 +1,20 @@
|
|
|
package com.sundata.internalevaluation.calc.calcUnit;
|
|
|
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.sundata.internalevaluation.calc.model.CalcResult;
|
|
|
import com.sundata.internalevaluation.calc.model.CalcUnit;
|
|
|
import com.sundata.internalevaluation.calc.model.finals.CalcType;
|
|
|
+import com.sundata.internalevaluation.configuration.model.SysReqRule;
|
|
|
+import com.sundata.internalevaluation.configuration.model.SysReqRules;
|
|
|
+import com.sundata.internalevaluation.configuration.service.SysReqRuleService;
|
|
|
+import com.sundata.internalevaluation.configuration.service.SysReqRulesService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -23,6 +29,15 @@ public class RulesCalcUnit extends CalcUnit {
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(RulesCalcUnit.class);
|
|
|
|
|
|
+ /**
|
|
|
+ * 规则集实体
|
|
|
+ */
|
|
|
+ private final SysReqRules reqRules;
|
|
|
+
|
|
|
+
|
|
|
+ private final SysReqRuleService sysReqRuleService;
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 创建数据单元的绝对对象,对象必须包含如下参数
|
|
|
*
|
|
@@ -30,8 +45,12 @@ public class RulesCalcUnit extends CalcUnit {
|
|
|
* @param calcName 计算对象名称
|
|
|
* @param initContext 计算单元初始化参数
|
|
|
*/
|
|
|
- public RulesCalcUnit(String calcCode, String calcName, Map<String, Object> initContext) {
|
|
|
+ public RulesCalcUnit(String calcCode, String calcName, Map<String, Object> initContext, SysReqRules reqRules, SysReqRuleService sysReqRuleService) {
|
|
|
super(calcCode, calcName, CalcType.RULES, initContext);
|
|
|
+
|
|
|
+ this.reqRules = reqRules;
|
|
|
+
|
|
|
+ this.sysReqRuleService = sysReqRuleService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -73,6 +92,8 @@ public class RulesCalcUnit extends CalcUnit {
|
|
|
// );
|
|
|
}
|
|
|
|
|
|
+ private List<SysReqRule> sysReqRuleList = new ArrayList<>();
|
|
|
+
|
|
|
/**
|
|
|
* 根据节点配置获取源节点;
|
|
|
*
|
|
@@ -80,13 +101,11 @@ public class RulesCalcUnit extends CalcUnit {
|
|
|
*/
|
|
|
@Override
|
|
|
public List<CalcUnit> getSourceCalcUnits() {
|
|
|
- // TODO 获取源头节点
|
|
|
+ List<SysReqRule> sysReqRules = sysReqRuleService.selectRuleListByRulesNo(reqRules.getRulesNo());
|
|
|
+ return sysReqRules.stream()
|
|
|
+ .map(rule-> new RuleCalcUnit(rule.getRuleNo(),rule.getRuleName(),
|
|
|
+ CalcType.RULE, Map.of("age",15), rule)).collect(Collectors.toList());
|
|
|
|
|
|
-// SpringUtil.
|
|
|
-
|
|
|
-
|
|
|
- return new ArrayList<>();
|
|
|
-// return ConfigImages.rulesCalcUnitListMap.get(this);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -117,25 +136,38 @@ public class RulesCalcUnit extends CalcUnit {
|
|
|
* @param sourceResults 源头计算节点的结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public void calc(final CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
|
|
|
- // Map<CalcUnit, CalcResult<String, Object>> sourceResults
|
|
|
-
|
|
|
- // TODO 实际的计算过程
|
|
|
-
|
|
|
- // 规则集 RULES-MAIN
|
|
|
-// sourceResults.forEach((a,b)->{
|
|
|
-//
|
|
|
-// if (a.getCalcCode().equals("RULE001")){
|
|
|
-// System.out.println(b);
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (b.get(a.getCalcCode()).equals("触发预警规则")) {
|
|
|
-// thisResult.put(this.getCalcCode(),"规则集拦截");
|
|
|
-// }
|
|
|
-// if (thisResult.isEmpty()){
|
|
|
-// thisResult.put(this.getCalcCode(),"规则集未拦截");
|
|
|
-// }
|
|
|
-// });
|
|
|
-
|
|
|
+ public void calc(final CalcResult<String, Object> thisResult,
|
|
|
+ String calculateInstanceNumber,
|
|
|
+ Map<String, Object> context,
|
|
|
+ Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
|
|
|
+
|
|
|
+ Map<Object, List<CalcUnit>> collect = sourceResults.entrySet().stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ s -> s.getValue().get(s.getKey().getCalcCode()),
|
|
|
+ Collectors.mapping(Map.Entry::getKey, Collectors.toList()))
|
|
|
+ );
|
|
|
+
|
|
|
+ List<CalcUnit> intercept = collect.get("intercept");
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ if (intercept != null && !intercept.isEmpty()) {
|
|
|
+ sb.append("触发拦截规则:\n");
|
|
|
+ intercept.forEach(a -> {
|
|
|
+ sb.append(" ·").append(a.getCalcCode()).append("-").append(a.getCalcName()).append("\n");
|
|
|
+ });
|
|
|
+ thisResult.put(this.getCalcCode(),sb.toString());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CalcUnit> warn = collect.get("warn");
|
|
|
+ if (warn != null && !warn.isEmpty()) {
|
|
|
+ sb.append("触发预警规则:\n");
|
|
|
+ warn.forEach(a -> {
|
|
|
+ sb.append(" ·").append(a.getCalcCode()).append("-").append(a.getCalcName()).append("\n");
|
|
|
+ });
|
|
|
+ thisResult.put(this.getCalcCode(),sb.toString());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ thisResult.put(this.getCalcCode(),"规则集未拦截");
|
|
|
}
|
|
|
}
|