parent
6941f85527
commit
2382901c45
|
@ -19,6 +19,10 @@ import java.util.List;
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class AssetStructure{
|
public class AssetStructure{
|
||||||
|
|
||||||
|
/**资产表id*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
/** 接入源名称 */
|
/** 接入源名称 */
|
||||||
private String accessSourceName;
|
private String accessSourceName;
|
||||||
|
|
||||||
|
@ -40,10 +44,19 @@ public class AssetStructure{
|
||||||
/**是否核心*/
|
/**是否核心*/
|
||||||
private String coreOrNot;
|
private String coreOrNot;
|
||||||
|
|
||||||
/**表注释*/
|
|
||||||
private String tableComment;
|
|
||||||
|
|
||||||
/**类型*/
|
/**类型*/
|
||||||
private Integer type;
|
private Integer type;
|
||||||
|
|
||||||
|
/**主机地址*/
|
||||||
|
private String hostAddress;
|
||||||
|
|
||||||
|
/**主机端口*/
|
||||||
|
private Integer hostPort;
|
||||||
|
|
||||||
|
/**数据库用户名*/
|
||||||
|
private String databaseUserName;
|
||||||
|
|
||||||
|
/**数据库用户密码*/
|
||||||
|
private String databaseUserPassword;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.muyu.data.source.domain.model;
|
package com.muyu.data.source.domain;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
|
@ -6,20 +6,20 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库表对象 DatabaseTable
|
* 数据库表对象 DataBaseTable
|
||||||
*
|
*
|
||||||
* @author DeKangLiu
|
* @author DeKangLiu
|
||||||
* on 2024/4/22
|
* on 2024/4/24
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class DatabaseTableModel {
|
public class DataBaseTable {
|
||||||
/**数据库表id*/
|
/**数据库表id*/
|
||||||
private Long id;
|
private Integer id;
|
||||||
|
|
||||||
/**数据库表名*/
|
/**数据库名称*/
|
||||||
private String tableName;
|
private String tableName;
|
||||||
|
|
||||||
/**字段名*/
|
/**字段名*/
|
||||||
|
@ -31,17 +31,17 @@ public class DatabaseTableModel {
|
||||||
/**是否核心*/
|
/**是否核心*/
|
||||||
private String isPrimaryKey;
|
private String isPrimaryKey;
|
||||||
|
|
||||||
/**Java类型*/
|
/**java类型*/
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
/**字段类型*/
|
/**字段类型*/
|
||||||
private String detailName;
|
private String detailType;
|
||||||
|
|
||||||
/**长度*/
|
/**小数点*/
|
||||||
private Integer length;
|
private Integer length;
|
||||||
|
|
||||||
/**小数点*/
|
/**小数点*/
|
||||||
private Integer decimalPlaces;
|
private Double decimalPlaces;
|
||||||
|
|
||||||
/**是否为空*/
|
/**是否为空*/
|
||||||
private String isNull;
|
private String isNull;
|
||||||
|
@ -49,4 +49,11 @@ public class DatabaseTableModel {
|
||||||
/**默认值*/
|
/**默认值*/
|
||||||
private String defaultValue;
|
private String defaultValue;
|
||||||
|
|
||||||
|
/**结构表id*/
|
||||||
|
private Integer structureId;
|
||||||
|
|
||||||
|
/**信息表id*/
|
||||||
|
private Integer informationId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DatabaseTableInformation
|
* 数据库表对象信息 DatabaseTableInformation
|
||||||
*
|
*
|
||||||
* @author DeKangLiu
|
* @author DeKangLiu
|
||||||
* on 2024/4/23
|
* on 2024/4/23
|
||||||
|
@ -18,7 +18,7 @@ import lombok.NoArgsConstructor;
|
||||||
public class DatabaseTableInformation {
|
public class DatabaseTableInformation {
|
||||||
|
|
||||||
/**数据库信息id*/
|
/**数据库信息id*/
|
||||||
private Long id;
|
private Integer id;
|
||||||
|
|
||||||
/**数据库表名*/
|
/**数据库表名*/
|
||||||
private String name;
|
private String name;
|
||||||
|
@ -40,4 +40,8 @@ public class DatabaseTableInformation {
|
||||||
|
|
||||||
/**类型*/
|
/**类型*/
|
||||||
private Integer type;
|
private Integer type;
|
||||||
|
|
||||||
|
/**资产结构id*/
|
||||||
|
private Integer structureId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import lombok.NoArgsConstructor;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestList
|
* 资产结构树形对象 Structure
|
||||||
*
|
*
|
||||||
* @author DeKangLiu
|
* @author DeKangLiu
|
||||||
* on 2024/4/24
|
* on 2024/4/24
|
||||||
|
@ -21,7 +21,7 @@ public class Structure {
|
||||||
/**数据库表信息对象*/
|
/**数据库表信息对象*/
|
||||||
private List<DatabaseTableInformation> databaseTableInformationList;
|
private List<DatabaseTableInformation> databaseTableInformationList;
|
||||||
|
|
||||||
/**资产结构对象*/
|
/**数据库表对象*/
|
||||||
private List<AssetStructure> assetStructureList;
|
private List<DataBaseTable> dataBaseTableList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
package com.muyu.data.source.domain.model;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据库对象 DataBaseModel
|
|
||||||
*
|
|
||||||
* @author DeKangLiu
|
|
||||||
* on 2024/4/23
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class DataBaseModel {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据库名称
|
|
||||||
*/
|
|
||||||
private String tableName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据库
|
|
||||||
*/
|
|
||||||
}
|
|
|
@ -4,17 +4,9 @@ import java.util.List;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import com.muyu.data.source.domain.*;
|
import com.muyu.data.source.domain.*;
|
||||||
import com.muyu.data.source.domain.model.DatabaseTableModel;
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
|
@ -117,29 +109,83 @@ public class DataSourceController extends BaseController {
|
||||||
List<AccessType> accessTypeList=dataSourceService.findAccessType();
|
List<AccessType> accessTypeList=dataSourceService.findAccessType();
|
||||||
return Result.success(accessTypeList);
|
return Result.success(accessTypeList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试连接
|
||||||
|
* @param dataSourceSaveReq
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@PostMapping("/testConnection")
|
@PostMapping("/testConnection")
|
||||||
public Result testConnection(@RequestBody DataSourceSaveReq dataSourceSaveReq){
|
public Result testConnection(@RequestBody DataSourceSaveReq dataSourceSaveReq){
|
||||||
return dataSourceService.testConnection(dataSourceSaveReq);
|
return dataSourceService.testConnection(dataSourceSaveReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据数据源对象同步代码
|
||||||
|
* @param dataSource
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@PostMapping("/synchronization")
|
@PostMapping("/synchronization")
|
||||||
public Result synchronization(@RequestBody DataSource dataSource){
|
public Result synchronization(@RequestBody DataSource dataSource){
|
||||||
return dataSourceService.synchronization(dataSource);
|
return dataSourceService.synchronization(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/findDataBaseTable")
|
|
||||||
public Result<List<DatabaseTableModel>> findDataBaseTable(){
|
|
||||||
return dataSourceService.findDataBaseTable();
|
|
||||||
}
|
|
||||||
@GetMapping("/findAssetStructure")
|
@GetMapping("/findAssetStructure")
|
||||||
public Result<List<AssetStructure>> findAssetStructure(){
|
public Result<List<AssetStructure>> findAssetStructure(){
|
||||||
return dataSourceService.findAssetStructure();
|
return dataSourceService.findAssetStructure();
|
||||||
}
|
}
|
||||||
|
@GetMapping("/findInformationById")
|
||||||
@GetMapping("/findStructure")
|
public Result<List<DatabaseTableInformation>> findInformationById(@RequestParam Integer id){
|
||||||
public Result<Structure> findStructure(){
|
return dataSourceService.findInformationById(id);
|
||||||
return dataSourceService.findStructure();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据资产表id获取字段表信息
|
||||||
|
* @param id
|
||||||
|
* @return 字段列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/findDataBaseTableById")
|
||||||
|
public Result<List<DataBaseTable>> findDataBaseTableById(@RequestParam Integer id){
|
||||||
|
return dataSourceService.findDataBaseTableById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据名字查询数据库
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/findDataBaseTableByName/{name}")
|
||||||
|
public Result<List<DataBaseTable>> findDataBaseTableByName( @PathVariable String name){
|
||||||
|
return dataSourceService.findDataBaseTableByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询数据库
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/findDataBaseTable")
|
||||||
|
public Result<DatabaseTableInformation> findDataBaseTable(@RequestParam Long id){
|
||||||
|
return dataSourceService.findDataBaseTable(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据资产id查询数据库信息表
|
||||||
|
* @param id
|
||||||
|
* @return 数据库信息列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/findDataBaseByAssetId")
|
||||||
|
public Result<List<DatabaseTableInformation>> findDataBaseByAssetId(@RequestParam Integer id){
|
||||||
|
return dataSourceService.findDataBaseByAssetId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据数据库信息表id查询字段表
|
||||||
|
* @param id
|
||||||
|
* @return 字段表列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/findDataBaseByInformationId")
|
||||||
|
public Result<List<DataBaseTable>> findDataBaseByInformationId(@RequestParam Integer id){
|
||||||
|
return dataSourceService.findDataBaseByInformationId(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,7 @@ package com.muyu.data.source.mapper;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.data.source.domain.AccessType;
|
import com.muyu.data.source.domain.*;
|
||||||
import com.muyu.data.source.domain.AssetStructure;
|
|
||||||
import com.muyu.data.source.domain.DataSource;
|
|
||||||
import com.muyu.data.source.domain.DatabaseTableInformation;
|
|
||||||
import com.muyu.data.source.domain.model.DatabaseTableModel;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,21 +16,37 @@ public interface DataSourceMapper extends BaseMapper<DataSource> {
|
||||||
|
|
||||||
List<AccessType> findAccessType();
|
List<AccessType> findAccessType();
|
||||||
|
|
||||||
void addAssets(@Param("assetStructure") List<AssetStructure> assetStructure);
|
|
||||||
|
|
||||||
void addAssets1(AssetStructure assetStructure);
|
|
||||||
|
|
||||||
List<AssetStructure> assetStructureList();
|
List<AssetStructure> assetStructureList();
|
||||||
|
|
||||||
DatabaseTableModel findByName(@Param("databaseName") String databaseName, @Param("databaseTableName") String databaseTableName);
|
|
||||||
|
|
||||||
List<DatabaseTableInformation> findByBaseName(@Param("databaseName") String databaseName);
|
List<DatabaseTableInformation> findByBaseName(@Param("databaseName") String databaseName);
|
||||||
|
|
||||||
void addDatabaseTableInformation(@Param("databaseTableInformationList") List<DatabaseTableInformation> databaseTableInformationList);
|
void addDatabaseTableInformation(@Param("databaseTableInformationList") List<DatabaseTableInformation> databaseTableInformationList, @Param("id") Long id);
|
||||||
|
|
||||||
void addDatabaseTableInfo(@Param("databaseTableInformations") ArrayList<DatabaseTableInformation> databaseTableInformations);
|
void addDatabaseTableInfo(@Param("databaseTableInformations") ArrayList<DatabaseTableInformation> databaseTableInformations);
|
||||||
|
|
||||||
List<AssetStructure> findAssetStructure();
|
|
||||||
|
|
||||||
List<DatabaseTableInformation> findInformation();
|
Integer addAssets(AssetStructure assetStructure);
|
||||||
|
|
||||||
|
List<DatabaseTableInformation> findInformationById(@Param("id") Integer id);
|
||||||
|
|
||||||
|
AssetStructure findAssetsById(@Param("id") Integer id);
|
||||||
|
|
||||||
|
List<DataBaseTable> findDataBaseTable(@Param("databaseName") String databaseName, @Param("name") String name);
|
||||||
|
|
||||||
|
void addDataBaseTable(@Param("dataBaseTable") List<DataBaseTable> dataBaseTable);
|
||||||
|
|
||||||
|
List<DataBaseTable> findDataBaseTableById(@Param("id") Integer id);
|
||||||
|
|
||||||
|
List<DataBaseTable> findDataBaseTableByName(@Param("name") String name);
|
||||||
|
|
||||||
|
DatabaseTableInformation findAssetById(@Param("id") Integer id);
|
||||||
|
|
||||||
|
DatabaseTableInformation findDataBaseTableBy(@Param("id") Long id);
|
||||||
|
|
||||||
|
List<DatabaseTableInformation> findDataBaseTableInformationById(@Param("id") Integer id);
|
||||||
|
|
||||||
|
// AssetStructure findDatabaseName(DataSource dataSource);
|
||||||
|
|
||||||
|
// void updateAssets(@Param("assetStructure") AssetStructure assetStructure, @Param("id") Long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.util.List;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.data.source.domain.*;
|
import com.muyu.data.source.domain.*;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.muyu.data.source.domain.model.DatabaseTableModel;
|
|
||||||
import com.muyu.data.source.domain.req.DataSourceSaveReq;
|
import com.muyu.data.source.domain.req.DataSourceSaveReq;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,9 +29,17 @@ public interface DataSourceService extends IService<DataSource> {
|
||||||
|
|
||||||
Result synchronization(DataSource dataSource);
|
Result synchronization(DataSource dataSource);
|
||||||
|
|
||||||
Result<List<DatabaseTableModel>> findDataBaseTable();
|
|
||||||
|
|
||||||
Result<List<AssetStructure>> findAssetStructure();
|
Result<List<AssetStructure>> findAssetStructure();
|
||||||
|
|
||||||
Result<Structure> findStructure();
|
Result<List<DatabaseTableInformation>> findInformationById(Integer id);
|
||||||
|
|
||||||
|
Result<List<DataBaseTable>> findDataBaseTableById(Integer id);
|
||||||
|
|
||||||
|
Result<List<DataBaseTable>> findDataBaseTableByName(String name);
|
||||||
|
|
||||||
|
Result<DatabaseTableInformation> findDataBaseTable(Long id);
|
||||||
|
|
||||||
|
Result<List<DatabaseTableInformation>> findDataBaseByAssetId(Integer id);
|
||||||
|
|
||||||
|
Result<List<DataBaseTable>> findDataBaseByInformationId(Integer id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,13 @@ 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.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.utils.ObjUtils;
|
import com.muyu.common.core.utils.ObjUtils;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
|
||||||
import com.muyu.data.source.domain.*;
|
import com.muyu.data.source.domain.*;
|
||||||
import com.muyu.data.source.domain.model.DatabaseTableModel;
|
|
||||||
import com.muyu.data.source.domain.req.DataSourceSaveReq;
|
import com.muyu.data.source.domain.req.DataSourceSaveReq;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -120,75 +119,193 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
||||||
@Override
|
@Override
|
||||||
public Result synchronization(DataSource dataSource) {
|
public Result synchronization(DataSource dataSource) {
|
||||||
|
|
||||||
|
//初始化容器
|
||||||
AssetStructure assetStructure = new AssetStructure();
|
AssetStructure assetStructure = new AssetStructure();
|
||||||
|
List<DatabaseTableInformation> list = new ArrayList<>();
|
||||||
|
|
||||||
ArrayList<String> tableNames = new ArrayList<>();
|
//连接jdbc驱动
|
||||||
List<DatabaseTableInformation> databaseTableInformationList=dataSourceMapper.findByBaseName(dataSource.getDatabaseName());
|
|
||||||
dataSourceMapper.addDatabaseTableInformation(databaseTableInformationList);
|
|
||||||
List<AssetStructure> list = new ArrayList<>();
|
|
||||||
|
|
||||||
String user=dataSource.getDatabaseUserName();
|
String user=dataSource.getDatabaseUserName();
|
||||||
String password=dataSource.getDatabaseUserPassword();
|
String password=dataSource.getDatabaseUserPassword();
|
||||||
String jdbcDriver="com.mysql.cj.jdbc.Driver";
|
String jdbcDriver="com.mysql.cj.jdbc.Driver";
|
||||||
String url = "jdbc:mysql://" + dataSource.getHostAddress() + ":" + dataSource.getHostPort() + "/" + dataSource.getDatabaseName();
|
String url = "jdbc:mysql://" + dataSource.getHostAddress() + ":" + dataSource.getHostPort() + "/" + dataSource.getDatabaseName();
|
||||||
String query="show tables ";
|
//查询条件
|
||||||
try(Connection con=DriverManager.getConnection(url,user,password);
|
String query="show tables";
|
||||||
Statement stmt=con.createStatement();
|
try (Connection con = DriverManager.getConnection(url, user, password)) {
|
||||||
ResultSet rs= stmt.executeQuery(query)) {
|
// 创建 PreparedStatement,并设置参数
|
||||||
ResultSetMetaData rsmd = rs.getMetaData();
|
PreparedStatement prepared = con.prepareStatement("SELECT " +
|
||||||
// 5. 处理查询结果
|
" TABLE_NAME AS `name`, " +
|
||||||
while (rs.next()) {
|
" TABLE_COMMENT AS `as`, " +
|
||||||
String tableName = rs.getString(1);
|
" TABLE_ROWS AS `dataTotal` " +
|
||||||
tableNames.add(tableName);
|
" FROM INFORMATION_SCHEMA.TABLES " +
|
||||||
}
|
" WHERE TABLE_SCHEMA = ?");
|
||||||
|
prepared.setString(1, dataSource.getDatabaseName()); // 设置数据库名称参数
|
||||||
|
|
||||||
assetStructure.setAccessSourceName(dataSource.getAccessSourceName());
|
|
||||||
assetStructure.setDatabaseName(dataSource.getDatabaseName());
|
|
||||||
assetStructure.setDataSourceSystemName(dataSource.getDataSourceSystemName());
|
|
||||||
|
|
||||||
assetStructure.setDatabaseTableName(rsmd.getTableName(1));
|
// 执行查询
|
||||||
|
ResultSet resultSet = prepared.executeQuery();
|
||||||
|
|
||||||
assetStructure.setDataVolume(rsmd.getColumnDisplaySize(1));
|
ResultSetMetaData rsmd = resultSet.getMetaData();
|
||||||
assetStructure.setDataQuantity(rsmd.getColumnDisplaySize(1));
|
// 5. 处理查询结果
|
||||||
|
while (resultSet.next()) {
|
||||||
|
String tableName = resultSet.getString("name");
|
||||||
|
String tableComment = resultSet.getString("as");
|
||||||
|
int tableRows = resultSet.getInt("dataTotal");
|
||||||
|
|
||||||
dataSourceMapper.addAssets1(assetStructure);
|
// 创建一个包含数据库表信息的对象
|
||||||
|
DatabaseTableInformation databaseTableInformation = DatabaseTableInformation.builder()
|
||||||
|
.name(tableName)
|
||||||
|
.as(tableComment)
|
||||||
|
.dataTotal(tableRows).build();
|
||||||
|
|
||||||
return Result.success("同步成功");
|
// 将对象添加到 ArrayList 中
|
||||||
|
list.add(databaseTableInformation);
|
||||||
} catch (SQLException e) {
|
}
|
||||||
System.out.println("连接失败"+e.getMessage());
|
//参数复制对象
|
||||||
return Result.error("同步失败");
|
assetStructure.setAccessSourceName(dataSource.getAccessSourceName());
|
||||||
|
assetStructure.setDatabaseName(dataSource.getDatabaseName());
|
||||||
|
assetStructure.setDataSourceSystemName(dataSource.getDataSourceSystemName());
|
||||||
|
assetStructure.setDatabaseTableName(rsmd.getTableName(1));
|
||||||
|
assetStructure.setDataVolume(rsmd.getColumnDisplaySize(1));
|
||||||
|
assetStructure.setDataQuantity(rsmd.getColumnDisplaySize(1));
|
||||||
|
if (list.size()==0){
|
||||||
|
return Result.error("数据库没有内容");
|
||||||
|
}
|
||||||
|
//同步到数据库
|
||||||
|
dataSourceMapper.addAssets(assetStructure);
|
||||||
|
//同步到数据库表信息库
|
||||||
|
dataSourceMapper.addDatabaseTableInformation(list,assetStructure.getId());
|
||||||
|
List<DataBaseTable> dataBaseTable = new ArrayList<>();
|
||||||
|
//列表循环
|
||||||
|
for (DatabaseTableInformation databaseTableInformation : list) {
|
||||||
|
//条件sql
|
||||||
|
PreparedStatement preparedStatement = con.prepareStatement(" SELECT " +
|
||||||
|
" TABLE_NAME AS 'tableName', " +
|
||||||
|
" COLUMN_NAME AS 'name', " +
|
||||||
|
" COLUMN_COMMENT AS 'comment', " +
|
||||||
|
" CASE WHEN COLUMN_KEY = 'PRI' THEN '是' ELSE '否' END AS 'isPrimaryKey', " +
|
||||||
|
" " +
|
||||||
|
" CASE " +
|
||||||
|
" WHEN DATA_TYPE = 'int' THEN 'Integer' " +
|
||||||
|
" WHEN DATA_TYPE = 'varchar' THEN 'String' " +
|
||||||
|
" WHEN DATA_TYPE = 'decimal' THEN 'BigDecimal' " +
|
||||||
|
" WHEN DATA_TYPE = 'tinyint' AND COLUMN_TYPE = 'tinyint(1)' THEN 'Boolean' " +
|
||||||
|
" " +
|
||||||
|
" ELSE DATA_TYPE " +
|
||||||
|
" END AS 'type', " +
|
||||||
|
" DATA_TYPE AS 'mappingType', " +
|
||||||
|
" COLUMN_TYPE AS 'detailType', " +
|
||||||
|
" CHARACTER_MAXIMUM_LENGTH AS 'length', " +
|
||||||
|
" NUMERIC_SCALE AS 'decimalPlaces', " +
|
||||||
|
" IS_NULLABLE AS 'isNull', " +
|
||||||
|
" COLUMN_DEFAULT AS 'defaultValue' " +
|
||||||
|
" FROM " +
|
||||||
|
" INFORMATION_SCHEMA.COLUMNS " +
|
||||||
|
" WHERE " +
|
||||||
|
" TABLE_SCHEMA = ?" +
|
||||||
|
" AND TABLE_NAME = ?");
|
||||||
|
preparedStatement.setString(1, dataSource.getDatabaseName());
|
||||||
|
preparedStatement.setString(2, databaseTableInformation.getName());
|
||||||
|
//执行查询
|
||||||
|
ResultSet executeQuery = preparedStatement.executeQuery();
|
||||||
|
ResultSetMetaData metaData = executeQuery.getMetaData();
|
||||||
|
// 5. 处理查询结果
|
||||||
|
while (executeQuery.next()) {
|
||||||
|
//获得返回值
|
||||||
|
String tableName = executeQuery.getString("tableName");
|
||||||
|
String name = executeQuery.getString("name");
|
||||||
|
String comment = executeQuery.getString("comment");
|
||||||
|
String isPrimaryKey = executeQuery.getString("isPrimaryKey");
|
||||||
|
String type = executeQuery.getString("type");
|
||||||
|
String detailType = executeQuery.getString("detailType");
|
||||||
|
Integer length = executeQuery.getInt("length");
|
||||||
|
Double decimalPlaces = executeQuery.getDouble("decimalPlaces");
|
||||||
|
String isNull = executeQuery.getString("isNull");
|
||||||
|
String defaultValue = executeQuery.getString("defaultValue");
|
||||||
|
//build构造方法
|
||||||
|
DataBaseTable build = DataBaseTable.builder()
|
||||||
|
.name(name)
|
||||||
|
.tableName(tableName)
|
||||||
|
.comment(comment)
|
||||||
|
.decimalPlaces(decimalPlaces)
|
||||||
|
.isPrimaryKey(isPrimaryKey)
|
||||||
|
.type(type)
|
||||||
|
.detailType(detailType)
|
||||||
|
.length(length)
|
||||||
|
.isNull(isNull)
|
||||||
|
.defaultValue(defaultValue)
|
||||||
|
.informationId(databaseTableInformation.getId())
|
||||||
|
.build();
|
||||||
|
//添加到列表
|
||||||
|
dataBaseTable.add(build);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
//添加数据库
|
||||||
|
dataSourceMapper.addDataBaseTable(dataBaseTable);
|
||||||
@Override
|
return Result.success("同步成功");
|
||||||
public Result<List<DatabaseTableModel>> findDataBaseTable() {
|
} catch (SQLException e) {
|
||||||
List<AssetStructure> assetStructureList=dataSourceMapper.assetStructureList();
|
System.out.println("连接失败"+e.getMessage());
|
||||||
List<DatabaseTableModel> databaseTableList = new ArrayList<>();
|
return Result.error("同步失败");
|
||||||
for (AssetStructure assetStructure : assetStructureList) {
|
|
||||||
DatabaseTableModel databaseTableModel=dataSourceMapper.findByName(assetStructure.getDatabaseName(),assetStructure.getDatabaseTableName());
|
|
||||||
System.out.println(databaseTableModel);
|
|
||||||
databaseTableList.add(databaseTableModel);
|
|
||||||
}
|
}
|
||||||
return Result.success(databaseTableList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<List<AssetStructure>> findAssetStructure() {
|
public Result<List<AssetStructure>> findAssetStructure() {
|
||||||
List<AssetStructure> assetStructureList=dataSourceMapper.assetStructureList();
|
List<AssetStructure> assetStructureList = dataSourceMapper.assetStructureList();
|
||||||
return Result.success(assetStructureList);
|
return Result.success(assetStructureList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Structure> findStructure() {
|
public Result<List<DatabaseTableInformation>> findInformationById(Integer id) {
|
||||||
Structure structure = new Structure();
|
Structure structure = new Structure();
|
||||||
List<AssetStructure> assetStructure = dataSourceMapper.findAssetStructure();
|
AssetStructure assetStructure=dataSourceMapper.findAssetsById(id);
|
||||||
structure.setAssetStructureList(assetStructure);
|
List<DatabaseTableInformation> databaseTableInformationList=dataSourceMapper.findInformationById(id);
|
||||||
List<DatabaseTableInformation> databaseTableInformationList=dataSourceMapper.findInformation();
|
ArrayList<DataBaseTable> dataBaseTableArrayList = new ArrayList<>();
|
||||||
structure.setDatabaseTableInformationList(databaseTableInformationList);
|
for (DatabaseTableInformation databaseTableInformation : databaseTableInformationList) {
|
||||||
return Result.success(structure);
|
List<DataBaseTable> dataBaseTableList=dataSourceMapper.findDataBaseTable(assetStructure.getDatabaseName(),databaseTableInformation.getName());
|
||||||
|
dataBaseTableArrayList.addAll(dataBaseTableList);
|
||||||
|
}
|
||||||
|
System.out.println(dataBaseTableArrayList);
|
||||||
|
return Result.success(databaseTableInformationList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<List<DataBaseTable>> findDataBaseTableById(Integer id) {
|
||||||
|
List<DatabaseTableInformation> databaseTableInformation=dataSourceMapper.findDataBaseTableInformationById(id);
|
||||||
|
|
||||||
|
ArrayList<DataBaseTable> dataBaseTables = new ArrayList<>();
|
||||||
|
for (DatabaseTableInformation tableInformation : databaseTableInformation) {
|
||||||
|
List<DataBaseTable> dataBaseTableList=dataSourceMapper.findDataBaseTableById(tableInformation.getId());
|
||||||
|
dataBaseTables.addAll(dataBaseTableList);
|
||||||
|
}
|
||||||
|
return Result.success(dataBaseTables);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<List<DataBaseTable>> findDataBaseTableByName(String name) {
|
||||||
|
List<DataBaseTable> dataBaseTableList=dataSourceMapper.findDataBaseTableByName(name);
|
||||||
|
return Result.success(dataBaseTableList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<DatabaseTableInformation> findDataBaseTable(Long id) {
|
||||||
|
DatabaseTableInformation databaseTableInformation=dataSourceMapper.findDataBaseTableBy(id);
|
||||||
|
return Result.success(databaseTableInformation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<List<DatabaseTableInformation>> findDataBaseByAssetId(Integer id) {
|
||||||
|
|
||||||
|
List<DatabaseTableInformation> databaseTableInformationList=dataSourceMapper.findDataBaseTableInformationById(id);
|
||||||
|
return Result.success(databaseTableInformationList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<List<DataBaseTable>> findDataBaseByInformationId(Integer id) {
|
||||||
|
List<DataBaseTable> dataBaseTableList=dataSourceMapper.findDataBaseTableById(id);
|
||||||
|
return Result.success(dataBaseTableList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,49 +29,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<sql id="selectDataSourceVo">
|
<sql id="selectDataSourceVo">
|
||||||
select id, access_source_name, data_source_system_name, host_address, host_port, data_access_type_id, database_name, data_connection_parameter, initial_quantity, maximum_quantity, maximum_time, maximum_frequency, remark, create_by, create_time, update_by, update_time ,database_user_name ,database_user_password from data_source
|
select id, access_source_name, data_source_system_name, host_address, host_port, data_access_type_id, database_name, data_connection_parameter, initial_quantity, maximum_quantity, maximum_time, maximum_frequency, remark, create_by, create_time, update_by, update_time ,database_user_name ,database_user_password from data_source
|
||||||
</sql>
|
</sql>
|
||||||
<insert id="addAssets">
|
|
||||||
|
|
||||||
INSERT INTO `data_management`.`asset_structure`
|
<insert id="addDatabaseTableInformation" useGeneratedKeys="true" keyProperty="databaseTableInformationList.id">
|
||||||
(`access_source_name`, `data_source_system_name`, `database_name`, `database_table_name`, `data_volume`, `data_quantity`, `core_or_not`)
|
|
||||||
VALUES
|
|
||||||
<foreach collection="assetStructure" item="assetStructure" separator=",">
|
|
||||||
(
|
|
||||||
#{assetStructure.accessSourceName},
|
|
||||||
#{assetStructure.dataSourceSystemName},
|
|
||||||
#{assetStructure.databaseName},
|
|
||||||
#{assetStructure.databaseTableName},
|
|
||||||
#{assetStructure.dataVolume},
|
|
||||||
#{assetStructure.dataQuantity},
|
|
||||||
'Y'
|
|
||||||
)
|
|
||||||
</foreach>
|
|
||||||
|
|
||||||
</insert>
|
|
||||||
<insert id="addAssets1">
|
|
||||||
INSERT INTO `data_management`.`asset_structure`
|
|
||||||
(`access_source_name`, `data_source_system_name`, `database_name`, `data_volume`, `data_quantity`, `core_or_not`)
|
|
||||||
VALUES
|
|
||||||
|
|
||||||
(
|
|
||||||
#{accessSourceName},
|
|
||||||
#{dataSourceSystemName},
|
|
||||||
#{databaseName},
|
|
||||||
#{dataVolume},
|
|
||||||
#{dataQuantity},
|
|
||||||
'Y'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
</insert>
|
|
||||||
<insert id="addDatabaseTableInformation">
|
|
||||||
INSERT INTO `data_management`.`database_table_information`
|
INSERT INTO `data_management`.`database_table_information`
|
||||||
( `name`, `as`, `dataTotal`)
|
( `name`, `as`, `dataTotal`,`structure_id`)
|
||||||
VALUES
|
VALUES
|
||||||
<foreach collection="databaseTableInformationList" item="databaseTableInformationList" separator=",">
|
<foreach collection="databaseTableInformationList" item="databaseTableInformationList" separator=",">
|
||||||
(
|
(
|
||||||
#{databaseTableInformationList.name},
|
#{databaseTableInformationList.name},
|
||||||
#{databaseTableInformationList.as},
|
#{databaseTableInformationList.as},
|
||||||
#{databaseTableInformationList.dataTotal}
|
#{databaseTableInformationList.dataTotal},
|
||||||
|
#{id}
|
||||||
)
|
)
|
||||||
</foreach>
|
</foreach>
|
||||||
|
|
||||||
|
@ -91,13 +59,99 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
)
|
)
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
<insert id="addAssets" useGeneratedKeys="true" keyProperty="id" parameterType="com.muyu.data.source.domain.AssetStructure">
|
||||||
|
INSERT INTO `data_management`.`asset_structure`
|
||||||
|
( `access_source_name`, `data_source_system_name`, `database_name`, `data_volume`, `databaseUserName`, `databaseUserPassword`, `hostAddress`, `hostPort`)
|
||||||
|
VALUES
|
||||||
|
|
||||||
|
(
|
||||||
|
|
||||||
|
#{accessSourceName},
|
||||||
|
#{dataSourceSystemName},
|
||||||
|
#{databaseName},
|
||||||
|
#{dataVolume},
|
||||||
|
#{databaseUserName},
|
||||||
|
#{databaseUserPassword},
|
||||||
|
#{hostAddress},
|
||||||
|
#{hostPort}
|
||||||
|
)
|
||||||
|
|
||||||
|
</insert>
|
||||||
|
<insert id="addDataBaseTable">
|
||||||
|
INSERT INTO `data_management`.`database_table`
|
||||||
|
(
|
||||||
|
`tableName`,
|
||||||
|
`name`,
|
||||||
|
`comment`,
|
||||||
|
`isPrimaryKey`,
|
||||||
|
`type`,
|
||||||
|
`detailType`,
|
||||||
|
`length`,
|
||||||
|
`decimalPlaces`,
|
||||||
|
`isNull`,
|
||||||
|
`defaultValue`,
|
||||||
|
`information_id`
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
<foreach collection="dataBaseTable" item="dataBaseTable" separator=",">
|
||||||
|
(
|
||||||
|
#{dataBaseTable.tableName},
|
||||||
|
#{dataBaseTable.name},
|
||||||
|
#{dataBaseTable.comment},
|
||||||
|
#{dataBaseTable.isPrimaryKey},
|
||||||
|
#{dataBaseTable.type},
|
||||||
|
#{dataBaseTable.detailType},
|
||||||
|
#{dataBaseTable.length},
|
||||||
|
#{dataBaseTable.decimalPlaces},
|
||||||
|
#{dataBaseTable.isNull},
|
||||||
|
#{dataBaseTable.defaultValue},
|
||||||
|
#{dataBaseTable.informationId}
|
||||||
|
)
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
<!-- <update id="updateAssets">-->
|
||||||
|
<!-- UPDATE `data_management`.`asset_structure` SET-->
|
||||||
|
<!-- `access_source_name` = #{assetStructure.accessSourceName},-->
|
||||||
|
<!-- `data_source_system_name` = #{assetStructure.dataSourceSystemName},-->
|
||||||
|
<!-- `database_name` = #{assetStructure.databaseName},-->
|
||||||
|
<!-- `data_volume` = #{assetStructure.dataVolume},-->
|
||||||
|
<!-- `type` = 0,-->
|
||||||
|
<!-- `databaseUserName` = #{assetStructure.databaseUserName},-->
|
||||||
|
<!-- `databaseUserPassword` = #{assetStructure.databaseUserPassword},-->
|
||||||
|
<!-- `hostAddress` = #{assetStructure.hostAddress},-->
|
||||||
|
<!-- `hostPort` = #{assetStructure.hostPort}-->
|
||||||
|
<!-- WHERE-->
|
||||||
|
<!-- `id` = #{assetStructure.id};-->
|
||||||
|
|
||||||
|
<!-- </update>-->
|
||||||
<select id="findAccessType" resultType="com.muyu.data.source.domain.AccessType">
|
<select id="findAccessType" resultType="com.muyu.data.source.domain.AccessType">
|
||||||
select * from access_type
|
select * from access_type
|
||||||
</select>
|
</select>
|
||||||
<select id="assetStructureList" resultType="com.muyu.data.source.domain.AssetStructure">
|
<select id="assetStructureList" resultType="com.muyu.data.source.domain.AssetStructure">
|
||||||
select * from asset_structure
|
select * from asset_structure
|
||||||
</select>
|
</select>
|
||||||
<select id="findByName" resultType="com.muyu.data.source.domain.model.DatabaseTableModel">
|
<select id="findByBaseName" resultType="com.muyu.data.source.domain.DatabaseTableInformation">
|
||||||
|
SELECT
|
||||||
|
TABLE_NAME as 'name',
|
||||||
|
TABLE_COMMENT as 'as',
|
||||||
|
TABLE_ROWS as 'dataTotal'
|
||||||
|
FROM INFORMATION_SCHEMA.TABLES
|
||||||
|
WHERE
|
||||||
|
TABLE_SCHEMA = #{databaseName}
|
||||||
|
</select>
|
||||||
|
<select id="findAssetStructure" resultType="com.muyu.data.source.domain.AssetStructure">
|
||||||
|
select * from asset_structure
|
||||||
|
</select>
|
||||||
|
<select id="findInformation" resultType="com.muyu.data.source.domain.DatabaseTableInformation">
|
||||||
|
select * from database_table_information where structure_id=#{id}
|
||||||
|
</select>
|
||||||
|
<select id="findInformationById" resultType="com.muyu.data.source.domain.DatabaseTableInformation">
|
||||||
|
select * from database_table_information where structure_id=#{id};
|
||||||
|
</select>
|
||||||
|
<select id="findAssetsById" resultType="com.muyu.data.source.domain.AssetStructure">
|
||||||
|
select * from asset_structure where id=#{id}
|
||||||
|
</select>
|
||||||
|
<select id="findDataBaseTable" resultType="com.muyu.data.source.domain.DataBaseTable">
|
||||||
SELECT
|
SELECT
|
||||||
TABLE_NAME AS 'tableName',
|
TABLE_NAME AS 'tableName',
|
||||||
COLUMN_NAME AS 'name',
|
COLUMN_NAME AS 'name',
|
||||||
|
@ -121,23 +175,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
FROM
|
FROM
|
||||||
INFORMATION_SCHEMA.COLUMNS
|
INFORMATION_SCHEMA.COLUMNS
|
||||||
WHERE
|
WHERE
|
||||||
TABLE_SCHEMA = #{databaseName}
|
TABLE_SCHEMA =#{databaseName}
|
||||||
AND TABLE_NAME = #{databaseTableName}
|
AND TABLE_NAME = #{name}
|
||||||
</select>
|
</select>
|
||||||
<select id="findByBaseName" resultType="com.muyu.data.source.domain.DatabaseTableInformation">
|
<select id="findDataBaseTableById" resultType="com.muyu.data.source.domain.DataBaseTable">
|
||||||
SELECT
|
select * from database_table where information_id=#{id}
|
||||||
TABLE_NAME as 'name',
|
|
||||||
TABLE_COMMENT as 'as',
|
|
||||||
TABLE_ROWS as 'dataTotal'
|
|
||||||
FROM INFORMATION_SCHEMA.TABLES
|
|
||||||
WHERE
|
|
||||||
TABLE_SCHEMA = #{databaseName}
|
|
||||||
</select>
|
</select>
|
||||||
<select id="findAssetStructure" resultType="com.muyu.data.source.domain.AssetStructure">
|
<select id="findDataBaseTableByName" resultType="com.muyu.data.source.domain.DataBaseTable">
|
||||||
select * from asset_structure
|
select * from database_table where tableName=#{name}
|
||||||
</select>
|
</select>
|
||||||
<select id="findInformation" resultType="com.muyu.data.source.domain.DatabaseTableInformation">
|
<select id="findAssetById" resultType="com.muyu.data.source.domain.DatabaseTableInformation">
|
||||||
select * from database_table_information
|
select * from database_table_information where structure_id=#{id}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="findDataBaseTableBy" resultType="com.muyu.data.source.domain.DatabaseTableInformation">
|
||||||
|
select * from database_table_information where id=#{id}
|
||||||
|
</select>
|
||||||
|
<select id="findDataBaseTableInformationById" resultType="com.muyu.data.source.domain.DatabaseTableInformation">
|
||||||
|
select * from database_table_information where structure_id=#{id}
|
||||||
|
</select>
|
||||||
|
<!-- <select id="findDatabaseName" resultType="com.muyu.data.source.domain.AssetStructure">-->
|
||||||
|
<!-- select * from asset_structure-->
|
||||||
|
<!-- <where>-->
|
||||||
|
<!-- <if test="databaseName!=null and databaseName!=''">-->
|
||||||
|
<!-- and database_name=#{databaseName}-->
|
||||||
|
<!-- </if>-->
|
||||||
|
<!-- <if test=""></if>-->
|
||||||
|
<!-- <if test="">-->
|
||||||
|
<!-- -->
|
||||||
|
<!-- </if>-->
|
||||||
|
<!-- </where>-->
|
||||||
|
<!-- </select>-->
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue