|
|
|
@ -0,0 +1,256 @@
|
|
|
|
|
package com.supervision.demo;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.supervision.common.utils.StringUtils;
|
|
|
|
|
import com.supervision.constant.JudgeResultEnum;
|
|
|
|
|
import com.supervision.police.dto.AtomicData;
|
|
|
|
|
import com.supervision.police.dto.JudgeLogic;
|
|
|
|
|
import com.supervision.police.dto.indexRule.Operand;
|
|
|
|
|
import com.supervision.police.dto.indexRule.OperandUnit;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class JudgeLogicTest {
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void dataDemo() {
|
|
|
|
|
List<JudgeLogic> judgeLogics = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JudgeLogic judgeLogic = new JudgeLogic();
|
|
|
|
|
judgeLogic.setGroupLogic("1");
|
|
|
|
|
judgeLogic.setRowLogic("1");
|
|
|
|
|
|
|
|
|
|
List<AtomicData> atomicDataList = new ArrayList<>();
|
|
|
|
|
AtomicData atomicData1 = new AtomicData();
|
|
|
|
|
atomicData1.setAtomicIndex("1");
|
|
|
|
|
atomicData1.setRelationalSymbol("1");
|
|
|
|
|
|
|
|
|
|
AtomicData atomicData2 = new AtomicData();
|
|
|
|
|
atomicData2.setAtomicIndex("2");
|
|
|
|
|
atomicData2.setRelationalSymbol("2");
|
|
|
|
|
atomicData2.setRowLogic("2");
|
|
|
|
|
OperandUnit operandUnit = new OperandUnit();
|
|
|
|
|
Operand leftOperand = new Operand();
|
|
|
|
|
leftOperand.setPropertyKey("合同金额");
|
|
|
|
|
leftOperand.setAggregateType("1");
|
|
|
|
|
|
|
|
|
|
Operand operand = new Operand();
|
|
|
|
|
operand.setAtomicIndexId("22");
|
|
|
|
|
operand.setPropertyKey("合同金额");
|
|
|
|
|
operand.setAggregateType("1");
|
|
|
|
|
|
|
|
|
|
operandUnit.setLeftOperand(leftOperand);
|
|
|
|
|
operandUnit.setRightOperand(operand);
|
|
|
|
|
operandUnit.setOperator(">");
|
|
|
|
|
|
|
|
|
|
atomicData2.setOperandUnitList(List.of(operandUnit));
|
|
|
|
|
|
|
|
|
|
atomicDataList.add(atomicData1);
|
|
|
|
|
atomicDataList.add(atomicData2);
|
|
|
|
|
|
|
|
|
|
judgeLogic.setAtomicData(atomicDataList);
|
|
|
|
|
|
|
|
|
|
judgeLogics.add(judgeLogic);
|
|
|
|
|
|
|
|
|
|
System.out.println(JSONUtil.toJsonStr(judgeLogics));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static boolean eval(List<JudgeLogic> judgeLogics) {
|
|
|
|
|
boolean finalJudgeResult = false;
|
|
|
|
|
// 遍历组
|
|
|
|
|
for (int i = 0; i < judgeLogics.size(); i++) {
|
|
|
|
|
// 组内结果
|
|
|
|
|
boolean innerGroupJudge = false;
|
|
|
|
|
JudgeLogic logic = judgeLogics.get(i);
|
|
|
|
|
// 获取组之间的的判断逻辑
|
|
|
|
|
String rowLogic = logic.getRowLogic();
|
|
|
|
|
// 首先对组内进行判断,判断组内的结果
|
|
|
|
|
List<AtomicData> atomicData = logic.getAtomicData();
|
|
|
|
|
for (int j = 0; j < atomicData.size(); j++) {
|
|
|
|
|
AtomicData data = atomicData.get(j);
|
|
|
|
|
// 先找到原子指标对应的大指标的结果
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String atomicIndexResult = getAtomicResult(data.getAtomicIndex());
|
|
|
|
|
String relationalSymbol = data.getRelationalSymbol();
|
|
|
|
|
JudgeResultEnum instance = JudgeResultEnum.getInstance(relationalSymbol);
|
|
|
|
|
boolean ato = StrUtil.equals(atomicIndexResult, instance.getCode());
|
|
|
|
|
if (j == 0) {
|
|
|
|
|
innerGroupJudge = ato;
|
|
|
|
|
} else if ("1".equals(rowLogic)) {
|
|
|
|
|
innerGroupJudge = innerGroupJudge && ato;
|
|
|
|
|
} else if ("2".equals(rowLogic)) {
|
|
|
|
|
innerGroupJudge = innerGroupJudge || ato;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 组间进行判断
|
|
|
|
|
String groupLogic = logic.getGroupLogic();
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
finalJudgeResult = innerGroupJudge;
|
|
|
|
|
} else {
|
|
|
|
|
// 如果组间判断为1 与,则进行与操作
|
|
|
|
|
if ("1".equals(groupLogic)) {
|
|
|
|
|
finalJudgeResult = finalJudgeResult && innerGroupJudge;
|
|
|
|
|
// 如果组间判断为或,则进行或操作
|
|
|
|
|
} else if ("2".equals(groupLogic)) {
|
|
|
|
|
finalJudgeResult = finalJudgeResult || innerGroupJudge;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return finalJudgeResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static boolean eval1(List<JudgeLogic> judgeLogics) {
|
|
|
|
|
boolean finalJudgeResult = false;
|
|
|
|
|
|
|
|
|
|
// 遍历每个 JudgeLogic(条件组)
|
|
|
|
|
for (int i = 0; i < judgeLogics.size(); i++) {
|
|
|
|
|
JudgeLogic logic = judgeLogics.get(i);
|
|
|
|
|
// 组内逻辑 ("1" 表示 AND,"2" 表示 OR)
|
|
|
|
|
String rowLogic = logic.getRowLogic();
|
|
|
|
|
|
|
|
|
|
// 计算当前组的判断结果
|
|
|
|
|
boolean innerGroupJudge = calculateGroupResult(logic.getAtomicData(), rowLogic);
|
|
|
|
|
|
|
|
|
|
// 根据组间逻辑 ("1" 表示 AND,"2" 表示 OR) 更新最终判断结果
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
finalJudgeResult = innerGroupJudge;
|
|
|
|
|
} else {
|
|
|
|
|
finalJudgeResult = applyGroupLogic(finalJudgeResult, innerGroupJudge, logic.getGroupLogic());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return finalJudgeResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static boolean calculateGroupResult(List<AtomicData> atomicDataList, String rowLogic) {
|
|
|
|
|
// 如果 atomicDataList 为空,直接返回 false
|
|
|
|
|
if (atomicDataList == null || atomicDataList.isEmpty()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean groupResult = false;
|
|
|
|
|
|
|
|
|
|
// 遍历 atomicDataList,根据组内逻辑计算组内判断结果
|
|
|
|
|
for (int i = 0; i < atomicDataList.size(); i++) {
|
|
|
|
|
AtomicData data = atomicDataList.get(i);
|
|
|
|
|
|
|
|
|
|
String rowLogic1 = data.getRowLogic();
|
|
|
|
|
List<OperandUnit> operandUnitList = data.getOperandUnitList();
|
|
|
|
|
// 获取原子指标对应的大指标的计算结果
|
|
|
|
|
String atomicIndexResult = getAtomicResult(data.getAtomicIndex());
|
|
|
|
|
|
|
|
|
|
// 获取运算符并计算当前原子指标是否满足条件
|
|
|
|
|
String relationalSymbol = data.getRelationalSymbol();
|
|
|
|
|
JudgeResultEnum instance = JudgeResultEnum.getInstance(relationalSymbol);
|
|
|
|
|
boolean currentResult = StrUtil.equals(atomicIndexResult, instance.getCode());
|
|
|
|
|
|
|
|
|
|
// 更新组内的判断结果
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
groupResult = currentResult;
|
|
|
|
|
} else {
|
|
|
|
|
groupResult = applyRowLogic(groupResult, currentResult, rowLogic);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return groupResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static boolean calculateOperandUnit(List<OperandUnit> operandUnitList, String rowLogic) {
|
|
|
|
|
// 如果 operandUnitList 为空,直接返回 false
|
|
|
|
|
if (operandUnitList == null || operandUnitList.isEmpty()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean groupResult = false;
|
|
|
|
|
|
|
|
|
|
// 遍历 atomicDataList,根据组内逻辑计算组内判断结果
|
|
|
|
|
/*for (int i = 0; i < operandUnitList.size(); i++) {
|
|
|
|
|
OperandUnit operandUnit = operandUnitList.get(i);
|
|
|
|
|
|
|
|
|
|
Operand leftOperand = operandUnit.getLeftOperand();
|
|
|
|
|
|
|
|
|
|
Object leftOperandValue = calculateOperand(leftOperand);
|
|
|
|
|
String operator = operandUnit.getOperator();
|
|
|
|
|
Object rightOperandValue = calculateOperand(operandUnit.getRightOperand());
|
|
|
|
|
|
|
|
|
|
// todo: 规则引擎表达式计算出结果
|
|
|
|
|
// 获取原子指标对应的大指标的计算结果
|
|
|
|
|
String atomicIndexResult = getAtomicResult(data.getAtomicIndex());
|
|
|
|
|
|
|
|
|
|
// 获取运算符并计算当前原子指标是否满足条件
|
|
|
|
|
String relationalSymbol = data.getRelationalSymbol();
|
|
|
|
|
JudgeResultEnum instance = JudgeResultEnum.getInstance(relationalSymbol);
|
|
|
|
|
boolean currentResult = StrUtil.equals(atomicIndexResult, instance.getCode());
|
|
|
|
|
|
|
|
|
|
// 更新组内的判断结果
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
groupResult = currentResult;
|
|
|
|
|
} else {
|
|
|
|
|
groupResult = applyRowLogic(groupResult, currentResult, rowLogic);
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
return groupResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Object calculateOperand(Operand operand) {
|
|
|
|
|
// 根据 operandType 获取对应的值
|
|
|
|
|
|
|
|
|
|
Object value = null;
|
|
|
|
|
String operandType = operand.getOperandType();
|
|
|
|
|
if ("4".equals(operandType)) {
|
|
|
|
|
value = operand.getValue();
|
|
|
|
|
}
|
|
|
|
|
if ("property".equals(operandType)) {
|
|
|
|
|
value = getPropertyValue(operand);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// todo: 聚合计算
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Object getPropertyValue(Operand operand) {
|
|
|
|
|
String atomicIndexId = operand.getAtomicIndexId();
|
|
|
|
|
String propertyKey = operand.getPropertyKey();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Object getAggregateValue(String aggregateType, String value) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static boolean applyRowLogic(boolean existingResult, boolean newResult, String rowLogic) {
|
|
|
|
|
// 根据 rowLogic ("1" 表示 AND,"2" 表示 OR) 计算组内结果
|
|
|
|
|
if ("1".equals(rowLogic)) {
|
|
|
|
|
return existingResult && newResult;
|
|
|
|
|
} else if ("2".equals(rowLogic)) {
|
|
|
|
|
return existingResult || newResult;
|
|
|
|
|
}
|
|
|
|
|
return existingResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static boolean applyGroupLogic(boolean existingResult, boolean newResult, String groupLogic) {
|
|
|
|
|
// 根据 groupLogic ("1" 表示 AND,"2" 表示 OR) 计算组间结果
|
|
|
|
|
if ("1".equals(groupLogic)) {
|
|
|
|
|
return existingResult && newResult;
|
|
|
|
|
} else if ("2".equals(groupLogic)) {
|
|
|
|
|
return existingResult || newResult;
|
|
|
|
|
}
|
|
|
|
|
return existingResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String getAtomicResult(String atomicIndexId) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|