Browse Source

合并数据集方式改变

ZhangYanJie 3 months ago
parent
commit
d527e14b50

+ 4 - 2
src/main/java/com/sundata/internalevaluation/calc/calcUnit/DataSetCalcUnit.java

@@ -14,6 +14,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicReference;
@@ -127,10 +128,11 @@ public class DataSetCalcUnit extends CalcUnit {
     public void calc(final CalcResult<String, Object> thisResult, String calculateInstanceNumber,Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
 
         // TODO 实际的计算过程
-        AtomicReference<CalcResult<String, Object>> resultMap = new AtomicReference<>();
+        // AtomicReference<CalcResult<String, Object>> resultMap = new AtomicReference<>();
+        Map<String,Object> resultMap = new HashMap<>();
         // 合并数据集
         sourceResults.forEach((calcUnit,result)-> {
-            resultMap.setOpaque(result);
+            resultMap.putAll(result);
         });
         thisResult.put(this.getCalcCode(),resultMap);
 

+ 12 - 15
src/main/java/com/sundata/internalevaluation/calc/calcUnit/IndexCalcUnit.java

@@ -18,10 +18,7 @@ import org.apache.calcite.schema.SchemaPlus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
@@ -168,32 +165,32 @@ public class IndexCalcUnit extends CalcUnit {
         // 记录其他指标出现次数
         AtomicInteger indexNumber = new AtomicInteger();
         // 声明只存放指标源头节点变量
-        AtomicReference<CalcResult<String, Object>> indexResult = new AtomicReference<>();
+        Map<String, Object> indexResult = new HashMap<>();
         // 声明只存放所有数据集源头节点变量
-        AtomicReference<CalcResult<String, Object>> dataSetResult = new AtomicReference<>();
+        Map<String, Object> dataSetResult = new HashMap<>();
 
         sourceResults.forEach((calcUnit,result) -> {
             // 数据集
             if ( calcUnit instanceof DataSetCalcUnit dataSetCalcUnit){
                 if(dataSetCalcUnit.getCalcType() == CalcType.DATASET){
                     dataSetNumber.getAndIncrement();
-                    dataSetResult.setOpaque(result);
+                    dataSetResult.putAll(result);
                 }
             }
             // 其他指标
             if( calcUnit instanceof IndexCalcUnit indexCalcUnit){
                 if(indexCalcUnit.getCalcType() == CalcType.INDEX){
                     indexNumber.getAndIncrement();
-                    indexResult.setOpaque(result);
+                    indexResult.putAll(result);
                 }
             }
         });
 
         if (dataSetNumber.get() > 0 && indexNumber.get() == 0){
 
-            String json = JsonUtil.toJSONString(dataSetResult.get());
-            SchemaPlus tableArea = JsonToCalciteExample.jsonTotable(this.indexConfigModel.getIndexNo(),json);
-            Set<String> tacleSet = tableArea.getSubSchema(this.indexConfigModel.getIndexNo()).getTableNames();
+            // String json = JsonUtil.toJSONString(dataSetResult.get());
+            //SchemaPlus tableArea = JsonToCalciteExample.jsonTotable(this.indexConfigModel.getIndexNo(),"");
+            //Set<String> tacleSet = tableArea.getSubSchema(this.indexConfigModel.getIndexNo()).getTableNames();
             // 如果数据集的数量大于0
             // 获取指标逻辑
             String logic = indexConfigModel.getIndexLogic();
@@ -207,19 +204,19 @@ public class IndexCalcUnit extends CalcUnit {
             // 获取指标逻辑
             String logic = indexConfigModel.getIndexLogic();
             // 执行公式,结果放入结果集
-            Object result = ScriptUtil.executeScript(indexConfigModel.getIndexNo(),logic,indexResult.get());
+            Object result = ScriptUtil.executeScript(indexConfigModel.getIndexNo(),logic,indexResult);
             // JsonToCalciteExample.jsonTotable()
             thisResult.put(this.getCalcCode(),result);
         }
         if (dataSetNumber.get() > 0 && indexNumber.get() >0) {
-            String json = JsonUtil.toJSONString(dataSetResult.get());
-            SchemaPlus tableArea = JsonToCalciteExample.jsonTotable(this.indexConfigModel.getIndexNo(),json);
+            //String json = JsonUtil.toJSONString(dataSetResult.get());
+            //SchemaPlus tableArea = JsonToCalciteExample.jsonTotable(this.indexConfigModel.getIndexNo(),"");
             // 同时具有指标和数据集
             // 获取指标逻辑
             String logic = indexConfigModel.getIndexLogic();
             // 先将sql作为一个  进行处理,将指标的结果作为参数带入模板成为一个新模板,后在将数据集的参数带入
 
-            String editSql =  TemplateUtil.execute(indexConfigModel.getIndexNo(),logic,indexResult.get());
+            String editSql =  TemplateUtil.execute(indexConfigModel.getIndexNo(),logic,indexResult);
 
 
             thisResult.put(this.getCalcCode(),DBExecutor.doQueryMap(editSql));