后台资产展示代码
parent
4be2e3beda
commit
9e3a867117
|
@ -13,6 +13,8 @@ import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Lenovo
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
|
@ -66,24 +68,26 @@ public class Children extends BaseEntity {
|
||||||
private Long assetId;
|
private Long assetId;
|
||||||
|
|
||||||
|
|
||||||
public TableInfoRep tableInfoRep(Children children) {
|
// public TableInfoRep tableInfoRep(Children children) {
|
||||||
return TableInfoRep.builder()
|
// return TableInfoRep.builder()
|
||||||
.id(children.getId())
|
// .id(children.getId())
|
||||||
. name(children.getName())
|
// . name(children.getName())
|
||||||
.annotation(children.getAnnotation())
|
// .annotation(children.getAnnotation())
|
||||||
.dataTotal(children.getDataTotal())
|
// .dataTotal(children.getDataTotal())
|
||||||
.type(children.getType())
|
// .type(children.getType())
|
||||||
.isCenter(children.getIsCenter())
|
// .isCenter(children.getIsCenter())
|
||||||
.assetId(children.getAssetId())
|
// .assetId(children.getAssetId())
|
||||||
.build();
|
// .build();
|
||||||
}
|
// }
|
||||||
public static TableInfoResp toTableInfoResp(Children children) {
|
// public static TableInfoResp toTableInfoResp(Children children) {
|
||||||
return TableInfoResp.builder()
|
// return TableInfoResp.builder()
|
||||||
.id(children.id)
|
// .id(children.id)
|
||||||
.name(children.name)
|
// .name(children.name)
|
||||||
.annotation(children.annotation)
|
// .annotation(children.annotation)
|
||||||
.isCenter(children.isCenter)
|
// .isCenter(children.isCenter)
|
||||||
.dataTotal(children.dataTotal)
|
// .dataTotal(children.dataTotal)
|
||||||
.build();
|
// .build();
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
package com.muyu.source.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.muyu.common.core.annotation.Excel;
|
||||||
|
import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结构对象 structure
|
||||||
|
*
|
||||||
|
* @author Saisai
|
||||||
|
* @date 2024-04-22
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@SuperBuilder
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName(value ="structure",autoResultMap = true) //数据库表相关
|
||||||
|
public class Structure extends BaseEntity
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 主键 */
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 表id */
|
||||||
|
@Excel(name = "表id")
|
||||||
|
private Long tableId;
|
||||||
|
|
||||||
|
/** 字段名称 */
|
||||||
|
@Excel(name = "字段名称")
|
||||||
|
private String columnName;
|
||||||
|
|
||||||
|
/** 字段注释 */
|
||||||
|
@Excel(name = "字段注释")
|
||||||
|
private String columnRemark;
|
||||||
|
|
||||||
|
/** 是否主键 'Y'是主键 'N'不是主键 */
|
||||||
|
@Excel(name = "是否主键 'Y'是主键 'N'不是主键")
|
||||||
|
private String isPrimary;
|
||||||
|
|
||||||
|
/** 数据类型 */
|
||||||
|
@Excel(name = "数据类型")
|
||||||
|
private String columnType;
|
||||||
|
|
||||||
|
/** 映射类型 */
|
||||||
|
@Excel(name = "映射类型")
|
||||||
|
private String javaType;
|
||||||
|
|
||||||
|
/** 字段长度 */
|
||||||
|
@Excel(name = "字段长度")
|
||||||
|
private String columnLength;
|
||||||
|
|
||||||
|
/** 小数位数 */
|
||||||
|
@Excel(name = "小数位数")
|
||||||
|
private String columnDecimals;
|
||||||
|
|
||||||
|
/** 是否为空 'Y'是 'N'不是 */
|
||||||
|
@Excel(name = "是否为空 'Y'是 'N'不是")
|
||||||
|
private String isNull;
|
||||||
|
|
||||||
|
/** 默认值 */
|
||||||
|
@Excel(name = "默认值")
|
||||||
|
private String defaultValue;
|
||||||
|
|
||||||
|
/** 是否字典 'Y'是 'N'不是 */
|
||||||
|
@Excel(name = "是否字典 'Y'是 'N'不是")
|
||||||
|
private String isDictionary;
|
||||||
|
|
||||||
|
/** 映射字典 */
|
||||||
|
@Excel(name = "映射字典")
|
||||||
|
private String dictionaryTable;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
package com.muyu.source.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.muyu.common.core.annotation.Excel;
|
||||||
|
import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
|
|
||||||
|
import com.muyu.source.domain.rep.TableInfoRep;
|
||||||
|
import com.muyu.source.domain.rep.TableInfoResp;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@SuperBuilder
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName(value ="table_info") //数据库表相关
|
||||||
|
public class TableInfo extends BaseEntity {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 主键 */
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private Long basicId;
|
||||||
|
|
||||||
|
/** 表名称/数据库 */
|
||||||
|
@Excel(name = "表名称/数据库")
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
/** 表备注 */
|
||||||
|
@Excel(name = "表备注")
|
||||||
|
private String tableRemark;
|
||||||
|
|
||||||
|
/** 表备注 */
|
||||||
|
@Excel(name = "数据来源类型")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/** 数据量 */
|
||||||
|
@Excel(name = "数据量")
|
||||||
|
private Long dataNum;
|
||||||
|
|
||||||
|
/** 是否核心 'Y'是 'N'不是 */
|
||||||
|
@Excel(name = "是否核心 'Y'是 'N'不是")
|
||||||
|
private String center;
|
||||||
|
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
|
||||||
|
public static TableInfoRep tableInfoRep(TableInfo tableInfo){
|
||||||
|
return TableInfoRep.builder()
|
||||||
|
.id(tableInfo.getId())
|
||||||
|
.basicId(tableInfo.getBasicId())
|
||||||
|
.tableName(tableInfo.getTableName())
|
||||||
|
.tableRemark(tableInfo.getTableRemark())
|
||||||
|
.type(tableInfo.getType())
|
||||||
|
.center(tableInfo.getCenter())
|
||||||
|
.parentId(tableInfo.getParentId())
|
||||||
|
.dataNum(tableInfo.getDataNum())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TableInfoResp toTableInfoResp(TableInfo tableInfo) {
|
||||||
|
return TableInfoResp.builder()
|
||||||
|
.id(tableInfo.id)
|
||||||
|
.tableName(tableInfo.tableName)
|
||||||
|
.tableRemark(tableInfo.tableRemark)
|
||||||
|
.isCenter(tableInfo.center)
|
||||||
|
.dataNum(tableInfo.dataNum)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ package com.muyu.source.domain.rep;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.muyu.common.core.annotation.Excel;
|
import com.muyu.common.core.annotation.Excel;
|
||||||
import com.muyu.source.domain.TableData;
|
import com.muyu.source.domain.Structure;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -11,9 +11,6 @@ import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Lenovo
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@ -28,26 +25,26 @@ public class TableInfoRep {
|
||||||
|
|
||||||
/** 表名称/数据库 */
|
/** 表名称/数据库 */
|
||||||
@Excel(name = "表名称/数据库")
|
@Excel(name = "表名称/数据库")
|
||||||
private String name;
|
private String tableName;
|
||||||
|
|
||||||
/** 表备注 */
|
/** 表备注 */
|
||||||
@Excel(name = "表备注")
|
@Excel(name = "表备注")
|
||||||
private String annotation;
|
private String tableRemark;
|
||||||
|
|
||||||
/** 数据来源类型 */
|
/** 表备注 */
|
||||||
@Excel(name = "数据来源类型")
|
@Excel(name = "数据来源类型")
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
/** 数据量 */
|
/** 数据量 */
|
||||||
@Excel(name = "数据量")
|
@Excel(name = "数据量")
|
||||||
private Integer dataTotal;
|
private Long dataNum;
|
||||||
|
|
||||||
/** 是否核心 'Y'是 'N'不是 */
|
/** 是否核心 'Y'是 'N'不是 */
|
||||||
@Excel(name = "是否核心 'Y'是 'N'不是")
|
@Excel(name = "是否核心 'Y'是 'N'不是")
|
||||||
private String isCenter;
|
private String center;
|
||||||
|
|
||||||
private Long assetId;
|
private Long parentId;
|
||||||
|
|
||||||
private List<TableData> tableDataList;
|
private List<Structure> structureList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.muyu.source.domain.rep;
|
package com.muyu.source.domain.rep;
|
||||||
|
|
||||||
import com.muyu.source.domain.Children;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -8,9 +7,6 @@ import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Lenovo
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@ -25,17 +21,19 @@ public class TableInfoResp {
|
||||||
/**
|
/**
|
||||||
* 表名称/数据库
|
* 表名称/数据库
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String tableName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表备注
|
* 表备注
|
||||||
*/
|
*/
|
||||||
private String annotation;
|
private String tableRemark;
|
||||||
|
|
||||||
/** 数据量 */
|
/** 数据量 */
|
||||||
private Integer dataTotal;
|
private Long dataNum;
|
||||||
|
|
||||||
/** 是否核心 'Y'是 'N'不是 */
|
/** 是否核心 'Y'是 'N'不是 */
|
||||||
private String isCenter;
|
private String isCenter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 子内容
|
* 子内容
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.muyu.source.domain.rep;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.muyu.source.domain.Children;
|
import com.muyu.source.domain.TableInfo;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -10,9 +10,6 @@ import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Lenovo
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@ -20,9 +17,9 @@ import java.util.List;
|
||||||
public class TableInfoTreeRep {
|
public class TableInfoTreeRep {
|
||||||
//主键
|
//主键
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
private Long id;
|
private Integer id;
|
||||||
|
|
||||||
private Children children;
|
private TableInfo tableInfo;
|
||||||
|
|
||||||
private List<TableInfoRep> tableInfoRepList;
|
private List<TableInfoRep> children;
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,12 +173,12 @@ public class DataSourceController extends BaseController {
|
||||||
* @param dataSource 数据源
|
* @param dataSource 数据源
|
||||||
* @return 是否同步成功
|
* @return 是否同步成功
|
||||||
*/
|
*/
|
||||||
@PostMapping("/synchronous")
|
// @PostMapping("/synchronous")
|
||||||
@Operation(summary = "同步数据源", description = "同步数据源")
|
// @Operation(summary = "同步数据源", description = "同步数据源")
|
||||||
public Result synchronous(@RequestBody DataSource dataSource){
|
// public Result synchronous(@RequestBody DataSource dataSource){
|
||||||
dataSourceService.synchronous(dataSource);
|
// dataSourceService.synchronous(dataSource);
|
||||||
return Result.success();
|
// return Result.success();
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -157,57 +157,60 @@ public class TableDataController extends BaseController {
|
||||||
* 查询表结构树
|
* 查询表结构树
|
||||||
* @return tableInfoTreeReps
|
* @return tableInfoTreeReps
|
||||||
*/
|
*/
|
||||||
@GetMapping("/findTableInfo")
|
// @GetMapping("/findTableInfo")
|
||||||
@Operation(summary = "查询表结构树", description = "查询表结构树")
|
// @Operation(summary = "查询表结构树", description = "查询表结构树")
|
||||||
public Result<List<TableInfoTreeRep>> findTableInfo() {
|
// public Result<List<TableInfoTreeRep>> findTableInfo() {
|
||||||
// AssetDataSource dataSource = assetDataSourceService.getOne(new LambdaQueryWrapper<>() {{
|
//// AssetDataSource dataSource = assetDataSourceService.getOne(new LambdaQueryWrapper<>() {{
|
||||||
|
//// eq(AssetDataSource::getType, "dataSource");
|
||||||
|
//// }});
|
||||||
|
// List<TableInfoTreeRep> tableInfoTreeReps = new ArrayList<TableInfoTreeRep>();
|
||||||
|
// List<AssetDataSource> dataSource = assetDataSourceService.list(new LambdaQueryWrapper<>() {{
|
||||||
// eq(AssetDataSource::getType, "dataSource");
|
// eq(AssetDataSource::getType, "dataSource");
|
||||||
// }});
|
// }});
|
||||||
ArrayList<TableInfoTreeRep> tableInfoTreeReps = new ArrayList<>();
|
// for (AssetDataSource assetDataSource : dataSource) {
|
||||||
List<AssetDataSource> dataSource = assetDataSourceService.list(new LambdaQueryWrapper<>() {{
|
// List<Children> childrenList =childrenService.findSourceList(assetDataSource.getId());
|
||||||
eq(AssetDataSource::getType, "dataSource");
|
// for (Children children : childrenList) {
|
||||||
}});
|
// TableInfoTreeRep tableInfoTreeRep = new TableInfoTreeRep();
|
||||||
for (AssetDataSource assetDataSource : dataSource) {
|
// tableInfoTreeRep.setChildren(children);
|
||||||
List<Children> childrenList =childrenService.findSourceList(assetDataSource.getId());
|
// List<TableInfoRep> tableInfoRepList =childrenService.findTablesList(children.getAssetId());
|
||||||
|
// tableInfoTreeRep.setTableInfoRepList(tableInfoRepList);
|
||||||
for (Children children : childrenList) {
|
// for(TableInfoRep tableInfoRep:tableInfoRepList){
|
||||||
TableInfoTreeRep tableInfoTreeRep = new TableInfoTreeRep();
|
// List<TableData> tableDataList =tableDataService.findTableDataList(tableInfoRep.getId());
|
||||||
tableInfoTreeRep.setChildren(children);
|
// tableInfoRep.setTableDataList(tableDataList);
|
||||||
List<TableInfoRep> tableInfoRepList =childrenService.findTablesList(children.getAssetId());
|
// }
|
||||||
tableInfoTreeRep.setTableInfoRepList(tableInfoRepList);
|
// tableInfoTreeReps.add(tableInfoTreeRep);
|
||||||
for(TableInfoRep tableInfoRep:tableInfoRepList){
|
// }
|
||||||
List<TableData> tableDataList =tableDataService.findTableDataList(tableInfoRep.getId());
|
// return Result.success(tableInfoTreeReps);
|
||||||
tableInfoRep.setTableDataList(tableDataList);
|
// }
|
||||||
}
|
// return Result.success(tableInfoTreeReps);
|
||||||
tableInfoTreeReps.add(tableInfoTreeRep);
|
// }
|
||||||
}
|
//
|
||||||
}
|
// /**
|
||||||
return Result.success(tableInfoTreeReps);
|
// * 根据表名查询表结构
|
||||||
}
|
// * @return
|
||||||
|
// */
|
||||||
/**
|
// @GetMapping("/findTableInfoList")
|
||||||
* 根据表名查询表结构
|
// @Operation(summary = "根据表名查询表结构", description = "根据表名查询表结构")
|
||||||
* @return
|
// public Result findByTableName(){
|
||||||
*/
|
// assetDataSourceService.list(new LambdaQueryWrapper<>(){{
|
||||||
@GetMapping("/findTableInfoList")
|
// eq(AssetDataSource::getType,"dataSource");
|
||||||
@Operation(summary = "根据表名查询表结构", description = "根据表名查询表结构")
|
// }});
|
||||||
public Result findByTableName(){
|
// //
|
||||||
List<Children> childrenList = childrenService.list();
|
// List<Children> childrenList = childrenService.list();
|
||||||
|
// List<TableInfoResp> list = childrenList.stream().map(children -> {
|
||||||
List<TableInfoResp> list = childrenList.stream().map(children -> {
|
// TableInfoResp tableInfoResp = Children.toTableInfoResp(children);
|
||||||
TableInfoResp tableInfoResp = Children.toTableInfoResp(children);
|
// tableInfoResp.setChildren(getChildren(children, childrenList));
|
||||||
tableInfoResp.setChildren(getChildren(children, childrenList));
|
// return tableInfoResp;
|
||||||
return tableInfoResp;
|
// }).toList();
|
||||||
}).toList();
|
// return Result.success(list);
|
||||||
return Result.success(list);
|
// }
|
||||||
}
|
//
|
||||||
|
// private List<TableInfoResp> getChildren(Children children, List<Children> childrenList) {
|
||||||
private List<TableInfoResp> getChildren(Children children, List<Children> childrenList) {
|
// return childrenList.stream().filter(children1 -> children1.getAssetId().equals(children.getId())).map(
|
||||||
return childrenList.stream().filter(children1 -> children1.getAssetId().equals(children.getId())).map(
|
// children2 -> Children.toTableInfoResp(children2)
|
||||||
children2 -> Children.toTableInfoResp(children2)
|
// ).toList();
|
||||||
).toList();
|
//
|
||||||
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
package com.muyu.source.controller;
|
||||||
|
|
||||||
|
import com.dtflys.forest.annotation.NotNull;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.source.domain.Structure;
|
||||||
|
import com.muyu.source.domain.TableInfo;
|
||||||
|
import com.muyu.source.domain.rep.TableInfoRep;
|
||||||
|
import com.muyu.source.domain.rep.TableInfoResp;
|
||||||
|
import com.muyu.source.domain.rep.TableInfoTreeRep;
|
||||||
|
import com.muyu.source.service.StructureService;
|
||||||
|
import com.muyu.source.service.TableInfoService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/tableInfo")
|
||||||
|
public class TableInfoController {
|
||||||
|
@Autowired
|
||||||
|
private TableInfoService tableInfoService;
|
||||||
|
@Autowired
|
||||||
|
private StructureService structureService;
|
||||||
|
|
||||||
|
@GetMapping("/findTableInfo")
|
||||||
|
public Result<List<TableInfoTreeRep>> findTableInfo() {
|
||||||
|
List<TableInfo> tableInfoList= tableInfoService.findSourceList();
|
||||||
|
|
||||||
|
List<TableInfoTreeRep> tableInfoTreeReps = new ArrayList<TableInfoTreeRep>();
|
||||||
|
|
||||||
|
for (TableInfo tableInfo : tableInfoList) {
|
||||||
|
TableInfoTreeRep tableInfoTreeRep = new TableInfoTreeRep();
|
||||||
|
tableInfoTreeRep.setTableInfo(tableInfo);
|
||||||
|
List<TableInfoRep> tableInfoRepList= tableInfoService.findTablesList(tableInfo.getId());
|
||||||
|
tableInfoTreeRep.setChildren(tableInfoRepList);
|
||||||
|
for (TableInfoRep tableInfoRep : tableInfoRepList) {
|
||||||
|
List<Structure> structureList=structureService.findStructureList(tableInfoRep.getId());
|
||||||
|
tableInfoRep.setStructureList(structureList);
|
||||||
|
}
|
||||||
|
tableInfoTreeReps.add(tableInfoTreeRep);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.success(tableInfoTreeReps);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/findTableInfoList")
|
||||||
|
public Result findByTableName() {
|
||||||
|
List<TableInfo> list = tableInfoService.list();
|
||||||
|
List<TableInfoResp> respList = list.stream().filter(tableInfo -> tableInfo.getParentId()==0).map(tableInfo -> {
|
||||||
|
TableInfoResp tableInfoResp = TableInfo.toTableInfoResp(tableInfo);
|
||||||
|
tableInfoResp.setChildren(getChildren(tableInfo, list));
|
||||||
|
return tableInfoResp;
|
||||||
|
}).toList();
|
||||||
|
return Result.success(respList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static List<TableInfoResp> getChildren(TableInfo tableInfo, List<TableInfo> list) {
|
||||||
|
return list.stream().filter(tableInfo1 -> tableInfo1.getParentId().equals(tableInfo.getId())).map(
|
||||||
|
tableInfo2 -> TableInfo.toTableInfoResp(tableInfo2)
|
||||||
|
).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/findStruceure/{id}")
|
||||||
|
public Result<List<Structure>> findStruceure(@PathVariable("id") Integer id) {
|
||||||
|
List<Structure> structureList= structureService.findStructurelistS(id);
|
||||||
|
return Result.success(structureList);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.muyu.source.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
import com.muyu.source.domain.Structure;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface StructureMapper extends BaseMapper<Structure> {
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.muyu.source.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
import com.muyu.source.domain.TableInfo;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface TableInfoMapper extends BaseMapper<TableInfo> {
|
||||||
|
}
|
|
@ -17,8 +17,8 @@ import java.util.List;
|
||||||
public interface ChildrenService extends IService<Children> {
|
public interface ChildrenService extends IService<Children> {
|
||||||
|
|
||||||
|
|
||||||
List<TableInfoRep> findTablesList(Long id);
|
// List<TableInfoRep> findTablesList(Long id);
|
||||||
|
//
|
||||||
|
//
|
||||||
List<Children> findSourceList(Long id);
|
// List<Children> findSourceList(Long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,5 +41,5 @@ public interface DataSourceService extends IService<DataSource> {
|
||||||
|
|
||||||
Boolean testConnection(DataSource dataSource);
|
Boolean testConnection(DataSource dataSource);
|
||||||
|
|
||||||
void synchronous(DataSource dataSource);
|
// void synchronous(DataSource dataSource);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,27 +23,27 @@ import java.util.List;
|
||||||
@Service
|
@Service
|
||||||
public class ChildrenServiceImpl extends ServiceImpl<ChildrenMapper, Children> implements ChildrenService {
|
public class ChildrenServiceImpl extends ServiceImpl<ChildrenMapper, Children> implements ChildrenService {
|
||||||
|
|
||||||
@Autowired
|
// @Autowired
|
||||||
private ChildrenMapper childrenMapper;
|
// private ChildrenMapper childrenMapper;
|
||||||
@Override
|
// @Override
|
||||||
public List<Children> findSourceList(Long id) {
|
// public List<Children> findSourceList(Long id) {
|
||||||
return childrenMapper.selectList(new LambdaQueryWrapper<>(Children.class){{
|
// return childrenMapper.selectList(new LambdaQueryWrapper<>(Children.class){{
|
||||||
eq(Children::getAssetId,id);
|
// eq(Children::getAssetId,id);
|
||||||
}});
|
// }});
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public List<TableInfoRep> findTablesList(Long id) {
|
// public List<TableInfoRep> findTablesList(Long id) {
|
||||||
List<Children> childrenList = childrenMapper.selectList(new LambdaQueryWrapper<>(Children.class)
|
// List<Children> childrenList = childrenMapper.selectList(new LambdaQueryWrapper<>(Children.class)
|
||||||
.eq(Children::getAssetId, id));
|
// .eq(Children::getAssetId, id));
|
||||||
ArrayList<TableInfoRep> tableInfoRepList = new ArrayList<>();
|
// ArrayList<TableInfoRep> tableInfoRepList = new ArrayList<>();
|
||||||
for (Children children : childrenList) {
|
// for (Children children : childrenList) {
|
||||||
TableInfoRep tableInfoRep =children.tableInfoRep(children);
|
// TableInfoRep tableInfoRep =children.tableInfoRep(children);
|
||||||
tableInfoRepList.add(tableInfoRep);
|
// tableInfoRepList.add(tableInfoRep);
|
||||||
}
|
// }
|
||||||
return tableInfoRepList;
|
// return tableInfoRepList;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -135,214 +135,214 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
||||||
*
|
*
|
||||||
* @param dataSource 数据源
|
* @param dataSource 数据源
|
||||||
*/
|
*/
|
||||||
@Override
|
// @Override
|
||||||
public void synchronous(DataSource dataSource) {
|
// public void synchronous(DataSource dataSource) {
|
||||||
// 获取指定ID的资产数据源对象
|
// // 获取指定ID的资产数据源对象
|
||||||
AssetDataSource dataSourceServiceOne = assetDataSourceService.getOne(new LambdaQueryWrapper<>() {{
|
// AssetDataSource dataSourceServiceOne = assetDataSourceService.getOne(new LambdaQueryWrapper<>() {{
|
||||||
eq(AssetDataSource::getId, dataSource.getId());
|
// eq(AssetDataSource::getId, dataSource.getId());
|
||||||
}});
|
// }});
|
||||||
//如果存在则进行删除
|
// //如果存在则进行删除
|
||||||
if (StringUtils.isNotNull(dataSourceServiceOne)) {
|
// if (StringUtils.isNotNull(dataSourceServiceOne)) {
|
||||||
// 根据资产数据源ID查询所有的表
|
// // 根据资产数据源ID查询所有的表
|
||||||
List<Children> childrenList = childrenService.list(new LambdaQueryWrapper<>() {{
|
// List<Children> childrenList = childrenService.list(new LambdaQueryWrapper<>() {{
|
||||||
eq(Children::getAssetId, dataSourceServiceOne.getId());
|
// eq(Children::getAssetId, dataSourceServiceOne.getId());
|
||||||
}});
|
// }});
|
||||||
|
//
|
||||||
childrenList.forEach(children -> {
|
// childrenList.forEach(children -> {
|
||||||
//删除表结构中表的所有数据
|
// //删除表结构中表的所有数据
|
||||||
tableDataService.remove(new LambdaQueryWrapper<>() {{
|
// tableDataService.remove(new LambdaQueryWrapper<>() {{
|
||||||
eq(TableData::getChildrenId, children.getId());
|
// eq(TableData::getChildrenId, children.getId());
|
||||||
}});
|
// }});
|
||||||
});
|
// });
|
||||||
// 删除数据库结构中所有的数据
|
// // 删除数据库结构中所有的数据
|
||||||
childrenService.remove(new LambdaQueryWrapper<>() {{
|
// childrenService.remove(new LambdaQueryWrapper<>() {{
|
||||||
eq(Children::getAssetId, dataSourceServiceOne.getId());
|
// eq(Children::getAssetId, dataSourceServiceOne.getId());
|
||||||
}});
|
// }});
|
||||||
assetDataSourceService.remove(new LambdaQueryWrapper<>() {{
|
// assetDataSourceService.remove(new LambdaQueryWrapper<>() {{
|
||||||
eq(AssetDataSource::getId, dataSourceServiceOne.getId());
|
// eq(AssetDataSource::getId, dataSourceServiceOne.getId());
|
||||||
}});
|
// }});
|
||||||
}
|
// }
|
||||||
AssetDataSource build = AssetDataSource.builder()
|
// AssetDataSource build = AssetDataSource.builder()
|
||||||
.id(dataSource.getId())
|
// .id(dataSource.getId())
|
||||||
.name(dataSource.getName())
|
// .name(dataSource.getName())
|
||||||
.systemName(dataSource.getSystemName())
|
// .systemName(dataSource.getSystemName())
|
||||||
.databaseName(dataSource.getDatabaseName())
|
// .databaseName(dataSource.getDatabaseName())
|
||||||
.type("dataSource")
|
// .type("dataSource")
|
||||||
.build();
|
// .build();
|
||||||
//添加资产数据源结构 库
|
// //添加资产数据源结构 库
|
||||||
assetDataSourceService.save(build);
|
// assetDataSourceService.save(build);
|
||||||
//添加资产数据源下的所有表结构 表
|
// //添加资产数据源下的所有表结构 表
|
||||||
List<Children> childrenList = addChildren(build);
|
// List<Children> childrenList = addChildren(build);
|
||||||
//循环遍历添加表结构的数据 字段
|
// //循环遍历添加表结构的数据 字段
|
||||||
childrenList.forEach(children -> {
|
// childrenList.forEach(children -> {
|
||||||
addTable(build, children.getName());
|
// addTable(build, children.getName());
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//同步数据库结构
|
// //同步数据库结构
|
||||||
private List<Children> addChildren(AssetDataSource build) {
|
// private List<Children> addChildren(AssetDataSource build) {
|
||||||
//获取数据源
|
// //获取数据源
|
||||||
DataSource dataSource = this.getOne(new LambdaQueryWrapper<>() {{
|
// DataSource dataSource = this.getOne(new LambdaQueryWrapper<>() {{
|
||||||
eq(DataSource::getName, build.getName());
|
// eq(DataSource::getName, build.getName());
|
||||||
eq(DataSource::getDatabaseName, build.getDatabaseName());
|
// eq(DataSource::getDatabaseName, build.getDatabaseName());
|
||||||
}});
|
// }});
|
||||||
//获取数据源类型
|
// //获取数据源类型
|
||||||
DataType dataType = dataTypeService.getOne(new LambdaQueryWrapper<>() {{
|
// DataType dataType = dataTypeService.getOne(new LambdaQueryWrapper<>() {{
|
||||||
eq(DataType::getType, dataSource.getDataType());
|
// eq(DataType::getType, dataSource.getDataType());
|
||||||
}});
|
// }});
|
||||||
//用于拼接jdbc连接数据库的路径
|
// //用于拼接jdbc连接数据库的路径
|
||||||
String jdbcUrl = "";
|
// String jdbcUrl = "";
|
||||||
//用于拼接sql语句
|
// //用于拼接sql语句
|
||||||
String sql = "";
|
// String sql = "";
|
||||||
//判断数据库类型
|
// //判断数据库类型
|
||||||
if ("MySql".equals(dataType.getType())) {
|
// if ("MySql".equals(dataType.getType())) {
|
||||||
//获取表名称以及表注释
|
// //获取表名称以及表注释
|
||||||
sql = "select TABLE_NAME,TABLE_COMMENT from INFORMATION_SCHEMA.Tables where table_schema =" + "'" + dataSource.getDatabaseName() + "'";
|
// sql = "select TABLE_NAME,TABLE_COMMENT from INFORMATION_SCHEMA.Tables where table_schema =" + "'" + dataSource.getDatabaseName() + "'";
|
||||||
}
|
// }
|
||||||
//拼接jdbc连接数据库的路径
|
// //拼接jdbc连接数据库的路径
|
||||||
jdbcUrl = dataType.getPrefix() + dataSource.getIp() + ":" + dataSource.getPort() + "/" +
|
// jdbcUrl = dataType.getPrefix() + dataSource.getIp() + ":" + dataSource.getPort() + "/" +
|
||||||
dataSource.getDatabaseName() + "?" + dataSource.getConnectionParam();
|
// dataSource.getDatabaseName() + "?" + dataSource.getConnectionParam();
|
||||||
try {
|
// try {
|
||||||
//加载驱动
|
// //加载驱动
|
||||||
Class.forName(dataType.getDriverManager());
|
// Class.forName(dataType.getDriverManager());
|
||||||
//获取连接
|
// //获取连接
|
||||||
Connection connection = DriverManager.getConnection(jdbcUrl, dataSource.getUserName(), dataSource.getPassword());
|
// Connection connection = DriverManager.getConnection(jdbcUrl, dataSource.getUserName(), dataSource.getPassword());
|
||||||
//执行sql语句
|
// //执行sql语句
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement(sql);
|
// PreparedStatement preparedStatement = connection.prepareStatement(sql);
|
||||||
//返回一个结果集 包含查询生成的数据
|
// //返回一个结果集 包含查询生成的数据
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
// ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
//遍历结果集
|
// //遍历结果集
|
||||||
while (resultSet.next()) {
|
// while (resultSet.next()) {
|
||||||
Children children = Children.builder()
|
// Children children = Children.builder()
|
||||||
.name(resultSet.getString("TABLE_NAME"))
|
// .name(resultSet.getString("TABLE_NAME"))
|
||||||
.remark(resultSet.getString("TABLE_COMMENT"))
|
// .remark(resultSet.getString("TABLE_COMMENT"))
|
||||||
.type("dataType")
|
// .type("dataType")
|
||||||
.isCenter("Y")
|
// .isCenter("Y")
|
||||||
.assetId(build.getId())
|
// .assetId(build.getId())
|
||||||
.build();
|
// .build();
|
||||||
//添加到数据库中
|
// //添加到数据库中
|
||||||
childrenService.save(children);
|
// childrenService.save(children);
|
||||||
}
|
// }
|
||||||
//关闭连接
|
// //关闭连接
|
||||||
connection.close();
|
// connection.close();
|
||||||
resultSet.close();
|
// resultSet.close();
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
//获取数据库结构
|
// //获取数据库结构
|
||||||
List<Children> childrenList = childrenService.list(new LambdaQueryWrapper<>() {{
|
// List<Children> childrenList = childrenService.list(new LambdaQueryWrapper<>() {{
|
||||||
eq(Children::getAssetId, build.getId());
|
// eq(Children::getAssetId, build.getId());
|
||||||
}});
|
// }});
|
||||||
try {
|
// try {
|
||||||
//加载驱动
|
// //加载驱动
|
||||||
Class.forName(dataType.getDriverManager());
|
// Class.forName(dataType.getDriverManager());
|
||||||
//获取连接
|
// //获取连接
|
||||||
Connection connection = DriverManager.getConnection(jdbcUrl, dataSource.getUserName(), dataSource.getPassword());
|
// Connection connection = DriverManager.getConnection(jdbcUrl, dataSource.getUserName(), dataSource.getPassword());
|
||||||
//创建一个Statement对象
|
// //创建一个Statement对象
|
||||||
Statement statement = connection.createStatement();
|
// Statement statement = connection.createStatement();
|
||||||
//遍历获取到的表结构集合
|
// //遍历获取到的表结构集合
|
||||||
childrenList.forEach(children -> {
|
// childrenList.forEach(children -> {
|
||||||
//查询指定数据库中指定表的记录数
|
// //查询指定数据库中指定表的记录数
|
||||||
String sql1 = "SELECT COUNT(*) AS tableNum FROM " + "`" + dataSource.getDatabaseName() + "`" + "." + "`" + children.getName() + "`";
|
// String sql1 = "SELECT COUNT(*) AS tableNum FROM " + "`" + dataSource.getDatabaseName() + "`" + "." + "`" + children.getName() + "`";
|
||||||
try {
|
// try {
|
||||||
//执行给定的sql语句
|
// //执行给定的sql语句
|
||||||
ResultSet resultSet = statement.executeQuery(sql1);
|
// ResultSet resultSet = statement.executeQuery(sql1);
|
||||||
while (resultSet.next()) {
|
// while (resultSet.next()) {
|
||||||
//检索resultSet对象当前行中的指定列的值
|
// //检索resultSet对象当前行中的指定列的值
|
||||||
int anInt = resultSet.getInt("tableNum");
|
// int anInt = resultSet.getInt("tableNum");
|
||||||
children.setDataTotal(anInt);
|
// children.setDataTotal(anInt);
|
||||||
childrenService.updateById(children);
|
// childrenService.updateById(children);
|
||||||
}
|
// }
|
||||||
resultSet.close();
|
// resultSet.close();
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
return childrenList;
|
// return childrenList;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//同步表结构
|
// //同步表结构
|
||||||
private void addTable(AssetDataSource build, String name) {
|
// private void addTable(AssetDataSource build, String name) {
|
||||||
// 查询数据源对象
|
// // 查询数据源对象
|
||||||
DataSource dataSource = this.getOne(new LambdaQueryWrapper<>() {{
|
// DataSource dataSource = this.getOne(new LambdaQueryWrapper<>() {{
|
||||||
eq(DataSource::getName, build.getName());
|
// eq(DataSource::getName, build.getName());
|
||||||
eq(DataSource::getDatabaseName, build.getDatabaseName());
|
// eq(DataSource::getDatabaseName, build.getDatabaseName());
|
||||||
}});
|
// }});
|
||||||
//获取表结构对象
|
// //获取表结构对象
|
||||||
Children serviceOne = childrenService.getOne(new LambdaQueryWrapper<>() {{
|
// Children serviceOne = childrenService.getOne(new LambdaQueryWrapper<>() {{
|
||||||
eq(Children::getName, name);
|
// eq(Children::getName, name);
|
||||||
}});
|
// }});
|
||||||
// 获取数据类型对象
|
// // 获取数据类型对象
|
||||||
DataType dataType = dataTypeService.getOne(new LambdaQueryWrapper<>() {{
|
// DataType dataType = dataTypeService.getOne(new LambdaQueryWrapper<>() {{
|
||||||
eq(DataType::getType, dataSource.getDataType());
|
// eq(DataType::getType, dataSource.getDataType());
|
||||||
}});
|
// }});
|
||||||
// 用于拼接jdbc连接数据库的路径
|
// // 用于拼接jdbc连接数据库的路径
|
||||||
String jdbcUrl = "";
|
// String jdbcUrl = "";
|
||||||
jdbcUrl = dataType.getPrefix() + dataSource.getIp() + ":" + dataSource.getPort() + "/" +
|
// jdbcUrl = dataType.getPrefix() + dataSource.getIp() + ":" + dataSource.getPort() + "/" +
|
||||||
dataSource.getDatabaseName() + "?" + dataSource.getConnectionParam();
|
// dataSource.getDatabaseName() + "?" + dataSource.getConnectionParam();
|
||||||
try {
|
// try {
|
||||||
//加载驱动
|
// //加载驱动
|
||||||
Class.forName(dataType.getDriverManager());
|
// Class.forName(dataType.getDriverManager());
|
||||||
//获取连接
|
// //获取连接
|
||||||
Connection connection = DriverManager.getConnection(jdbcUrl, dataSource.getUserName(), dataSource.getPassword());
|
// Connection connection = DriverManager.getConnection(jdbcUrl, dataSource.getUserName(), dataSource.getPassword());
|
||||||
//获取数据库元数据
|
// //获取数据库元数据
|
||||||
DatabaseMetaData metaData = connection.getMetaData();
|
// DatabaseMetaData metaData = connection.getMetaData();
|
||||||
//获取指定数据库中指定表的字段信息
|
// //获取指定数据库中指定表的字段信息
|
||||||
ResultSet columns = metaData.getColumns(dataSource.getDatabaseName(), dataSource.getDatabaseName(), name, "%");
|
// ResultSet columns = metaData.getColumns(dataSource.getDatabaseName(), dataSource.getDatabaseName(), name, "%");
|
||||||
//获取指定数据库中指定表的主键信息
|
// //获取指定数据库中指定表的主键信息
|
||||||
ResultSet primaryKeys = metaData.getPrimaryKeys(dataSource.getDatabaseName(), dataSource.getDatabaseName(), name);
|
// ResultSet primaryKeys = metaData.getPrimaryKeys(dataSource.getDatabaseName(), dataSource.getDatabaseName(), name);
|
||||||
//获取指定数据库中指定表的主键名称
|
// //获取指定数据库中指定表的主键名称
|
||||||
String primaryKey = "";
|
// String primaryKey = "";
|
||||||
//遍历主键信息
|
// //遍历主键信息
|
||||||
while (primaryKeys.next()) {
|
// while (primaryKeys.next()) {
|
||||||
primaryKey = primaryKeys.getString("COLUMN_NAME");
|
// primaryKey = primaryKeys.getString("COLUMN_NAME");
|
||||||
}
|
// }
|
||||||
//遍历字段信息
|
// //遍历字段信息
|
||||||
while (columns.next()) {
|
// while (columns.next()) {
|
||||||
//获取字段名称
|
// //获取字段名称
|
||||||
String columnName = columns.getString("COLUMN_NAME");
|
// String columnName = columns.getString("COLUMN_NAME");
|
||||||
//获取字段备注
|
// //获取字段备注
|
||||||
String columnComment = columns.getString("REMARKS");
|
// String columnComment = columns.getString("REMARKS");
|
||||||
//获取字段类型
|
// //获取字段类型
|
||||||
String columnType = columns.getString("TYPE_NAME");
|
// String columnType = columns.getString("TYPE_NAME");
|
||||||
//获取字段长度
|
// //获取字段长度
|
||||||
int columnSize = columns.getInt("COLUMN_SIZE");
|
// int columnSize = columns.getInt("COLUMN_SIZE");
|
||||||
//获取字段小数位数
|
// //获取字段小数位数
|
||||||
int decimalDigits = columns.getInt("DECIMAL_DIGITS");
|
// int decimalDigits = columns.getInt("DECIMAL_DIGITS");
|
||||||
//判断字段是否为空
|
// //判断字段是否为空
|
||||||
String isNullable = columns.getString("IS_NULLABLE");
|
// String isNullable = columns.getString("IS_NULLABLE");
|
||||||
//判断字段是否为默认值
|
// //判断字段是否为默认值
|
||||||
String columnDefault = columns.getString("COLUMN_DEF");
|
// String columnDefault = columns.getString("COLUMN_DEF");
|
||||||
// 添加字段
|
// // 添加字段
|
||||||
TableData tableData = TableData.builder()
|
// TableData tableData = TableData.builder()
|
||||||
.name(columnName)
|
// .name(columnName)
|
||||||
.comment(columnComment)
|
// .comment(columnComment)
|
||||||
.isPrimaryKey(columnName.equals(primaryKey) ? "Y" : "N")
|
// .isPrimaryKey(columnName.equals(primaryKey) ? "Y" : "N")
|
||||||
.type(columnType)
|
// .type(columnType)
|
||||||
.length(columnSize)
|
// .length(columnSize)
|
||||||
.decimalPlaces(decimalDigits)
|
// .decimalPlaces(decimalDigits)
|
||||||
.isNull(isNullable.equals("YES") ? "Y" : "N")
|
// .isNull(isNullable.equals("YES") ? "Y" : "N")
|
||||||
.defaultValue(columnDefault)
|
// .defaultValue(columnDefault)
|
||||||
.isDict("N")
|
// .isDict("N")
|
||||||
.dictKey("")
|
// .dictKey("")
|
||||||
.childrenId(serviceOne.getId())
|
// .childrenId(serviceOne.getId())
|
||||||
.build();
|
// .build();
|
||||||
//添加字段信息到数据库中
|
// //添加字段信息到数据库中
|
||||||
tableDataService.save(tableData);
|
// tableDataService.save(tableData);
|
||||||
}
|
// }
|
||||||
//关闭资源
|
// //关闭资源
|
||||||
columns.close();
|
// columns.close();
|
||||||
primaryKeys.close();
|
// primaryKeys.close();
|
||||||
connection.close();
|
// connection.close();
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.muyu.source.service.Impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
||||||
|
import com.muyu.source.domain.Structure;
|
||||||
|
import com.muyu.source.mapper.StructureMapper;
|
||||||
|
import com.muyu.source.service.StructureService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure> implements StructureService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Structure> findStructureList(Long id) {
|
||||||
|
LambdaQueryWrapper<Structure> structureLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
structureLambdaQueryWrapper.eq(Structure::getTableId, id);
|
||||||
|
List<Structure> list = this.list(structureLambdaQueryWrapper);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Structure> findStructurelistS(Integer id) {
|
||||||
|
LambdaQueryWrapper<Structure> structureLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
structureLambdaQueryWrapper.eq(Structure::getTableId, id);
|
||||||
|
List<Structure> list = this.list(structureLambdaQueryWrapper);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -73,11 +73,11 @@ public class TableDataServiceImpl extends ServiceImpl<TableDataMapper, TableData
|
||||||
return this.count(queryWrapper) > 0;
|
return this.count(queryWrapper) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public List<TableData> findTableDataList(Long id) {
|
// public List<TableData> findTableDataList(Long id) {
|
||||||
LambdaQueryWrapper<TableData> lambdaQueryWrapper = new LambdaQueryWrapper<TableData>().eq(TableData::getChildrenId, id);
|
// LambdaQueryWrapper<TableData> lambdaQueryWrapper = new LambdaQueryWrapper<TableData>().eq(TableData::getChildrenId, id);
|
||||||
return this.list(lambdaQueryWrapper);
|
// return this.list(lambdaQueryWrapper);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package com.muyu.source.service.Impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
||||||
|
import com.muyu.source.domain.TableInfo;
|
||||||
|
import com.muyu.source.domain.rep.TableInfoRep;
|
||||||
|
import com.muyu.source.mapper.TableInfoMapper;
|
||||||
|
import com.muyu.source.service.TableInfoService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TableServiceImpl extends ServiceImpl<TableInfoMapper, TableInfo> implements TableInfoService {
|
||||||
|
@Autowired
|
||||||
|
private TableInfoMapper tableInfoMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableInfo selectTableInfoByName(TableInfo tableInfoInsert) {
|
||||||
|
LambdaQueryWrapper<TableInfo> tableInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
// tableInfoLambdaQueryWrapper.eq(TableInfo::getId, tableInfoInsert.getId());
|
||||||
|
//
|
||||||
|
|
||||||
|
tableInfoLambdaQueryWrapper.eq(TableInfo::getBasicId, tableInfoInsert.getBasicId());
|
||||||
|
tableInfoLambdaQueryWrapper.eq(TableInfo::getTableName, tableInfoInsert.getTableName())
|
||||||
|
.eq(TableInfo::getParentId, tableInfoInsert.getParentId());
|
||||||
|
|
||||||
|
return this.tableInfoMapper.selectOne(tableInfoLambdaQueryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TableInfo> findSourceList() {
|
||||||
|
List<TableInfo> tableInfoList = tableInfoMapper.selectList(new LambdaQueryWrapper<TableInfo>(TableInfo.class)
|
||||||
|
.eq(TableInfo::getParentId, 0));
|
||||||
|
|
||||||
|
return tableInfoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TableInfoRep> findTablesList(Long id) {
|
||||||
|
List<TableInfo> tableInfoList = tableInfoMapper.selectList(new LambdaQueryWrapper<TableInfo>(TableInfo.class).eq(
|
||||||
|
TableInfo::getParentId, id
|
||||||
|
));
|
||||||
|
|
||||||
|
List<TableInfoRep> tableInfoRepList = new ArrayList<>();
|
||||||
|
for (TableInfo tableInfo : tableInfoList) {
|
||||||
|
TableInfoRep tableInfoRep = TableInfo.tableInfoRep(tableInfo);
|
||||||
|
tableInfoRepList.add(tableInfoRep);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tableInfoRepList;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.muyu.source.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.muyu.source.domain.Structure;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface StructureService extends IService<Structure> {
|
||||||
|
List<Structure> findStructureList(Long id);
|
||||||
|
|
||||||
|
List<Structure> findStructurelistS(Integer id);
|
||||||
|
|
||||||
|
}
|
|
@ -39,5 +39,5 @@ public interface TableDataService extends IService<TableData> {
|
||||||
Boolean checkIdUnique(TableData tableData);
|
Boolean checkIdUnique(TableData tableData);
|
||||||
|
|
||||||
|
|
||||||
List<TableData> findTableDataList(Long id);
|
// List<TableData> findTableDataList(Long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.muyu.source.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.muyu.source.domain.TableInfo;
|
||||||
|
import com.muyu.source.domain.rep.TableInfoRep;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface TableInfoService extends IService<TableInfo> {
|
||||||
|
|
||||||
|
TableInfo selectTableInfoByName(TableInfo tableInfoInsert);
|
||||||
|
|
||||||
|
List<TableInfo> findSourceList();
|
||||||
|
|
||||||
|
List<TableInfoRep> findTablesList(Long id);
|
||||||
|
}
|
Loading…
Reference in New Issue