数据资产(完善)
parent
595299ec50
commit
9e421b2c4d
|
@ -20,4 +20,6 @@ import java.util.Map;
|
||||||
public class AssetsModule {
|
public class AssetsModule {
|
||||||
private HashMap<String, String> structure;
|
private HashMap<String, String> structure;
|
||||||
private List<Map<String, VTClass>> kvtList;
|
private List<Map<String, VTClass>> kvtList;
|
||||||
|
|
||||||
|
private List<TableAssets> tableAssets;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.muyu.etl.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName TableAssets
|
||||||
|
* @Description 描述
|
||||||
|
* @Author Xin.Yao
|
||||||
|
* @Date 2024/4/21 11:20
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class TableAssets {
|
||||||
|
private String Field;
|
||||||
|
private String Type;
|
||||||
|
private String Null;
|
||||||
|
private String Key;
|
||||||
|
private String Default;
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.utils.DateUtils;
|
import com.muyu.common.core.utils.DateUtils;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.etl.domain.AssetsModule;
|
import com.muyu.etl.domain.AssetsModule;
|
||||||
|
import com.muyu.etl.domain.TableAssets;
|
||||||
import com.muyu.etl.domain.VTClass;
|
import com.muyu.etl.domain.VTClass;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -211,14 +212,54 @@ public class DataSourceServiceImpl implements IDataSourceService
|
||||||
return assetsModule;
|
return assetsModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<TableAssets> getTableAssets(DataSource dataSource){
|
||||||
|
String user = dataSource.getUsername();
|
||||||
|
String password = dataSource.getPassword();
|
||||||
|
String jdbcDriver = "com.mysql.cj.jdbc.Driver";
|
||||||
|
String jdbcUrl = "jdbc:mysql://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
||||||
|
Connection conn = null;
|
||||||
|
List<TableAssets> tableAssets = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
Class.forName(jdbcDriver);
|
||||||
|
conn = DriverManager.getConnection(jdbcUrl, user, password);
|
||||||
|
} catch (SQLException | ClassNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Class.forName(jdbcDriver);
|
||||||
|
conn = DriverManager.getConnection(jdbcUrl, user, password);
|
||||||
|
} catch (SQLException | ClassNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
PreparedStatement pst = conn.prepareStatement("DESCRIBE "+dataSource.getTableName());
|
||||||
|
ResultSet resultSet = pst.executeQuery();
|
||||||
|
ResultSetMetaData rsd = resultSet.getMetaData();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
TableAssets tableAsset = new TableAssets();
|
||||||
|
tableAsset.setField(resultSet.getString("Field"));
|
||||||
|
tableAsset.setType(resultSet.getString("Type"));
|
||||||
|
tableAsset.setNull(resultSet.getString("Null"));
|
||||||
|
tableAsset.setKey(resultSet.getString("Key"));
|
||||||
|
tableAsset.setDefault(resultSet.getString("Default"));
|
||||||
|
tableAssets.add(tableAsset);
|
||||||
|
}
|
||||||
|
|
||||||
|
pst.close();
|
||||||
|
} catch(SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return tableAssets;
|
||||||
|
}
|
||||||
|
|
||||||
public AssetsModule getAssets(DataSource dataSource){
|
public AssetsModule getAssets(DataSource dataSource){
|
||||||
String user = dataSource.getUsername();
|
String user = dataSource.getUsername();
|
||||||
String password = dataSource.getPassword();
|
String password = dataSource.getPassword();
|
||||||
String jdbcDriver = "com.mysql.cj.jdbc.Driver";
|
String jdbcDriver = "com.mysql.cj.jdbc.Driver";
|
||||||
String jdbcUrl = "jdbc:mysql://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
String jdbcUrl = "jdbc:mysql://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
List<Map<String, VTClass>> kvtList = new ArrayList<>();
|
|
||||||
HashMap<String, String> map = new HashMap<>();
|
HashMap<String, String> map = new HashMap<>();
|
||||||
|
List<TableAssets> tableAssets = getTableAssets(dataSource);
|
||||||
try {
|
try {
|
||||||
Class.forName(jdbcDriver);
|
Class.forName(jdbcDriver);
|
||||||
conn = DriverManager.getConnection(jdbcUrl, user, password);
|
conn = DriverManager.getConnection(jdbcUrl, user, password);
|
||||||
|
@ -231,10 +272,6 @@ public class DataSourceServiceImpl implements IDataSourceService
|
||||||
ResultSetMetaData rsd = resultSet.getMetaData();
|
ResultSetMetaData rsd = resultSet.getMetaData();
|
||||||
for(int i = 1; i <= rsd.getColumnCount(); i++) {
|
for(int i = 1; i <= rsd.getColumnCount(); i++) {
|
||||||
String substring = rsd.getColumnClassName(i).substring(rsd.getColumnClassName(i).indexOf("java.lang.") + 10);
|
String substring = rsd.getColumnClassName(i).substring(rsd.getColumnClassName(i).indexOf("java.lang.") + 10);
|
||||||
System.out.print("java类型:"+substring);
|
|
||||||
System.out.print(" 数据库类型:"+rsd.getColumnTypeName(i));
|
|
||||||
System.out.print(" 字段名称:"+rsd.getColumnName(i));
|
|
||||||
System.out.println();
|
|
||||||
map.put(rsd.getColumnName(i),substring);
|
map.put(rsd.getColumnName(i),substring);
|
||||||
}
|
}
|
||||||
pst.close();
|
pst.close();
|
||||||
|
@ -242,8 +279,8 @@ public class DataSourceServiceImpl implements IDataSourceService
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
AssetsModule assetsModule = new AssetsModule();
|
AssetsModule assetsModule = new AssetsModule();
|
||||||
assetsModule.setKvtList(kvtList);
|
|
||||||
assetsModule.setStructure(map);
|
assetsModule.setStructure(map);
|
||||||
|
assetsModule.setTableAssets(tableAssets);
|
||||||
return assetsModule;
|
return assetsModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue