|
@@ -118,19 +118,17 @@ public class IndexCalcUnit extends CalcUnit {
|
|
dataSetCalcList = dataSetList.stream().map(dataSetModel -> new DataSetCalcUnit
|
|
dataSetCalcList = dataSetList.stream().map(dataSetModel -> new DataSetCalcUnit
|
|
(dataSetModel.getDataSetNo(),dataSetModel.getDataSetName(),Map.of(),dataSetModel)).collect(Collectors.toList());
|
|
(dataSetModel.getDataSetNo(),dataSetModel.getDataSetName(),Map.of(),dataSetModel)).collect(Collectors.toList());
|
|
}
|
|
}
|
|
-// selectList.stream().map(sourceModel -> new IndexSourceCalcUnit
|
|
|
|
-// (sourceModel.getOtherIndexNo(),"",CalcType.INDEX,Map.of(),sourceModel));
|
|
|
|
|
|
+
|
|
// 结果封装
|
|
// 结果封装
|
|
if (null != indexCalcList) {
|
|
if (null != indexCalcList) {
|
|
resultCalcMap.addAll(indexCalcList);
|
|
resultCalcMap.addAll(indexCalcList);
|
|
}
|
|
}
|
|
|
|
+
|
|
if (null != dataSetCalcList) {
|
|
if (null != dataSetCalcList) {
|
|
resultCalcMap.addAll(dataSetCalcList);
|
|
resultCalcMap.addAll(dataSetCalcList);
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ // 返回所有源头节点
|
|
return resultCalcMap;
|
|
return resultCalcMap;
|
|
-// return ConfigImages.indexCalcUnitListMap.get(this);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -174,55 +172,56 @@ public class IndexCalcUnit extends CalcUnit {
|
|
Map<String, Object> indexResult = new HashMap<>();
|
|
Map<String, Object> indexResult = new HashMap<>();
|
|
// 声明只存放所有数据集源头节点变量
|
|
// 声明只存放所有数据集源头节点变量
|
|
Map<String, Object> dataSetResult = new HashMap<>();
|
|
Map<String, Object> dataSetResult = new HashMap<>();
|
|
-
|
|
|
|
|
|
+ // 遍历结果集
|
|
sourceResults.forEach((calcUnit,result) -> {
|
|
sourceResults.forEach((calcUnit,result) -> {
|
|
// 数据集
|
|
// 数据集
|
|
if ( calcUnit instanceof DataSetCalcUnit dataSetCalcUnit){
|
|
if ( calcUnit instanceof DataSetCalcUnit dataSetCalcUnit){
|
|
if(dataSetCalcUnit.getCalcType() == CalcType.DATASET){
|
|
if(dataSetCalcUnit.getCalcType() == CalcType.DATASET){
|
|
|
|
+ // 记录记过集次数
|
|
dataSetNumber.getAndIncrement();
|
|
dataSetNumber.getAndIncrement();
|
|
- dataSetResult.putAll((Map) result.get(calcUnit.getCalcCode()));
|
|
|
|
|
|
+ // 将源头节点的返回值取出
|
|
|
|
+ dataSetResult.putAll(result);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 其他指标
|
|
// 其他指标
|
|
if( calcUnit instanceof IndexCalcUnit indexCalcUnit){
|
|
if( calcUnit instanceof IndexCalcUnit indexCalcUnit){
|
|
if(indexCalcUnit.getCalcType() == CalcType.INDEX){
|
|
if(indexCalcUnit.getCalcType() == CalcType.INDEX){
|
|
|
|
+ // 记录指标出现次数
|
|
indexNumber.getAndIncrement();
|
|
indexNumber.getAndIncrement();
|
|
|
|
+ // 记录指标节点的返回值
|
|
indexResult.putAll(result);
|
|
indexResult.putAll(result);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-
|
|
|
|
- // TODO
|
|
|
|
- // TODO
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ // TODO 计算过程开始
|
|
if (dataSetNumber.get() > 0 && indexNumber.get() == 0){
|
|
if (dataSetNumber.get() > 0 && indexNumber.get() == 0){
|
|
-
|
|
|
|
|
|
+ // 如果数据集的数量大于0
|
|
|
|
+ // 将数据集返回结果转化成json
|
|
String json = JsonUtil.toJSONString(dataSetResult);
|
|
String json = JsonUtil.toJSONString(dataSetResult);
|
|
|
|
+ // 实例化组建域对象
|
|
JsonToCalciteExample jsonUtil = new JsonToCalciteExample();
|
|
JsonToCalciteExample jsonUtil = new JsonToCalciteExample();
|
|
-
|
|
|
|
-
|
|
|
|
- // 如果数据集的数量大于0
|
|
|
|
// 获取指标逻辑
|
|
// 获取指标逻辑
|
|
String logic = indexConfigModel.getIndexLogic();
|
|
String logic = indexConfigModel.getIndexLogic();
|
|
|
|
+ // 获取域名
|
|
|
|
|
|
- Object resValue = jsonUtil.jsonTotable(this.getCalcCode(),json,logic);
|
|
|
|
-
|
|
|
|
- // 执行sql,并放进结果集内
|
|
|
|
|
|
+ // 执行sql
|
|
|
|
+ Object resValue = jsonUtil.jsonTotable(json,logic);
|
|
|
|
|
|
- // TODO 计算逻辑
|
|
|
|
|
|
+ // 执行结果放进结果集内
|
|
thisResult.put(this.getCalcCode(),resValue);
|
|
thisResult.put(this.getCalcCode(),resValue);
|
|
}
|
|
}
|
|
|
|
+
|
|
if(indexNumber.get() > 0 && dataSetNumber.get() == 0){
|
|
if(indexNumber.get() > 0 && dataSetNumber.get() == 0){
|
|
// 如果指标的数量大于0
|
|
// 如果指标的数量大于0
|
|
// 获取指标逻辑
|
|
// 获取指标逻辑
|
|
String logic = indexConfigModel.getIndexLogic();
|
|
String logic = indexConfigModel.getIndexLogic();
|
|
// 执行公式,结果放入结果集
|
|
// 执行公式,结果放入结果集
|
|
Object result = ScriptUtil.executeScript(indexConfigModel.getIndexNo(),logic,indexResult);
|
|
Object result = ScriptUtil.executeScript(indexConfigModel.getIndexNo(),logic,indexResult);
|
|
- // JsonToCalciteExample.jsonTotable()
|
|
|
|
|
|
+ // 指标执行公式放入结果集
|
|
thisResult.put(this.getCalcCode(),result);
|
|
thisResult.put(this.getCalcCode(),result);
|
|
}
|
|
}
|
|
|
|
+
|
|
if (dataSetNumber.get() > 0 && indexNumber.get() >0) {
|
|
if (dataSetNumber.get() > 0 && indexNumber.get() >0) {
|
|
// 同时具有指标和数据集
|
|
// 同时具有指标和数据集
|
|
JsonToCalciteExample jsonUtil = new JsonToCalciteExample();
|
|
JsonToCalciteExample jsonUtil = new JsonToCalciteExample();
|
|
@@ -233,43 +232,12 @@ public class IndexCalcUnit extends CalcUnit {
|
|
// 将数据集得到的数据转json
|
|
// 将数据集得到的数据转json
|
|
String json = JsonUtil.toJSONString(dataSetResult);
|
|
String json = JsonUtil.toJSONString(dataSetResult);
|
|
// 执行拿结果
|
|
// 执行拿结果
|
|
- Object resValue = jsonUtil.jsonTotable(this.indexConfigModel.getIndexNo(),json,editSql);
|
|
|
|
|
|
+ Object resValue = jsonUtil.jsonTotable(json,editSql);
|
|
// 放结果
|
|
// 放结果
|
|
thisResult.put(this.getCalcCode(),resValue);
|
|
thisResult.put(this.getCalcCode(),resValue);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
- *
|
|
|
|
- * @param calciteConnection
|
|
|
|
- * @param sql
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public Object getConnectionTable (CalciteConnection calciteConnection,String sql) {
|
|
|
|
- //获取域
|
|
|
|
- SchemaPlus rootSchemafter = calciteConnection.getRootSchema();
|
|
|
|
- //根域中获取子域
|
|
|
|
- SchemaPlus childrenSchema=rootSchemafter.getSubSchema(this.getCalcCode());
|
|
|
|
- //子域名
|
|
|
|
- String childrenName = childrenSchema.getName();
|
|
|
|
- System.out.println("childrenName: " + childrenName);
|
|
|
|
- //子域中表名
|
|
|
|
- tableSet = childrenSchema.getTableNames();
|
|
|
|
-
|
|
|
|
- String value = "";
|
|
|
|
|
|
|
|
- try {
|
|
|
|
- Statement statement = calciteConnection.createStatement();
|
|
|
|
- ResultSet resultSet = statement.executeQuery(sql);
|
|
|
|
- if (resultSet.next()){
|
|
|
|
- //value = resultSet.getString(1);
|
|
|
|
- return resultSet.getObject(1);
|
|
|
|
-// System.out.println();
|
|
|
|
- }
|
|
|
|
- } catch (SQLException e) {
|
|
|
|
- throw new RuntimeException(e);
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|