Compare commits
No commits in common. "30c80ffabb1d8c062a0f54d03685b8ff1ed49967" and "8ddd6a86092e81b098d463fd32637a4e493f02ab" have entirely different histories.
30c80ffabb
...
8ddd6a8609
|
@ -38,13 +38,13 @@ public class DatabaseTable {
|
|||
private String type;
|
||||
|
||||
/**字段类型*/
|
||||
private String detailType;
|
||||
private String detailName;
|
||||
|
||||
/**长度*/
|
||||
private Long length;
|
||||
private Integer length;
|
||||
|
||||
/**小数点*/
|
||||
private Double decimalPlaces;
|
||||
private Integer decimalPlaces;
|
||||
|
||||
/**是否为空*/
|
||||
private String isNull;
|
||||
|
@ -59,6 +59,4 @@ public class DatabaseTable {
|
|||
* 映射字典
|
||||
*/
|
||||
private String dictKey;
|
||||
/** 数据库名称 */
|
||||
private String databaseName;
|
||||
}
|
||||
|
|
|
@ -50,4 +50,12 @@ 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 AnNan.Wang
|
||||
* on 2024/4/23
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DataBaseModel {
|
||||
/**
|
||||
* 数据名称
|
||||
*/
|
||||
private String databaseName;
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
}
|
|
@ -56,8 +56,4 @@ public class DatabaseTableModel {
|
|||
* 映射字典
|
||||
*/
|
||||
private String dictKey;
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
private String databaseName;
|
||||
}
|
||||
|
|
|
@ -18,12 +18,29 @@ 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 name;
|
||||
private String port;
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ 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.*;
|
||||
|
@ -128,8 +129,8 @@ public class DataSourceController extends BaseController {
|
|||
|
||||
//查询结构
|
||||
@PostMapping("/findDataBaseTable")
|
||||
public Result<List<DatabaseTableModel>> findDataBaseTable(@RequestBody DatabaseConnect databaseConnect){
|
||||
return dataSourceService.findDataBaseTable(databaseConnect);
|
||||
public Result<List<DatabaseTableModel>> findDataBaseTable(@RequestParam("databaseTableName") String databaseTableName){
|
||||
return dataSourceService.findDataBaseTable(databaseTableName);
|
||||
}
|
||||
|
||||
|
||||
|
@ -144,15 +145,4 @@ 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@ 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.*;
|
||||
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.req.DatabaseConnect;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
|
@ -27,7 +29,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, @Param("databaseName") String databaseName);
|
||||
void addDatabaseTableInformation(@Param("databaseTableInformationList") List<DatabaseTableInformation> databaseTableInformationList, @Param("id") Integer id);
|
||||
|
||||
void addDatabaseTableInfo(@Param("databaseTableInformations") ArrayList<DatabaseTableInformation> databaseTableInformations);
|
||||
|
||||
|
@ -35,12 +37,7 @@ 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);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ 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接口
|
||||
|
@ -31,14 +30,10 @@ public interface DataSourceService extends IService<DataSource> {
|
|||
|
||||
Result synchronization(DataSource dataSource);
|
||||
|
||||
Result<List<DatabaseTableModel>> findDataBaseTable(DatabaseConnect databaseConnect);
|
||||
Result<List<DatabaseTableModel>> findDataBaseTable(String databaseTableName);
|
||||
|
||||
|
||||
Result<Structure> findStructure();
|
||||
|
||||
Result<Structure> structureList(Integer id);
|
||||
|
||||
Result<List<DatabaseTableModel>> database(String name);
|
||||
|
||||
Result<List<DatabaseTableInformation>> table(String databaseName);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ 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;
|
||||
|
@ -152,7 +151,6 @@ 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', " +
|
||||
|
@ -180,25 +178,8 @@ 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()
|
||||
|
@ -206,7 +187,6 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
.as(tableComment)
|
||||
.dataTotal(tableRows)
|
||||
.build();
|
||||
|
||||
// 将对象添加到 ArrayList 中
|
||||
arrayList.add(build);
|
||||
}
|
||||
|
@ -229,7 +209,7 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
|
||||
Integer id = assetStructure.getId();
|
||||
|
||||
dataSourceMapper.addDatabaseTableInformation(arrayList,id,dataSource.getDatabaseName());
|
||||
dataSourceMapper.addDatabaseTableInformation(arrayList,id);
|
||||
return Result.success("同步成功");
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
@ -240,9 +220,18 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result<List<DatabaseTableModel>> findDataBaseTable(DatabaseConnect databaseConnect) {
|
||||
List<DatabaseTableModel> information = dataSourceMapper.DatabaseTableList(databaseConnect.getDatabaseName(),databaseConnect.getName());
|
||||
return Result.success(information);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -263,18 +252,4 @@ 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,15 +65,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</insert>
|
||||
<insert id="addDatabaseTableInformation">
|
||||
INSERT INTO `data_management`.`database_table_information`
|
||||
( `name`, `as`, `dataTotal`,`structure_id`,`database_name`)
|
||||
( `name`, `as`, `dataTotal`,`structure_id`)
|
||||
VALUES
|
||||
<foreach collection="databaseTableInformationList" item="databaseTableInformationList" separator=",">
|
||||
(
|
||||
#{databaseTableInformationList.name},
|
||||
#{databaseTableInformationList.as},
|
||||
#{databaseTableInformationList.dataTotal},
|
||||
#{id},
|
||||
#{databaseName}
|
||||
#{id}
|
||||
)
|
||||
</foreach>
|
||||
|
||||
|
@ -93,38 +92,6 @@ 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>
|
||||
|
@ -171,22 +138,8 @@ 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="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>
|
||||
<select id="assetStructureList" resultType="com.muyu.data.source.domain.AssetStructure">
|
||||
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue