Răsfoiți Sursa

数据源接口和jdbc逻辑修改提交

ZhangYanJie 3 luni în urmă
părinte
comite
2271dbded5

+ 21 - 14
src/main/java/com/sundata/internalevaluation/calc/calcUnit/DataSourcesCalcUnit.java

@@ -81,15 +81,28 @@ public class DataSourcesCalcUnit extends CalcUnit {
         DataSourcesService sourcesService = SpringUtil.getBean(DataSourcesService.class);
         SysInterfaceService sysInterfaceService = SpringUtil.getBean(SysInterfaceService.class);
         DataSourcesModel selectModel = sourcesService.selectDetailData(this.dataSourcesModel.getDataSourcesNo());
-        List<String> interfaceNos = selectModel.getRequestInterfaces();
+
+        // 记录所有源头节点
+        List<CalcUnit> allUnitList = new ArrayList<>();
+
         List<SysInterface> sysInterfaceModelList = new ArrayList<>();
-        for ( String s : interfaceNos) {
-            sysInterfaceModelList.add(sysInterfaceService.getById(s));
+
+        // 接口源节点
+        if ("INTERFACE".equals(dataSourcesModel.getDataSourcesType())) {
+            List<String> interfaceNos = selectModel.getRequestInterfaces();
+            for ( String s : interfaceNos) {
+                sysInterfaceModelList.add(sysInterfaceService.getById(s));
+            }
+            List<CalcUnit> interFaceList = sysInterfaceModelList.stream().map(interfaceModel -> new InterfaceCalcUnit(interfaceModel.getId(),interfaceModel.getInterfaceName(),CalcType.INTERFACE,Map.of(),interfaceModel)).collect(Collectors.toList());
+            allUnitList.addAll(interFaceList);
+        }
+
+        // 查询逻辑源节点
+        if ("JDBC".equals(dataSourcesModel.getDataSourcesType())) {
+            List<CalcUnit> queryList = dataSourcesModel.getQueryLogic().stream().map(queryParam -> new QueryLogicCalcUnit(queryParam.getDataItemName(),queryParam.getScriptDescription(),CalcType.QUERYLOGIC,Map.of(),queryParam)).collect(Collectors.toList());
+            allUnitList.addAll(queryList);
         }
-        List<CalcUnit> interFaceList = sysInterfaceModelList.stream().map(interfaceModel -> new InterfaceCalcUnit(interfaceModel.getId(),interfaceModel.getInterfaceName(),CalcType.INTERFACE,Map.of(),interfaceModel)).collect(Collectors.toList());
-        List<CalcUnit> queryList = dataSourcesModel.getQueryLogic().stream().map(queryParam -> new QueryLogicCalcUnit(queryParam.getDataItemName(),queryParam.getScriptDescription(),CalcType.QUERYLOGIC,Map.of(),queryParam)).collect(Collectors.toList());
-        interFaceList.addAll(queryList);
-        return interFaceList;
+        return allUnitList;
 
         // 取得个配置信息
 //        List<DataSourcesModel> dataList = sourcesService.getDataList(new DataSourcesModel());
@@ -150,14 +163,8 @@ public class DataSourcesCalcUnit extends CalcUnit {
             } else if ("JDBC".equals(dataSourcesModel.getDataSourcesType())) {
                 // 数据来源类型为jdbc时处理逻辑
                 if (calcUnit instanceof QueryLogicCalcUnit queryLogicCalcUnit) {
-                    // 取得查询逻辑脚本
-                    String sqlTemplate = queryLogicCalcUnit.queryLogicModel.getSelectSqlScript();
-                    // 执行模板
-                    String sql = TemplateUtil.execute(calcUnit.getCalcCode(), sqlTemplate, result);
-                    // 查询本地数据库
-                    Map<String, Object> stringObjectMap = DBExecutor.doQueryMap(sql);
                     // 结果封装,数据项名做key
-                    thisResult.put(queryLogicCalcUnit.queryLogicModel.getDataItemName(), stringObjectMap);
+                    thisResult.put(queryLogicCalcUnit.queryLogicModel.getDataItemName(), result.get(queryLogicCalcUnit.getCalcCode()));
                 }
             }
         });

+ 10 - 1
src/main/java/com/sundata/internalevaluation/calc/calcUnit/QueryLogicCalcUnit.java

@@ -1,9 +1,11 @@
 package com.sundata.internalevaluation.calc.calcUnit;
 
+import com.sundata.common.util.DBExecutor;
 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.QueryLogicModel;
+import com.sundata.internalevaluation.script.TemplateUtil;
 
 import java.util.List;
 import java.util.Map;
@@ -93,6 +95,13 @@ public class QueryLogicCalcUnit extends CalcUnit {
      */
     @Override
     public void calc(CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
-
+        // 取得查询逻辑脚本
+        String sqlTemplate = this.queryLogicModel.getSelectSqlScript();
+        // 执行模板
+        String sql = TemplateUtil.execute(this.getCalcCode(), sqlTemplate, context);
+        // 查询本地数据库
+        List<Map<String, Object>> maps = DBExecutor.doQueryMapList(sql);
+        // 结果封装,数据项名做key
+        thisResult.put(this.queryLogicModel.getDataItemName(), maps);
     }
 }

+ 2 - 1
src/main/java/com/sundata/internalevaluation/conf/JsonToCalciteExample.java

@@ -59,9 +59,10 @@ public class JsonToCalciteExample {
 
             //调用张艳杰接收连接方法
             resValue = getConnectionTable(calciteConnection,sql);
-
+            // 关闭连接信息
             connection.close();
         } catch (Exception e) {
+            e.printStackTrace();
             throw new RuntimeException(e);
         }
         return resValue;