style(): 修改代码格式

dev
chao 2024-04-24 15:51:47 +08:00
parent d24a344ac4
commit 1e1797f443
3 changed files with 61 additions and 53 deletions

View File

@ -233,12 +233,13 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
if ("mysql".equals(dataType.getDataType())) { if ("mysql".equals(dataType.getDataType())) {
driveClass = dataType.getDriverManager(); driveClass = dataType.getDriverManager();
jdbcUrl = dataType.getJdbcPre() + dataSource.getDataSourceIp() + ":" + dataSource.getDataSourcePort() + "/" + dataSource.getDataSourceDatabaseName() + "?" + dataSource.getAdditionalConfiguration(); jdbcUrl = dataType.getJdbcPre() + dataSource.getDataSourceIp() + ":" + dataSource.getDataSourcePort() + "/" + dataSource.getDataSourceDatabaseName() + "?" + dataSource.getAdditionalConfiguration();
String tableSQL = "select * from information_schema.tables where TABLE_SCHEMA = " + "'" + dataSource.getDataSourceDatabaseName() + "'";
// 加载数据库驱动 // 加载数据库驱动
Class.forName(driveClass); Class.forName(driveClass);
// 连接数据库 // 连接数据库
Connection conn = DriverManager.getConnection(jdbcUrl, dataSource.getDataSourceUsername(), dataSource.getDataSourcePassword()); Connection conn = DriverManager.getConnection(jdbcUrl, dataSource.getDataSourceUsername(), dataSource.getDataSourcePassword());
Statement st = conn.createStatement(); Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from information_schema.tables where TABLE_SCHEMA = " + "'" + dataSource.getDataSourceDatabaseName() + "'"); ResultSet rs = st.executeQuery(tableSQL);
while (rs.next()) { while (rs.next()) {
// 获取表名 // 获取表名
String tableName = rs.getString("TABLE_NAME"); String tableName = rs.getString("TABLE_NAME");
@ -247,16 +248,17 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
// 添加数据 // 添加数据
// 表数据数量 // 表数据数量
assetStructureTableList.add( assetStructureTableList.add(
new AssetStructureTable() {{ AssetStructureTable.builder()
setAssetStructureId(entity.getId()); .assetStructureId(entity.getId())
setTableName(tableName); .tableName(tableName)
setTableNameAnnotation(tableNameAnnotation); .tableNameAnnotation(tableNameAnnotation)
}} .build()
); );
} }
assetStructureTableList.stream().forEach(assetStructureTable -> { assetStructureTableList.stream().forEach(assetStructureTable -> {
String tableDataCountSQL = "select count(*) as countNum from " + assetStructureTable.getTableName();
try { try {
ResultSet rs2 = st.executeQuery("select count(*) as countNum from " + assetStructureTable.getTableName()); ResultSet rs2 = st.executeQuery(tableDataCountSQL);
while (rs2.next()) { while (rs2.next()) {
assetStructureTable.setTableDataCount(rs2.getLong("countNum")); assetStructureTable.setTableDataCount(rs2.getLong("countNum"));
} }
@ -291,13 +293,14 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
} }
rs4.close(); rs4.close();
String dataDetailsSQL = "select * from " + assetStructureTable.getTableName() + " where 1=2";
// 字段类型 // 字段类型
String typeName = rs3.getString("TYPE_NAME"); String typeName = rs3.getString("TYPE_NAME");
// 映射类型 // 映射类型
String mappingType = null; String mappingType = null;
PreparedStatement st1 = conn.prepareStatement("select * from " + assetStructureTable.getTableName() + " where 1=2"); PreparedStatement st1 = conn.prepareStatement(dataDetailsSQL);
ResultSetMetaData rsmd = st1.executeQuery().getMetaData(); ResultSetMetaData rsmd = st1.executeQuery().getMetaData();
for (int i = 0; i < rsmd.getColumnCount(); i++) { for (int i = 0; i < rsmd.getColumnCount(); i++) {
if (columnName.equals(rsmd.getColumnName(i + 1))) { if (columnName.equals(rsmd.getColumnName(i + 1))) {
@ -320,19 +323,19 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
boolean finalIsPrimaryKey = isPrimaryKey; boolean finalIsPrimaryKey = isPrimaryKey;
String finalMappingType = mappingType; String finalMappingType = mappingType;
assetTableDetails.add( assetTableDetails.add(
new AssetTableDetails() {{ AssetTableDetails.builder()
setAssetStructureTableId(assetStructureTable.getId()); .assetStructureTableId(assetStructureTable.getId())
setName(columnName); .name(columnName)
setAnnotation(remarks); .annotation(remarks)
setPrimaryOrNot(finalIsPrimaryKey ? "Y" : "N"); .primaryOrNot(finalIsPrimaryKey ? "Y" : "N")
setType(typeName); .type(typeName)
setMappingType(finalMappingType); .mappingType(finalMappingType)
setLength((long) columnSize); .length((long) columnSize)
setDecimalPoint((long) decimalDigits); .decimalPoint((long) decimalDigits)
setNullOrNot(isNullable ? "Y" : "N"); .nullOrNot(isNullable ? "Y" : "N")
setDefaultValue(defaultValue); .defaultValue(defaultValue)
setYesNoDictionary(null); .yesNoDictionary(null)
}} .build()
); );
} }
rs3.close(); rs3.close();
@ -408,12 +411,13 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
if ("mysql".equals(dataType.getDataType())) { if ("mysql".equals(dataType.getDataType())) {
driveClass = dataType.getDriverManager(); driveClass = dataType.getDriverManager();
jdbcUrl = dataType.getJdbcPre() + dataSource.getDataSourceIp() + ":" + dataSource.getDataSourcePort() + "/" + dataSource.getDataSourceDatabaseName() + "?" + dataSource.getAdditionalConfiguration(); jdbcUrl = dataType.getJdbcPre() + dataSource.getDataSourceIp() + ":" + dataSource.getDataSourcePort() + "/" + dataSource.getDataSourceDatabaseName() + "?" + dataSource.getAdditionalConfiguration();
String tableSQL = "select * from information_schema.tables where TABLE_SCHEMA = " + "'" + dataSource.getDataSourceDatabaseName() + "'";
// 加载数据库驱动 // 加载数据库驱动
Class.forName(driveClass); Class.forName(driveClass);
// 连接数据库 // 连接数据库
Connection conn = DriverManager.getConnection(jdbcUrl, dataSource.getDataSourceUsername(), dataSource.getDataSourcePassword()); Connection conn = DriverManager.getConnection(jdbcUrl, dataSource.getDataSourceUsername(), dataSource.getDataSourcePassword());
Statement st = conn.createStatement(); Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from information_schema.tables where TABLE_SCHEMA = " + "'" + dataSource.getDataSourceDatabaseName() + "'"); ResultSet rs = st.executeQuery(tableSQL);
while (rs.next()) { while (rs.next()) {
// 获取表名 // 获取表名
String tableName = rs.getString("TABLE_NAME"); String tableName = rs.getString("TABLE_NAME");
@ -422,16 +426,17 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
// 添加数据 // 添加数据
// 表数据数量 // 表数据数量
assetStructureTableList.add( assetStructureTableList.add(
new AssetStructureTable() {{ AssetStructureTable.builder()
setAssetStructureId(entity.getId()); .assetStructureId(entity.getId())
setTableName(tableName); .tableName(tableName)
setTableNameAnnotation(tableNameAnnotation); .tableNameAnnotation(tableNameAnnotation)
}} .build()
); );
} }
assetStructureTableList.stream().forEach(assetStructureTable -> { assetStructureTableList.stream().forEach(assetStructureTable -> {
String tableDataCountSQL = "select count(*) as countNum from " + assetStructureTable.getTableName();
try { try {
ResultSet rs2 = st.executeQuery("select count(*) as countNum from " + assetStructureTable.getTableName()); ResultSet rs2 = st.executeQuery(tableDataCountSQL);
while (rs2.next()) { while (rs2.next()) {
assetStructureTable.setTableDataCount(rs2.getLong("countNum")); assetStructureTable.setTableDataCount(rs2.getLong("countNum"));
} }
@ -473,13 +478,15 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
} }
rs4.close(); rs4.close();
String dataDetailsSQL = "select * from " + assetStructureTable.getTableName() + " where 1=2";
// 字段类型 // 字段类型
String typeName = rs3.getString("TYPE_NAME"); String typeName = rs3.getString("TYPE_NAME");
// 映射类型 // 映射类型
String mappingType = null; String mappingType = null;
PreparedStatement st1 = conn.prepareStatement("select * from " + assetStructureTable.getTableName() + " where 1=2"); PreparedStatement st1 = conn.prepareStatement(dataDetailsSQL);
ResultSetMetaData rsmd = st1.executeQuery().getMetaData(); ResultSetMetaData rsmd = st1.executeQuery().getMetaData();
for (int i = 0; i < rsmd.getColumnCount(); i++) { for (int i = 0; i < rsmd.getColumnCount(); i++) {
if (columnName.equals(rsmd.getColumnName(i + 1))) { if (columnName.equals(rsmd.getColumnName(i + 1))) {
@ -502,19 +509,19 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
boolean finalIsPrimaryKey = isPrimaryKey; boolean finalIsPrimaryKey = isPrimaryKey;
String finalMappingType = mappingType; String finalMappingType = mappingType;
assetTableDetails.add( assetTableDetails.add(
new AssetTableDetails() {{ AssetTableDetails.builder()
setAssetStructureTableId(assetStructureTable.getId()); .assetStructureTableId(assetStructureTable.getId())
setName(columnName); .name(columnName)
setAnnotation(remarks); .annotation(remarks)
setPrimaryOrNot(finalIsPrimaryKey ? "Y" : "N"); .primaryOrNot(finalIsPrimaryKey ? "Y" : "N")
setType(typeName); .type(typeName)
setMappingType(finalMappingType); .mappingType(finalMappingType)
setLength((long) columnSize); .length((long) columnSize)
setDecimalPoint((long) decimalDigits); .decimalPoint((long) decimalDigits)
setNullOrNot(isNullable ? "Y" : "N"); .nullOrNot(isNullable ? "Y" : "N")
setDefaultValue(defaultValue); .defaultValue(defaultValue)
setYesNoDictionary(null); .yesNoDictionary(null)
}} .build()
); );
} }
rs3.close(); rs3.close();

View File

@ -46,10 +46,10 @@ public class AssetStructureServiceImpl extends ServiceImpl<AssetStructureMapper,
assetStructureTableDataCount = assetStructureTableList.stream().mapToLong(AssetStructureTable::getTableDataCount).sum(); assetStructureTableDataCount = assetStructureTableList.stream().mapToLong(AssetStructureTable::getTableDataCount).sum();
return new AssetStructureResp(){{ return AssetStructureResp.builder()
setAssetStructureList(assetStructureList); .assetStructureList(assetStructureList)
setAssetStructureTableCount(assetStructureTableCount); .assetStructureTableCount(assetStructureTableCount)
setAssetStructureTableDataCount(assetStructureTableDataCount); .assetStructureTableDataCount(assetStructureTableDataCount)
}}; .build();
} }
} }

View File

@ -18,9 +18,10 @@ import java.util.List;
* @CreateTime: 2024/4/22 5:22 * @CreateTime: 2024/4/22 5:22
*/ */
@Service @Service
public class AssetStructureTableServiceImpl extends ServiceImpl<AssetStructureTableMapper, AssetStructureTable> implements IAssetStructureTableService { public class AssetStructureTableServiceImpl extends ServiceImpl<AssetStructureTableMapper, AssetStructureTable> implements IAssetStructureTableService {
/** /**
* *
*
* @param assetStructureId id * @param assetStructureId id
* @return * @return
*/ */
@ -34,10 +35,10 @@ public class AssetStructureTableServiceImpl extends ServiceImpl<AssetStructureT
long tableCount = assetStructureTableList.size(); long tableCount = assetStructureTableList.size();
long tableDataCount = assetStructureTableList.stream().mapToLong(AssetStructureTable::getTableDataCount).sum(); long tableDataCount = assetStructureTableList.stream().mapToLong(AssetStructureTable::getTableDataCount).sum();
return new AssetStructureTableResp(){{ return AssetStructureTableResp.builder()
setAssetStructureList(assetStructureTableList); .assetStructureList(assetStructureTableList)
setTableCount(tableCount); .tableCount(tableCount)
setTableDataCount(tableDataCount);; .tableDataCount(tableDataCount)
}}; .build();
} }
} }