parent
6941f85527
commit
2382901c45
|
@ -19,6 +19,10 @@ import java.util.List;
|
|||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AssetStructure{
|
||||
|
||||
/**资产表id*/
|
||||
private Long id;
|
||||
|
||||
/** 接入源名称 */
|
||||
private String accessSourceName;
|
||||
|
||||
|
@ -40,10 +44,19 @@ public class AssetStructure{
|
|||
/**是否核心*/
|
||||
private String coreOrNot;
|
||||
|
||||
/**表注释*/
|
||||
private String tableComment;
|
||||
|
||||
/**类型*/
|
||||
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.Builder;
|
||||
|
@ -6,20 +6,20 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 数据库表对象 DatabaseTable
|
||||
* 数据库表对象 DataBaseTable
|
||||
*
|
||||
* @author DeKangLiu
|
||||
* on 2024/4/22
|
||||
* on 2024/4/24
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DatabaseTableModel {
|
||||
public class DataBaseTable {
|
||||
/**数据库表id*/
|
||||
private Long id;
|
||||
private Integer id;
|
||||
|
||||
/**数据库表名*/
|
||||
/**数据库名称*/
|
||||
private String tableName;
|
||||
|
||||
/**字段名*/
|
||||
|
@ -31,17 +31,17 @@ public class DatabaseTableModel {
|
|||
/**是否核心*/
|
||||
private String isPrimaryKey;
|
||||
|
||||
/**Java类型*/
|
||||
/**java类型*/
|
||||
private String type;
|
||||
|
||||
/**字段类型*/
|
||||
private String detailName;
|
||||
private String detailType;
|
||||
|
||||
/**长度*/
|
||||
/**小数点*/
|
||||
private Integer length;
|
||||
|
||||
/**小数点*/
|
||||
private Integer decimalPlaces;
|
||||
private Double decimalPlaces;
|
||||
|
||||
/**是否为空*/
|
||||
private String isNull;
|
||||
|
@ -49,4 +49,11 @@ public class DatabaseTableModel {
|
|||
/**默认值*/
|
||||
private String defaultValue;
|
||||
|
||||
/**结构表id*/
|
||||
private Integer structureId;
|
||||
|
||||
/**信息表id*/
|
||||
private Integer informationId;
|
||||
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* DatabaseTableInformation
|
||||
* 数据库表对象信息 DatabaseTableInformation
|
||||
*
|
||||
* @author DeKangLiu
|
||||
* on 2024/4/23
|
||||
|
@ -18,7 +18,7 @@ import lombok.NoArgsConstructor;
|
|||
public class DatabaseTableInformation {
|
||||
|
||||
/**数据库信息id*/
|
||||
private Long id;
|
||||
private Integer id;
|
||||
|
||||
/**数据库表名*/
|
||||
private String name;
|
||||
|
@ -40,4 +40,8 @@ public class DatabaseTableInformation {
|
|||
|
||||
/**类型*/
|
||||
private Integer type;
|
||||
|
||||
/**资产结构id*/
|
||||
private Integer structureId;
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import lombok.NoArgsConstructor;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TestList
|
||||
* 资产结构树形对象 Structure
|
||||
*
|
||||
* @author DeKangLiu
|
||||
* on 2024/4/24
|
||||
|
@ -21,7 +21,7 @@ public class Structure {
|
|||
/**数据库表信息对象*/
|
||||
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 com.muyu.data.source.domain.*;
|
||||
import com.muyu.data.source.domain.model.DatabaseTableModel;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
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 org.springframework.web.bind.annotation.*;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
|
@ -117,29 +109,83 @@ public class DataSourceController extends BaseController {
|
|||
List<AccessType> accessTypeList=dataSourceService.findAccessType();
|
||||
return Result.success(accessTypeList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试连接
|
||||
* @param dataSourceSaveReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/testConnection")
|
||||
public Result testConnection(@RequestBody DataSourceSaveReq dataSourceSaveReq){
|
||||
return dataSourceService.testConnection(dataSourceSaveReq);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数据源对象同步代码
|
||||
* @param dataSource
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/synchronization")
|
||||
public Result synchronization(@RequestBody DataSource dataSource){
|
||||
return dataSourceService.synchronization(dataSource);
|
||||
}
|
||||
|
||||
@GetMapping("/findDataBaseTable")
|
||||
public Result<List<DatabaseTableModel>> findDataBaseTable(){
|
||||
return dataSourceService.findDataBaseTable();
|
||||
}
|
||||
@GetMapping("/findAssetStructure")
|
||||
public Result<List<AssetStructure>> findAssetStructure(){
|
||||
return dataSourceService.findAssetStructure();
|
||||
}
|
||||
|
||||
@GetMapping("/findStructure")
|
||||
public Result<Structure> findStructure(){
|
||||
return dataSourceService.findStructure();
|
||||
@GetMapping("/findInformationById")
|
||||
public Result<List<DatabaseTableInformation>> findInformationById(@RequestParam Integer id){
|
||||
return dataSourceService.findInformationById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据资产表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.List;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.data.source.domain.AccessType;
|
||||
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 com.muyu.data.source.domain.*;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
|
@ -20,21 +16,37 @@ public interface DataSourceMapper extends BaseMapper<DataSource> {
|
|||
|
||||
List<AccessType> findAccessType();
|
||||
|
||||
void addAssets(@Param("assetStructure") List<AssetStructure> assetStructure);
|
||||
|
||||
void addAssets1(AssetStructure assetStructure);
|
||||
|
||||
List<AssetStructure> assetStructureList();
|
||||
|
||||
DatabaseTableModel findByName(@Param("databaseName") String databaseName, @Param("databaseTableName") String databaseTableName);
|
||||
|
||||
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);
|
||||
|
||||
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.data.source.domain.*;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.data.source.domain.model.DatabaseTableModel;
|
||||
import com.muyu.data.source.domain.req.DataSourceSaveReq;
|
||||
|
||||
/**
|
||||
|
@ -30,9 +29,17 @@ public interface DataSourceService extends IService<DataSource> {
|
|||
|
||||
Result synchronization(DataSource dataSource);
|
||||
|
||||
Result<List<DatabaseTableModel>> findDataBaseTable();
|
||||
|
||||
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.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
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.model.DatabaseTableModel;
|
||||
import com.muyu.data.source.domain.req.DataSourceSaveReq;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -120,41 +119,129 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
@Override
|
||||
public Result synchronization(DataSource dataSource) {
|
||||
|
||||
//初始化容器
|
||||
AssetStructure assetStructure = new AssetStructure();
|
||||
List<DatabaseTableInformation> list = new ArrayList<>();
|
||||
|
||||
ArrayList<String> tableNames = new ArrayList<>();
|
||||
List<DatabaseTableInformation> databaseTableInformationList=dataSourceMapper.findByBaseName(dataSource.getDatabaseName());
|
||||
dataSourceMapper.addDatabaseTableInformation(databaseTableInformationList);
|
||||
List<AssetStructure> list = new ArrayList<>();
|
||||
|
||||
//连接jdbc驱动
|
||||
String user=dataSource.getDatabaseUserName();
|
||||
String password=dataSource.getDatabaseUserPassword();
|
||||
String jdbcDriver="com.mysql.cj.jdbc.Driver";
|
||||
String url = "jdbc:mysql://" + dataSource.getHostAddress() + ":" + dataSource.getHostPort() + "/" + dataSource.getDatabaseName();
|
||||
String query="show tables ";
|
||||
try(Connection con=DriverManager.getConnection(url,user,password);
|
||||
Statement stmt=con.createStatement();
|
||||
ResultSet rs= stmt.executeQuery(query)) {
|
||||
ResultSetMetaData rsmd = rs.getMetaData();
|
||||
// 5. 处理查询结果
|
||||
while (rs.next()) {
|
||||
String tableName = rs.getString(1);
|
||||
tableNames.add(tableName);
|
||||
}
|
||||
//查询条件
|
||||
String query="show tables";
|
||||
try (Connection con = DriverManager.getConnection(url, user, password)) {
|
||||
// 创建 PreparedStatement,并设置参数
|
||||
PreparedStatement prepared = con.prepareStatement("SELECT " +
|
||||
" TABLE_NAME AS `name`, " +
|
||||
" TABLE_COMMENT AS `as`, " +
|
||||
" TABLE_ROWS AS `dataTotal` " +
|
||||
" FROM INFORMATION_SCHEMA.TABLES " +
|
||||
" WHERE TABLE_SCHEMA = ?");
|
||||
prepared.setString(1, dataSource.getDatabaseName()); // 设置数据库名称参数
|
||||
|
||||
|
||||
// 执行查询
|
||||
ResultSet resultSet = prepared.executeQuery();
|
||||
|
||||
ResultSetMetaData rsmd = resultSet.getMetaData();
|
||||
// 5. 处理查询结果
|
||||
while (resultSet.next()) {
|
||||
String tableName = resultSet.getString("name");
|
||||
String tableComment = resultSet.getString("as");
|
||||
int tableRows = resultSet.getInt("dataTotal");
|
||||
|
||||
// 创建一个包含数据库表信息的对象
|
||||
DatabaseTableInformation databaseTableInformation = DatabaseTableInformation.builder()
|
||||
.name(tableName)
|
||||
.as(tableComment)
|
||||
.dataTotal(tableRows).build();
|
||||
|
||||
// 将对象添加到 ArrayList 中
|
||||
list.add(databaseTableInformation);
|
||||
}
|
||||
//参数复制对象
|
||||
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));
|
||||
|
||||
dataSourceMapper.addAssets1(assetStructure);
|
||||
|
||||
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);
|
||||
return Result.success("同步成功");
|
||||
|
||||
} catch (SQLException e) {
|
||||
System.out.println("连接失败"+e.getMessage());
|
||||
return Result.error("同步失败");
|
||||
|
@ -162,33 +249,63 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<List<DatabaseTableModel>> findDataBaseTable() {
|
||||
List<AssetStructure> assetStructureList=dataSourceMapper.assetStructureList();
|
||||
List<DatabaseTableModel> databaseTableList = new ArrayList<>();
|
||||
for (AssetStructure assetStructure : assetStructureList) {
|
||||
DatabaseTableModel databaseTableModel=dataSourceMapper.findByName(assetStructure.getDatabaseName(),assetStructure.getDatabaseTableName());
|
||||
System.out.println(databaseTableModel);
|
||||
databaseTableList.add(databaseTableModel);
|
||||
}
|
||||
return Result.success(databaseTableList);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Result<List<AssetStructure>> findAssetStructure() {
|
||||
List<AssetStructure> assetStructureList=dataSourceMapper.assetStructureList();
|
||||
List<AssetStructure> assetStructureList = dataSourceMapper.assetStructureList();
|
||||
return Result.success(assetStructureList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Structure> findStructure() {
|
||||
public Result<List<DatabaseTableInformation>> findInformationById(Integer id) {
|
||||
Structure structure = new Structure();
|
||||
List<AssetStructure> assetStructure = dataSourceMapper.findAssetStructure();
|
||||
structure.setAssetStructureList(assetStructure);
|
||||
List<DatabaseTableInformation> databaseTableInformationList=dataSourceMapper.findInformation();
|
||||
structure.setDatabaseTableInformationList(databaseTableInformationList);
|
||||
return Result.success(structure);
|
||||
AssetStructure assetStructure=dataSourceMapper.findAssetsById(id);
|
||||
List<DatabaseTableInformation> databaseTableInformationList=dataSourceMapper.findInformationById(id);
|
||||
ArrayList<DataBaseTable> dataBaseTableArrayList = new ArrayList<>();
|
||||
for (DatabaseTableInformation databaseTableInformation : databaseTableInformationList) {
|
||||
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">
|
||||
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>
|
||||
<insert id="addAssets">
|
||||
|
||||
INSERT INTO `data_management`.`asset_structure`
|
||||
(`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 id="addDatabaseTableInformation" useGeneratedKeys="true" keyProperty="databaseTableInformationList.id">
|
||||
INSERT INTO `data_management`.`database_table_information`
|
||||
( `name`, `as`, `dataTotal`)
|
||||
( `name`, `as`, `dataTotal`,`structure_id`)
|
||||
VALUES
|
||||
<foreach collection="databaseTableInformationList" item="databaseTableInformationList" separator=",">
|
||||
(
|
||||
#{databaseTableInformationList.name},
|
||||
#{databaseTableInformationList.as},
|
||||
#{databaseTableInformationList.dataTotal}
|
||||
#{databaseTableInformationList.dataTotal},
|
||||
#{id}
|
||||
)
|
||||
</foreach>
|
||||
|
||||
|
@ -91,13 +59,99 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
)
|
||||
</foreach>
|
||||
</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 * from access_type
|
||||
</select>
|
||||
<select id="assetStructureList" resultType="com.muyu.data.source.domain.AssetStructure">
|
||||
select * from asset_structure
|
||||
</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
|
||||
TABLE_NAME AS 'tableName',
|
||||
COLUMN_NAME AS 'name',
|
||||
|
@ -121,23 +175,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
FROM
|
||||
INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE
|
||||
TABLE_SCHEMA = #{databaseName}
|
||||
AND TABLE_NAME = #{databaseTableName}
|
||||
TABLE_SCHEMA =#{databaseName}
|
||||
AND TABLE_NAME = #{name}
|
||||
</select>
|
||||
<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 id="findDataBaseTableById" resultType="com.muyu.data.source.domain.DataBaseTable">
|
||||
select * from database_table where information_id=#{id}
|
||||
</select>
|
||||
<select id="findAssetStructure" resultType="com.muyu.data.source.domain.AssetStructure">
|
||||
select * from asset_structure
|
||||
<select id="findDataBaseTableByName" resultType="com.muyu.data.source.domain.DataBaseTable">
|
||||
select * from database_table where tableName=#{name}
|
||||
</select>
|
||||
<select id="findInformation" resultType="com.muyu.data.source.domain.DatabaseTableInformation">
|
||||
select * from database_table_information
|
||||
<select id="findAssetById" resultType="com.muyu.data.source.domain.DatabaseTableInformation">
|
||||
select * from database_table_information where structure_id=#{id}
|
||||
</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>
|
||||
|
|
Loading…
Reference in New Issue