master
parent
eba62a3d7f
commit
e6147847e2
|
@ -0,0 +1,213 @@
|
||||||
|
package com.muyu.common.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.etl.property.domain.req.etlDataScore.EtlDataScoreAddReq;
|
||||||
|
import com.muyu.etl.property.domain.req.etlDataScore.EtlDataScoreUpdReq;
|
||||||
|
import com.muyu.etl.property.pool.config.BaseConfig;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:李庆帅
|
||||||
|
* @Package:com.muyu.etl.domain.resp
|
||||||
|
* @Project:cloud-etl-property
|
||||||
|
* @name:EtlDataScore 数据来源信息实体类
|
||||||
|
* @Date:2024/8/21 11:02
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Tag(name = "数据来源信息")
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName(value = "etl_data_score", autoResultMap = true)
|
||||||
|
public class EtlDataScore extends BaseEntity {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
* */
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long id ;
|
||||||
|
/**
|
||||||
|
* 数据来源名称
|
||||||
|
* */
|
||||||
|
@Excel(name = "数据来源名称")
|
||||||
|
private String name ;
|
||||||
|
|
||||||
|
// /** 数据来源系统名称 */
|
||||||
|
// @Excel(name = "数据来源系统名称")
|
||||||
|
// private String dataSourcesSystemName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据来源类型
|
||||||
|
* */
|
||||||
|
@Excel(name = "数据来源类型")
|
||||||
|
private String type ;
|
||||||
|
/**
|
||||||
|
* 数据来源地址
|
||||||
|
* */
|
||||||
|
@Excel(name = "数据来源地址")
|
||||||
|
private String host ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 来源地址端口号
|
||||||
|
* */
|
||||||
|
@Excel(name = "来源地址端口号")
|
||||||
|
private String port ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存放数据库名称
|
||||||
|
* */
|
||||||
|
@Excel(name = "存放数据库名称")
|
||||||
|
private String databaseName ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库登录名
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
@Excel(name = "数据库登录名")
|
||||||
|
private String userName ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库登录密码
|
||||||
|
* */
|
||||||
|
@Excel(name = "数据库登录密码")
|
||||||
|
private String password ;
|
||||||
|
/**
|
||||||
|
* 数据库字符集编码
|
||||||
|
* */
|
||||||
|
@Excel(name = "数据库字符集编码")
|
||||||
|
private String dbEncoding ;
|
||||||
|
/**
|
||||||
|
* 参数
|
||||||
|
* */
|
||||||
|
@Excel(name = "参数")
|
||||||
|
private String param ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态 1初始化 2 不初始化
|
||||||
|
* */
|
||||||
|
// @Excel(name = "状态")
|
||||||
|
private String status ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始连接数量
|
||||||
|
* */
|
||||||
|
@Excel(name = "初始连接数量")
|
||||||
|
private Integer initCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大连接数量
|
||||||
|
* */
|
||||||
|
@Excel(name = "最大连接数量")
|
||||||
|
private Integer maxCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大等待时间
|
||||||
|
* */
|
||||||
|
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
// @Schema(description = "最大等待时间",defaultValue = "2024-7-31 14:30:29",type = "Date")
|
||||||
|
//3000ms
|
||||||
|
@Excel(name = "最大等待时间")
|
||||||
|
private Integer maxTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大等待次数
|
||||||
|
* */
|
||||||
|
@Excel(name = "最大等待次数")
|
||||||
|
private Integer maxFrequency;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 驱动 com.mysql.cj.jdbc.Driver
|
||||||
|
* */
|
||||||
|
@Excel(name = "驱动",defaultValue = "com.mysql.cj.jdbc.Driver")
|
||||||
|
private String driverName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
@Excel(name = "备注")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 添加
|
||||||
|
// * @param req
|
||||||
|
// * @return
|
||||||
|
// */
|
||||||
|
// public static EtlDataScore addBuild(EtlDataScoreAddReq req){
|
||||||
|
// return EtlDataScore.builder()
|
||||||
|
// .type(req.getType())
|
||||||
|
// .name(req.getName())
|
||||||
|
// .host(req.getHost())
|
||||||
|
// .port(req.getPort())
|
||||||
|
// .databaseName(req.getDatabaseName())
|
||||||
|
// .userName(req.getUserName())
|
||||||
|
// .password(req.getPassword())
|
||||||
|
// .param(req.getParam())
|
||||||
|
// .status(req.getStatus())
|
||||||
|
// .initCount(req.getInitCount())
|
||||||
|
// .maxCount(req.getMaxCount())
|
||||||
|
// .maxTime(req.getMaxTime())
|
||||||
|
// .maxFrequency(req.getMaxFrequency())
|
||||||
|
// .driverName("com.mysql.cj.jdbc.Driver")
|
||||||
|
// .build();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 修改
|
||||||
|
// * @param req
|
||||||
|
// * @return
|
||||||
|
// */
|
||||||
|
// public static EtlDataScore updBuild(EtlDataScoreUpdReq req, Supplier<Long> idSupplier){
|
||||||
|
// return EtlDataScore.builder()
|
||||||
|
// .id(idSupplier.get())
|
||||||
|
// .type(req.getType())
|
||||||
|
// .name(req.getName())
|
||||||
|
// .host(req.getHost())
|
||||||
|
// .port(req.getPort())
|
||||||
|
// .databaseName(req.getDatabaseName())
|
||||||
|
// .userName(req.getUserName())
|
||||||
|
// .password(req.getPassword())
|
||||||
|
// .param(req.getParam())
|
||||||
|
// .status(req.getStatus())
|
||||||
|
// .initCount(req.getInitCount())
|
||||||
|
// .maxCount(req.getMaxCount())
|
||||||
|
// .maxTime(req.getMaxTime())
|
||||||
|
// .maxFrequency(req.getMaxFrequency())
|
||||||
|
// .driverName(req.getDriverName())
|
||||||
|
// .build();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 获取数据库连接
|
||||||
|
// * @return
|
||||||
|
// */
|
||||||
|
// public String getUrl(){
|
||||||
|
// StringBuilder urlSb = new StringBuilder(BaseConfig.MYSQLJDBCPRO);
|
||||||
|
// urlSb.append(this.host);//拼接ip
|
||||||
|
// urlSb.append(":");
|
||||||
|
// urlSb.append(this.port); //拼接端口
|
||||||
|
// urlSb.append("/");
|
||||||
|
// urlSb.append(this.databaseName);//拼接数据库
|
||||||
|
// urlSb.append("?");
|
||||||
|
// urlSb.append(this.param);//useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
|
// return urlSb.toString();
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -81,6 +81,11 @@
|
||||||
<artifactId>cloud-property-common</artifactId>
|
<artifactId>cloud-property-common</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-modules-system</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -73,4 +73,34 @@ public class DataRunNameController {
|
||||||
|
|
||||||
return Result.success(dataRunNameService.findTableValue(dataId,tableName));
|
return Result.success(dataRunNameService.findTableValue(dataId,tableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据类型转换
|
||||||
|
* @par 数据类型转换ID
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
@PostMapping("/selectBasicList")
|
||||||
|
@Operation(summary = "获取数据库名",description = "返回所有数据库以及所有表的结果集")
|
||||||
|
public Result<List<DataValue>> selectBasicList(){
|
||||||
|
|
||||||
|
return Result.success(dataRunNameService.selectBasicList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表中的数据值前台调用 闪闪
|
||||||
|
* @param basicId 响应参数
|
||||||
|
* @param tableName 响应参数
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
@PostMapping("/findTableValueList")
|
||||||
|
@Operation(summary = "获取表中的数据值提供给任务模块调用",
|
||||||
|
description = "获取表中的数据值提供给任务模块调用")
|
||||||
|
public Result findTableValueByTableName(@RequestParam("basicId") Long basicId,
|
||||||
|
@RequestParam("dataId") String dataId,
|
||||||
|
@RequestParam("tableName") String tableName){
|
||||||
|
|
||||||
|
|
||||||
|
List<DataValue> list = dataRunNameService.findTableValueByTableName(basicId,dataId,tableName);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import com.muyu.common.domain.Connect;
|
||||||
import com.muyu.common.domain.DataName;
|
import com.muyu.common.domain.DataName;
|
||||||
import com.muyu.common.domain.DataValue;
|
import com.muyu.common.domain.DataValue;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,4 +38,21 @@ public interface DataRunNameService {
|
||||||
* @return 返回结果
|
* @return 返回结果
|
||||||
*/
|
*/
|
||||||
List<DataValue> findTableValue( String dataId,String tableName);
|
List<DataValue> findTableValue( String dataId,String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据类型转换
|
||||||
|
* @par 数据类型转换ID
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
List<DataValue> selectBasicList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表中的数据值前台调用 闪闪
|
||||||
|
*
|
||||||
|
* @param basicId 响应参数
|
||||||
|
* @param tableName 响应参数
|
||||||
|
* @param dataId
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
List<DataValue> findTableValueByTableName(Long basicId, String dataId, String tableName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,6 +154,8 @@ public class DataRunNameServiceImpl implements DataRunNameService {
|
||||||
public List<DataValue> findTableValue( String dataId,String tableName) {
|
public List<DataValue> findTableValue( String dataId,String tableName) {
|
||||||
DataName byId = dataNameService.getById(dataId);
|
DataName byId = dataNameService.getById(dataId);
|
||||||
MySqlQuery mySqlQuery = new MySqlQuery();
|
MySqlQuery mySqlQuery = new MySqlQuery();
|
||||||
|
// 设置数据源ID
|
||||||
|
mySqlQuery.setDataSourceId(String.valueOf(dataId));
|
||||||
|
|
||||||
DruidDataSource connRs1 = JdbcHelper.getConnRs(byId.getName());
|
DruidDataSource connRs1 = JdbcHelper.getConnRs(byId.getName());
|
||||||
DruidPooledConnection conn = null;
|
DruidPooledConnection conn = null;
|
||||||
|
@ -169,6 +171,15 @@ public class DataRunNameServiceImpl implements DataRunNameService {
|
||||||
try {
|
try {
|
||||||
PreparedStatement preparedStatement = conn.prepareStatement("select * FROM "+tableName);
|
PreparedStatement preparedStatement = conn.prepareStatement("select * FROM "+tableName);
|
||||||
|
|
||||||
|
getDataResult(conn, list, preparedStatement);
|
||||||
|
JdbcHelper.close(conn,null,null);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getDataResult(DruidPooledConnection conn, List<DataValue> list, PreparedStatement preparedStatement) throws SQLException {
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||||
int columnCount = metaData.getColumnCount();
|
int columnCount = metaData.getColumnCount();
|
||||||
|
@ -195,14 +206,60 @@ public class DataRunNameServiceImpl implements DataRunNameService {
|
||||||
list.add(build);
|
list.add(build);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JdbcHelper.close(conn,preparedStatement,resultSet);
|
JdbcHelper.close(null,preparedStatement,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据类型转换
|
||||||
|
* @par 数据类型转换ID
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<DataValue> selectBasicList() {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表中的数据值前台调用 闪闪
|
||||||
|
*
|
||||||
|
* @param basicId 响应参数
|
||||||
|
* @param tableName 响应参数
|
||||||
|
* @param dataId
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<DataValue> findTableValueByTableName(Long basicId, String dataId, String tableName) {
|
||||||
|
{
|
||||||
|
// 创建一个MySQL查询对象
|
||||||
|
MySqlQuery mySqlQuery = new MySqlQuery();
|
||||||
|
// 设置数据源ID
|
||||||
|
mySqlQuery.setDataSourceId(String.valueOf(basicId));
|
||||||
|
// 从服务中获取TableFie对象,根据基本ID
|
||||||
|
TableFie byId = tableFieldService.getById(basicId);
|
||||||
|
// 创建MySQL连接池对象,并初始化
|
||||||
|
DataName byIds = dataNameService.getById(dataId);
|
||||||
|
|
||||||
|
|
||||||
|
// 从连接池获取数据库连接
|
||||||
|
DruidDataSource conn = JdbcHelper.getConnRs(byIds.getName());
|
||||||
|
// 初始化一个列表,用于存储数据值对象
|
||||||
|
List<DataValue> list = new ArrayList<>();
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
try {
|
||||||
|
DruidPooledConnection connection = conn.getConnection();
|
||||||
|
// 准备SQL查询语句
|
||||||
|
connection.prepareStatement("select * FROM "+tableName);
|
||||||
|
// 执行查询,获取结果集
|
||||||
|
getDataResult(connection, list, preparedStatement);
|
||||||
|
// 释放数据库连接
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// 如果发生SQL异常,抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 返回包含数据值的列表
|
||||||
|
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue