feat():数据接入树级结构

ruoyi_test
sunshine7058 2024-04-24 22:24:03 +08:00
parent 8a493532a1
commit e3f57b5883
28 changed files with 484 additions and 149 deletions

View File

@ -1,5 +1,8 @@
package com.muyu.data.source.domain; package com.muyu.data.source.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -18,14 +21,17 @@ import lombok.experimental.SuperBuilder;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class AssetDataSource { public class AssetDataSource {
// 主键
private Long id; // 主键
// 名称 @TableId(value = "id", type = IdType.AUTO)
private String name; @ApiModelProperty(name = "编号", value = "编号")
// 系统名 private Long id;
private String systemName; // 接入数据源名称
// 数据库名称 private String name;
private String databaseName; // 数据来源系统名
//类型 private String systemName;
private String type; // 数据库名称
private String databaseName;
//前台展示类型
private String type;
} }

View File

@ -1,12 +1,16 @@
package com.muyu.data.source.domain; package com.muyu.data.source.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
/** /**
* *
* *
* @author HuFangMing * @author HuFangMing
* @ClassName: Children * @ClassName: Children
@ -17,11 +21,33 @@ import lombok.experimental.SuperBuilder;
@SuperBuilder @SuperBuilder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@TableName("children")
public class Children { public class Children {
private Long id;
private String name; /**
private String as; *
private Long dataTotal; **/
private String type; @TableId(value = "id", type = IdType.AUTO)
private Long assetId; @ApiModelProperty(name = "编号", value = "编号")
private Long id;
/**
*
**/
private String name;
/**
*
**/
private String annotation;
/**
*
**/
private Long dataTotal;
/**
*
**/
private String type;
/**
* id
**/
private Long assetId;
} }

View File

@ -16,7 +16,7 @@ import com.muyu.data.source.domain.req.DatabaseTypeEditReq;
import com.muyu.common.core.web.domain.BaseEntity; import com.muyu.common.core.web.domain.BaseEntity;
/** /**
* database_type * database_type
* *
* @author hufangming * @author hufangming
* @date 2024-04-21 * @date 2024-04-21

View File

@ -1,5 +1,8 @@
package com.muyu.data.source.domain; package com.muyu.data.source.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -17,18 +20,61 @@ import lombok.experimental.SuperBuilder;
@SuperBuilder @SuperBuilder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class TableData { public class TableData {
private Long id;
private String name; /**
private String comment; *
private String isPrimaryKey; **/
private String type; @TableId(value = "id", type = IdType.AUTO)
private String mappingType; @ApiModelProperty(name = "编号", value = "编号")
private Long length; private Long id;
private Long decimalPlaces; /**
private String isNull; *
private String defaultValue; **/
private String isDict; private String name;
private String dictKey; /**
private Long childrenId; *
**/
private String comment;
/**
*
**/
private String isPrimaryKey;
/**
*
**/
private String type;
/**
*
**/
private String mappingType;
/**
*
**/
private Long length;
/**
*
**/
private Long decimalPlaces;
/**
*
**/
private String isNull;
/**
*
**/
private String defaultValue;
/**
*
**/
private String isDict;
/**
*
**/
private String dictKey;
/**
* id
**/
private Long childrenId;
} }

View File

@ -19,6 +19,13 @@ import lombok.experimental.SuperBuilder;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class ShowTableReq { public class ShowTableReq {
private AssetDataSource assetDataSource;
private String tableName; /**
*
*/
private AssetDataSource assetDataSource;
/**
*
*/
private String tableName;
} }

View File

@ -18,12 +18,37 @@ import lombok.experimental.SuperBuilder;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class ColumnResp { public class ColumnResp {
private String columnName;
private String columnComment; /**
private String columnKey; *
private String columnType; **/
private Long length; private String columnName;
private Long numericScale; /**
private String isNullable; *
private String columnDefault; **/
private String columnComment;
/**
*
**/
private String columnKey;
/**
*
**/
private String columnType;
/**
*
**/
private Long length;
/**
*
**/
private Long numericScale;
/**
*
**/
private String isNullable;
/**
*
**/
private String columnDefault;
} }

View File

@ -18,7 +18,17 @@ import lombok.experimental.SuperBuilder;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class CountResp { public class CountResp {
private Long assetStructureCount;
private Long assetStructureTableCount; /**
private Long assetStructureTableDataCount; *
**/
private Long assetStructureCount;
/**
*
**/
private Long assetStructureTableCount;
/**
*
**/
private Long assetStructureTableDataCount;
} }

View File

@ -6,7 +6,7 @@ import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
/** /**
* *
* *
* @author HuFangMing * @author HuFangMing
* @ClassName: Table * @ClassName: Table
@ -18,7 +18,17 @@ import lombok.experimental.SuperBuilder;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class Table { public class Table {
private String tableName;
private String tableComment; /**
private Long tableRows; *
*/
private String tableName;
/**
*
*/
private String tableComment;
/**
*
*/
private Long tableRows;
} }

View File

@ -0,0 +1,18 @@
package com.muyu.data.source.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
*
* @author HuFangMing
* @ClassName: AssetDataSourceController
* @createTime: 2024/4/24 17:00
*/
@RestController
@RequestMapping("/assetDataSource")
public class AssetDataSourceController {
}

View File

@ -0,0 +1,18 @@
package com.muyu.data.source.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
*
* @author HuFangMing
* @ClassName: ChildrenController
* @createTime: 2024/4/24 17:02
*/
@RestController
@RequestMapping("/children")
public class ChildrenController {
}

View File

@ -3,6 +3,7 @@ package com.muyu.data.source.controller;
import com.muyu.data.source.domain.AssetDataSource; import com.muyu.data.source.domain.AssetDataSource;
import com.muyu.data.source.domain.Children; import com.muyu.data.source.domain.Children;
import com.muyu.data.source.domain.DatabaseType; import com.muyu.data.source.domain.DatabaseType;
import com.muyu.data.source.domain.TableData;
import com.muyu.data.source.domain.req.ShowTableReq; import com.muyu.data.source.domain.req.ShowTableReq;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -167,7 +168,7 @@ public class DataSourceController extends BaseController {
*/ */
@RequiresPermissions("data:source:selecttablelist") @RequiresPermissions("data:source:selecttablelist")
@GetMapping("/selectTableList") @GetMapping("/selectTableList")
public Result<List<DatabaseType>> selectTableList(){ public Result<List<TableData>> selectTableList(){
return Result.success( dataSourceService.selectTableList()); return Result.success( dataSourceService.selectTableList());
} }
@ -183,6 +184,14 @@ public class DataSourceController extends BaseController {
return Result.success( dataSourceService.selectTableDataCount()); return Result.success( dataSourceService.selectTableDataCount());
} }
/**
* childrenId
*/
@GetMapping("/selectTableData/{id}")
public Result selectTableData(@PathVariable("id")Long id){
List<TableData> tableDataList=dataSourceService.selectTableData(id);
return Result.success(tableDataList);
}
} }

View File

@ -0,0 +1,18 @@
package com.muyu.data.source.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
*
* @author HuFangMing
* @ClassName: TableDateController
* @createTime: 2024/4/24 17:04
*/
@RestController
@RequestMapping("/")
public class TableDateController {
}

View File

@ -0,0 +1,17 @@
package com.muyu.data.source.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.data.source.domain.AssetDataSource;
/**
* mapper
*
* @author HuFangMing
* @ClassName: AssetDataSourceMapper
* @createTime: 2024/4/24 17:08
*/
public interface AssetDataSourceMapper extends BaseMapper<AssetDataSource> {
}

View File

@ -0,0 +1,17 @@
package com.muyu.data.source.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.data.source.domain.Children;
/**
* mapper
*
* @author HuFangMing
* @ClassName: ChildrenMapper
* @createTime: 2024/4/24 17:10
*/
public interface ChildrenMapper extends BaseMapper<Children> {
}

View File

@ -20,25 +20,9 @@ import com.muyu.data.source.domain.DataSource;
public interface DataSourceMapper extends BaseMapper<DataSource> { public interface DataSourceMapper extends BaseMapper<DataSource> {
Result insertAsset(AssetDataSource assetDataSource);
List<AssetDataSource> selectAssetList();
List<Table> selectTable(String databaseName);
Result addChildren(Children children);
List<Children> getChildrenList(Long id);
List<ColumnResp> selectColumn(@Param("databaseName") String databaseName, @Param("tableName") String tableName); List<ColumnResp> selectColumn(@Param("databaseName") String databaseName, @Param("tableName") String tableName);
Children selectChildren(@Param("id") Long id, @Param("tableName") String tableName); List<Table> selectTable(@Param("databaseName") String databaseName);
void addTableData(TableData tableData);
List<TableData> getTableDataList(Long id);
List<TableData> selectTableData();
List<Children> selectChildrenList(); List<Children> selectChildrenList();
} }

View File

@ -0,0 +1,18 @@
package com.muyu.data.source.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.data.source.domain.TableData;
/**
* mapper
*
* @author HuFangMing
* @ClassName: TableDataMapper
* @createTime: 2024/4/24 17:12
*/
public interface TableDataMapper extends BaseMapper<TableData> {
}

View File

@ -0,0 +1,17 @@
package com.muyu.data.source.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.data.source.domain.AssetDataSource;
/**
*
*
* @author HuFangMing
* @ClassName: AssetDataSourceService
* @createTime: 2024/4/24 17:15
*/
public interface AssetDataSourceService extends IService<AssetDataSource> {
}

View File

@ -0,0 +1,17 @@
package com.muyu.data.source.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.data.source.domain.Children;
/**
*
*
* @author HuFangMing
* @ClassName: ChildrenService
* @createTime: 2024/4/24 17:16
*/
public interface ChildrenService extends IService<Children> {
}

View File

@ -1,10 +1,8 @@
package com.muyu.data.source.service; package com.muyu.data.source.service;
import com.muyu.common.core.domain.Result; import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.data.source.domain.AssetDataSource; import com.muyu.data.source.domain.AssetDataSource;
import com.muyu.data.source.domain.Children; import com.muyu.data.source.domain.Children;
import com.muyu.data.source.domain.DatabaseType;
import com.muyu.data.source.domain.TableData; import com.muyu.data.source.domain.TableData;
import com.muyu.data.source.domain.req.ShowTableReq; import com.muyu.data.source.domain.req.ShowTableReq;
import com.muyu.data.source.domain.resp.CountResp; import com.muyu.data.source.domain.resp.CountResp;
@ -41,4 +39,6 @@ public interface DataSourceService extends IService<DataSource> {
CountResp selectTableDataCount(); CountResp selectTableDataCount();
List<TableData> selectTableData(Long id);
} }

View File

@ -0,0 +1,17 @@
package com.muyu.data.source.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.data.source.domain.TableData;
/**
*
*
* @author HuFangMing
* @ClassName: TableDataService
* @createTime: 2024/4/24 17:17
*/
public interface TableDataService extends IService<TableData> {
}

View File

@ -0,0 +1,18 @@
package com.muyu.data.source.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.data.source.domain.AssetDataSource;
import com.muyu.data.source.mapper.AssetDataSourceMapper;
import com.muyu.data.source.service.AssetDataSourceService;
import org.springframework.stereotype.Service;
/**
* @author HuFangMing
* @ClassName: AssetDataSourceServiceImpl
* @createTime: 2024/4/24 17:18
*/
@Service
public class AssetDataSourceServiceImpl extends ServiceImpl<AssetDataSourceMapper, AssetDataSource> implements AssetDataSourceService {
}

View File

@ -0,0 +1,18 @@
package com.muyu.data.source.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.data.source.domain.Children;
import com.muyu.data.source.mapper.ChildrenMapper;
import com.muyu.data.source.service.ChildrenService;
import org.springframework.stereotype.Service;
/**
* @author HuFangMing
* @ClassName: ChildrenServiceImpl
* @createTime: 2024/4/24 17:20
*/
@Service
public class ChildrenServiceImpl extends ServiceImpl<ChildrenMapper, Children> implements ChildrenService {
}

View File

@ -10,7 +10,10 @@ import com.muyu.data.source.domain.req.ShowTableReq;
import com.muyu.data.source.domain.resp.ColumnResp; import com.muyu.data.source.domain.resp.ColumnResp;
import com.muyu.data.source.domain.resp.CountResp; import com.muyu.data.source.domain.resp.CountResp;
import com.muyu.data.source.domain.resp.Table; import com.muyu.data.source.domain.resp.Table;
import com.muyu.data.source.service.AssetDataSourceService;
import com.muyu.data.source.service.ChildrenService;
import com.muyu.data.source.service.DatabaseTypeService; import com.muyu.data.source.service.DatabaseTypeService;
import com.muyu.data.source.service.TableDataService;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -24,6 +27,7 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
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.data.redis.connection.DataType;
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.domain.DataSource;
@ -45,8 +49,13 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
@Autowired @Autowired
private DataSourceMapper dataSourceMapper; private DataSourceMapper dataSourceMapper;
@Autowired @Autowired
private DataSourceService dataSourceService; private AssetDataSourceService assetDataSourceService;
@Autowired
private ChildrenService childrenService;
@Autowired
private TableDataService tableDataService;
@Autowired @Autowired
private DatabaseTypeService databaseTypeService; private DatabaseTypeService databaseTypeService;
@ -82,27 +91,13 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
*/ */
@Override @Override
public Boolean testConnection(DataSource dataSource) { public Boolean testConnection(DataSource dataSource) {
List<DataSource> dataSourceList = this.list( DatabaseType dataType = databaseTypeService.getOne(new LambdaQueryWrapper<>() {{
new LambdaQueryWrapper<DataSource>() eq(DatabaseType::getDatabaseName, dataSource.getDataType());
.eq(DataSource::getDataType, dataSource.getDataType()) }});
);
// 使用Set进行去重
Set<DataSource> uniqueDataSources = new HashSet<>(dataSourceList);
Optional<DataSource> source = uniqueDataSources.stream().distinct().findFirst();
if (source.isPresent()) {
dataSource = source.get();
}
String jdbcUrl = ""; String jdbcUrl = "";
String driveClass = ""; String driveClass = "";
boolean flag = false; boolean flag = false;
DatabaseType dataType = databaseTypeService.getOne(
new LambdaQueryWrapper<DatabaseType>()
.eq(DatabaseType::getDatabaseId, dataSource.getDataType())
);
if (dataType.getDatabaseName().equals("mysql") || dataType.equals("MYSQL")) { if (dataType.getDatabaseName().equals("mysql") || dataType.equals("MYSQL")) {
driveClass = dataType.getDriverManager(); driveClass = dataType.getDriverManager();
@ -158,21 +153,21 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
@Override @Override
public Boolean syncConnection(DataSource dataSource) { public Boolean syncConnection(DataSource dataSource) {
if ("mysql".equals(dataSource.getDataType())) { if ("mysql".equals(dataSource.getDataType())) {
AssetDataSource.builder() AssetDataSource assetDataSource = AssetDataSource.builder()
.name(dataSource.getName()) .name(dataSource.getName())
.systemName(dataSource.getSystemName()) .systemName(dataSource.getSystemName())
.databaseName(dataSource.getDatabaseName()) .databaseName(dataSource.getDatabaseName())
.type("dataSource") .type("dataSource")
.build(); .build();
return assetDataSourceService.save(assetDataSource);
} }
return null; return false;
} }
@Override @Override
public List<AssetDataSource> getAssetList() { public List<AssetDataSource> getAssetList() {
List<AssetDataSource> list = dataSourceMapper.selectAssetList(); List<AssetDataSource> assetDataSourceList = assetDataSourceService.list();
return list; return assetDataSourceList;
} }
@Override @Override
@ -185,7 +180,9 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
//数据库类型为mysql //数据库类型为mysql
if ("mysql".equals(dataSource.getDataType())) { if ("mysql".equals(dataSource.getDataType())) {
//根据id查询表描述 //根据id查询表描述
List<Children> childrenList = dataSourceMapper.getChildrenList(assetDataSource.getId()); List<Children> childrenList = childrenService.list(new LambdaQueryWrapper<Children>() {{
eq(Children::getAssetId, assetDataSource.getId());
}});
//获取表描述的集合 //获取表描述的集合
List<Table> tableList = dataSourceMapper.selectTable(assetDataSource.getDatabaseName()); List<Table> tableList = dataSourceMapper.selectTable(assetDataSource.getDatabaseName());
//判断是否存在 //判断是否存在
@ -193,13 +190,13 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
tableList.forEach(table -> { tableList.forEach(table -> {
Children children = Children.builder() Children children = Children.builder()
.name(table.getTableName()) .name(table.getTableName())
.as(table.getTableComment()) .annotation(table.getTableComment())
.dataTotal(table.getTableRows()) .dataTotal(table.getTableRows())
.type("dataTble") .type("dataTble")
.assetId(assetDataSource.getId()) .assetId(assetDataSource.getId())
.build(); .build();
//添加到数据库 //添加到数据库
dataSourceMapper.addChildren(children); childrenService.save(children);
}); });
} }
@ -217,19 +214,22 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
eq(DataSource::getName, showTableReq.getAssetDataSource().getName()); eq(DataSource::getName, showTableReq.getAssetDataSource().getName());
eq(DataSource::getDatabaseName, showTableReq.getAssetDataSource().getDatabaseName()); eq(DataSource::getDatabaseName, showTableReq.getAssetDataSource().getDatabaseName());
}}); }});
Children children = dataSourceMapper.selectChildren(showTableReq.getAssetDataSource().getId(), Children children = childrenService.getOne(new LambdaQueryWrapper<>(){{
showTableReq.getTableName()); eq(Children::getAssetId, showTableReq.getAssetDataSource().getId());
eq(Children::getName,showTableReq.getTableName());
}});
// 获取数据类型对象 // 获取数据类型对象
Result<DatabaseType> dataTypeResult = dataTypeController.getByType(dataSource.getDataType()); DatabaseType dataType=databaseTypeService.getOne(new LambdaQueryWrapper<>(){{
if (Result.isError(dataTypeResult)) { eq(DatabaseType::getDatabaseName, dataSource.getDataType());
throw new RuntimeException("数据类型不存在"); }
} });
DatabaseType dataType = dataTypeResult.getData();
String jdbcUrl = dataType.getUrlPre() + dataSource.getHost() + ":" + dataSource.getPort() + "/" String jdbcUrl = dataType.getUrlPre() + dataSource.getHost() + ":" + dataSource.getPort() + "/"
+ dataSource.getDatabaseName() + "?" + dataSource.getConnectionParam(); + dataSource.getDatabaseName() + "?" + dataSource.getConnectionParam();
List<ColumnResp> columnRespList = dataSourceMapper.selectColumn(dataSource.getDatabaseName(), List<ColumnResp> columnRespList = dataSourceMapper.selectColumn(dataSource.getDatabaseName(),
showTableReq.getTableName()); showTableReq.getTableName());
List<TableData> tableDataList = dataSourceMapper.getTableDataList(children.getId()); List<TableData> tableDataList = tableDataService.list(new LambdaQueryWrapper<>(){{
eq(TableData::getChildrenId, children.getId());
}});
if (tableDataList == null || tableDataList.size() == 0) { if (tableDataList == null || tableDataList.size() == 0) {
columnRespList.forEach(columnResp -> { columnRespList.forEach(columnResp -> {
@ -249,7 +249,7 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
.dictKey(null) .dictKey(null)
.childrenId(children.getId()) .childrenId(children.getId())
.build(); .build();
dataSourceMapper.addTableData(tableData); tableDataService.save(tableData);
}); });
} }
return Result.success(); return Result.success();
@ -257,15 +257,15 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
@Override @Override
public List<TableData> selectTableList() { public List<TableData> selectTableList() {
List<TableData> tableDataList = dataSourceMapper.selectTableData(); List<TableData> tableDataList = tableDataService.list();
return tableDataList; return tableDataList;
} }
@Override @Override
public CountResp selectTableDataCount() { public CountResp selectTableDataCount() {
List<AssetDataSource> assetDataSourceList = dataSourceMapper.selectAssetList(); List<AssetDataSource> assetDataSourceList = assetDataSourceService.list();
long size = assetDataSourceList.size(); long size = assetDataSourceList.size();
List<Children> childrenList = dataSourceMapper.selectChildrenList(); List<Children> childrenList = childrenService.list();
long size1 = childrenList.size(); long size1 = childrenList.size();
long sum = childrenList.stream().mapToLong(Children::getDataTotal).sum(); long sum = childrenList.stream().mapToLong(Children::getDataTotal).sum();
CountResp countResp = CountResp.builder() CountResp countResp = CountResp.builder()
@ -276,6 +276,14 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
return countResp; return countResp;
} }
@Override
public List<TableData> selectTableData(Long id) {
List<TableData> tableDataList = tableDataService.list(new LambdaQueryWrapper<>() {{
eq(TableData::getChildrenId, id);
}});
return tableDataList;
}
public static String getJavaType(String driveClass, String url, String username, String password, String tableName, String columnName) { public static String getJavaType(String driveClass, String url, String username, String password, String tableName, String columnName) {
Connection connection = buildConnection(driveClass, url, username, password); Connection connection = buildConnection(driveClass, url, username, password);
PreparedStatement pst = null; PreparedStatement pst = null;

View File

@ -0,0 +1,20 @@
package com.muyu.data.source.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.data.source.domain.TableData;
import com.muyu.data.source.mapper.TableDataMapper;
import com.muyu.data.source.service.TableDataService;
import org.springframework.stereotype.Service;
/**
*
*
* @author HuFangMing
* @ClassName: TableDataServiceImpl
* @createTime: 2024/4/24 18:58
*/
@Service
public class TableDataServiceImpl extends ServiceImpl<TableDataMapper, TableData> implements TableDataService {
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--
1.在mybats的开发中namespace有特殊的意思一定要是对应接口的全限定名
通过namespace可以简历mapper.xml和接口之间的关系(名字不重要,位置不重要)
-->
<mapper namespace="com.muyu.data.source.mapper.AssetDataSourceMapper">
</mapper>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--
1.在mybats的开发中namespace有特殊的意思一定要是对应接口的全限定名
通过namespace可以简历mapper.xml和接口之间的关系(名字不重要,位置不重要)
-->
<mapper namespace="com.muyu.data.source.mapper.ChildrenMapper">
</mapper>

View File

@ -32,25 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select id, name, system_name, database_name, database_type, host, port, user, password, type, connection_param, status, init_num, max_num, max_wait_time, max_wait_size, remark, create_by, create_time, update_by, update_time from data_source select id, name, system_name, database_name, database_type, host, port, user, password, type, connection_param, status, init_num, max_num, max_wait_time, max_wait_size, remark, create_by, create_time, update_by, update_time from data_source
</sql> </sql>
<insert id="insertAsset">
INSERT INTO `data_source`.`asset_data_source` (`name`, `system_name`, `database_name`, `type`)
VALUES (#{name}, #{systemName}, #{databaseName}, #{type});
</insert>
<insert id="addChildren">
INSERT INTO `data_source`.`children` (`name`, `as`, `data_total`, `type`, `asset_id`)
VALUES (#{name}, #{as}, #{dataTotal}, #{type}, #{assetId});
</insert>
<insert id="addTableData">
INSERT INTO `data_source`.`table_data` (`name`, `comment`, `is_primary_key`, `type`, `mapping_type`, `length`, `decimal_places`, `is_null`, `default_value`, `is_dict`, `dict_key`, `children_id`)
VALUES (#{name}, #{comment}, #{isPrimaryKey}, #{type}, #{mappingType}, #{length}, #{decimalPlaces}, #{isNull}, #{defaultValue}, #{isDict}, #{dictKey}, #{childrenId});
</insert>
<select id="selectAssetList" resultType="com.muyu.data.source.domain.AssetDataSource">
select *
from asset_data_source
</select>
<select id="selectTable" resultType="com.muyu.data.source.domain.resp.Table"> <select id="selectTable" resultType="com.muyu.data.source.domain.resp.Table">
select table_name, select table_name,
@ -60,11 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where table_schema = #{databaseName} where table_schema = #{databaseName}
</select> </select>
<select id="getChildrenList" resultType="com.muyu.data.source.domain.Children">
select *
from children
where asset_id = #{id}
</select>
<select id="selectColumn" resultType="com.muyu.data.source.domain.resp.ColumnResp"> <select id="selectColumn" resultType="com.muyu.data.source.domain.resp.ColumnResp">
SELECT COLUMN_NAME as column_name, SELECT COLUMN_NAME as column_name,
@ -79,26 +57,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where table_schema = #{databaseName} where table_schema = #{databaseName}
AND table_name = #{tableName} AND table_name = #{tableName}
</select> </select>
<select id="getTableDataList" resultType="com.muyu.data.source.domain.TableData">
select * from table_data where children_id=#{id}
</select>
<select id="selectChildren" resultType="com.muyu.data.source.domain.Children">
select * from children
<where>
<if test="id != null">
and asset_id=#{id}
</if>
<if test="tableName != null">
and name=#{tableName}
</if>
</where>
</select>
<select id="selectTableData" resultType="com.muyu.data.source.domain.TableData">
select * from table_data
</select>
<select id="selectChildrenList" resultType="com.muyu.data.source.domain.Children"> <select id="selectChildrenList" resultType="com.muyu.data.source.domain.Children">
select * from children select * from children
</select> </select>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--
1.在mybats的开发中namespace有特殊的意思一定要是对应接口的全限定名
通过namespace可以简历mapper.xml和接口之间的关系(名字不重要,位置不重要)
-->
<mapper namespace="com.muyu.data.source.mapper.TableDataMapper">
</mapper>