|
@@ -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 实际的计算过程
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|