feat:增加了oracle,postgresql,sqlserver()
parent
776e0ab77b
commit
aeca277369
|
@ -21,6 +21,12 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<!-- PostgreSQL JDBC驱动 -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
|
|
@ -1,7 +1,24 @@
|
|||
package com.zx.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
|
||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.common.log.annotation.Log;
|
||||
import com.muyu.common.log.enums.BusinessType;
|
||||
import com.zx.domain.req.AssetModel;
|
||||
import com.zx.service.Impl.AssetModelService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
import static com.muyu.common.core.domain.Result.success;
|
||||
import static com.muyu.common.core.utils.PageUtils.startPage;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
|
@ -10,11 +27,72 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
* @Created: 2024/4/23 8:39
|
||||
*/
|
||||
@RestController
|
||||
public class AssetModulesController {
|
||||
@RequestMapping("/model")
|
||||
public class AssetModulesController extends BaseController {
|
||||
@Autowired
|
||||
private AssetModelService assetModulesService;
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<AssetModel>> list(AssetModel assetModel)
|
||||
{
|
||||
startPage();
|
||||
List<AssetModel> list = assetModulesService.selectAssetModelList(assetModel);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出【请填写功能名称】列表
|
||||
*/
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, AssetModel assetModel)
|
||||
{
|
||||
List<AssetModel> list = assetModulesService.selectAssetModelList(assetModel);
|
||||
ExcelUtil<AssetModel> util = new ExcelUtil<AssetModel>(AssetModel.class);
|
||||
util.exportExcel(response, list, "【请填写功能名称】数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取【请填写功能名称】详细信息
|
||||
*/
|
||||
@GetMapping(value = "/{id}")
|
||||
public Result getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(assetModulesService.selectAssetModelById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*/
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public Result add(@RequestBody AssetModel assetModel)
|
||||
{
|
||||
return toAjax(assetModulesService.insertAssetModel(assetModel));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*/
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public Result edit(@RequestBody AssetModel assetModel)
|
||||
{
|
||||
return toAjax(assetModulesService.updateAssetModel(assetModel));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除【请填写功能名称】
|
||||
*/
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(assetModulesService.deleteAssetModelByIds(ids));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.zx.controller;
|
|||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.common.log.annotation.Log;
|
||||
import com.muyu.common.log.enums.BusinessType;
|
||||
|
@ -11,9 +10,7 @@ import com.muyu.common.security.annotation.RequiresPermissions;
|
|||
import com.zx.domain.req.JdbcClass;
|
||||
import com.zx.service.Impl.KvtService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 控制层
|
||||
|
@ -33,24 +30,53 @@ public class KvtController extends BaseController {
|
|||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*/
|
||||
@RequiresPermissions("kvt:jdbc:list")
|
||||
@RequiresPermissions("system:source:list")
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<JdbcClass>> list(JdbcClass dataSource)
|
||||
public Result<TableDataInfo<JdbcClass>> list(JdbcClass jdbcClass)
|
||||
{
|
||||
startPage();
|
||||
List<JdbcClass> list = kvtService.selectList(dataSource);
|
||||
List<JdbcClass> list = kvtService.selectList(jdbcClass);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出【请填写功能名称】列表
|
||||
*/
|
||||
@PostMapping("/AssetsList")
|
||||
public Result assetsList(@RequestBody JdbcClass jdbcClass)
|
||||
{
|
||||
return kvtService.assesList(jdbcClass);
|
||||
}
|
||||
|
||||
@PostMapping("/SynchronousData")
|
||||
public Result synchronousData(@RequestBody JdbcClass jdbcClass)
|
||||
{
|
||||
return kvtService.synchronousData(jdbcClass);
|
||||
}
|
||||
/**
|
||||
* 数据结构
|
||||
* */
|
||||
@PostMapping("/DataAssetList")
|
||||
public Result dataAssetList(@RequestBody JdbcClass jdbcClass)
|
||||
{
|
||||
return kvtService.dattaList(jdbcClass);
|
||||
}
|
||||
|
||||
@PostMapping("/AssetModelList")
|
||||
public Result assetModelList(@RequestBody JdbcClass jdbcClass)
|
||||
{
|
||||
return kvtService.assrtModelList(jdbcClass);
|
||||
}
|
||||
|
||||
@PostMapping("/StructureList")
|
||||
public Result structureList(@RequestBody JdbcClass jdbcClass)
|
||||
{
|
||||
return kvtService.getTableList(jdbcClass);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取【请填写功能名称】详细信息
|
||||
*/
|
||||
@RequiresPermissions("kvt:jdbc:query")
|
||||
@RequiresPermissions("system:source:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public Result getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
|
@ -60,38 +86,38 @@ public class KvtController extends BaseController {
|
|||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*/
|
||||
@RequiresPermissions("kvt:jdbc:add")
|
||||
@RequiresPermissions("system:source:add")
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public Result add(@RequestBody JdbcClass dataSource)
|
||||
public Result add(@RequestBody JdbcClass jdbcClass)
|
||||
{
|
||||
return toAjax(kvtService.insertJdbc(dataSource));
|
||||
return toAjax(kvtService.insertJdbc(jdbcClass));
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试连接
|
||||
*/
|
||||
@Log(title = "测试连接", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/TestConn")
|
||||
public Result testConnection(@RequestBody JdbcClass dataSource) throws ClassNotFoundException {
|
||||
return kvtService.testConn(dataSource);
|
||||
@PostMapping("/TestConnection")
|
||||
public Result testConnection(@RequestBody JdbcClass jdbcClass) throws ClassNotFoundException {
|
||||
return kvtService.testConn(jdbcClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*/
|
||||
@RequiresPermissions("kvt:jdbc:edit")
|
||||
@RequiresPermissions("system:source:edit")
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public Result edit(@RequestBody JdbcClass dataSource)
|
||||
public Result edit(@RequestBody JdbcClass jdbcClass)
|
||||
{
|
||||
return toAjax(kvtService.updateJdbc(dataSource));
|
||||
return toAjax(kvtService.updateJdbc(jdbcClass));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除【请填写功能名称】
|
||||
*/
|
||||
@RequiresPermissions("kvt:jdbc:remove")
|
||||
@RequiresPermissions("system:source:remove")
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result remove(@PathVariable Long[] ids)
|
||||
|
@ -101,26 +127,6 @@ public class KvtController extends BaseController {
|
|||
|
||||
|
||||
|
||||
@PostMapping("assesList")
|
||||
public Result assesList(@RequestBody JdbcClass jdbcClass){
|
||||
return kvtService.assesList(jdbcClass);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("getDataBig")
|
||||
public Result getDataBig(@RequestBody JdbcClass jdbcClass){
|
||||
return kvtService.getTableList(jdbcClass);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("getCount")
|
||||
public Result getCount(@RequestBody JdbcClass jdbcClass){
|
||||
return kvtService.getCount(jdbcClass);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,234 +0,0 @@
|
|||
package com.zx.domain;
|
||||
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/** 链接数据库的地址
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/4/20 9:37
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class JdbcClass extends BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** $column.columnComment */
|
||||
private Long id;
|
||||
|
||||
/** $column.columnComment */
|
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||
private String dataSourceName;
|
||||
|
||||
/** $column.columnComment */
|
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||
private String linkAddress;
|
||||
|
||||
private String sql;
|
||||
|
||||
private String tableName;
|
||||
|
||||
/** $column.columnComment */
|
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||
private String port;
|
||||
|
||||
/** $column.columnComment */
|
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||
private String databaseName;
|
||||
|
||||
/** $column.columnComment */
|
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||
private String username;
|
||||
|
||||
/** $column.columnComment */
|
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||
private String password;
|
||||
|
||||
/** 数据连接参数 */
|
||||
@Excel(name = "数据连接参数")
|
||||
private String connectionParam;
|
||||
|
||||
/** 初始连接数量 */
|
||||
@Excel(name = "初始连接数量")
|
||||
private Long initNum;
|
||||
|
||||
/** 最大连接数量 */
|
||||
@Excel(name = "最大连接数量")
|
||||
private Long maxNum;
|
||||
|
||||
/** 最大等待时间 */
|
||||
@Excel(name = "最大等待时间")
|
||||
private Long maxWaitTime;
|
||||
|
||||
/** 最大等待次数 */
|
||||
@Excel(name = "最大等待次数")
|
||||
private Long maxWaitSize;
|
||||
|
||||
/** $column.columnComment */
|
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||
private String type;
|
||||
|
||||
/** 数据来源名称 */
|
||||
@Excel(name = "数据来源名称")
|
||||
private String systemName;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
public void setDataSourceName(String dataSourceName)
|
||||
{
|
||||
this.dataSourceName = dataSourceName;
|
||||
}
|
||||
|
||||
public String getDataSourceName()
|
||||
{
|
||||
return dataSourceName;
|
||||
}
|
||||
public void setLinkAddress(String linkAddress)
|
||||
{
|
||||
this.linkAddress = linkAddress;
|
||||
}
|
||||
|
||||
public String getLinkAddress()
|
||||
{
|
||||
return this.linkAddress;
|
||||
}
|
||||
public void setPort(String port)
|
||||
{
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getPort()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
public void setDatabaseName(String databaseName)
|
||||
{
|
||||
this.databaseName = databaseName;
|
||||
}
|
||||
|
||||
public String getDatabaseName()
|
||||
{
|
||||
return databaseName;
|
||||
}
|
||||
public void setUsername(String username)
|
||||
{
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getUsername()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
public void setPassword(String password)
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
public void setConnectionParam(String connectionParam)
|
||||
{
|
||||
this.connectionParam = connectionParam;
|
||||
}
|
||||
|
||||
public String getConnectionParam()
|
||||
{
|
||||
return connectionParam;
|
||||
}
|
||||
public void setInitNum(Long initNum)
|
||||
{
|
||||
this.initNum = initNum;
|
||||
}
|
||||
|
||||
public Long getInitNum()
|
||||
{
|
||||
return initNum;
|
||||
}
|
||||
public void setMaxNum(Long maxNum)
|
||||
{
|
||||
this.maxNum = maxNum;
|
||||
}
|
||||
|
||||
public Long getMaxNum()
|
||||
{
|
||||
return maxNum;
|
||||
}
|
||||
public void setMaxWaitTime(Long maxWaitTime)
|
||||
{
|
||||
this.maxWaitTime = maxWaitTime;
|
||||
}
|
||||
|
||||
public Long getMaxWaitTime()
|
||||
{
|
||||
return maxWaitTime;
|
||||
}
|
||||
public void setMaxWaitSize(Long maxWaitSize)
|
||||
{
|
||||
this.maxWaitSize = maxWaitSize;
|
||||
}
|
||||
|
||||
public Long getMaxWaitSize()
|
||||
{
|
||||
return maxWaitSize;
|
||||
}
|
||||
public void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
public void setSystemName(String systemName)
|
||||
{
|
||||
this.systemName = systemName;
|
||||
}
|
||||
|
||||
public String getSystemName()
|
||||
{
|
||||
return systemName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("dataSourceName", getDataSourceName())
|
||||
.append("linkAddress", getLinkAddress())
|
||||
.append("port", getPort())
|
||||
.append("databaseName", getDatabaseName())
|
||||
.append("username", getUsername())
|
||||
.append("password", getPassword())
|
||||
.append("connectionParam", getConnectionParam())
|
||||
.append("initNum", getInitNum())
|
||||
.append("maxNum", getMaxNum())
|
||||
.append("maxWaitTime", getMaxWaitTime())
|
||||
.append("maxWaitSize", getMaxWaitSize())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("remark", getRemark())
|
||||
.append("type", getType())
|
||||
.append("systemName", getSystemName())
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package com.zx.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangXu
|
||||
* @Created: 2024/4/22 19:13
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Structure {
|
||||
/**
|
||||
*字段
|
||||
* */
|
||||
private String COLUMN_NAME;
|
||||
/**
|
||||
*注释
|
||||
* */
|
||||
private String COLUMN_COMMENT;
|
||||
/**
|
||||
*主键
|
||||
* */
|
||||
private String PRIMARY;
|
||||
/**
|
||||
*数据类型
|
||||
* */
|
||||
private String DATA_TYPE;
|
||||
/**
|
||||
*最大长度
|
||||
* */
|
||||
private String CHARACTER_MAXIMUM;
|
||||
/**
|
||||
*是否为空
|
||||
* */
|
||||
private String IS_NULLABLE;
|
||||
/**
|
||||
*默认值
|
||||
* */
|
||||
private String COLUMN_DEFAULT;
|
||||
/**
|
||||
*类型加长度
|
||||
* */
|
||||
private String COLUMN_TYPE;
|
||||
|
||||
}
|
|
@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
|
@ -15,15 +17,50 @@ import lombok.NoArgsConstructor;
|
|||
@NoArgsConstructor
|
||||
public class TableAssets {
|
||||
|
||||
private String Field;
|
||||
|
||||
private String Type;
|
||||
|
||||
private String Null;
|
||||
|
||||
private String Key;
|
||||
|
||||
private String Default;
|
||||
/**
|
||||
* 字段名
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 字段注释
|
||||
*/
|
||||
private String comment;
|
||||
/**
|
||||
* 是否主键
|
||||
*/
|
||||
private String isPrimaryKey;
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 映射类型
|
||||
*/
|
||||
private String mappingType;
|
||||
/**
|
||||
* 长度
|
||||
*/
|
||||
private String length;
|
||||
/**
|
||||
* 小数位
|
||||
*/
|
||||
private String decimalPlaces;
|
||||
/**
|
||||
* 是否可为空
|
||||
*/
|
||||
private String isNull;
|
||||
/**
|
||||
* 默认值
|
||||
*/
|
||||
private String defaultValue;
|
||||
/**
|
||||
* 是否字典
|
||||
*/
|
||||
private String isDict;
|
||||
/**
|
||||
* 字典key
|
||||
*/
|
||||
private String dictKey;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,10 @@ public class JdbcClass extends BaseEntity {
|
|||
|
||||
/** $column.columnComment */
|
||||
private Long id;
|
||||
/**
|
||||
* 连接驱动
|
||||
* */
|
||||
private String jdbcDriver;
|
||||
|
||||
/** $column.columnComment */
|
||||
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
|
||||
|
@ -69,6 +73,8 @@ public class JdbcClass extends BaseEntity {
|
|||
@Excel(name = "最大等待时间")
|
||||
private Long maxWaitTime;
|
||||
|
||||
private Long count;
|
||||
|
||||
/** 最大等待次数 */
|
||||
@Excel(name = "最大等待次数")
|
||||
private Long maxWaitSize;
|
||||
|
@ -81,8 +87,9 @@ public class JdbcClass extends BaseEntity {
|
|||
@Excel(name = "数据来源名称")
|
||||
private String systemName;
|
||||
|
||||
private String modeName;
|
||||
|
||||
|
||||
private List<String> tableAssetsList;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.zx.domain.response;
|
||||
|
||||
import com.zx.domain.TableAssets;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/4/23 14:29
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TableDetail {
|
||||
/**
|
||||
* 表名称
|
||||
* */
|
||||
private String tableName;
|
||||
/**
|
||||
*表备注
|
||||
* */
|
||||
private String tableComment;
|
||||
/**
|
||||
*数量
|
||||
* */
|
||||
private Long tableCount;
|
||||
/**
|
||||
*整体
|
||||
* */
|
||||
private List<TableAssets> tableAssetsList;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.zx.mapper;
|
||||
|
||||
import com.zx.domain.req.DataAsset;
|
||||
import feign.Param;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import javax.lang.model.type.ArrayType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/4/23 14:33
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataAssetMapper {
|
||||
/**
|
||||
* 查询【请填写功能名称】
|
||||
*
|
||||
* @param id 【请填写功能名称】主键
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
public DataAsset selectDataAssetById(Long id);
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*
|
||||
* @param dataAsset 【请填写功能名称】
|
||||
* @return 【请填写功能名称】集合
|
||||
*/
|
||||
public List<DataAsset> selectDataAssetList(DataAsset dataAsset);
|
||||
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*
|
||||
* @param dataAsset 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDataAsset(DataAsset dataAsset);
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*
|
||||
* @param dataAsset 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDataAsset(DataAsset dataAsset);
|
||||
|
||||
/**
|
||||
* 删除【请填写功能名称】
|
||||
*
|
||||
* @param id 【请填写功能名称】主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDataAssetById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除【请填写功能名称】
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDataAssetByIds(Long[] ids);
|
||||
|
||||
void batchInsert(@Param("dataAssets") ArrayList<DataAsset> dataAssets);
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
package com.zx.mapper;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.zx.domain.req.JdbcClass;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
@ -44,4 +45,8 @@ public interface KvtMapper {
|
|||
* */
|
||||
public int deleteAllJdbc(Long[] ids);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
package com.zx.service.Impl;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
import com.zx.domain.req.DataAsset;
|
||||
import com.zx.domain.req.JdbcClass;
|
||||
import com.zx.mapper.DataAssetMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
* @JdkVersion: 17
|
||||
* @Author: zhangxu
|
||||
* @Created: 2024/4/23 14:40
|
||||
*/
|
||||
public class DataAssetServiceImpl implements DataAssetService{
|
||||
|
||||
@Autowired
|
||||
private DataAssetMapper dataAssetMapper;
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】
|
||||
*
|
||||
* @param id 【请填写功能名称】主键
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
@Override
|
||||
public DataAsset selectDataAssetById(Long id)
|
||||
{
|
||||
return dataAssetMapper.selectDataAssetById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*
|
||||
* @param dataAsset 【请填写功能名称】
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
@Override
|
||||
public List<DataAsset> selectDataAssetList(DataAsset dataAsset)
|
||||
{
|
||||
return dataAssetMapper.selectDataAssetList(dataAsset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*
|
||||
* @param dataAsset 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertDataAsset(DataAsset dataAsset)
|
||||
{
|
||||
dataAsset.setCreateTime(DateUtils.getNowDate());
|
||||
return dataAssetMapper.insertDataAsset(dataAsset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*
|
||||
* @param dataAsset 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateDataAsset(DataAsset dataAsset)
|
||||
{
|
||||
dataAsset.setUpdateTime(DateUtils.getNowDate());
|
||||
return dataAssetMapper.updateDataAsset(dataAsset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除【请填写功能名称】
|
||||
*
|
||||
* @param ids 需要删除的【请填写功能名称】主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDataAssetByIds(Long[] ids)
|
||||
{
|
||||
return dataAssetMapper.deleteDataAssetByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除【请填写功能名称】信息
|
||||
*
|
||||
* @param id 【请填写功能名称】主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDataAssetById(Long id)
|
||||
{
|
||||
return dataAssetMapper.deleteDataAssetById(id);
|
||||
}
|
||||
}
|
|
@ -61,4 +61,9 @@ public interface KvtService {
|
|||
|
||||
|
||||
|
||||
Result synchronousData(JdbcClass jdbcClass);
|
||||
|
||||
Result dattaList(JdbcClass jdbcClass);
|
||||
|
||||
Result assrtModelList(JdbcClass jdbcClass);
|
||||
}
|
||||
|
|
|
@ -5,14 +5,19 @@ import com.muyu.common.core.utils.DateUtils;
|
|||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.zx.domain.AssetsData;
|
||||
import com.zx.domain.DataKvt;
|
||||
import com.zx.domain.req.AssetModel;
|
||||
import com.zx.domain.req.DataAsset;
|
||||
import com.zx.domain.req.JdbcClass;
|
||||
import com.zx.domain.TableAssets;
|
||||
|
||||
import com.zx.mapper.AssetModelMapper;
|
||||
import com.zx.mapper.DataAssetMapper;
|
||||
import com.zx.mapper.KvtMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -29,6 +34,12 @@ public class KvtServiceImpl implements KvtService{
|
|||
@Autowired
|
||||
private KvtMapper kvtMapper;
|
||||
|
||||
@Autowired
|
||||
private DataAssetMapper dataAssetMapper;
|
||||
|
||||
@Autowired
|
||||
private AssetModelMapper assetModelMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public JdbcClass selectJdbcById(Long id) {
|
||||
|
@ -38,39 +49,6 @@ public class KvtServiceImpl implements KvtService{
|
|||
@Override
|
||||
public List<JdbcClass> selectList(JdbcClass jdbcClass) {
|
||||
List<JdbcClass> jdbcClasses = kvtMapper.selectList(jdbcClass);
|
||||
jdbcClasses.stream().map(jdbcClass1 -> {
|
||||
// 获取JdbcClass对象中的数据库连接信息
|
||||
String user= jdbcClass.getUsername();
|
||||
String pwd= jdbcClass.getPassword();
|
||||
String driver="com.mysql.cj.jdbc.Driver";
|
||||
// 构造数据库连接URL
|
||||
String url="jdbc:mysql://"+jdbcClass.getLinkAddress()+":"+jdbcClass.getPort()+"/"+jdbcClass.getDatabaseName();
|
||||
Connection connection =null;
|
||||
Result result = null;
|
||||
try {
|
||||
result = this.testConn(jdbcClass);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (result.getCode()==200){
|
||||
try {
|
||||
Class.forName(driver);
|
||||
connection = DriverManager.getConnection(url,user,pwd);
|
||||
List<String> list = new ArrayList<>();
|
||||
String sql="SELECT table_name FROM information_schema.tables WHERE table_schema = '"+jdbcClass.getDatabaseName()+"'";
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(sql);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
while (resultSet.next()){
|
||||
list.add(resultSet.getString("table_name"));
|
||||
}
|
||||
jdbcClass.setTableAssetsList(list);
|
||||
preparedStatement.close();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}).toList();
|
||||
return jdbcClasses;
|
||||
}
|
||||
|
||||
|
@ -103,8 +81,37 @@ public class KvtServiceImpl implements KvtService{
|
|||
|
||||
@Override
|
||||
public Result testConn(JdbcClass jdbcClass) throws ClassNotFoundException {
|
||||
// 获取JdbcClass对象中的数据库连接信息
|
||||
String user= jdbcClass.getUsername();
|
||||
// // 获取JdbcClass对象中的数据库连接信息
|
||||
// String user= jdbcClass.getUsername();
|
||||
// String pwd= jdbcClass.getPassword();
|
||||
// String driver="com.mysql.cj.jdbc.Driver";
|
||||
// // 构造数据库连接URL
|
||||
// String url="jdbc:mysql://"+jdbcClass.getLinkAddress()+":"+jdbcClass.getPort()+"/"+jdbcClass.getDatabaseName();
|
||||
// // 如果有额外的连接参数,则附加到URL后
|
||||
// if (jdbcClass.getConnectionParam()!=null && jdbcClass.getConnectionParam()!=""){
|
||||
// url=url+"?"+jdbcClass.getConnectionParam();
|
||||
// }
|
||||
// Connection connection=null;
|
||||
// try {
|
||||
// // 加载数据库驱动
|
||||
// Class.forName(driver);
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// // 如果驱动类未找到,返回连接失败信息
|
||||
// return Result.error("连接失败,请检查");
|
||||
// }
|
||||
// try {
|
||||
// // 尝试获取数据库连接并关闭
|
||||
// connection= DriverManager.getConnection(url,user,pwd);
|
||||
// connection.close();
|
||||
// } catch (Exception e) {
|
||||
// // 如果连接过程中出现异常,返回连接失败信息
|
||||
// return Result.error("连接失败");
|
||||
// }
|
||||
// // 连接成功,返回成功信息
|
||||
// return Result.success("连接成功");
|
||||
|
||||
if (jdbcClass.getType().equals("MySql")){
|
||||
String user= jdbcClass.getUsername();
|
||||
String pwd= jdbcClass.getPassword();
|
||||
String driver="com.mysql.cj.jdbc.Driver";
|
||||
// 构造数据库连接URL
|
||||
|
@ -114,23 +121,41 @@ public class KvtServiceImpl implements KvtService{
|
|||
url=url+"?"+jdbcClass.getConnectionParam();
|
||||
}
|
||||
Connection connection=null;
|
||||
try {
|
||||
// 加载数据库驱动
|
||||
Class.forName(driver);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// 如果驱动类未找到,返回连接失败信息
|
||||
return Result.error("连接失败,请检查");
|
||||
try {
|
||||
Class.forName(driver);
|
||||
} catch (ClassNotFoundException e) {
|
||||
return Result.error("连接失败");
|
||||
}
|
||||
try {
|
||||
connection=DriverManager.getConnection(url,user,pwd);
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
return Result.success("连接成功");
|
||||
}
|
||||
}else {
|
||||
String user= jdbcClass.getUsername();
|
||||
String pwd= jdbcClass.getPassword();
|
||||
String driver="org.postgresql.Driver";
|
||||
String uel="jdbc:postgresql://"+jdbcClass.getLinkAddress()+":"+jdbcClass.getPort()+"/"+jdbcClass.getDatabaseName();
|
||||
if (jdbcClass.getConnectionParam()!=null&&jdbcClass.getConnectionParam()!=""){
|
||||
uel=uel+"?"+jdbcClass.getConnectionParam();
|
||||
}
|
||||
Connection connection=null;
|
||||
try {
|
||||
Class.forName(driver);
|
||||
} catch (ClassNotFoundException e) {
|
||||
return Result.error("连接失败");
|
||||
}
|
||||
try {
|
||||
connection=DriverManager.getConnection(uel,pwd,user);
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
return Result.error("链接失败");
|
||||
}
|
||||
|
||||
}
|
||||
try {
|
||||
// 尝试获取数据库连接并关闭
|
||||
connection= DriverManager.getConnection(url,user,pwd);
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
// 如果连接过程中出现异常,返回连接失败信息
|
||||
return Result.error("连接失败");
|
||||
}
|
||||
// 连接成功,返回成功信息
|
||||
return Result.success("连接成功");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -163,7 +188,7 @@ public class KvtServiceImpl implements KvtService{
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
String sql=" SELECT COUNT(*)FROM information_schema.tables WHERE table_schema =?";
|
||||
String sql="SELECT COUNT(*)FROM information_schema.tables WHERE table_schema =?";
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(sql);
|
||||
preparedStatement.setString(1,jdbcClass.getDatabaseName());
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
|
@ -182,6 +207,9 @@ public class KvtServiceImpl implements KvtService{
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public AssetsData getData(JdbcClass jdbcClass){
|
||||
String user=jdbcClass.getUsername();
|
||||
String pwd=jdbcClass.getPassword();
|
||||
|
@ -230,45 +258,103 @@ public class KvtServiceImpl implements KvtService{
|
|||
return assetsData;
|
||||
}
|
||||
|
||||
public List<TableAssets> getTableAssets(JdbcClass jdbcClass){
|
||||
public List<AssetModel> getTableAssets(JdbcClass jdbcClass,String tableName){
|
||||
// 初始化数据库连接信息
|
||||
String user= jdbcClass.getUsername();
|
||||
String pwd= jdbcClass.getPassword();
|
||||
String driver="com.mysql.cj.jdbc.Driver";
|
||||
String url="jdbc:mysql://"+jdbcClass.getLinkAddress()+":"+jdbcClass.getPort()+"/"+jdbcClass.getDatabaseName();
|
||||
String driver="";
|
||||
String url="";
|
||||
url="jdbc:"+jdbcClass.getType().toLowerCase()+"://"+jdbcClass.getLinkAddress()+":"+jdbcClass.getPort()+"/"+jdbcClass.getDatabaseName();
|
||||
if (jdbcClass.getType().equals("mysql")){
|
||||
driver="com.mysql.cj.jdbc.Driver";
|
||||
}else if (jdbcClass.getType().equals("oracle")){
|
||||
driver="oracle.jdbc.driver.OracleDriver";
|
||||
}else if (jdbcClass.getType().equals("sqlserver")){
|
||||
driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
||||
}else if (jdbcClass.getType().equals("postgresql")){
|
||||
driver="org.postgresql.Driver";
|
||||
}
|
||||
if (jdbcClass.getType().equals("oracle")){
|
||||
url="jdbc:oracle:thin:@"+jdbcClass.getLinkAddress()+":"+jdbcClass.getPort()+":"+jdbcClass.getDatabaseName();
|
||||
}
|
||||
if (jdbcClass.getType().equals("postgresql")){
|
||||
url="jdbc:postgresql://"+jdbcClass.getLinkAddress()+":"+jdbcClass.getPort()+"/"+jdbcClass.getDatabaseName();
|
||||
}
|
||||
if (jdbcClass.getType().equals("sqlserver")){
|
||||
url="jdbc:sqlserver://"+jdbcClass.getLinkAddress()+":"+jdbcClass.getPort()+";DatabaseName="+jdbcClass.getDatabaseName();
|
||||
}
|
||||
if (jdbcClass.getType().equals("mysql")){
|
||||
url="jdbc:mysql://"+jdbcClass.getLinkAddress()+":"+jdbcClass.getPort()+"/"+jdbcClass.getDatabaseName();
|
||||
}
|
||||
|
||||
|
||||
// 定义空的connection
|
||||
Connection connection=null;
|
||||
List<TableAssets> tableAssets = new ArrayList<>();
|
||||
List<AssetModel> assetsData = new ArrayList<>();
|
||||
HashMap<String, String> hashMap = new HashMap<>();
|
||||
|
||||
// 尝试加载驱动并建立数据库连接
|
||||
try {
|
||||
Class.forName(driver);
|
||||
Class.forName(jdbcClass.getJdbcDriver());
|
||||
connection=DriverManager.getConnection(url,user,pwd);
|
||||
} catch (SQLException|ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
// 执行SQL查询,获取表的描述信息
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SHOW COLUMNS FROM" + jdbcClass.getTableName());
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT COLUMN_NAME,DATA_TYPE,IS_NULLABLE,COLUMN_KEY,COLUMN_DEFAULT,COLUMN_COMMENT,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '"+jdbcClass.getDatabaseName()+"' AND TABLE_NAME = '"+tableName+"'");
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
|
||||
// 遍历查询结果,填充TableAssets对象列表
|
||||
while (resultSet.next()){
|
||||
TableAssets tableAsset = new TableAssets();
|
||||
tableAsset.setField(resultSet.getString(1));
|
||||
tableAsset.setType(resultSet.getString(2));
|
||||
tableAsset.setNull(resultSet.getString(3));
|
||||
tableAsset.setKey(resultSet.getString(4));
|
||||
tableAsset.setDefault(resultSet.getString(5));
|
||||
tableAssets.add(tableAsset); // 此处应该是将tableAsset添加到list,而不是add(tableAsset)。
|
||||
AssetModel assetModel = new AssetModel();
|
||||
assetModel.setComment(resultSet.getString("COLUMN_COMMENT"));
|
||||
assetModel.setName(resultSet.getString("COLUMN_NAME"));
|
||||
if (resultSet.getString("CHARACTER_MAXIMUM_LENGTH")!=null){
|
||||
assetModel.setLength(resultSet.getString("CHARACTER_MAXIMUM_LENGTH"));
|
||||
}else if (resultSet.getString("NUMERIC_PRECISION")!=null){
|
||||
assetModel.setLength(resultSet.getString("NUMERIC_PRECISION"));
|
||||
}else{
|
||||
assetModel.setLength("-");
|
||||
}
|
||||
if (resultSet.getString("NUMERIC_SCALE")!=null){
|
||||
assetModel.setDecimalPlaces(resultSet.getString("NUMERIC_SCALE"));
|
||||
}else{
|
||||
assetModel.setDecimalPlaces("-");
|
||||
}
|
||||
|
||||
//是否不可为空
|
||||
if (resultSet.getString("IS_NULLABLE").equals("NO")){
|
||||
assetModel.setIsNull("N");
|
||||
}else{
|
||||
assetModel.setIsNull("Y");
|
||||
}
|
||||
//是否有默认值
|
||||
if (resultSet.getString("COLUMN_DEFAULT")!=null){
|
||||
assetModel.setDefaultValue(resultSet.getString("COLUMN_DEFAULT"));
|
||||
}else{
|
||||
assetModel.setDefaultValue("-");
|
||||
}
|
||||
assetModel.setIsDict("");
|
||||
assetModel.setDictKey("");
|
||||
assetModel.setType(resultSet.getString("DATA_TYPE"));
|
||||
//是否主键
|
||||
if ("PRI".equals(resultSet.getString("COLUMN_KEY"))){
|
||||
assetModel.setIsPrimaryKey("Y");
|
||||
}else{
|
||||
assetModel.setIsPrimaryKey("N");
|
||||
}
|
||||
assetModel.setCreateBy(SecurityUtils.getUsername());
|
||||
assetModel.setCreateTime(new Date());
|
||||
assetModel.setMappingType("String");
|
||||
assetsData.add(assetModel);
|
||||
}
|
||||
preparedStatement.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tableAssets;
|
||||
return assetsData;
|
||||
}
|
||||
|
||||
|
||||
|
@ -280,7 +366,7 @@ public class KvtServiceImpl implements KvtService{
|
|||
Connection conn = null;
|
||||
List<Map<String, DataKvt>> kvtList = new ArrayList<>();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
List<TableAssets> tableAssets = getTableAssets(jdbcClass);
|
||||
List<AssetModel> tableAssets = getTableAssets(jdbcClass,jdbcClass.getTableName());
|
||||
try {
|
||||
Class.forName(jdbcDriver);
|
||||
conn = DriverManager.getConnection(jdbcUrl, user, password);
|
||||
|
@ -295,6 +381,9 @@ public class KvtServiceImpl implements KvtService{
|
|||
System.out.println();
|
||||
map.put(rsd.getColumnName(i),substring);
|
||||
}
|
||||
for (AssetModel tableAsset : tableAssets) {
|
||||
tableAsset.setMappingType(map.get(tableAsset.getType()));
|
||||
}
|
||||
preparedStatement.close();
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
@ -305,7 +394,6 @@ public class KvtServiceImpl implements KvtService{
|
|||
AssetsData assetsModule = new AssetsData();
|
||||
assetsModule.setKvtList(kvtList);
|
||||
assetsModule.setTableAssets(map);
|
||||
assetsModule.setTableAssetsList(tableAssets);
|
||||
return assetsModule;
|
||||
}
|
||||
|
||||
|
@ -319,7 +407,66 @@ public class KvtServiceImpl implements KvtService{
|
|||
String pwd=jdbcClass.getPassword();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 数据的同步
|
||||
* */
|
||||
|
||||
@Override
|
||||
public Result synchronousData(JdbcClass jdbcClass) {
|
||||
String mysql = "SELECT TABLE_NAME t_name,TABLE_COMMENT table_comment,TABLE_ROWS table_rows,(SELECT count(*) FROM INFORMATION_SCHEMA.columns WHERE TABLE_SCHEMA = '"+jdbcClass.getDatabaseName()+"' and TABLE_NAME=t_name) fields FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='"+jdbcClass.getDatabaseName()+"'";
|
||||
String user = jdbcClass.getUsername();
|
||||
String pwd = jdbcClass.getPassword();
|
||||
String jdbc = "com.mysql.cj.jdbc.Driver";
|
||||
String jdbcUrl = "jdbc:mysql://" + jdbcClass.getLinkAddress() + ":" + jdbcClass.getPort() + "/" + jdbcClass.getDatabaseName();
|
||||
Connection connection = null;
|
||||
ArrayList<DataAsset> dataAssets = new ArrayList<>();
|
||||
try {
|
||||
Class.forName(jdbc);
|
||||
connection = DriverManager.getConnection(jdbcUrl, user, pwd);
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(mysql);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
DataAsset dataAsset = new DataAsset();
|
||||
dataAsset.setTableName(resultSet.getString("t_name"));
|
||||
dataAsset.setTableComment(resultSet.getString("table_comment"));
|
||||
dataAsset.setTableCount(Long.valueOf(resultSet.getString("table_rows")));
|
||||
dataAsset.setFields(Long.valueOf(resultSet.getString("fields")));
|
||||
dataAsset.setDataSourceId(jdbcClass.getId());
|
||||
dataAsset.setCreateBy(SecurityUtils.getUsername());
|
||||
dataAsset.setCreateTime(new java.util.Date());
|
||||
dataAssets.add(dataAsset);
|
||||
}
|
||||
dataAssetMapper.batchInsert(dataAssets);
|
||||
for (DataAsset dataAsset : dataAssets) {
|
||||
List<AssetModel> tableAssets = getTableAssets(jdbcClass, dataAsset.getTableName());
|
||||
tableAssets.stream().forEach(assetModel -> assetModel.setDataAssetId(dataAsset.getId()));
|
||||
assetModelMapper.batchInsert(tableAssets);
|
||||
}
|
||||
} catch ( SQLException | ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Result dattaList (JdbcClass jdbcClass){
|
||||
DataAsset dataAsset = new DataAsset();
|
||||
dataAsset.setDataSourceId(jdbcClass.getId());
|
||||
List<DataAsset> dataAssets = dataAssetMapper.selectDataAssetList(dataAsset);
|
||||
return Result.success(dataAssets);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result assrtModelList (JdbcClass jdbcClass){
|
||||
AssetModel assetModel = new AssetModel();
|
||||
assetModel.setDataAssetId(jdbcClass.getId());
|
||||
List<AssetModel> assetModels = assetModelMapper.selectAssetModelList(assetModel);
|
||||
return Result.success(assetModels);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue