|
@@ -1,19 +1,29 @@
|
|
|
package com.sundata.internalevaluation.calc.calcUnit;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.sundata.common.util.DBExecutor;
|
|
|
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 com.sundata.internalevaluation.configuration.model.IndexConfigModel;
|
|
|
+import com.sundata.internalevaluation.configuration.model.IndexSourceModel;
|
|
|
+import com.sundata.internalevaluation.configuration.service.IndexConfigService;
|
|
|
+import com.sundata.internalevaluation.script.ScriptUtil;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
public class IndexCalcUnit extends CalcUnit {
|
|
|
|
|
|
+ private IndexConfigService indexConfigService;
|
|
|
+
|
|
|
+ private IndexConfigModel indexConfigModel;
|
|
|
+
|
|
|
private static final Logger log = LoggerFactory.getLogger(IndexCalcUnit.class);
|
|
|
/**
|
|
|
* 创建数据单元的绝对对象,对象必须包含如下参数
|
|
@@ -22,8 +32,10 @@ public class IndexCalcUnit extends CalcUnit {
|
|
|
* @param calcName 计算对象名称
|
|
|
* @param initContext 计算单元初始化参数
|
|
|
*/
|
|
|
- public IndexCalcUnit(String calcCode, String calcName, Map<String, Object> initContext) {
|
|
|
+ public IndexCalcUnit(String calcCode, String calcName, Map<String, Object> initContext, IndexConfigModel indexConfigModel,IndexConfigService indexConfigService) {
|
|
|
super(calcCode, calcName, CalcType.INDEX, initContext);
|
|
|
+ this.indexConfigModel = indexConfigModel;
|
|
|
+ this.indexConfigService = indexConfigService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -65,6 +77,9 @@ public class IndexCalcUnit extends CalcUnit {
|
|
|
@Override
|
|
|
public List<CalcUnit> getSourceCalcUnits() {
|
|
|
// TODO 获取源头节点
|
|
|
+ List<IndexSourceModel> indexList = indexConfigService.getIndexSourceList(new IndexConfigModel());
|
|
|
+ indexList.stream().map(sourceModel -> new IndexSourceCalcUnit
|
|
|
+ (sourceModel.getIndexNo(),sourceModel.getIndexName(),CalcType.INDEX,Map.of(),sourceModel));
|
|
|
return new ArrayList<>();
|
|
|
// return ConfigImages.indexCalcUnitListMap.get(this);
|
|
|
}
|
|
@@ -103,6 +118,52 @@ public class IndexCalcUnit extends CalcUnit {
|
|
|
|
|
|
// TODO 实际的计算过程
|
|
|
|
|
|
+ AtomicInteger i = new AtomicInteger();
|
|
|
+ AtomicInteger j = new AtomicInteger();
|
|
|
+ CalcResult<String, Object> indexResult = null;
|
|
|
+ CalcResult<String, Object> dataSetResult = null;
|
|
|
+ // List<IndexSourceModel> sourceModelList = indexConfigModel.getIndexSourceModel();
|
|
|
+ sourceResults.forEach((calcUnit,result) -> {
|
|
|
+ // 数据集
|
|
|
+ if ( calcUnit instanceof DataSetCalcUnit dataSetCalcUnit){
|
|
|
+ if(dataSetCalcUnit.getCalcType() == CalcType.DATASET){
|
|
|
+ i.getAndIncrement();
|
|
|
+ dataSetResult.putAll(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 其他指标
|
|
|
+ if( calcUnit instanceof IndexCalcUnit indexCalcUnit){
|
|
|
+ if(indexCalcUnit.getCalcType() == CalcType.INDEX){
|
|
|
+ j.getAndIncrement();
|
|
|
+ indexResult.putAll(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ sourceResults.forEach((calcUnit,result) -> {
|
|
|
+ if (i.get() > 0 && j.get() == 0){
|
|
|
+ // 如果数据集的数量大于0
|
|
|
+ String logic = indexConfigModel.getIndexLogic();
|
|
|
+ // 执行sql,并放进结果集内
|
|
|
+ thisResult.put(this.getCalcCode(),DBExecutor.doQueryMap(logic));
|
|
|
+ }
|
|
|
+ if(j.get() > 0 && i.get() == 0){
|
|
|
+ // 如果指标的数量大于0
|
|
|
+ String logic = indexConfigModel.getIndexLogic();
|
|
|
+ // 执行模板,结果放入结果集
|
|
|
+ ScriptUtil.executeScript(indexConfigModel.getIndexNo(),logic,result);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ if (i.get() > 0 && j.get() >0) {
|
|
|
+ // 同时具有指标和数据集
|
|
|
+ String logic = indexConfigModel.getIndexLogic();
|
|
|
+ // 先将sql作为一个模板进行处理,将指标的结果作为参数带入模板成为一个新模板,后在将数据集的参数带入
|
|
|
+ String editSql = (String) ScriptUtil.executeScript(indexConfigModel.getIndexNo(),logic,indexResult);
|
|
|
+ thisResult.put(this.getCalcCode(),DBExecutor.doQueryMap(logic,dataSetResult));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
// Map<CalcUnit, CalcResult<String, Object>> dataMap = new HashMap<>();
|
|
|
//
|