|
@@ -6,16 +6,15 @@ import com.model.bo.ToSql;
|
|
|
import com.model.po.Databases;
|
|
import com.model.po.Databases;
|
|
|
import com.model.pojo.RepCode;
|
|
import com.model.pojo.RepCode;
|
|
|
import com.model.pojo.RepEntity;
|
|
import com.model.pojo.RepEntity;
|
|
|
|
|
+import com.model.vo.dataVo.ColumnTypeInfo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.sql.Connection;
|
|
import java.sql.Connection;
|
|
|
import java.sql.DriverManager;
|
|
import java.sql.DriverManager;
|
|
|
import java.sql.SQLException;
|
|
import java.sql.SQLException;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.Iterator;
|
|
|
|
|
-import java.util.LinkedHashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
public class ImplementSqlService {
|
|
public class ImplementSqlService {
|
|
@@ -29,28 +28,84 @@ public class ImplementSqlService {
|
|
|
*/
|
|
*/
|
|
|
public RepEntity implementSql(ToSql toSql) {
|
|
public RepEntity implementSql(ToSql toSql) {
|
|
|
String sqlStr = toSql.getStrSql();
|
|
String sqlStr = toSql.getStrSql();
|
|
|
-// String tableName = "";
|
|
|
|
|
-
|
|
|
|
|
-// try{
|
|
|
|
|
-// tableName = SqlMatch.matchSql(sqlStr).toUpperCase();
|
|
|
|
|
-// }catch (Exception e){
|
|
|
|
|
-// return new RepEntity(RepCode.ChartsNameNull);
|
|
|
|
|
-// }
|
|
|
|
|
System.out.println(sqlStr);
|
|
System.out.println(sqlStr);
|
|
|
if ("".equals(sqlStr) || sqlStr == null) {
|
|
if ("".equals(sqlStr) || sqlStr == null) {
|
|
|
return new RepEntity(RepCode.ChartsNameNull);
|
|
return new RepEntity(RepCode.ChartsNameNull);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
List<LinkedHashMap<String, Object>> columnData = dataColumnMapper.getColumn(sqlStr.toUpperCase());
|
|
List<LinkedHashMap<String, Object>> columnData = dataColumnMapper.getColumn(sqlStr.toUpperCase());
|
|
|
|
|
+ LinkedHashMap<String, String> tarValue = getColumnType(columnData);
|
|
|
|
|
+
|
|
|
|
|
+ //取列名
|
|
|
|
|
+ List<ColumnTypeInfo> isList = new ArrayList<>();
|
|
|
LinkedHashMap<String, Object> columnDataKey = columnData.get(0);
|
|
LinkedHashMap<String, Object> columnDataKey = columnData.get(0);
|
|
|
- List<String> columnNames = new ArrayList<>();
|
|
|
|
|
Iterator<String> iter = columnDataKey.keySet().iterator();
|
|
Iterator<String> iter = columnDataKey.keySet().iterator();
|
|
|
while (iter.hasNext()){
|
|
while (iter.hasNext()){
|
|
|
String key = iter.next();
|
|
String key = iter.next();
|
|
|
- columnNames .add(key);
|
|
|
|
|
|
|
+ String vaul = tarValue.get(key);
|
|
|
|
|
+ ColumnTypeInfo columnTypeInfo = new ColumnTypeInfo();
|
|
|
|
|
+ columnTypeInfo.setColumnName(key);
|
|
|
|
|
+ columnTypeInfo.setColumnType(vaul);
|
|
|
|
|
+ isList.add(columnTypeInfo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return new RepEntity(RepCode.success, columnNames);
|
|
|
|
|
|
|
+ return new RepEntity(RepCode.success,isList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ 判断列类型
|
|
|
|
|
+ */
|
|
|
|
|
+ public LinkedHashMap<String, String> getColumnType(List<LinkedHashMap<String, Object>> columnData){
|
|
|
|
|
+ LinkedHashMap<String, String> tarValue = new LinkedHashMap<>();
|
|
|
|
|
+ for (int i = 0; i < columnData.size(); i++){
|
|
|
|
|
+ LinkedHashMap<String, Object> columnDataMap = columnData.get(i);
|
|
|
|
|
+ Iterator<String> cm = columnDataMap.keySet().iterator();
|
|
|
|
|
+ while (cm.hasNext()){
|
|
|
|
|
+ String key = cm.next();
|
|
|
|
|
+ if (tarValue.containsKey(key)){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ Object value = columnDataMap.get(key);
|
|
|
|
|
+ if (value == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ String values = getType(value);
|
|
|
|
|
+ tarValue.put(key, values);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (tarValue.size() == columnDataMap.size()){
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return tarValue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ 判断值类型
|
|
|
|
|
+ */
|
|
|
|
|
+ public String getType(Object obj){
|
|
|
|
|
+ if(obj instanceof String){
|
|
|
|
|
+ return "String";
|
|
|
|
|
+ }else if (obj instanceof Double){
|
|
|
|
|
+ return "Double";
|
|
|
|
|
+ }else if (obj instanceof Integer){
|
|
|
|
|
+ return "Integer";
|
|
|
|
|
+ }else if (obj instanceof Date){
|
|
|
|
|
+ return "Date";
|
|
|
|
|
+ }else if (obj instanceof Boolean){
|
|
|
|
|
+ return "Boolean";
|
|
|
|
|
+ }else if(obj instanceof Byte){
|
|
|
|
|
+ return "Byte";
|
|
|
|
|
+ }else if (obj instanceof Short){
|
|
|
|
|
+ return "Short";
|
|
|
|
|
+ }else if (obj instanceof BigDecimal){
|
|
|
|
|
+ return "BigDecimal";
|
|
|
|
|
+ }else if (obj instanceof Object){
|
|
|
|
|
+ return "Object";
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|