feat: 数据结构展示数据
parent
45b7970463
commit
408fae6c9e
|
@ -0,0 +1,31 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>muyu-common</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<groupId>com.bwie</groupId>
|
||||||
|
<artifactId>muyu-common-data-standard</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<description>
|
||||||
|
muyu-common-data-standard数据标准包
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>muyu-common-core</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -18,6 +18,7 @@
|
||||||
<module>muyu-common-datascope</module>
|
<module>muyu-common-datascope</module>
|
||||||
<module>muyu-common-datasource</module>
|
<module>muyu-common-datasource</module>
|
||||||
<module>muyu-common-system</module>
|
<module>muyu-common-system</module>
|
||||||
|
<module>muyu-common-data-standard</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>muyu-common</artifactId>
|
<artifactId>muyu-common</artifactId>
|
||||||
|
|
|
@ -208,7 +208,7 @@ public class DataSourceController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/findDataSourceByDataBaseId")
|
@PostMapping("/findDataSourceByDataBaseId")
|
||||||
public Result findDataSourceByDataBaseId(@RequestParam Integer id){
|
public Result<List<DataValue>> findDataSourceByDataBaseId(@RequestParam Integer id){
|
||||||
return dataSourceService.findDataSourceByDataBaseId(id);
|
return dataSourceService.findDataSourceByDataBaseId(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,8 @@ public interface DataSourceMapper extends BaseMapper<DataSource> {
|
||||||
|
|
||||||
DataBaseTable findDataBaseTableId(@Param("id") Integer id);
|
DataBaseTable findDataBaseTableId(@Param("id") Integer id);
|
||||||
|
|
||||||
|
void addDataValue(@Param("dataValueList") List<DataValue> dataValueList);
|
||||||
|
|
||||||
// AssetStructure findDatabaseName(DataSource dataSource);
|
// AssetStructure findDatabaseName(DataSource dataSource);
|
||||||
|
|
||||||
// void updateAssets(@Param("assetStructure") AssetStructure assetStructure, @Param("id") Long id);
|
// void updateAssets(@Param("assetStructure") AssetStructure assetStructure, @Param("id") Long id);
|
||||||
|
|
|
@ -47,5 +47,5 @@ public interface DataSourceService extends IService<DataSource> {
|
||||||
|
|
||||||
Result updateDatabaseTable(DataBaseTable dataBaseTable);
|
Result updateDatabaseTable(DataBaseTable dataBaseTable);
|
||||||
|
|
||||||
Result findDataSourceByDataBaseId(Integer id);
|
Result<List<DataValue>> findDataSourceByDataBaseId(Integer id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@ package com.muyu.data.source.service.impl;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
@ -166,29 +164,8 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
||||||
list.add(databaseTableInformation);
|
list.add(databaseTableInformation);
|
||||||
|
|
||||||
|
|
||||||
System.out.println("222"+tableName);
|
|
||||||
String sqlServer="select * from "+tableName;
|
|
||||||
Statement statement = con.createStatement();
|
|
||||||
ResultSet preparedStatement = statement.executeQuery(sqlServer);
|
|
||||||
|
|
||||||
ResultSetMetaData metaData = preparedStatement.getMetaData();
|
|
||||||
while (preparedStatement.next()){
|
|
||||||
for (int i = 1; i <= metaData.getColumnCount(); i++) {
|
|
||||||
DataValue dataValue = new DataValue();
|
|
||||||
String columnName = metaData.getColumnName(i);
|
|
||||||
dataValue.setValue(preparedStatement.getObject(i));
|
|
||||||
// dataValue.setType(preparedStatement.getString("type"));
|
|
||||||
dataValue.setKey(dataSource.getDataSourceSystemName()+"-"+tableName+"-"+columnName);
|
|
||||||
dataValueList.add(dataValue);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println(dataValueList);
|
|
||||||
System.out.println("================================");
|
|
||||||
for (DataValue value : dataValueList) {
|
|
||||||
System.out.println("123"+value);
|
|
||||||
}
|
|
||||||
System.out.println("================================");
|
|
||||||
//参数复制对象
|
//参数复制对象
|
||||||
assetStructure.setAccessSourceName(dataSource.getAccessSourceName());
|
assetStructure.setAccessSourceName(dataSource.getAccessSourceName());
|
||||||
assetStructure.setDatabaseName(dataSource.getDatabaseName());
|
assetStructure.setDatabaseName(dataSource.getDatabaseName());
|
||||||
|
@ -239,6 +216,10 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
||||||
preparedStatement.setString(1, dataSource.getDatabaseName());
|
preparedStatement.setString(1, dataSource.getDatabaseName());
|
||||||
preparedStatement.setString(2, databaseTableInformation.getName());
|
preparedStatement.setString(2, databaseTableInformation.getName());
|
||||||
//执行查询
|
//执行查询
|
||||||
|
|
||||||
|
|
||||||
|
// System.out.println(dataValueList);
|
||||||
|
// dataSourceMapper.addDataValue(dataValueList);
|
||||||
ResultSet executeQuery = preparedStatement.executeQuery();
|
ResultSet executeQuery = preparedStatement.executeQuery();
|
||||||
ResultSetMetaData metaData = executeQuery.getMetaData();
|
ResultSetMetaData metaData = executeQuery.getMetaData();
|
||||||
// 5. 处理查询结果
|
// 5. 处理查询结果
|
||||||
|
@ -270,8 +251,10 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
||||||
.build();
|
.build();
|
||||||
//添加到列表
|
//添加到列表
|
||||||
dataBaseTable.add(build);
|
dataBaseTable.add(build);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加数据库
|
//添加数据库
|
||||||
dataSourceMapper.addDataBaseTable(dataBaseTable);
|
dataSourceMapper.addDataBaseTable(dataBaseTable);
|
||||||
return Result.success("同步成功");
|
return Result.success("同步成功");
|
||||||
|
@ -322,7 +305,6 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
||||||
return Result.success(dataBaseTableList);
|
return Result.success(dataBaseTableList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result<DatabaseTableInformation> findDataBaseTable(Long id) {
|
public Result<DatabaseTableInformation> findDataBaseTable(Long id) {
|
||||||
DatabaseTableInformation databaseTableInformation=dataSourceMapper.findDataBaseTableBy(id);
|
DatabaseTableInformation databaseTableInformation=dataSourceMapper.findDataBaseTableBy(id);
|
||||||
return Result.success(databaseTableInformation);
|
return Result.success(databaseTableInformation);
|
||||||
|
@ -355,9 +337,9 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result findDataSourceByDataBaseId(Integer id) {
|
public Result<List<DataValue>> findDataSourceByDataBaseId(Integer id) {
|
||||||
DataBaseTable dataBaseTable=dataSourceMapper.findDataBaseTableId(id);
|
// DataBaseTable dataBaseTable=dataSourceMapper.findDataBaseTableId(id);
|
||||||
DatabaseTableInformation databaseTableInformation=dataSourceMapper.findDataBaseTableBy(Long.valueOf(dataBaseTable.getInformationId()));
|
DatabaseTableInformation databaseTableInformation=dataSourceMapper.findDataBaseTableBy(Long.valueOf(id));
|
||||||
AssetStructure assetStructure=dataSourceMapper.findAssetsById(databaseTableInformation.getStructureId());
|
AssetStructure assetStructure=dataSourceMapper.findAssetsById(databaseTableInformation.getStructureId());
|
||||||
|
|
||||||
//连接驱动
|
//连接驱动
|
||||||
|
@ -367,28 +349,32 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
||||||
String url = "jdbc:mysql://" + assetStructure.getHostAddress() + ":" + assetStructure.getHostPort() + "/" + assetStructure.getDatabaseName();
|
String url = "jdbc:mysql://" + assetStructure.getHostAddress() + ":" + assetStructure.getHostPort() + "/" + assetStructure.getDatabaseName();
|
||||||
|
|
||||||
//查询条件
|
//查询条件
|
||||||
String query="select * from "+databaseTableInformation.getName()+"limit 1 ";
|
String query="select * from "+databaseTableInformation.getName();
|
||||||
|
|
||||||
|
List<DataValue> dataValueList = new ArrayList<>();
|
||||||
try (Connection con = DriverManager.getConnection(url, user, password)){
|
try (Connection con = DriverManager.getConnection(url, user, password)){
|
||||||
|
|
||||||
PreparedStatement preparedStatement = con.prepareStatement(query);
|
Statement statement = con.createStatement();
|
||||||
ResultSet executeQuery = preparedStatement.executeQuery();
|
ResultSet executeQuery = statement.executeQuery(query);
|
||||||
System.out.println("13");
|
ResultSetMetaData metaData = executeQuery.getMetaData();
|
||||||
return Result.success(executeQuery);
|
while (executeQuery.next()){
|
||||||
// ResultSetMetaData metaData1 = executeQuery.getMetaData();
|
for (int i = 1; i <= metaData.getColumnCount(); i++) {
|
||||||
|
DataValue dataValue = new DataValue();
|
||||||
// ResultSetMetaData metaData = preparedStatement.getMetaData();
|
String columnName = metaData.getColumnName(i);
|
||||||
// ParameterMetaData parameterMetaData = preparedStatement.getParameterMetaData();
|
dataValue.setValue(executeQuery.getObject(i));
|
||||||
// System.out.println(parameterMetaData);
|
dataValue.setType(metaData.getColumnTypeName(i));
|
||||||
// return Result.success(metaData1);
|
dataValue.setInformationId(databaseTableInformation.getId());
|
||||||
// System.out.println(metaData);
|
dataValue.setKey(columnName);
|
||||||
// return Result.success(metaData);
|
dataValueList.add(dataValue);
|
||||||
}catch (Exception e){
|
}
|
||||||
|
}
|
||||||
|
System.out.println(dataValueList);
|
||||||
|
return Result.success(dataValueList);
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
System.out.println("连接失败"+e.getMessage());
|
System.out.println("连接失败"+e.getMessage());
|
||||||
return Result.error("连接失败");
|
return Result.error("连接失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
)
|
)
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
<insert id="addDataValue">
|
||||||
|
INSERT INTO `data_management`.`data_value`
|
||||||
|
(
|
||||||
|
`key`,
|
||||||
|
`value`,
|
||||||
|
`type`,
|
||||||
|
`information_id`
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
<foreach collection="dataValueList" item="dataValueList" separator=",">
|
||||||
|
(
|
||||||
|
#{dataValueList.key},
|
||||||
|
#{dataValueList.value},
|
||||||
|
#{dataValueList.type},
|
||||||
|
#{dataValueList.informationId}
|
||||||
|
)
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
<update id="updateDatabaseTable">
|
<update id="updateDatabaseTable">
|
||||||
UPDATE `data_management`.`database_table` SET
|
UPDATE `data_management`.`database_table` SET
|
||||||
`tableName` = #{dataBaseTable.tableName},
|
`tableName` = #{dataBaseTable.tableName},
|
||||||
|
|
Loading…
Reference in New Issue