fix: 同步库缺少字段的问题

feat:     查询资产结构列表
master
baize 2024-04-24 17:14:45 +08:00
parent d0131f4d97
commit 6941f85527
10 changed files with 318 additions and 26 deletions

View File

@ -40,5 +40,10 @@ public class AssetStructure{
/**是否核心*/ /**是否核心*/
private String coreOrNot; private String coreOrNot;
/**表注释*/
private String tableComment;
/**类型*/
private Integer type;
} }

View File

@ -0,0 +1,43 @@
package com.muyu.data.source.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* DatabaseTableInformation
*
* @author DeKangLiu
* on 2024/4/23
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DatabaseTableInformation {
/**数据库信息id*/
private Long id;
/**数据库表名*/
private String name;
/**数据库表备注*/
private String as;
/**数据库表条数*/
private Integer dataTotal;
/**接入源名称*/
private String accessSourceName;
/**数据来源名称*/
private String dataSourceSystemName;
/**数据库名称*/
private String databaseName;
/**类型*/
private Integer type;
}

View File

@ -0,0 +1,27 @@
package com.muyu.data.source.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* TestList
*
* @author DeKangLiu
* on 2024/4/24
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Structure {
/**数据库表信息对象*/
private List<DatabaseTableInformation> databaseTableInformationList;
/**资产结构对象*/
private List<AssetStructure> assetStructureList;
}

View File

@ -0,0 +1,28 @@
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;
/**
*
*/
}

View File

@ -0,0 +1,52 @@
package com.muyu.data.source.domain.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* DatabaseTable
*
* @author DeKangLiu
* on 2024/4/22
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DatabaseTableModel {
/**数据库表id*/
private Long id;
/**数据库表名*/
private String tableName;
/**字段名*/
private String name;
/**字段注释*/
private String comment;
/**是否核心*/
private String isPrimaryKey;
/**Java类型*/
private String type;
/**字段类型*/
private String detailName;
/**长度*/
private Integer length;
/**小数点*/
private Integer decimalPlaces;
/**是否为空*/
private String isNull;
/**默认值*/
private String defaultValue;
}

View File

@ -3,8 +3,8 @@ package com.muyu.data.source.controller;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
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.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.GetMapping;
@ -21,7 +21,6 @@ import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log; import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType; import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions; import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.data.source.domain.DataSource;
import com.muyu.data.source.domain.req.DataSourceQueryReq; import com.muyu.data.source.domain.req.DataSourceQueryReq;
import com.muyu.data.source.domain.req.DataSourceSaveReq; import com.muyu.data.source.domain.req.DataSourceSaveReq;
import com.muyu.data.source.domain.req.DataSourceEditReq; import com.muyu.data.source.domain.req.DataSourceEditReq;
@ -127,4 +126,20 @@ public class DataSourceController extends BaseController {
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")
public Result<List<AssetStructure>> findAssetStructure(){
return dataSourceService.findAssetStructure();
}
@GetMapping("/findStructure")
public Result<Structure> findStructure(){
return dataSourceService.findStructure();
}
} }

View File

@ -1,10 +1,13 @@
package com.muyu.data.source.mapper; package com.muyu.data.source.mapper;
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.AccessType;
import com.muyu.data.source.domain.AssetStructure; import com.muyu.data.source.domain.AssetStructure;
import com.muyu.data.source.domain.DataSource; 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,4 +23,18 @@ public interface DataSourceMapper extends BaseMapper<DataSource> {
void addAssets(@Param("assetStructure") List<AssetStructure> assetStructure); void addAssets(@Param("assetStructure") List<AssetStructure> assetStructure);
void addAssets1(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 addDatabaseTableInfo(@Param("databaseTableInformations") ArrayList<DatabaseTableInformation> databaseTableInformations);
List<AssetStructure> findAssetStructure();
List<DatabaseTableInformation> findInformation();
} }

View File

@ -3,10 +3,9 @@ package com.muyu.data.source.service;
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.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.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,4 +29,10 @@ public interface DataSourceService extends IService<DataSource> {
Result synchronization(DataSource dataSource); Result synchronization(DataSource dataSource);
Result<List<DatabaseTableModel>> findDataBaseTable();
Result<List<AssetStructure>> findAssetStructure();
Result<Structure> findStructure();
} }

View File

@ -8,14 +8,13 @@ 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.common.security.utils.SecurityUtils;
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.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;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.muyu.data.source.mapper.DataSourceMapper; import com.muyu.data.source.mapper.DataSourceMapper;
import com.muyu.data.source.domain.DataSource;
import com.muyu.data.source.service.DataSourceService; import com.muyu.data.source.service.DataSourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -111,10 +110,11 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
Statement stmt = con.createStatement(); Statement stmt = con.createStatement();
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); log.error("连接失败:"+e.getMessage());
return Result.error("连接失败");
} }
return Result.error("连接失败"); return Result.success();
} }
@Override @Override
@ -123,9 +123,10 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
AssetStructure assetStructure = new AssetStructure(); AssetStructure assetStructure = new AssetStructure();
ArrayList<String> tableNames = new ArrayList<>(); ArrayList<String> tableNames = new ArrayList<>();
List<DatabaseTableInformation> databaseTableInformationList=dataSourceMapper.findByBaseName(dataSource.getDatabaseName());
dataSourceMapper.addDatabaseTableInformation(databaseTableInformationList);
List<AssetStructure> list = new ArrayList<>(); 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";
@ -140,21 +141,18 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
String tableName = rs.getString(1); String tableName = rs.getString(1);
tableNames.add(tableName); tableNames.add(tableName);
} }
System.out.println(tableNames);
for (String tableName : tableNames) {
assetStructure.setAccessSourceName(dataSource.getAccessSourceName()); assetStructure.setAccessSourceName(dataSource.getAccessSourceName());
assetStructure.setDatabaseName(dataSource.getDatabaseName()); assetStructure.setDatabaseName(dataSource.getDatabaseName());
assetStructure.setDataSourceSystemName(dataSource.getDataSourceSystemName()); assetStructure.setDataSourceSystemName(dataSource.getDataSourceSystemName());
for (int a = 0; a < rsmd.getColumnCount(); a++) {
assetStructure.setDatabaseTableName(rsmd.getTableName(a+1)); assetStructure.setDatabaseTableName(rsmd.getTableName(1));
assetStructure.setDataQuantity(rsmd.getColumnDisplaySize(a+1));
assetStructure.setDataVolume(rsmd.getColumnDisplaySize(a+1)); assetStructure.setDataVolume(rsmd.getColumnDisplaySize(1));
} assetStructure.setDataQuantity(rsmd.getColumnDisplaySize(1));
assetStructure.setDatabaseTableName(tableName);
// assetStructure.setCreateBy(SecurityUtils.getUsername());
// assetStructure.setCreateTime(new Date());
dataSourceMapper.addAssets1(assetStructure); dataSourceMapper.addAssets1(assetStructure);
}
return Result.success("同步成功"); return Result.success("同步成功");
} catch (SQLException e) { } catch (SQLException e) {
@ -164,5 +162,34 @@ 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();
return Result.success(assetStructureList);
}
@Override
public Result<Structure> findStructure() {
Structure structure = new Structure();
List<AssetStructure> assetStructure = dataSourceMapper.findAssetStructure();
structure.setAssetStructureList(assetStructure);
List<DatabaseTableInformation> databaseTableInformationList=dataSourceMapper.findInformation();
structure.setDatabaseTableInformationList(databaseTableInformationList);
return Result.success(structure);
}
} }

View File

@ -49,22 +49,95 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</insert> </insert>
<insert id="addAssets1"> <insert id="addAssets1">
INSERT INTO `data_management`.`asset_structure` 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`) (`access_source_name`, `data_source_system_name`, `database_name`, `data_volume`, `data_quantity`, `core_or_not`)
VALUES VALUES
( (
#{accessSourceName}, #{accessSourceName},
#{dataSourceSystemName}, #{dataSourceSystemName},
#{databaseName}, #{databaseName},
#{databaseTableName},
#{dataVolume}, #{dataVolume},
#{dataQuantity}, #{dataQuantity},
'Y' 'Y'
) )
</insert>
<insert id="addDatabaseTableInformation">
INSERT INTO `data_management`.`database_table_information`
( `name`, `as`, `dataTotal`)
VALUES
<foreach collection="databaseTableInformationList" item="databaseTableInformationList" separator=",">
(
#{databaseTableInformationList.name},
#{databaseTableInformationList.as},
#{databaseTableInformationList.dataTotal}
)
</foreach>
</insert>
<insert id="addDatabaseTableInfo">
INSERT INTO `data_management`.`database_table_information` ( `name`, `as`, `dataTotal`, `access_source_name`, `data_source_system_name`, `database_name`)
VALUES
<foreach collection="databaseTableInformations" item="databaseTableInformations" separator=",">
(
#{databaseTableInformations.name},
#{databaseTableInformations.as},
#{databaseTableInformations.dataTotal},
#{databaseTableInformations.accessSourceName},
#{databaseTableInformations.dataSourceSystemName},
#{databaseTableInformations.databaseName}
)
</foreach>
</insert> </insert>
<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 * from asset_structure
</select>
<select id="findByName" resultType="com.muyu.data.source.domain.model.DatabaseTableModel">
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 = #{databaseName}
AND TABLE_NAME = #{databaseTableName}
</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>
<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
</select>
</mapper> </mapper>