Эх сурвалжийг харах

Merge remote-tracking branch 'origin/master' into last

zhao_gqing 2 сар өмнө
parent
commit
67f1c789bd

+ 38 - 57
src/main/java/com/sundata/internalevaluation/calc/calcUnit/IndexCalcUnit.java

@@ -13,6 +13,7 @@ import com.sundata.internalevaluation.configuration.model.IndexSourceModel;
 import com.sundata.internalevaluation.configuration.service.DataSetConfigService;
 import com.sundata.internalevaluation.configuration.service.IndexConfigService;
 import com.sundata.internalevaluation.script.ScriptUtil;
+import com.sundata.internalevaluation.script.TemplateUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -20,6 +21,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
 public class IndexCalcUnit extends CalcUnit {
@@ -149,81 +151,60 @@ public class IndexCalcUnit extends CalcUnit {
     public void calc(final CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
 
         // TODO 实际的计算过程
+        // 记录数据集出现次数
+        AtomicInteger dataSetNumber = new AtomicInteger();
+        // 记录其他指标出现次数
+        AtomicInteger indexNumber = new AtomicInteger();
+        // 声明只存放指标源头节点变量
+        AtomicReference<CalcResult<String, Object>> indexResult = new AtomicReference<>();
+        // 声明只存放所有数据集源头节点变量
+        AtomicReference<CalcResult<String, Object>> dataSetResult = new AtomicReference<>();
 
-        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);
+                    dataSetNumber.getAndIncrement();
+                    dataSetResult.setOpaque(result);
                 }
             }
             // 其他指标
             if( calcUnit instanceof IndexCalcUnit indexCalcUnit){
                 if(indexCalcUnit.getCalcType() == CalcType.INDEX){
-                    j.getAndIncrement();
-                    indexResult.putAll(result);
+                    indexNumber.getAndIncrement();
+                    indexResult.setOpaque(result);
                 }
             }
         });
-        StringBuffer sb = new StringBuffer();
-        sourceResults.forEach((calcUnit,result) -> {
-            if (i.get() > 0 && j.get() == 0){
-                // 如果数据集的数量大于0
-                String logic = indexConfigModel.getIndexLogic();
-                // 执行sql,并放进结果集内
-                // JsonToCalciteExample.jsonTotable()
-                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);
-                // JsonToCalciteExample.jsonTotable()
-                // thisResult.put(this.getCalcCode(),DBExecutor.doQueryMap(logic,dataSetResult));
-            }
 
-        });
-        if (i.get() > 0 && j.get() >0) {
-            // 同时具有指标和数据集
+        if (dataSetNumber.get() > 0 && indexNumber.get() == 0){
+            // 如果数据集的数量大于0
+            // 获取指标逻辑
             String logic = indexConfigModel.getIndexLogic();
-            // 先将sql作为一个模板进行处理,将指标的结果作为参数带入模板成为一个新模板,后在将数据集的参数带入
-            String editSql = (String) ScriptUtil.executeScript(indexConfigModel.getIndexNo(),logic,indexResult);
+            // 执行sql,并放进结果集内
             // JsonToCalciteExample.jsonTotable()
-            thisResult.put(this.getCalcCode(),DBExecutor.doQueryMap(logic,dataSetResult));
+            // TODO 计算逻辑
+            thisResult.put(this.getCalcCode(),DBExecutor.doQueryMap(logic));
         }
+        if(indexNumber.get() > 0 && dataSetNumber.get() == 0){
+            // 如果指标的数量大于0
+            // 获取指标逻辑
+            String logic = indexConfigModel.getIndexLogic();
+            // 执行公式,结果放入结果集
+            Object result = ScriptUtil.executeScript(indexConfigModel.getIndexNo(),logic,indexResult.get());
+            // JsonToCalciteExample.jsonTotable()
+            thisResult.put(this.getCalcCode(),result);
+        }
+        if (dataSetNumber.get() > 0 && indexNumber.get() >0) {
+            // 同时具有指标和数据集
+            // 获取指标逻辑
+            String logic = indexConfigModel.getIndexLogic();
+            // 先将sql作为一个  进行处理,将指标的结果作为参数带入模板成为一个新模板,后在将数据集的参数带入
 
+            String editSql =  TemplateUtil.execute(indexConfigModel.getIndexNo(),logic,indexResult.get());
+            // JsonToCalciteExample.jsonTotable()
 
-
-//        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);
-//            }
-//        });
+            thisResult.put(this.getCalcCode(),DBExecutor.doQueryMap(editSql));
+        }
     }
 }

+ 5 - 0
src/main/java/com/sundata/internalevaluation/configuration/mybatis/DataSetConfigMapper.xml

@@ -80,4 +80,9 @@
         </where>
     </select>
 
+    <!-- 数据源字典 -->
+    <select id="selectDataSource" resultType="com.sundata.admin.nounmanage.model.DictContent">
+        select  DATASOURCESNO as id, DATASOURCESNAME as text from SYS_DATA_SOURCES
+    </select>
+
 </mapper>