fix(测试接口)
parent
c584b3995c
commit
6859c23df1
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-common-data-standard</artifactId>
|
||||
<description>muyu-common-data-standard数据标准包</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!--项目核心包-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,45 @@
|
|||
package com.muyu.common.data.standard.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/5
|
||||
* @Description: 数据模型
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DataModel {
|
||||
|
||||
/**
|
||||
* 数据键
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 数据值
|
||||
*/
|
||||
private Object value;
|
||||
|
||||
/**
|
||||
* 源标准-枚举
|
||||
*/
|
||||
private String sourceType;
|
||||
|
||||
/**
|
||||
* 处理标准-枚举
|
||||
*/
|
||||
private String processType;
|
||||
|
||||
/**
|
||||
* 处理类型
|
||||
*/
|
||||
private Class<?> processClass;
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.muyu.common.data.standard.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/5
|
||||
* @Description: 一页
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DataSetModel {
|
||||
|
||||
/**
|
||||
* 集合
|
||||
*/
|
||||
private RecordModel[] dataSetModelArr = null;
|
||||
|
||||
private int setLength ;
|
||||
|
||||
public static DataSetModel build(int dataSetModelLength){
|
||||
return build(new RecordModel[dataSetModelLength]);
|
||||
}
|
||||
|
||||
public static DataSetModel build(RecordModel[] dataSerModel){
|
||||
return DataSetModel.builder()
|
||||
.dataSetModelArr(dataSerModel)
|
||||
.setLength(dataSerModel.length)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.common.data.standard.model;
|
||||
|
||||
import com.muyu.common.data.standard.utils.EtlUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/5
|
||||
* @Description: 记录模型
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RecordModel {
|
||||
/**
|
||||
* 制定主键2
|
||||
*/
|
||||
private String[] keys ;
|
||||
|
||||
/**
|
||||
* 主键数据
|
||||
*/
|
||||
private DataModel[] keyForValue;
|
||||
/**
|
||||
* 单条记录
|
||||
*/
|
||||
private DataModel[] dataModelArr = null;
|
||||
|
||||
private int recordLength;
|
||||
public static RecordModel build(int dataModelLength,String[] keys){
|
||||
return build(new DataModel[dataModelLength],keys);
|
||||
}
|
||||
|
||||
public static RecordModel build(DataModel[] dataModelArr, String[] keys){
|
||||
return RecordModel.builder()
|
||||
.dataModelArr(dataModelArr)
|
||||
.recordLength(dataModelArr.length)
|
||||
.keys(keys)
|
||||
.keyForValue(
|
||||
Arrays.stream(dataModelArr)
|
||||
.filter(dataModel -> EtlUtils.valAsArr(keys,dataModel.getKey()))
|
||||
.toArray(value -> new DataModel[0])
|
||||
)
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.common.data.standard.utils;
|
||||
|
||||
/**
|
||||
* Etl工具类
|
||||
*
|
||||
* @ClassName EtlUtils
|
||||
* @Author AnNan.Wang
|
||||
* @Date 2024/5/15 17:10
|
||||
*/
|
||||
|
||||
|
||||
public class EtlUtils {
|
||||
/**
|
||||
* 判断key是否在数值当中
|
||||
* @param keys key数值
|
||||
* @param key key值
|
||||
* @return 是否存在
|
||||
*/
|
||||
public static boolean valAsArr(String[] keys,String key){
|
||||
for (String _key : keys) {
|
||||
if (_key.equals(key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -16,5 +16,22 @@
|
|||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.2.6</version> <!-- 使用最新的 Druid 版本 -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-data-source-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package com.muyu.method.druid;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.muyu.data.source.domain.DataSource;
|
||||
import jdk.jfr.Label;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.bouncycastle.crypto.macs.HMac;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* druid 德鲁伊连接池配置
|
||||
*
|
||||
* @author AnNan.Wang
|
||||
* @ClassName: druidPort
|
||||
* @createTime: 2024/5/16 14:11
|
||||
*/
|
||||
@Log4j2
|
||||
public class druidPort{
|
||||
|
||||
private static HashMap<String, DruidDataSource> dataSourceMap = new HashMap<>();
|
||||
|
||||
|
||||
//初始化数据库连接池
|
||||
public static void init(DataSource dataSource){
|
||||
DruidDataSource druidDataSource = new DruidDataSource();
|
||||
//用户名
|
||||
druidDataSource.setUsername(dataSource.getDatabaseUserName());
|
||||
//密码
|
||||
druidDataSource.setPassword(dataSource.getDatabaseUserPassword());
|
||||
|
||||
String name =null;
|
||||
|
||||
if (dataSource.getDataAccessTypeId() == 1) {
|
||||
name = "jdbc:mysql://";
|
||||
}else {
|
||||
name = "jdbc:postgresql://";
|
||||
}
|
||||
|
||||
//URL
|
||||
druidDataSource.setUrl(name+dataSource.getHostAddress()+":"+dataSource.getHostPort()+"/"+dataSource.getDatabaseName());
|
||||
|
||||
//初始连接数
|
||||
druidDataSource.setInitialSize(dataSource.getInitialQuantity());
|
||||
//最大活动连接数
|
||||
druidDataSource.setMaxActive(dataSource.getMaximumQuantity());
|
||||
//最小空闲连接数
|
||||
druidDataSource.setMinIdle(dataSource.getMaximumFrequency());
|
||||
//最大等待时间
|
||||
druidDataSource.setMaxWait(dataSource.getMaximumTime());
|
||||
|
||||
try {
|
||||
druidDataSource.init();
|
||||
} catch (SQLException e) {
|
||||
log.info("初始化数据源失败");
|
||||
}
|
||||
dataSourceMap.put(dataSource.getAccessSourceName()+dataSource.getId(),druidDataSource);
|
||||
}
|
||||
|
||||
//获取连接池信息
|
||||
public static void getNum(String key){
|
||||
DruidDataSource druidDataSource = dataSourceMap.get(key);
|
||||
log.info(key + "正在使用连接" + druidDataSource.getActiveCount() + "个,线程数量:" + druidDataSource.getPoolingCount() + "个");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Connection getConnection(String key){
|
||||
DruidDataSource druidDataSource = dataSourceMap.get(key);
|
||||
if (druidDataSource != null) {
|
||||
try {
|
||||
return druidDataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void close(Connection connection){
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
log.error("释放连接失败");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@
|
|||
<module>muyu-common-system</module>
|
||||
<module>muyu-common-cache</module>
|
||||
<module>muyu-common-method</module>
|
||||
<module>muyu-common-data-standard</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>muyu-common</artifactId>
|
||||
|
|
|
@ -7,6 +7,8 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
|||
import com.muyu.data.source.domain.DataSource;
|
||||
import com.muyu.data.source.domain.req.DataSourceQueryReq;
|
||||
import com.muyu.data.source.remote.RemoteDataManagerService;
|
||||
import com.muyu.method.druid.druidPort;
|
||||
import com.muyu.source.clinet.jdbcUtils.JDBCConcreteClass;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
|
@ -35,14 +37,5 @@ public class DataSourceClinetRunner implements ApplicationRunner {
|
|||
TableDataInfo<DataSource> data = list.getData();
|
||||
List<DataSource> rows = data.getRows();
|
||||
|
||||
for (DataSource row : rows) {
|
||||
MysqlPool mysqlPool = new MysqlPool(MysqlPoolConfig.buildConfig(row));
|
||||
mysqlPool.init();
|
||||
Connection connection = mysqlPool.creatConnection();
|
||||
log.info(connection);
|
||||
mysqlPool.reaplase(connection);
|
||||
|
||||
}
|
||||
log.info(rows.size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
package com.muyu.source.clinet.connection.pool;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.muyu.common.core.exception.ServiceException;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.zaxxer.hikari.util.DriverDataSource;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 连接池上下文 (管理连接)
|
||||
*
|
||||
* @ClassName ConnectionPoolContext
|
||||
* @Author AnNan.Wang
|
||||
* @Date 2024/5/15 18:45
|
||||
*/
|
||||
|
||||
@Log4j2
|
||||
public class ConnectionPoolContext {
|
||||
|
||||
private ConnectionPoolContext(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 进行存储所有连接的容器
|
||||
*/
|
||||
private final static ConcurrentHashMap<String, DruidDataSource> connectionPoolContext
|
||||
= new ConcurrentHashMap<>(16);
|
||||
|
||||
/**
|
||||
* 新增连接池
|
||||
* @param key 键
|
||||
* @param druidDataSource 连接池
|
||||
*/
|
||||
public static void setConnection(String key, DruidDataSource druidDataSource){
|
||||
if (connectionPoolContext.containsKey(key)) {
|
||||
throw new ServiceException(
|
||||
StringUtils.format("连接池Key-【{}】已经存在",key)
|
||||
);
|
||||
}
|
||||
connectionPoolContext.put(key, druidDataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过key获取连接池
|
||||
* @param key 键
|
||||
* @return 连接池
|
||||
*/
|
||||
public static DruidDataSource getConnection(String key) {
|
||||
return connectionPoolContext.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过key删除连接池
|
||||
* @param key 键
|
||||
*/
|
||||
public static void removeConnection(String key) {
|
||||
try (DruidDataSource druidDataSource = connectionPoolContext.remove(key)) {
|
||||
druidDataSource.close();
|
||||
}catch (Exception e){
|
||||
log.warn("连接池关闭异常:[{}] - [{}]",key,e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.muyu.source.clinet.connection.service;
|
||||
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.muyu.data.source.domain.DataSource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.muyu.source.clinet.connection.pool.ConnectionPoolContext.*;
|
||||
|
||||
/**
|
||||
* 连接池管理对象
|
||||
*
|
||||
* @ClassName ConnectionPoolManagement
|
||||
* @Author AnNan.Wang
|
||||
* @Date 2024/5/16 19:39
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class ConnectionPoolManagementService {
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
public void init(List<DataSource> dataSources){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public void createPool(DataSource dataSource){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取
|
||||
* @param dataSource
|
||||
*/
|
||||
public DruidPooledConnection get(DataSource dataSource){
|
||||
return getConnection(dataSource.getAccessSourceName());
|
||||
}
|
||||
|
||||
public DruidPooledConnection get(String key){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 还
|
||||
*/
|
||||
|
||||
public void returnConnection(DruidPooledConnection connection){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
|
||||
public void remove(DataSource dataSource){
|
||||
|
||||
}
|
||||
public void remove(String key){
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.muyu.source.clinet.jdbcUtils;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
/**
|
||||
* jdbc抽象类
|
||||
* @author YunFei.Du
|
||||
* @date 15:34 2024/5/14
|
||||
*/
|
||||
|
||||
@Component
|
||||
public abstract class JDBCAbstractClass {
|
||||
|
||||
|
||||
public abstract PreparedStatement getPreparedStatement(Connection connection, String sql);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.source.clinet.jdbcUtils;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* jdbc实体类
|
||||
* @author YunFei.Du
|
||||
* @date 15:36 2024/5/14
|
||||
*/
|
||||
@Log4j2
|
||||
public class JDBCConcreteClass extends JDBCAbstractClass{
|
||||
@Override
|
||||
public PreparedStatement getPreparedStatement(Connection connection,String sql) {
|
||||
try {
|
||||
PreparedStatement preparedStatement = connection.prepareStatement ( sql );
|
||||
log.info ( "查询结果:" + preparedStatement );
|
||||
return preparedStatement;
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException ( e );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,10 +4,7 @@ import com.muyu.common.core.domain.Result;
|
|||
import com.muyu.data.source.domain.Asset;
|
||||
import com.muyu.data.source.service.AssetService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -25,8 +22,8 @@ public class AssetController {
|
|||
@Autowired
|
||||
private AssetService assetService;
|
||||
|
||||
@GetMapping("/assetsList")
|
||||
public Result<List<Asset>> assetsList(){
|
||||
return assetService.assetsList();
|
||||
@PostMapping("/assetsList")
|
||||
public Result<List<Asset>> assetsList(@RequestBody String tableName){
|
||||
return assetService.assetsList(tableName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||
* @createTime: 2024/5/14 10:32
|
||||
*/
|
||||
public interface AssetService extends IService<Asset> {
|
||||
Result<List<Asset>> assetsList();
|
||||
Result<List<Asset>> assetsList(String tableName);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -27,10 +27,18 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset>
|
|||
|
||||
|
||||
@Override
|
||||
public Result<List<Asset>> assetsList() {
|
||||
System.out.println(assetMapper.selectList(null));
|
||||
public Result<List<Asset>> assetsList(String tableName) {
|
||||
System.out.println(assetMapper.selectList(
|
||||
new LambdaQueryWrapper<Asset>(){{
|
||||
eq(Asset::getTableName,tableName);
|
||||
}}
|
||||
));
|
||||
return Result.success(
|
||||
assetMapper.selectList(null)
|
||||
assetMapper.selectList(
|
||||
new LambdaQueryWrapper<Asset>(){{
|
||||
eq(Asset::getTableName,tableName);
|
||||
}}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue