JoeLazy преди 4 месеца
родител
ревизия
3d4c7a255e

+ 132 - 0
src/main/java/com/sundata/internalevaluation/calc/calcUnit/DataSetCalcUnit.java

@@ -0,0 +1,132 @@
+package com.sundata.internalevaluation.calc.calcUnit;
+
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
+import com.sundata.internalevaluation.calc.model.CalcException;
+import com.sundata.internalevaluation.calc.model.CalcResult;
+import com.sundata.internalevaluation.calc.model.CalcUnit;
+import com.sundata.internalevaluation.calc.model.finals.CalcType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 数据集的计算单元
+ */
+public class DataSetCalcUnit extends CalcUnit {
+    private static final Logger log = LoggerFactory.getLogger(DataSetCalcUnit.class);
+    /**
+     * 创建数据单元的绝对对象,对象必须包含如下参数
+     *
+     * @param calcCode    计算对象编号
+     * @param calcName    计算对象名称
+     * @param initContext 计算单元初始化参数
+     */
+    public DataSetCalcUnit(String calcCode, String calcName, Map<String, Object> initContext) {
+        super(calcCode, calcName, CalcType.DATAITEM, initContext);
+    }
+
+    /**
+     * 判断是否已经计算过数据了
+     *
+     * @param calculateInstanceNumber 计算流水号
+     * @return 是否计算过 true 计算过 false 没有计算过
+     */
+    @Override
+    public boolean isCalcFinished(String calculateInstanceNumber) {
+        // TODO 计算是否已经计算
+        return false;
+//        return DataImages.dataSetCalcUnitHashMap.containsKey(calculateInstanceNumber)&&DataImages.dataSetCalcUnitHashMap.get(calculateInstanceNumber).stream().anyMatch(a->a.getCalcCode().equals(this.getCalcCode()));
+    }
+
+    /**
+     * 初始化计算结果的方法,如果已经计算过,在实现过程中,应当在此方法中根据计算流水号重新初始化 resultContext 结果对象,为其他依赖对象做准备
+     * 若明明计算过本单元但再次计算时没有初始化该对象,则计算依赖出现问题无法定位与处理
+     *
+     * @param calculateInstanceNumber 计算流水号
+     */
+    @Override
+    public void initResultContext(String calculateInstanceNumber) {
+        // TODO 初始化
+//        List<DataSetCalcUnit> dataSetCalcUnits = DataImages.dataSetCalcUnitHashMap.get(calculateInstanceNumber);
+        List<DataSetCalcUnit> dataSetCalcUnits = new ArrayList<>();
+        // 筛选并查找对象,如果找不到则报错
+        if(dataSetCalcUnits.stream().noneMatch(a -> a.getCalcCode().equals(this.getCalcCode()))){
+            throw new CalcException(calculateInstanceNumber, StrUtil.format("无法找到已计算完成的结果,计算单元编号:{},计算流水号为:{}。", this.getCalcCode(),calculateInstanceNumber));
+        }
+        this.setResultContext(dataSetCalcUnits.stream().filter(a->a.getCalcCode().equals(this.getCalcCode())).findFirst().get().getResultContext());
+    }
+
+    /**
+     * 根据节点配置获取源节点;
+     *
+     * @return 所有源头节点
+     */
+    @Override
+    public List<CalcUnit> getSourceCalcUnits() {
+        // TODO 获取源头节点
+        return new ArrayList<>();
+//        return ConfigImages.dataSetCalcUnitListMap.get(this);
+    }
+
+    /**
+     * 计算之后的方法,可实现为空
+     *
+     * @param context 计算参数过程数据
+     */
+    @Override
+    public void afterCalc(Map<String, Object> context) {
+        context.put(RandomUtil.randomNumbers(5)+"-1", this.getCalcCode());
+        log.debug("计算之后的参数结构:{}",context);
+    }
+
+    /**
+     * 计算之前,可实现空
+     *
+     * @param context 计算参数过程数据
+     */
+    @Override
+    public void beforeCalc(Map<String, Object> context) {
+        context.put(RandomUtil.randomNumbers(5)+"-2", this.getCalcCode());
+        log.debug("计算之前的参数结构:{}",context);
+    }
+
+    /**
+     * 必须实现的主体计算内容
+     *
+     * @param context 节点计算参数清单
+     * @param sourceResults 整个计算过程中的节点结果
+     */
+    @Override
+    public void calc(final CalcResult<String, Object> thisResult, String calculateInstanceNumber,Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
+//        log.debug("模拟计算过程,计算参数为:【{}】,来源结果数据为:【{}】",context, sourceResults);
+//        List<User> userList = new ArrayList<>();
+//        List<Bussiness> bussinesseList = new ArrayList<>();
+//        Faker faker = Faker.instance(Locale.CHINA);
+//        thisResult.put(this.getCalcCode()+"-1", faker.number().randomNumber());
+//        thisResult.put(this.getCalcCode()+"-2", faker.number().randomNumber());
+//
+//        for (int i = 0; i < 1000; i++) {
+//            userList.add(new User(faker.number().randomDigitNotZero(),faker.name().fullName(),faker.number().numberBetween(1,90),faker.address().fullAddress(),faker.internet().emailAddress("sundatasoft.com"), faker.phoneNumber().cellPhone(),faker.date().birthday()));
+//        }
+//        for (int i = 0; i < 100_000; i++) {
+//            bussinesseList.add(new Bussiness(faker.number().randomDigitNotZero(),faker.name().fullName(),faker.number().randomDouble(6,100,1000000),faker.number().numberBetween(1,90)));
+//        }
+//        thisResult.put(this.getCalcCode()+"-user", userList);
+//        thisResult.put(this.getCalcCode()+"-buss", bussinesseList);
+//
+////        log.debug("模拟计算完成,结果对象为:【{}】",thisResult);
+//
+//        context.put(calculateInstanceNumber+"-"+this.getCalcCode(),thisResult);
+//        log.debug("对参数二次修改:{}",context);
+
+        // TODO 实际的计算过程
+
+
+    }
+
+
+}

+ 95 - 0
src/main/java/com/sundata/internalevaluation/calc/calcUnit/DataSourcesCalcUnit.java

@@ -0,0 +1,95 @@
+package com.sundata.internalevaluation.calc.calcUnit;
+
+import com.sundata.internalevaluation.calc.model.CalcResult;
+import com.sundata.internalevaluation.calc.model.CalcUnit;
+import com.sundata.internalevaluation.calc.model.finals.CalcType;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author JoeLazy
+ * @date 2025-02-12 10:46:08
+ * @description: 数据来源计算单元
+ */
+public class DataSourcesCalcUnit extends CalcUnit {
+    /**
+    /**
+     * 创建数据单元的绝对对象,对象必须包含如下参数
+     *
+     * @param calcCode    计算对象编号
+     * @param calcName    计算对象名称
+     * @param calcType    计算类型
+     * @param initContext 计算单元初始化参数
+     */
+    public DataSourcesCalcUnit(String calcCode, String calcName, CalcType calcType, Map<String, Object> initContext) {
+        super(calcCode, calcName, calcType, initContext);
+    }
+
+    /**
+     * 判断是否已经计算过数据了
+     *
+     * @param calculateInstanceNumber 计算流水号
+     * @return 是否计算过 true 计算过 false 没有计算过
+     */
+    @Override
+    public boolean isCalcFinished(String calculateInstanceNumber) {
+        return false;
+    }
+
+    /**
+     * 初始化计算结果的方法,如果已经计算过,在实现过程中,应当在此方法中根据计算流水号重新初始化 resultContext 结果对象,为其他依赖对象做准备
+     * 若明明计算过本单元但再次计算时没有初始化该对象,则计算依赖出现问题无法定位与处理
+     *
+     * @param calculateInstanceNumber 计算流水号
+     */
+    @Override
+    public void initResultContext(String calculateInstanceNumber) {
+
+    }
+
+    /**
+     * 根据节点配置获取源节点;
+     *
+     * @return 所有源头节点
+     */
+    @Override
+    public List<CalcUnit> getSourceCalcUnits() {
+        return List.of();
+    }
+
+    /**
+     * 计算之后的方法,可实现为空
+     *
+     * @param context
+     */
+    @Override
+    public void afterCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 计算之前,可实现空
+     *
+     * @param context
+     */
+    @Override
+    public void beforeCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 必须实现的主体计算内容
+     *
+     * @param thisResult              本计算单元的结果
+     * @param calculateInstanceNumber 计算流水号
+     * @param context                 节点计算参数清单
+     * @param sourceResults           源头计算节点的结果
+     */
+    @Override
+    public void calc(CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
+
+    }
+}

+ 94 - 0
src/main/java/com/sundata/internalevaluation/calc/calcUnit/DateItemCalcUnit.java

@@ -0,0 +1,94 @@
+package com.sundata.internalevaluation.calc.calcUnit;
+
+import com.sundata.internalevaluation.calc.model.CalcResult;
+import com.sundata.internalevaluation.calc.model.CalcUnit;
+import com.sundata.internalevaluation.calc.model.finals.CalcType;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author JoeLazy
+ * @date 2025-02-12 10:43:38
+ * @description: 数据项计算单元
+ */
+public class DateItemCalcUnit extends CalcUnit {
+    /**
+     * 创建数据单元的绝对对象,对象必须包含如下参数
+     *
+     * @param calcCode    计算对象编号
+     * @param calcName    计算对象名称
+     * @param calcType    计算类型
+     * @param initContext 计算单元初始化参数
+     */
+    public DateItemCalcUnit(String calcCode, String calcName, CalcType calcType, Map<String, Object> initContext) {
+        super(calcCode, calcName, calcType, initContext);
+    }
+
+    /**
+     * 判断是否已经计算过数据了
+     *
+     * @param calculateInstanceNumber 计算流水号
+     * @return 是否计算过 true 计算过 false 没有计算过
+     */
+    @Override
+    public boolean isCalcFinished(String calculateInstanceNumber) {
+        return false;
+    }
+
+    /**
+     * 初始化计算结果的方法,如果已经计算过,在实现过程中,应当在此方法中根据计算流水号重新初始化 resultContext 结果对象,为其他依赖对象做准备
+     * 若明明计算过本单元但再次计算时没有初始化该对象,则计算依赖出现问题无法定位与处理
+     *
+     * @param calculateInstanceNumber 计算流水号
+     */
+    @Override
+    public void initResultContext(String calculateInstanceNumber) {
+
+    }
+
+    /**
+     * 根据节点配置获取源节点;
+     *
+     * @return 所有源头节点
+     */
+    @Override
+    public List<CalcUnit> getSourceCalcUnits() {
+        return List.of();
+    }
+
+    /**
+     * 计算之后的方法,可实现为空
+     *
+     * @param context
+     */
+    @Override
+    public void afterCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 计算之前,可实现空
+     *
+     * @param context
+     */
+    @Override
+    public void beforeCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 必须实现的主体计算内容
+     *
+     * @param thisResult              本计算单元的结果
+     * @param calculateInstanceNumber 计算流水号
+     * @param context                 节点计算参数清单
+     * @param sourceResults           源头计算节点的结果
+     */
+    @Override
+    public void calc(CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
+
+    }
+}

+ 132 - 0
src/main/java/com/sundata/internalevaluation/calc/calcUnit/IndexCalcUnit.java

@@ -0,0 +1,132 @@
+package com.sundata.internalevaluation.calc.calcUnit;
+
+import cn.hutool.core.util.StrUtil;
+import com.sundata.internalevaluation.calc.model.CalcException;
+import com.sundata.internalevaluation.calc.model.CalcResult;
+import com.sundata.internalevaluation.calc.model.CalcUnit;
+import com.sundata.internalevaluation.calc.model.finals.CalcType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class IndexCalcUnit extends CalcUnit {
+
+    private static final Logger log = LoggerFactory.getLogger(IndexCalcUnit.class);
+    /**
+     * 创建数据单元的绝对对象,对象必须包含如下参数
+     *
+     * @param calcCode    计算对象编号
+     * @param calcName    计算对象名称
+     * @param initContext 计算单元初始化参数
+     */
+    public IndexCalcUnit(String calcCode, String calcName, Map<String, Object> initContext) {
+        super(calcCode, calcName, CalcType.INDEX, initContext);
+    }
+
+    /**
+     * 判断是否已经计算过数据了
+     *
+     * @param calculateInstanceNumber 计算流水号
+     * @return 是否计算过 true 计算过 false 没有计算过
+     */
+    @Override
+    public boolean isCalcFinished(String calculateInstanceNumber) {
+        // TODO 计算是否已经计算
+        return false;
+//        return DataImages.indexCalcUnitHashMap.containsKey(calculateInstanceNumber) && DataImages.indexCalcUnitHashMap.get(calculateInstanceNumber).stream().anyMatch(a -> a.getCalcCode().equals(this.getCalcCode()));
+    }
+
+    /**
+     * 初始化计算结果的方法,如果已经计算过,在实现过程中,应当在此方法中根据计算流水号重新初始化 resultContext 结果对象,为其他依赖对象做准备
+     * 若明明计算过本单元但再次计算时没有初始化该对象,则计算依赖出现问题无法定位与处理
+     *
+     * @param calculateInstanceNumber 计算流水号
+     */
+    @Override
+    public void initResultContext(String calculateInstanceNumber) {
+        // TODO 初始化
+        List<IndexCalcUnit> indexCalcUnits = new ArrayList<>();
+//        List<IndexCalcUnit> indexCalcUnits = DataImages.indexCalcUnitHashMap.get(calculateInstanceNumber);
+        // 筛选并查找对象,如果找不到则报错
+        if (indexCalcUnits.stream().noneMatch(a -> a.getCalcCode().equals(this.getCalcCode()))) {
+            throw new CalcException(calculateInstanceNumber, StrUtil.format("无法找到已计算完成的结果,计算单元编号:{},计算流水号为:{}。", this.getCalcCode(), calculateInstanceNumber));
+        }
+        this.setResultContext(indexCalcUnits.stream().filter(a -> a.getCalcCode().equals(this.getCalcCode())).findFirst().get().getResultContext());
+    }
+
+    /**
+     * 根据节点配置获取源节点;
+     *
+     * @return 所有源头节点
+     */
+    @Override
+    public List<CalcUnit> getSourceCalcUnits() {
+        // TODO 获取源头节点
+        return new ArrayList<>();
+//        return ConfigImages.indexCalcUnitListMap.get(this);
+    }
+
+
+    /**
+     * 计算之后的方法,可实现为空
+     *
+     * @param context 计算参数过程数据
+     */
+    @Override
+    public void afterCalc(Map<String, Object> context) {
+        log.debug("计算之后的参数结构:{}",context);
+    }
+
+    /**
+     * 计算之前,可实现空
+     *
+     * @param context 计算参数过程数据
+     */
+    @Override
+    public void beforeCalc(Map<String, Object> context) {
+        log.debug("计算之前的参数结构:{}",context);
+    }
+
+
+
+    /**
+     * 必须实现的主体计算内容
+     *
+     * @param context 节点计算参数清单
+     * @param sourceResults 整个计算过程中的节点结果
+     */
+    @Override
+    public void calc(final CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
+
+        // TODO 实际的计算过程
+
+
+//        Map<CalcUnit, CalcResult<String, Object>> dataMap = new HashMap<>();
+//
+//        // 获取 数据源 A 配置的 用户
+//        // 获取 数据源 B 配置的 业务
+//        sourceResults.forEach((calcUnit, result) -> {
+//            if (calcUnit.getCalcCode().equals("data")) {
+//                dataMap.put(calcUnit, result);
+//            }
+//        });
+//
+//        // 计算 年龄小于50的用户数量 X 指标
+//        // 计算 价格大于 500 的业务数量 Y 指标
+//        dataMap.forEach((calcUnit, result) -> {
+//            if (calcUnit.getCalcCode().equals("data")) {
+//                List<User> userList = (ArrayList<User>) result.get("data-user");
+//                long userCount = userList.stream().filter(user -> user.age()<50).count();
+//                thisResult.put(this.getCalcCode()+"-userCount",userCount);
+//            }
+//            if (calcUnit.getCalcCode().equals("data")) {
+//                List<Bussiness> bussinesseList = (ArrayList<Bussiness>) result.get("data-buss");
+//                long bussCount = bussinesseList.stream().filter(bussiness -> bussiness.price()>500).count();
+//                thisResult.put(this.getCalcCode()+"-bussCount",bussCount);
+//            }
+//        });
+    }
+}

+ 94 - 0
src/main/java/com/sundata/internalevaluation/calc/calcUnit/IndexListCalcUnit.java

@@ -0,0 +1,94 @@
+package com.sundata.internalevaluation.calc.calcUnit;
+
+import com.sundata.internalevaluation.calc.model.CalcResult;
+import com.sundata.internalevaluation.calc.model.CalcUnit;
+import com.sundata.internalevaluation.calc.model.finals.CalcType;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author JoeLazy
+ * @date 2025-02-12 10:42:06
+ * @description: 指标清单计算单元
+ */
+public class IndexListCalcUnit extends CalcUnit {
+    /**
+     * 创建数据单元的绝对对象,对象必须包含如下参数
+     *
+     * @param calcCode    计算对象编号
+     * @param calcName    计算对象名称
+     * @param calcType    计算类型
+     * @param initContext 计算单元初始化参数
+     */
+    public IndexListCalcUnit(String calcCode, String calcName, CalcType calcType, Map<String, Object> initContext) {
+        super(calcCode, calcName, calcType, initContext);
+    }
+
+    /**
+     * 判断是否已经计算过数据了
+     *
+     * @param calculateInstanceNumber 计算流水号
+     * @return 是否计算过 true 计算过 false 没有计算过
+     */
+    @Override
+    public boolean isCalcFinished(String calculateInstanceNumber) {
+        return false;
+    }
+
+    /**
+     * 初始化计算结果的方法,如果已经计算过,在实现过程中,应当在此方法中根据计算流水号重新初始化 resultContext 结果对象,为其他依赖对象做准备
+     * 若明明计算过本单元但再次计算时没有初始化该对象,则计算依赖出现问题无法定位与处理
+     *
+     * @param calculateInstanceNumber 计算流水号
+     */
+    @Override
+    public void initResultContext(String calculateInstanceNumber) {
+
+    }
+
+    /**
+     * 根据节点配置获取源节点;
+     *
+     * @return 所有源头节点
+     */
+    @Override
+    public List<CalcUnit> getSourceCalcUnits() {
+        return List.of();
+    }
+
+    /**
+     * 计算之后的方法,可实现为空
+     *
+     * @param context
+     */
+    @Override
+    public void afterCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 计算之前,可实现空
+     *
+     * @param context
+     */
+    @Override
+    public void beforeCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 必须实现的主体计算内容
+     *
+     * @param thisResult              本计算单元的结果
+     * @param calculateInstanceNumber 计算流水号
+     * @param context                 节点计算参数清单
+     * @param sourceResults           源头计算节点的结果
+     */
+    @Override
+    public void calc(CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
+
+    }
+}

+ 94 - 0
src/main/java/com/sundata/internalevaluation/calc/calcUnit/InputParamCalcUnit.java

@@ -0,0 +1,94 @@
+package com.sundata.internalevaluation.calc.calcUnit;
+
+import com.sundata.internalevaluation.calc.model.CalcResult;
+import com.sundata.internalevaluation.calc.model.CalcUnit;
+import com.sundata.internalevaluation.calc.model.finals.CalcType;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author JoeLazy
+ * @date 2025-02-12 10:45:18
+ * @description: 输入参数计算单元
+ */
+public class InputParamCalcUnit extends CalcUnit {
+    /**
+     * 创建数据单元的绝对对象,对象必须包含如下参数
+     *
+     * @param calcCode    计算对象编号
+     * @param calcName    计算对象名称
+     * @param calcType    计算类型
+     * @param initContext 计算单元初始化参数
+     */
+    public InputParamCalcUnit(String calcCode, String calcName, CalcType calcType, Map<String, Object> initContext) {
+        super(calcCode, calcName, calcType, initContext);
+    }
+
+    /**
+     * 判断是否已经计算过数据了
+     *
+     * @param calculateInstanceNumber 计算流水号
+     * @return 是否计算过 true 计算过 false 没有计算过
+     */
+    @Override
+    public boolean isCalcFinished(String calculateInstanceNumber) {
+        return false;
+    }
+
+    /**
+     * 初始化计算结果的方法,如果已经计算过,在实现过程中,应当在此方法中根据计算流水号重新初始化 resultContext 结果对象,为其他依赖对象做准备
+     * 若明明计算过本单元但再次计算时没有初始化该对象,则计算依赖出现问题无法定位与处理
+     *
+     * @param calculateInstanceNumber 计算流水号
+     */
+    @Override
+    public void initResultContext(String calculateInstanceNumber) {
+
+    }
+
+    /**
+     * 根据节点配置获取源节点;
+     *
+     * @return 所有源头节点
+     */
+    @Override
+    public List<CalcUnit> getSourceCalcUnits() {
+        return List.of();
+    }
+
+    /**
+     * 计算之后的方法,可实现为空
+     *
+     * @param context
+     */
+    @Override
+    public void afterCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 计算之前,可实现空
+     *
+     * @param context
+     */
+    @Override
+    public void beforeCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 必须实现的主体计算内容
+     *
+     * @param thisResult              本计算单元的结果
+     * @param calculateInstanceNumber 计算流水号
+     * @param context                 节点计算参数清单
+     * @param sourceResults           源头计算节点的结果
+     */
+    @Override
+    public void calc(CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
+
+    }
+}

+ 94 - 0
src/main/java/com/sundata/internalevaluation/calc/calcUnit/InterfaceCalcUnit.java

@@ -0,0 +1,94 @@
+package com.sundata.internalevaluation.calc.calcUnit;
+
+import com.sundata.internalevaluation.calc.model.CalcResult;
+import com.sundata.internalevaluation.calc.model.CalcUnit;
+import com.sundata.internalevaluation.calc.model.finals.CalcType;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author JoeLazy
+ * @date 2025-02-12 10:40:49
+ * @description: 接口计算单元
+ */
+public class InterfaceCalcUnit extends CalcUnit {
+    /**
+     * 创建数据单元的绝对对象,对象必须包含如下参数
+     *
+     * @param calcCode    计算对象编号
+     * @param calcName    计算对象名称
+     * @param calcType    计算类型
+     * @param initContext 计算单元初始化参数
+     */
+    public InterfaceCalcUnit(String calcCode, String calcName, CalcType calcType, Map<String, Object> initContext) {
+        super(calcCode, calcName, calcType, initContext);
+    }
+
+    /**
+     * 判断是否已经计算过数据了
+     *
+     * @param calculateInstanceNumber 计算流水号
+     * @return 是否计算过 true 计算过 false 没有计算过
+     */
+    @Override
+    public boolean isCalcFinished(String calculateInstanceNumber) {
+        return false;
+    }
+
+    /**
+     * 初始化计算结果的方法,如果已经计算过,在实现过程中,应当在此方法中根据计算流水号重新初始化 resultContext 结果对象,为其他依赖对象做准备
+     * 若明明计算过本单元但再次计算时没有初始化该对象,则计算依赖出现问题无法定位与处理
+     *
+     * @param calculateInstanceNumber 计算流水号
+     */
+    @Override
+    public void initResultContext(String calculateInstanceNumber) {
+
+    }
+
+    /**
+     * 根据节点配置获取源节点;
+     *
+     * @return 所有源头节点
+     */
+    @Override
+    public List<CalcUnit> getSourceCalcUnits() {
+        return List.of();
+    }
+
+    /**
+     * 计算之后的方法,可实现为空
+     *
+     * @param context
+     */
+    @Override
+    public void afterCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 计算之前,可实现空
+     *
+     * @param context
+     */
+    @Override
+    public void beforeCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 必须实现的主体计算内容
+     *
+     * @param thisResult              本计算单元的结果
+     * @param calculateInstanceNumber 计算流水号
+     * @param context                 节点计算参数清单
+     * @param sourceResults           源头计算节点的结果
+     */
+    @Override
+    public void calc(CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
+
+    }
+}

+ 94 - 0
src/main/java/com/sundata/internalevaluation/calc/calcUnit/ModelCalcUnit.java

@@ -0,0 +1,94 @@
+package com.sundata.internalevaluation.calc.calcUnit;
+
+import com.sundata.internalevaluation.calc.model.CalcResult;
+import com.sundata.internalevaluation.calc.model.CalcUnit;
+import com.sundata.internalevaluation.calc.model.finals.CalcType;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author JoeLazy
+ * @date 2025-02-12 10:42:54
+ * @description: 模型计算单元
+ */
+public class ModelCalcUnit extends CalcUnit {
+    /**
+     * 创建数据单元的绝对对象,对象必须包含如下参数
+     *
+     * @param calcCode    计算对象编号
+     * @param calcName    计算对象名称
+     * @param calcType    计算类型
+     * @param initContext 计算单元初始化参数
+     */
+    public ModelCalcUnit(String calcCode, String calcName, CalcType calcType, Map<String, Object> initContext) {
+        super(calcCode, calcName, calcType, initContext);
+    }
+
+    /**
+     * 判断是否已经计算过数据了
+     *
+     * @param calculateInstanceNumber 计算流水号
+     * @return 是否计算过 true 计算过 false 没有计算过
+     */
+    @Override
+    public boolean isCalcFinished(String calculateInstanceNumber) {
+        return false;
+    }
+
+    /**
+     * 初始化计算结果的方法,如果已经计算过,在实现过程中,应当在此方法中根据计算流水号重新初始化 resultContext 结果对象,为其他依赖对象做准备
+     * 若明明计算过本单元但再次计算时没有初始化该对象,则计算依赖出现问题无法定位与处理
+     *
+     * @param calculateInstanceNumber 计算流水号
+     */
+    @Override
+    public void initResultContext(String calculateInstanceNumber) {
+
+    }
+
+    /**
+     * 根据节点配置获取源节点;
+     *
+     * @return 所有源头节点
+     */
+    @Override
+    public List<CalcUnit> getSourceCalcUnits() {
+        return List.of();
+    }
+
+    /**
+     * 计算之后的方法,可实现为空
+     *
+     * @param context
+     */
+    @Override
+    public void afterCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 计算之前,可实现空
+     *
+     * @param context
+     */
+    @Override
+    public void beforeCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 必须实现的主体计算内容
+     *
+     * @param thisResult              本计算单元的结果
+     * @param calculateInstanceNumber 计算流水号
+     * @param context                 节点计算参数清单
+     * @param sourceResults           源头计算节点的结果
+     */
+    @Override
+    public void calc(CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
+
+    }
+}

+ 94 - 0
src/main/java/com/sundata/internalevaluation/calc/calcUnit/QueryLogicCalcUnit.java

@@ -0,0 +1,94 @@
+package com.sundata.internalevaluation.calc.calcUnit;
+
+import com.sundata.internalevaluation.calc.model.CalcResult;
+import com.sundata.internalevaluation.calc.model.CalcUnit;
+import com.sundata.internalevaluation.calc.model.finals.CalcType;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author JoeLazy
+ * @date 2025-02-12 10:44:34
+ * @description: 查询逻辑计算单元
+ */
+public class QueryLogicCalcUnit extends CalcUnit {
+    /**
+     * 创建数据单元的绝对对象,对象必须包含如下参数
+     *
+     * @param calcCode    计算对象编号
+     * @param calcName    计算对象名称
+     * @param calcType    计算类型
+     * @param initContext 计算单元初始化参数
+     */
+    public QueryLogicCalcUnit(String calcCode, String calcName, CalcType calcType, Map<String, Object> initContext) {
+        super(calcCode, calcName, calcType, initContext);
+    }
+
+    /**
+     * 判断是否已经计算过数据了
+     *
+     * @param calculateInstanceNumber 计算流水号
+     * @return 是否计算过 true 计算过 false 没有计算过
+     */
+    @Override
+    public boolean isCalcFinished(String calculateInstanceNumber) {
+        return false;
+    }
+
+    /**
+     * 初始化计算结果的方法,如果已经计算过,在实现过程中,应当在此方法中根据计算流水号重新初始化 resultContext 结果对象,为其他依赖对象做准备
+     * 若明明计算过本单元但再次计算时没有初始化该对象,则计算依赖出现问题无法定位与处理
+     *
+     * @param calculateInstanceNumber 计算流水号
+     */
+    @Override
+    public void initResultContext(String calculateInstanceNumber) {
+
+    }
+
+    /**
+     * 根据节点配置获取源节点;
+     *
+     * @return 所有源头节点
+     */
+    @Override
+    public List<CalcUnit> getSourceCalcUnits() {
+        return List.of();
+    }
+
+    /**
+     * 计算之后的方法,可实现为空
+     *
+     * @param context
+     */
+    @Override
+    public void afterCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 计算之前,可实现空
+     *
+     * @param context
+     */
+    @Override
+    public void beforeCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 必须实现的主体计算内容
+     *
+     * @param thisResult              本计算单元的结果
+     * @param calculateInstanceNumber 计算流水号
+     * @param context                 节点计算参数清单
+     * @param sourceResults           源头计算节点的结果
+     */
+    @Override
+    public void calc(CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
+
+    }
+}

+ 96 - 0
src/main/java/com/sundata/internalevaluation/calc/calcUnit/RuleCalcUnit.java

@@ -0,0 +1,96 @@
+package com.sundata.internalevaluation.calc.calcUnit;
+
+import com.sundata.internalevaluation.calc.model.CalcResult;
+import com.sundata.internalevaluation.calc.model.CalcUnit;
+import com.sundata.internalevaluation.calc.model.finals.CalcType;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author JoeLazy
+ * @date 2025-02-12 09:31:30
+ * @description: 规则计算单元
+ */
+public class RuleCalcUnit extends CalcUnit {
+
+    /**
+     * 创建数据单元的绝对对象,对象必须包含如下参数
+     *
+     * @param calcCode    计算对象编号
+     * @param calcName    计算对象名称
+     * @param calcType    计算类型
+     * @param initContext 计算单元初始化参数
+     */
+    public RuleCalcUnit(String calcCode, String calcName, CalcType calcType, Map<String, Object> initContext) {
+        super(calcCode, calcName, calcType, initContext);
+
+    }
+
+    /**
+     * 判断是否已经计算过数据了
+     *
+     * @param calculateInstanceNumber 计算流水号
+     * @return 是否计算过 true 计算过 false 没有计算过
+     */
+    @Override
+    public boolean isCalcFinished(String calculateInstanceNumber) {
+        return false;
+    }
+
+    /**
+     * 初始化计算结果的方法,如果已经计算过,在实现过程中,应当在此方法中根据计算流水号重新初始化 resultContext 结果对象,为其他依赖对象做准备
+     * 若明明计算过本单元但再次计算时没有初始化该对象,则计算依赖出现问题无法定位与处理
+     *
+     * @param calculateInstanceNumber 计算流水号
+     */
+    @Override
+    public void initResultContext(String calculateInstanceNumber) {
+
+    }
+
+    /**
+     * 根据节点配置获取源节点;
+     *
+     * @return 所有源头节点
+     */
+    @Override
+    public List<CalcUnit> getSourceCalcUnits() {
+        return List.of();
+    }
+
+    /**
+     * 计算之后的方法,可实现为空
+     *
+     * @param context
+     */
+    @Override
+    public void afterCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 计算之前,可实现空
+     *
+     * @param context
+     */
+    @Override
+    public void beforeCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 必须实现的主体计算内容
+     *
+     * @param thisResult              本计算单元的结果
+     * @param calculateInstanceNumber 计算流水号
+     * @param context                 节点计算参数清单
+     * @param sourceResults           源头计算节点的结果
+     */
+    @Override
+    public void calc(CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
+        // TODO 实际的计算过程
+    }
+}

+ 141 - 0
src/main/java/com/sundata/internalevaluation/calc/calcUnit/RulesCalcUnit.java

@@ -0,0 +1,141 @@
+package com.sundata.internalevaluation.calc.calcUnit;
+
+import com.sundata.internalevaluation.calc.model.CalcResult;
+import com.sundata.internalevaluation.calc.model.CalcUnit;
+import com.sundata.internalevaluation.calc.model.finals.CalcType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author JoeLazy
+ * @date 2025-02-12 09:32:30
+ * @description: 规则集计算单元
+ */
+
+public class RulesCalcUnit extends CalcUnit {
+
+    private static final Logger log = LoggerFactory.getLogger(RulesCalcUnit.class);
+
+    /**
+     * 创建数据单元的绝对对象,对象必须包含如下参数
+     *
+     * @param calcCode    计算对象编号
+     * @param calcName    计算对象名称
+     * @param initContext 计算单元初始化参数
+     */
+    public RulesCalcUnit(String calcCode, String calcName, Map<String, Object> initContext) {
+        super(calcCode, calcName, CalcType.RULES, initContext);
+    }
+
+    /**
+     * 判断是否已经计算过数据了
+     *
+     * @param calculateInstanceNumber 计算流水号
+     * @return 是否计算过 true 计算过 false 没有计算过
+     */
+    @Override
+    public boolean isCalcFinished(String calculateInstanceNumber) {
+        // 计算是否计算过
+
+        return false;
+//        return DataImages.rulesCalcUnitHashMap.containsKey(calculateInstanceNumber)
+//                && DataImages.rulesCalcUnitHashMap.get(calculateInstanceNumber)
+//                .stream().anyMatch(a -> a.getCalcCode().equals(this.getCalcCode()));
+    }
+
+    /**
+     * 初始化计算结果的方法,
+     * 如果已经计算过,在实现过程中,应当在此方法中根据计算流水号重新初始化 resultContext 结果对象,为其他依赖对象做准备
+     * 若明明计算过本单元但再次计算时没有初始化该对象,则计算依赖出现问题无法定位与处理
+     *
+     * @param calculateInstanceNumber 计算流水号
+     */
+    @Override
+    public void initResultContext(String calculateInstanceNumber) {
+        // TODO 初始化
+//        List<RulesCalcUnit> rulesCalcUnits = new ArrayList<>();
+////        List<RulesCalcUnit> rulesCalcUnits = DataImages.rulesCalcUnitHashMap.get(calculateInstanceNumber);
+//        // 筛选并查找对象,如果找不到则报错
+//        if (rulesCalcUnits.stream().noneMatch(a -> a.getCalcCode().equals(this.getCalcCode()))) {
+//            throw new CalcException(calculateInstanceNumber, StrUtil.format("无法找到已计算完成的结果,计算单元编号:{},计算流水号为:{}。", this.getCalcCode(), calculateInstanceNumber));
+//        }
+//        this.setResultContext(
+//                rulesCalcUnits.stream()
+//                        .filter(a -> a.getCalcCode().equals(this.getCalcCode()))
+//                        .findFirst().get().getResultContext()
+//        );
+    }
+
+    /**
+     * 根据节点配置获取源节点;
+     *
+     * @return 所有源头节点
+     */
+    @Override
+    public List<CalcUnit> getSourceCalcUnits() {
+        // TODO 获取源头节点
+
+//        SpringUtil.
+
+
+        return new ArrayList<>();
+//        return ConfigImages.rulesCalcUnitListMap.get(this);
+    }
+
+    /**
+     * 计算之后的方法,可实现为空
+     *
+     * @param context 计算参数过程数据
+     */
+    @Override
+    public void afterCalc(Map<String, Object> context) {
+        log.debug("计算之后的参数结构:{}", context);
+    }
+
+    /**
+     * 计算之前,可实现空
+     *
+     * @param context 计算参数过程数据
+     */
+    @Override
+    public void beforeCalc(Map<String, Object> context) {
+        log.debug("计算之前的参数结构:{}", context);
+    }
+
+
+    /**
+     * 必须实现的主体计算内容
+     *
+     * @param context 节点计算参数清单
+     * @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(),"规则集未拦截");
+//            }
+//        });
+
+    }
+}

+ 1 - 0
src/main/java/com/sundata/internalevaluation/calc/model/CalcUnit.java

@@ -94,6 +94,7 @@ public abstract class CalcUnit implements Calc, Serializable {
     }
 
 
+    @Override
     public void startCalc(String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
         setStatus(CalcStatus.RUNNING);
         if (isCalcFinished(calculateInstanceNumber)) { // 如果已经计算过则不再执行计算处理,仅需要通过 initResultContext 初始化 resultContext 对象

+ 27 - 0
src/main/java/com/sundata/internalevaluation/calc/running/CalcRunning.java

@@ -24,15 +24,33 @@ import java.util.concurrent.ForkJoinPool;
 public class CalcRunning {
     private static final Logger log = LoggerFactory.getLogger(CalcRunning.class);
 
+
+    /**
+     * 正在运行的计算流水号
+     */
     private static final ConcurrentSkipListSet<String> runningList = new ConcurrentSkipListSet<>();
 
+
+    /**
+     * 计算方法
+     * @param calculateInstanceNumber 计算流水号
+     * @param calcUnit 集体的计算单元
+     * @param context 初始化参数
+     * @return 计算结果
+     */
     public CalcTaskResult startCalc(String calculateInstanceNumber, CalcUnit calcUnit, Map<String, Object> context) {
 
+        // 流水号为空  生成流水号
         if (StrUtil.isEmpty(calculateInstanceNumber)) {
             calculateInstanceNumber = UUID.randomUUID(Boolean.TRUE).toString(Boolean.TRUE);
         }
+
+
+        // 计算结果
         Map<String, Object> resultMap = new HashMap<>();
         resultMap.put("calculateInstanceNumber",calculateInstanceNumber);
+
+        // 返回值对象
         CalcTaskResult result = new CalcTaskResult(CalcTaskResultType.SUCCESS, "200", "计算成功!", resultMap);
 
         if (runningList.contains(calculateInstanceNumber)) {
@@ -42,18 +60,27 @@ public class CalcRunning {
             return result;
         }
         runningList.add(calculateInstanceNumber);
+
+
         // 创建自定义线程工厂
         CalcUnitThreadFactory factory = new CalcUnitThreadFactory(calculateInstanceNumber);
 
         // 创建 ForkJoinPool 并使用自定义线程工厂
         ForkJoinPool customPool = new ForkJoinPool(4, factory, null, false);
+
+        // ??
         final ConcurrentHashMap<String, Object> content = new ConcurrentHashMap<>();
+        // 当前节点计算结果
         final ConcurrentHashMap<CalcUnit, CalcResult<String, Object>> results = new ConcurrentHashMap<>();
+        // 子级节点计算结果
         final ConcurrentHashMap<CalcUnit, CalcResult<String, Object>> childResults = new ConcurrentHashMap<>();
+
+        // 图结构对象
         final Graph<CalcUnit, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class);
 
         graph.addVertex(calcUnit);
         graphAddVertex(graph,calcUnit,calcUnit.getSourceCalcUnits());
+
         // 提交任务到自定义线程池
         CalcRecursiveTask task = new CalcRecursiveTask(calculateInstanceNumber, calcUnit, content, graph, results,childResults);
         CalcResult<String ,Object> resultMain = customPool.submit(task).join();

+ 1 - 0
src/main/java/com/sundata/internalevaluation/calc/running/threads/CalcRecursiveTask.java

@@ -16,6 +16,7 @@ import java.util.concurrent.RecursiveTask;
 
 /**
  * 分解用的任务类,结果有 ClacResult 组成
+ * @author JoeLazy
  */
 public class CalcRecursiveTask extends RecursiveTask<CalcResult<String, Object>> {