diff --git a/backend/src/main/java/io/dataease/datasource/dto/TableFiled.java b/backend/src/main/java/io/dataease/datasource/dto/TableFiled.java new file mode 100644 index 0000000000..efcf83594d --- /dev/null +++ b/backend/src/main/java/io/dataease/datasource/dto/TableFiled.java @@ -0,0 +1,15 @@ +package io.dataease.datasource.dto; + +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class TableFiled { + + private String fieldName; + private String remarks; + private String fieldType; + private int fieldSize; + +} diff --git a/backend/src/main/java/io/dataease/datasource/provider/DatasourceProvider.java b/backend/src/main/java/io/dataease/datasource/provider/DatasourceProvider.java index 6654c40741..7117254d5a 100644 --- a/backend/src/main/java/io/dataease/datasource/provider/DatasourceProvider.java +++ b/backend/src/main/java/io/dataease/datasource/provider/DatasourceProvider.java @@ -1,7 +1,9 @@ package io.dataease.datasource.provider; import io.dataease.base.domain.Datasource; +import io.dataease.datasource.dto.TableFiled; +import java.util.ArrayList; import java.util.List; public abstract class DatasourceProvider { @@ -31,6 +33,10 @@ public abstract class DatasourceProvider { abstract public List getTables() throws Exception; + public List getTableFileds(String table) throws Exception{ + return new ArrayList<>(); + }; + public void test() throws Exception { getData(); } diff --git a/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java b/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java index fe8cb0efa4..512003122e 100644 --- a/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java +++ b/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java @@ -3,15 +3,14 @@ package io.dataease.datasource.provider; import com.google.gson.Gson; import io.dataease.datasource.constants.DatasourceTypes; import io.dataease.datasource.dto.MysqlConfigrationDTO; +import io.dataease.datasource.dto.TableFiled; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import java.sql.*; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; +import java.util.*; + import io.dataease.datasource.constants.DatasourceTypes.*; -import java.util.Properties; @Service("jdbc") @@ -42,7 +41,9 @@ public class JdbcProvider extends DatasourceProvider{ } list.add(row); } - } catch (Exception e) { + } catch (SQLException e){ + throw new Exception("ERROR:" + e.getMessage(), e); + }catch (Exception e) { throw new Exception("ERROR:" + e.getMessage(), e); } return list; @@ -64,6 +65,39 @@ public class JdbcProvider extends DatasourceProvider{ return tables; } + @Override + public List getTableFileds(String table) throws Exception{ + List list = new LinkedList<>(); + try ( + Connection connection = getConnection(); + ) { + DatabaseMetaData databaseMetaData = connection.getMetaData(); + ResultSet resultSet = databaseMetaData.getColumns(null, "%", table.toUpperCase(), "%"); + while (resultSet.next()) { + String tableName=resultSet.getString("TABLE_NAME"); + String database = resultSet.getString("TABLE_CAT"); + if(tableName.equals(table) && database.equalsIgnoreCase(getDatabase())){ + TableFiled tableFiled = new TableFiled(); + String colName = resultSet.getString("COLUMN_NAME"); + tableFiled.setFieldName(colName); + String remarks = resultSet.getString("REMARKS"); + if(remarks == null || remarks.equals("")){ + remarks = colName; + } + tableFiled.setRemarks(remarks); + String dbType = resultSet.getString("TYPE_NAME"); + tableFiled.setFieldType(dbType); + list.add(tableFiled); + } + } + } catch (SQLException e){ + throw new Exception("ERROR:" + e.getMessage(), e); + }catch (Exception e) { + throw new Exception("ERROR:" + e.getMessage(), e); + } + return list; + }; + @Override public void test() throws Exception { String queryStr = "show tables"; @@ -74,7 +108,6 @@ public class JdbcProvider extends DatasourceProvider{ } } - private Connection getConnection() throws Exception { String username = null; String password = null; @@ -102,4 +135,51 @@ public class JdbcProvider extends DatasourceProvider{ return DriverManager.getConnection(jdbcurl, props); } + private String getDatabase(){ + DatasourceTypes datasourceType = DatasourceTypes.valueOf(getDatasource().getType()); + switch (datasourceType) { + case mysql: + MysqlConfigrationDTO mysqlConfigrationDTO = new Gson().fromJson(getDatasource().getConfiguration(), MysqlConfigrationDTO.class); + return mysqlConfigrationDTO.getDataBase(); + default: + return null; + } + } + + private static String getSchema(Connection conn) throws Exception { + String schema; + schema = conn.getMetaData().getUserName(); + System.out.println(schema); + if ((schema == null) || (schema.length() == 0)) { + throw new Exception("ORACLE数据库模式不允许为空"); + } + return schema.toUpperCase().toString(); + } + + private static String changeDbType(String dbType) { + dbType = dbType.toUpperCase(); + switch(dbType){ + case "VARCHAR": + case "VARCHAR2": + case "CHAR": + return "1"; + case "NUMBER": + case "DECIMAL": + return "4"; + case "INT": + case "SMALLINT": + case "INTEGER": + return "2"; + case "BIGINT": + return "6"; + case "DATETIME": + case "TIMESTAMP": + case "DATE": + return "7"; + default: + return "1"; + } + } + + } diff --git a/frontend/src/business/components/settings/system/Datasource.vue b/frontend/src/business/components/settings/system/Datasource.vue index d0e2b1c0e6..faafa93ef8 100644 --- a/frontend/src/business/components/settings/system/Datasource.vue +++ b/frontend/src/business/components/settings/system/Datasource.vue @@ -21,34 +21,6 @@ :total="total"/> - - - - - - - - - - - - - - - - - - - @@ -90,7 +62,8 @@