feat():展示树形结构信息和表结构
parent
e3f57b5883
commit
b9a19fbdd9
|
@ -2,6 +2,7 @@ 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.Data;
|
||||
|
@ -20,11 +21,11 @@ import lombok.experimental.SuperBuilder;
|
|||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName(value = "asset_data_source")
|
||||
public class AssetDataSource {
|
||||
|
||||
// 主键
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
@ApiModelProperty(name = "编号", value = "编号")
|
||||
private Long id;
|
||||
// 接入数据源名称
|
||||
private String name;
|
||||
|
|
|
@ -23,7 +23,7 @@ public class ShowTableReq {
|
|||
/**
|
||||
* 资产数据源
|
||||
*/
|
||||
private AssetDataSource assetDataSource;
|
||||
private AssetDataSource assetStructure;
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
|
|
|
@ -5,6 +5,7 @@ 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.req.ShowTableReq;
|
||||
import com.muyu.data.source.domain.resp.CountResp;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
@ -147,7 +148,7 @@ public class DataSourceController extends BaseController {
|
|||
* 获取数据库下表描述
|
||||
*/
|
||||
@RequiresPermissions("data:source:childrenlist")
|
||||
@GetMapping("/getChildrenList")
|
||||
@PostMapping("/getChildrenList")
|
||||
public Result<List<Children>> getChildrenList(@RequestBody AssetDataSource assetDataSource){
|
||||
|
||||
return Result.success( dataSourceService.getChildrenList(assetDataSource));
|
||||
|
@ -157,20 +158,11 @@ public class DataSourceController extends BaseController {
|
|||
* 获取表下的字段描述
|
||||
*/
|
||||
@RequiresPermissions("data:source:addtbledate")
|
||||
@GetMapping("/addTbleDate")
|
||||
@PostMapping("/addTableData")
|
||||
public Result addTbleDate(@RequestBody ShowTableReq showTableReq){
|
||||
|
||||
return Result.success( dataSourceService.addTbleDate(showTableReq));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有表结构
|
||||
*/
|
||||
@RequiresPermissions("data:source:selecttablelist")
|
||||
@GetMapping("/selectTableList")
|
||||
public Result<List<TableData>> selectTableList(){
|
||||
|
||||
return Result.success( dataSourceService.selectTableList());
|
||||
dataSourceService.addTbleDate(showTableReq);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
|
@ -192,6 +184,13 @@ public class DataSourceController extends BaseController {
|
|||
List<TableData> tableDataList=dataSourceService.selectTableData(id);
|
||||
return Result.success(tableDataList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单个数据库下表总数
|
||||
*/
|
||||
@GetMapping("/getTableDataCount/{id}")
|
||||
public Result getTableDataCount(@PathVariable("id")Long id){
|
||||
CountResp countResp =dataSourceService.getTableDataCount(id);
|
||||
return Result.success(countResp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,10 +6,11 @@ import com.muyu.data.source.domain.Children;
|
|||
import com.muyu.data.source.domain.TableData;
|
||||
import com.muyu.data.source.domain.resp.ColumnResp;
|
||||
import com.muyu.data.source.domain.resp.Table;
|
||||
import feign.Param;
|
||||
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.data.source.domain.DataSource;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 数据源Mapper接口
|
||||
|
@ -23,6 +24,4 @@ public interface DataSourceMapper extends BaseMapper<DataSource> {
|
|||
List<ColumnResp> selectColumn(@Param("databaseName") String databaseName, @Param("tableName") String tableName);
|
||||
|
||||
List<Table> selectTable(@Param("databaseName") String databaseName);
|
||||
|
||||
List<Children> selectChildrenList();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.muyu.data.source.service;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.data.source.domain.AssetDataSource;
|
||||
import com.muyu.data.source.domain.Children;
|
||||
import com.muyu.data.source.domain.TableData;
|
||||
|
@ -33,12 +32,13 @@ public interface DataSourceService extends IService<DataSource> {
|
|||
|
||||
List<Children> getChildrenList(AssetDataSource assetDataSource );
|
||||
|
||||
Result addTbleDate(ShowTableReq showTableReq);
|
||||
void addTbleDate(ShowTableReq showTableReq);
|
||||
|
||||
List<TableData> selectTableList();
|
||||
|
||||
|
||||
CountResp selectTableDataCount();
|
||||
|
||||
List<TableData> selectTableData(Long id);
|
||||
|
||||
CountResp getTableDataCount(Long id);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.muyu.data.source.service.impl;
|
||||
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.data.source.domain.AssetDataSource;
|
||||
import com.muyu.data.source.domain.Children;
|
||||
import com.muyu.data.source.domain.DatabaseType;
|
||||
|
@ -19,15 +18,11 @@ import java.sql.DriverManager;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.muyu.common.core.utils.ObjUtils;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.muyu.data.source.mapper.DataSourceMapper;
|
||||
import com.muyu.data.source.domain.DataSource;
|
||||
|
@ -192,7 +187,7 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
.name(table.getTableName())
|
||||
.annotation(table.getTableComment())
|
||||
.dataTotal(table.getTableRows())
|
||||
.type("dataTble")
|
||||
.type("dataTable")
|
||||
.assetId(assetDataSource.getId())
|
||||
.build();
|
||||
//添加到数据库
|
||||
|
@ -208,26 +203,35 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
|
||||
|
||||
@Override
|
||||
public Result addTbleDate(ShowTableReq showTableReq) {
|
||||
public void addTbleDate(ShowTableReq showTableReq) {
|
||||
// 查询数据源对象
|
||||
DataSource dataSource = this.getOne(new LambdaQueryWrapper<>() {{
|
||||
eq(DataSource::getName, showTableReq.getAssetDataSource().getName());
|
||||
eq(DataSource::getDatabaseName, showTableReq.getAssetDataSource().getDatabaseName());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
DataSource dataSource = this.getOne(new LambdaQueryWrapper<>() {{
|
||||
eq(DataSource::getName, showTableReq.getAssetStructure().getName());
|
||||
eq(DataSource::getDatabaseName, showTableReq.getAssetStructure().getDatabaseName());
|
||||
}});
|
||||
Children children = childrenService.getOne(new LambdaQueryWrapper<>(){{
|
||||
eq(Children::getAssetId, showTableReq.getAssetDataSource().getId());
|
||||
eq(Children::getName,showTableReq.getTableName());
|
||||
Children children = childrenService.getOne(new LambdaQueryWrapper<>() {{
|
||||
eq(Children::getAssetId, showTableReq.getAssetStructure().getId());
|
||||
eq(Children::getName, showTableReq.getTableName());
|
||||
}});
|
||||
// 获取数据类型对象
|
||||
DatabaseType dataType=databaseTypeService.getOne(new LambdaQueryWrapper<>(){{
|
||||
eq(DatabaseType::getDatabaseName, dataSource.getDataType());
|
||||
}
|
||||
});
|
||||
DatabaseType dataType = databaseTypeService.getOne(new LambdaQueryWrapper<>() {
|
||||
{
|
||||
eq(DatabaseType::getDatabaseName, dataSource.getDataType());
|
||||
}
|
||||
});
|
||||
String jdbcUrl = dataType.getUrlPre() + dataSource.getHost() + ":" + dataSource.getPort() + "/"
|
||||
+ dataSource.getDatabaseName() + "?" + dataSource.getConnectionParam();
|
||||
List<ColumnResp> columnRespList = dataSourceMapper.selectColumn(dataSource.getDatabaseName(),
|
||||
showTableReq.getTableName());
|
||||
List<TableData> tableDataList = tableDataService.list(new LambdaQueryWrapper<>(){{
|
||||
List<TableData> tableDataList = tableDataService.list(new LambdaQueryWrapper<>() {{
|
||||
eq(TableData::getChildrenId, children.getId());
|
||||
}});
|
||||
|
||||
|
@ -252,14 +256,9 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
tableDataService.save(tableData);
|
||||
});
|
||||
}
|
||||
return Result.success();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableData> selectTableList() {
|
||||
List<TableData> tableDataList = tableDataService.list();
|
||||
return tableDataList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CountResp selectTableDataCount() {
|
||||
|
@ -284,6 +283,21 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
return tableDataList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CountResp getTableDataCount(Long id) {
|
||||
List<Children> childrenList = childrenService.list(new LambdaQueryWrapper<>() {{
|
||||
eq(Children::getAssetId, id);
|
||||
}});
|
||||
long size = childrenList.size();
|
||||
long sum = childrenList.stream().mapToLong(Children::getDataTotal).sum();
|
||||
return CountResp.builder()
|
||||
.assetStructureCount(0L)
|
||||
.assetStructureTableCount(size)
|
||||
.assetStructureTableDataCount(sum)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static String getJavaType(String driveClass, String url, String username, String password, String tableName, String columnName) {
|
||||
Connection connection = buildConnection(driveClass, url, username, password);
|
||||
PreparedStatement pst = null;
|
||||
|
|
|
@ -9,7 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="name" column="name" />
|
||||
<result property="systemName" column="system_name" />
|
||||
<result property="databaseName" column="database_name" />
|
||||
<result property="dataType" column="database_type" />
|
||||
<result property="dataType" column="data_type" />
|
||||
<result property="host" column="host" />
|
||||
<result property="port" column="port" />
|
||||
<result property="user" column="user" />
|
||||
|
@ -29,7 +29,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</resultMap>
|
||||
|
||||
<sql id="selectDataSourceVo">
|
||||
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, data_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>
|
||||
|
||||
|
||||
|
@ -57,7 +57,5 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
where table_schema = #{databaseName}
|
||||
AND table_name = #{tableName}
|
||||
</select>
|
||||
<select id="selectChildrenList" resultType="com.muyu.data.source.domain.Children">
|
||||
select * from children
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue