|
|
@@ -8,6 +8,9 @@ import com.usoftchina.bi.core.base.RepCode;
|
|
|
import com.usoftchina.bi.core.base.RepEntity;
|
|
|
import com.usoftchina.bi.server.model.vo.dataVo.ColumnTypeInfo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.jdbc.support.rowset.SqlRowSet;
|
|
|
+import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
@@ -21,12 +24,14 @@ public class ImplementSqlService {
|
|
|
DataColumnMapper dataColumnMapper;
|
|
|
@Autowired
|
|
|
DataConnectorMapper dataConnectorMapper;
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
/*
|
|
|
执行数据源
|
|
|
*/
|
|
|
public RepEntity implementSql(ToSql toSql) {
|
|
|
- List<String> checkSql = java.util.Arrays.asList(toSql.getStrSql().toLowerCase().split(" "));
|
|
|
+ List<String> checkSql = Arrays.asList(toSql.getStrSql().toLowerCase().split(" "));
|
|
|
if (checkSql.contains("update") || checkSql.contains("delete") || checkSql.contains("insert") ||
|
|
|
checkSql.contains("drop") || checkSql.contains("create") || checkSql.contains("comment")){
|
|
|
return new RepEntity(RepCode.SqlWarn);
|
|
|
@@ -36,22 +41,16 @@ public class ImplementSqlService {
|
|
|
return new RepEntity(RepCode.ChartsNameNull);
|
|
|
}
|
|
|
|
|
|
- LinkedHashMap<String, Object> columnData = dataColumnMapper.getColumn(sqlStr);
|
|
|
- LinkedHashMap<String, String> tarValue = getColumnType(columnData);
|
|
|
-
|
|
|
- List<ColumnTypeInfo> isList = new ArrayList<>();
|
|
|
-
|
|
|
- Iterator<String> iter = columnData.keySet().iterator();
|
|
|
- while (iter.hasNext()){
|
|
|
- String key = iter.next();
|
|
|
- String vaul = tarValue.get(key);
|
|
|
- ColumnTypeInfo columnTypeInfo = new ColumnTypeInfo();
|
|
|
- columnTypeInfo.setColumnName(key);
|
|
|
- columnTypeInfo.setColumnType(vaul);
|
|
|
- isList.add(columnTypeInfo);
|
|
|
+ SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet(sqlStr);
|
|
|
+ SqlRowSetMetaData metaData = sqlRowSet.getMetaData();
|
|
|
+ int length = metaData.getColumnCount();
|
|
|
+ List<ColumnTypeInfo> columnTypeInfoList = new ArrayList<>();
|
|
|
+ for (int i = 1; i <= length; i++) {
|
|
|
+ String typeName = metaData.getColumnClassName(i);
|
|
|
+ typeName = metaData.getColumnClassName(i).substring(typeName.lastIndexOf(".") + 1);
|
|
|
+ columnTypeInfoList.add(new ColumnTypeInfo(metaData.getColumnName(i), typeName));
|
|
|
}
|
|
|
-
|
|
|
- return new RepEntity(RepCode.success,isList);
|
|
|
+ return new RepEntity(RepCode.success,columnTypeInfoList);
|
|
|
}
|
|
|
|
|
|
/*
|