|
@@ -14,10 +14,15 @@ 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.apache.calcite.jdbc.CalciteConnection;
|
|
|
import org.apache.calcite.schema.SchemaPlus;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import java.sql.ResultSet;
|
|
|
+import java.sql.ResultSetMetaData;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.sql.Statement;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
@@ -28,6 +33,10 @@ public class IndexCalcUnit extends CalcUnit {
|
|
|
private final IndexConfigModel indexConfigModel;
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(IndexCalcUnit.class);
|
|
|
+
|
|
|
+ // 接收表集
|
|
|
+ private Set<String> tableSet = null;
|
|
|
+
|
|
|
/**
|
|
|
* 创建数据单元的绝对对象,对象必须包含如下参数
|
|
|
*
|
|
@@ -188,16 +197,20 @@ public class IndexCalcUnit extends CalcUnit {
|
|
|
|
|
|
if (dataSetNumber.get() > 0 && indexNumber.get() == 0){
|
|
|
|
|
|
- // String json = JsonUtil.toJSONString(dataSetResult.get());
|
|
|
- //SchemaPlus tableArea = JsonToCalciteExample.jsonTotable(this.indexConfigModel.getIndexNo(),"");
|
|
|
- //Set<String> tacleSet = tableArea.getSubSchema(this.indexConfigModel.getIndexNo()).getTableNames();
|
|
|
+ String json = JsonUtil.toJSONString(dataSetResult);
|
|
|
+ JsonToCalciteExample jsonUtil = new JsonToCalciteExample();
|
|
|
+
|
|
|
+
|
|
|
// 如果数据集的数量大于0
|
|
|
// 获取指标逻辑
|
|
|
String logic = indexConfigModel.getIndexLogic();
|
|
|
+
|
|
|
+ String resValue = jsonUtil.jsonTotable(this.indexConfigModel.getIndexNo(),json,logic);
|
|
|
+
|
|
|
// 执行sql,并放进结果集内
|
|
|
|
|
|
// TODO 计算逻辑
|
|
|
- thisResult.put(this.getCalcCode(),DBExecutor.doQueryMap(logic));
|
|
|
+ thisResult.put(this.getCalcCode(),resValue);
|
|
|
}
|
|
|
if(indexNumber.get() > 0 && dataSetNumber.get() == 0){
|
|
|
// 如果指标的数量大于0
|
|
@@ -209,17 +222,45 @@ public class IndexCalcUnit extends CalcUnit {
|
|
|
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(),"");
|
|
|
// 同时具有指标和数据集
|
|
|
+ JsonToCalciteExample jsonUtil = new JsonToCalciteExample();
|
|
|
// 获取指标逻辑
|
|
|
String logic = indexConfigModel.getIndexLogic();
|
|
|
- // 先将sql作为一个 进行处理,将指标的结果作为参数带入模板成为一个新模板,后在将数据集的参数带入
|
|
|
-
|
|
|
+ // 先将sql中指标公式替换掉,再将得到的sql执行
|
|
|
String editSql = TemplateUtil.execute(indexConfigModel.getIndexNo(),logic,indexResult);
|
|
|
+ // 将数据集得到的数据转json
|
|
|
+ String json = JsonUtil.toJSONString(dataSetResult);
|
|
|
+ // 执行拿结果
|
|
|
+ String resValue = jsonUtil.jsonTotable(this.indexConfigModel.getIndexNo(),json,editSql);
|
|
|
+ // 放结果
|
|
|
+ thisResult.put(this.getCalcCode(),resValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ public String getConnectionTable (CalciteConnection calciteConnection,String sql) {
|
|
|
+ //获取域
|
|
|
+ SchemaPlus rootSchemafter = calciteConnection.getRootSchema();
|
|
|
+ //根域中获取子域
|
|
|
+ SchemaPlus childrenSchema=rootSchemafter.getSubSchema("test");
|
|
|
+ //子域名
|
|
|
+ String childrenName = childrenSchema.getName();
|
|
|
+ System.out.println("childrenName: " + childrenName);
|
|
|
+ //子域中表名
|
|
|
+ tableSet = childrenSchema.getTableNames();
|
|
|
|
|
|
- thisResult.put(this.getCalcCode(),DBExecutor.doQueryMap(editSql));
|
|
|
+ String value = "";
|
|
|
+
|
|
|
+ try {
|
|
|
+ Statement statement = calciteConnection.createStatement();
|
|
|
+ ResultSet resultSet = statement.executeQuery(sql);
|
|
|
+ if (resultSet.next()){
|
|
|
+ value = resultSet.getString(1);
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ return value;
|
|
|
}
|
|
|
}
|
|
|
}
|