feat: 新增资产模型详细信息

master
031026 2024-04-26 10:11:10 +08:00
commit 787cc065d9
10 changed files with 129 additions and 86 deletions

View File

@ -38,13 +38,13 @@ public class DatabaseTable {
private String type;
/**字段类型*/
private String detailName;
private String detailType;
/**长度*/
private Integer length;
private Long length;
/**小数点*/
private Integer decimalPlaces;
private Double decimalPlaces;
/**是否为空*/
private String isNull;
@ -59,4 +59,6 @@ public class DatabaseTable {
*
*/
private String dictKey;
/** 数据库名称 */
private String databaseName;
}

View File

@ -50,12 +50,4 @@ public class DatabaseTableInformation {
* ID
*/
private Integer structureId;
public DatabaseTableInformation databaseTableInformation (String tableName, String tableComment, int tableRows) {
return DatabaseTableInformation.builder()
.name(tableName)
.as(tableComment)
.dataTotal(tableRows)
.build();
}
}

View File

@ -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 AnNan.Wang
* on 2024/4/23
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DataBaseModel {
/**
*
*/
private String databaseName;
/**
*
*/
private String tableName;
}

View File

@ -56,4 +56,8 @@ public class DatabaseTableModel {
*
*/
private String dictKey;
/**
*
*/
private String databaseName;
}

View File

@ -18,29 +18,12 @@ import lombok.experimental.SuperBuilder;
@NoArgsConstructor
@AllArgsConstructor
public class DatabaseConnect {
/**
*
*/
private String username;
/**
*
*/
private String password;
/**
*
*/
private String host;
/**
*
*/
private String type;
/**
*
*/
private String databaseName;
/**
*
*
*/
private String port;
private String name;
}

View File

@ -4,7 +4,6 @@ import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.muyu.data.source.domain.*;
import com.muyu.data.source.domain.model.DataBaseModel;
import com.muyu.data.source.domain.model.DatabaseTableModel;
import com.muyu.data.source.domain.req.DatabaseConnect;
import io.swagger.annotations.*;
@ -129,8 +128,8 @@ public class DataSourceController extends BaseController {
//查询结构
@PostMapping("/findDataBaseTable")
public Result<List<DatabaseTableModel>> findDataBaseTable(@RequestParam("databaseTableName") String databaseTableName){
return dataSourceService.findDataBaseTable(databaseTableName);
public Result<List<DatabaseTableModel>> findDataBaseTable(@RequestBody DatabaseConnect databaseConnect){
return dataSourceService.findDataBaseTable(databaseConnect);
}
@ -145,4 +144,15 @@ public class DataSourceController extends BaseController {
public Result<Structure> structureList(@RequestParam("id") Integer id){
return dataSourceService.structureList(id);
}
//根据表名查询详细信息
@PostMapping("/database")
public Result<List<DatabaseTableModel>> database (@RequestParam("name") String name){
return dataSourceService.database(name);
}
@PostMapping("/table")
public Result<List<DatabaseTableInformation>> table (@RequestParam("databaseName") String databaseName){
return dataSourceService.table(databaseName);
}
}

View File

@ -3,11 +3,9 @@ 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.*;
import com.muyu.data.source.domain.model.DatabaseTableModel;
import com.muyu.data.source.domain.req.DatabaseConnect;
import org.apache.ibatis.annotations.Param;
/**
@ -29,7 +27,7 @@ public interface DataSourceMapper extends BaseMapper<DataSource> {
List<DatabaseTableInformation> findByBaseName(@Param("databaseName") String databaseName);
void addDatabaseTableInformation(@Param("databaseTableInformationList") List<DatabaseTableInformation> databaseTableInformationList, @Param("id") Integer id);
void addDatabaseTableInformation(@Param("databaseTableInformationList") List<DatabaseTableInformation> databaseTableInformationList, @Param("id") Integer id, @Param("databaseName") String databaseName);
void addDatabaseTableInfo(@Param("databaseTableInformations") ArrayList<DatabaseTableInformation> databaseTableInformations);
@ -37,7 +35,12 @@ public interface DataSourceMapper extends BaseMapper<DataSource> {
List<DatabaseTableInformation> findInformation(Integer id);
List<AssetStructure> assetStructureList();
void DatabaseTableAdd(@Param("databaseTables") List<DatabaseTable> databaseTables);
List<DatabaseTableModel> DatabaseTableList(@Param("databaseName") String databaseName, @Param("name") String name);
List<DatabaseTableModel> database(@Param("name") String name);
List<DatabaseTableInformation> table(@Param("databaseName") String databaseName);
}

View File

@ -7,6 +7,7 @@ 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;
import com.muyu.data.source.domain.req.DatabaseConnect;
/**
* Service
@ -30,10 +31,14 @@ public interface DataSourceService extends IService<DataSource> {
Result synchronization(DataSource dataSource);
Result<List<DatabaseTableModel>> findDataBaseTable(String databaseTableName);
Result<List<DatabaseTableModel>> findDataBaseTable(DatabaseConnect databaseConnect);
Result<Structure> findStructure();
Result<Structure> structureList(Integer id);
Result<List<DatabaseTableModel>> database(String name);
Result<List<DatabaseTableInformation>> table(String databaseName);
}

View File

@ -9,6 +9,7 @@ import com.muyu.common.core.utils.ObjUtils;
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.DatabaseConnect;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -151,6 +152,7 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
//表条数
int tableRows = resultSet.getInt("dataTotal");
//查询出表结构
PreparedStatement preparedStatement = con.prepareStatement(" SELECT " +
" TABLE_NAME AS 'tableName', " +
" COLUMN_NAME AS 'name', " +
@ -178,8 +180,25 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
preparedStatement.setString(1,dataSource.getDatabaseName());
preparedStatement.setString(2,tableName);
ResultSet executed = preparedStatement.executeQuery();
ResultSetMetaData metaData = executed.getMetaData();
List<DatabaseTable> databaseTables = new ArrayList<>();
while (executed.next()) {
DatabaseTable databaseTable = new DatabaseTable();
databaseTable.setTableName(tableName);
databaseTable.setName( executed.getString("name"));
databaseTable.setComment( executed.getString("comment"));
databaseTable.setIsPrimaryKey( executed.getString("isPrimaryKey"));
databaseTable.setType( executed.getString("type"));
databaseTable.setDetailType( executed.getString("mappingType"));
databaseTable.setLength( executed.getLong("length"));
databaseTable.setDecimalPlaces( executed.getDouble("decimalPlaces"));
databaseTable.setIsNull( executed.getString("isNull"));
databaseTable.setDefaultValue( executed.getString("defaultValue"));
databaseTable.setDatabaseName(dataSource.getDatabaseName());
databaseTables.add(databaseTable);
}
//添加进入数据库
dataSourceMapper.DatabaseTableAdd(databaseTables);
// 创建 DatabaseTableInformation对象
DatabaseTableInformation build = DatabaseTableInformation.builder()
@ -187,6 +206,7 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
.as(tableComment)
.dataTotal(tableRows)
.build();
// 将对象添加到 ArrayList 中
arrayList.add(build);
}
@ -209,7 +229,7 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
Integer id = assetStructure.getId();
dataSourceMapper.addDatabaseTableInformation(arrayList,id);
dataSourceMapper.addDatabaseTableInformation(arrayList,id,dataSource.getDatabaseName());
return Result.success("同步成功");
} catch (SQLException e) {
@ -220,18 +240,9 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
}
@Override
public Result<List<DatabaseTableModel>> findDataBaseTable(String databaseTableName) {
List<AssetStructure> assetStructureList=dataSourceMapper.assetStructureList();
List<DatabaseTableModel> databaseTableList = new ArrayList<>();
for (AssetStructure assetStructure : assetStructureList) {
DatabaseTableModel databaseTableModel=dataSourceMapper.findByName(assetStructure.getDatabaseName(),databaseTableName);
databaseTableList.add(databaseTableModel);
}
System.out.println(databaseTableList);
return Result.success(databaseTableList);
public Result<List<DatabaseTableModel>> findDataBaseTable(DatabaseConnect databaseConnect) {
List<DatabaseTableModel> information = dataSourceMapper.DatabaseTableList(databaseConnect.getDatabaseName(),databaseConnect.getName());
return Result.success(information);
}
@ -252,4 +263,18 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
structure.setDatabaseTableInformationList(information);
return Result.success(structure);
}
@Override
public Result<List<DatabaseTableModel>> database(String name) {
List<DatabaseTableModel> information = dataSourceMapper.database(name);
return Result.success(information);
}
@Override
public Result<List<DatabaseTableInformation>> table(String databaseName) {
List<DatabaseTableInformation> information = dataSourceMapper.table(databaseName);
return Result.success(information);
}
}

View File

@ -65,14 +65,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</insert>
<insert id="addDatabaseTableInformation">
INSERT INTO `data_management`.`database_table_information`
( `name`, `as`, `dataTotal`,`structure_id`)
( `name`, `as`, `dataTotal`,`structure_id`,`database_name`)
VALUES
<foreach collection="databaseTableInformationList" item="databaseTableInformationList" separator=",">
(
#{databaseTableInformationList.name},
#{databaseTableInformationList.as},
#{databaseTableInformationList.dataTotal},
#{id}
#{id},
#{databaseName}
)
</foreach>
@ -92,6 +93,38 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
)
</foreach>
</insert>
<insert id="DatabaseTableAdd">
INSERT INTO
`data_management`.`database_table`
(
`tableName`,
`name`,
`comment`,
`isPrimaryKey`,
`type`,
`detailType`,
`length`,
`decimalPlaces`,
`isNull`,
`defaultValue`,
`database_name`)
VALUES
<foreach collection="databaseTables" item="databaseTable" separator=",">
(
#{databaseTable.tableName},
#{databaseTable.name},
#{databaseTable.comment},
#{databaseTable.isPrimaryKey},
#{databaseTable.type},
#{databaseTable.detailType},
#{databaseTable.length},
#{databaseTable.decimalPlaces},
#{databaseTable.isNull},
#{databaseTable.defaultValue},
#{databaseTable.databaseName}
)
</foreach>
</insert>
<select id="findAccessType" resultType="com.muyu.data.source.domain.AccessType">
select * from access_type
</select>
@ -138,8 +171,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="findInformation" resultType="com.muyu.data.source.domain.DatabaseTableInformation">
select * from database_table_information where structure_id=#{id}
</select>
<select id="assetStructureList" resultType="com.muyu.data.source.domain.AssetStructure">
<select id="DatabaseTableList" resultType="com.muyu.data.source.domain.model.DatabaseTableModel">
select
*
from
database_table
where
`tableName`=#{name}
and
`database_name`=#{databaseName}
</select>
<select id="database" resultType="com.muyu.data.source.domain.model.DatabaseTableModel">
select * from database_table where tableName=#{name}
</select>
<select id="table" resultType="com.muyu.data.source.domain.DatabaseTableInformation">
select * from database_table_information where database_name=#{databaseName}
</select>
</mapper>