|
@@ -8,13 +8,18 @@ import com.bowintek.practice.mapper.cquery.TempCQuery;
|
|
|
import com.bowintek.practice.model.*;
|
|
|
import com.bowintek.practice.services.service.GenSqlStringService;
|
|
|
import com.bowintek.practice.services.service.TempService;
|
|
|
+import com.bowintek.practice.util.multipdb.DBTypeEnum;
|
|
|
+import com.bowintek.practice.util.multipdb.SwitchDataSource;
|
|
|
import com.bowintek.practice.vo.temp.SqlColumnModel;
|
|
|
import com.bowintek.practice.vo.temp.SqlFieldModel;
|
|
|
import com.bowintek.practice.vo.temp.TempObjectModel;
|
|
|
import com.bowintek.practice.vo.temp.TempSaveResult;
|
|
|
+import org.apache.ibatis.jdbc.SqlRunner;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.DriverManager;
|
|
|
import java.text.MessageFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.RecursiveTask;
|
|
@@ -26,6 +31,25 @@ public class GenSqlStringServiceImpl implements GenSqlStringService {
|
|
|
SrSubjectMapper srSubjectMapper;
|
|
|
@Autowired
|
|
|
SrSubjectfieldMapper srSubjectfieldMapper;
|
|
|
+ @Autowired
|
|
|
+ TempCQuery tempCQuery;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @SwitchDataSource(DBTypeEnum.POSTGRE)
|
|
|
+ public List<Map<String,Object>> getListBySqlString(String sqlString){
|
|
|
+ //return tempCQuery.getListBySqlString(sqlString);
|
|
|
+ try {
|
|
|
+ Connection connection = DriverManager.getConnection(
|
|
|
+ "jdbc:mysql://office.bowintek.com:3306/practicedb?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai",
|
|
|
+ "root", "bowin123");
|
|
|
+ SqlRunner sqlRunner = new SqlRunner(connection);
|
|
|
+ return sqlRunner.selectAll(sqlString);
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ ex.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//查询语句生成,要素点:查询主表、关联子表、查询字段、查询条件
|
|
|
//查询主表:FROM (sr_subject.execSql) AS T
|
|
@@ -35,7 +59,7 @@ public class GenSqlStringServiceImpl implements GenSqlStringService {
|
|
|
//输出字段 AS:ReFieldName0,1,2...;依据维度度量排序来
|
|
|
//表名 AS:T 主表,T0,1,2...;子表,依据维度度量子表排序来
|
|
|
@Override
|
|
|
- public void Generation(TempObjectModel data, String userID){
|
|
|
+ public String Generation(TempObjectModel data, String userID){
|
|
|
//取得字段原本定义
|
|
|
data.sub = srSubjectMapper.selectByPrimaryKey(data.temp.getSubId());
|
|
|
List<SrSubjectfield> fileds = getSubjectfieldsBySubId(data.temp.getSubId());
|
|
@@ -101,14 +125,15 @@ public class GenSqlStringServiceImpl implements GenSqlStringService {
|
|
|
System.out.println("data.orderBy:"+data.orderBy);
|
|
|
|
|
|
if(aliasMap.containsKey(data.orderBy)){
|
|
|
- if(IsNullEmpty(data.orderByString)) data.orderByString = "aes";
|
|
|
+ if(IsNullEmpty(data.orderByString)) data.orderByString = "asc";
|
|
|
SqlColumnModel cmOrder = aliasMap.get(data.orderBy);
|
|
|
orderByString = MessageFormat.format("ORDER BY {0} {1}", cmOrder.getDisplayColumn(), data.orderByString);
|
|
|
}
|
|
|
|
|
|
- String mainSqlStrimg = MessageFormat.format("SELECT {0} \nFROM ({1}) AS T {2} \nGROUP BY {3} \nWHERE 1=1 {4} \n\n{5}",
|
|
|
- colString, data.sub.getExecSql(), leftTableString, groupString, whereString, orderByString);
|
|
|
+ String mainSqlStrimg = MessageFormat.format("SELECT {0} \nFROM {1} AS T {2} \nWHERE 1=1 {3} \nGROUP BY {4} \n\n{5}",
|
|
|
+ colString, data.sub.getExecSql(), leftTableString, whereString, groupString, orderByString);
|
|
|
System.out.println(mainSqlStrimg);
|
|
|
+ return mainSqlStrimg;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -127,7 +152,7 @@ public class GenSqlStringServiceImpl implements GenSqlStringService {
|
|
|
return value == null || value.isEmpty();
|
|
|
}
|
|
|
public String genWhereString(SrTempfield stf){
|
|
|
- if(stf.getOperation().isEmpty() || stf.getValue1().isEmpty())
|
|
|
+ if(IsNullEmpty(stf.getOperation()) || IsNullEmpty(stf.getValue1()))
|
|
|
return genRemark("genWhereString", stf.getTempFeildId());
|
|
|
|
|
|
if(stf.getOperation().equals("="))
|
|
@@ -141,8 +166,8 @@ public class GenSqlStringServiceImpl implements GenSqlStringService {
|
|
|
}
|
|
|
|
|
|
public String genWhereNumber(SrTempfield stf){
|
|
|
- if(stf.getOperation().isEmpty() || stf.getValue1().isEmpty() ||
|
|
|
- (stf.getOperation().equals("limit") && stf.getValue2().isEmpty()))
|
|
|
+ if(IsNullEmpty(stf.getOperation()) || IsNullEmpty(stf.getValue1()) ||
|
|
|
+ (stf.getOperation().equals("limit") && IsNullEmpty(stf.getValue2())))
|
|
|
return genRemark("genWhereNumber", stf.getTempFeildId());
|
|
|
|
|
|
if(stf.getOperation().equals("limit"))
|
|
@@ -153,21 +178,22 @@ public class GenSqlStringServiceImpl implements GenSqlStringService {
|
|
|
}
|
|
|
|
|
|
public String genWhereDate(SrTempfield stf){
|
|
|
- if(stf.getOperation().isEmpty()) return genRemark("genWhereDate", stf.getTempFeildId());
|
|
|
+ if(IsNullEmpty(stf.getOperation())) return genRemark("genWhereDate", stf.getTempFeildId());
|
|
|
|
|
|
String where = "";
|
|
|
- if(!stf.getValue1().isEmpty())
|
|
|
+ if(!IsNullEmpty(stf.getValue1()))
|
|
|
where += MessageFormat.format("\n\tAND T.{0} >= {1}", stf.getFieldAlias(),
|
|
|
"'"+stf.getValue1()+"'");
|
|
|
- if(!stf.getValue2().isEmpty())
|
|
|
+ if(!IsNullEmpty(stf.getValue2()))
|
|
|
where += MessageFormat.format("\n\tAND T.{0} <= {1}", stf.getFieldAlias(),
|
|
|
"'"+stf.getValue2()+"'");
|
|
|
|
|
|
- return where.isEmpty()?genRemark("genWhereDate", stf.getTempFeildId()) : where;
|
|
|
+ return IsNullEmpty(where)?genRemark("genWhereDate", stf.getTempFeildId()) : where;
|
|
|
}
|
|
|
|
|
|
public String genRemark(String fun,String key) {
|
|
|
- return "\n/*" + fun + " " + key + " is gen err*/";
|
|
|
+ //return "\n/*" + fun + " " + key + " is gen err*/";
|
|
|
+ return "";
|
|
|
}
|
|
|
|
|
|
public SrSubjectfield findFieldByFieldId(List<SrSubjectfield> fields, String fieldId){
|
|
@@ -186,7 +212,7 @@ public class GenSqlStringServiceImpl implements GenSqlStringService {
|
|
|
public SqlColumnModel getSqlColumn(int isForeignKey, String filedAlias, String leftFieldId, String rightFieldId,
|
|
|
String referencesTab, String displayColumn, int index){
|
|
|
SqlColumnModel model = new SqlColumnModel();
|
|
|
- if(isForeignKey==0 || leftFieldId.isEmpty() || rightFieldId.isEmpty() || referencesTab.isEmpty() || displayColumn.isEmpty()){
|
|
|
+ if(isForeignKey==0 || IsNullEmpty(leftFieldId) || IsNullEmpty(rightFieldId) || IsNullEmpty(referencesTab) || IsNullEmpty(displayColumn)){
|
|
|
model.setIsForeignKey(false);
|
|
|
model.setTableAlias("T");
|
|
|
model.setDisplayColumn(MessageFormat.format("{0}.{1}","T", filedAlias));
|