Cui YongXing 2024-09-11 09:39:48 +08:00
commit 72b79413c0
81 changed files with 4806 additions and 0 deletions

33
.gitignore vendored 100644
View File

@ -0,0 +1,33 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/
logs
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

16
Dockerfile 100644
View File

@ -0,0 +1,16 @@
#指定构建镜像的起始镜像
FROM anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/dragonwell:17.0.4.0.4.8-standard-ga-8.6
#定义时区参数
ENV TZ=Asia/Shanghai
#设置时区
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo '$TZ' > /etc/timezone
#挂载目录
VOLUME ["/home/logs/cloud-etl-datasources"]
#拷贝执行jar报
COPY ./cloud-datasources-server/target/cloud-datasources.jar /home/app.jar
ENTRYPOINT ["java","-Dfile.encoding=utf-8","-jar"]
CMD ["/home/app.jar"]

View File

@ -0,0 +1,38 @@
<?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>cloud-etl-datasources</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>cloud-datasources-client</artifactId>
<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>cloud-datasources-common</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-etl</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-datasources-remote</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,7 @@
package com.muyu.client.basic;
import com.muyu.common.domain.DataSources;
public interface DataSourceConfig {
public DataSources queryById(Long id);
}

View File

@ -0,0 +1,7 @@
package com.muyu.client.basic.basic;
import com.muyu.common.domain.DataSources;
public interface DataSourceConfig {
public DataSources queryById(Long id);
}

View File

@ -0,0 +1,20 @@
package com.muyu.client.basic.basic.impl;
import com.muyu.client.basic.basic.DataSourceConfig;
import com.muyu.common.domain.DataSources;
import com.muyu.remote.DataSourcesRemote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class DataSourceConfigImpl implements DataSourceConfig {
@Autowired
private DataSourcesRemote dataSourcesRemote;
@Override
public DataSources queryById(Long id) {
return dataSourcesRemote.queryById(id).getData();
}
}

View File

@ -0,0 +1,22 @@
package com.muyu.client.basic.impl;
import com.muyu.client.basic.DataSourceConfig;
import com.muyu.common.domain.DataSources;
import com.muyu.remote.DataSourcesRemote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class DataSourceConfigImpl implements DataSourceConfig {
@Autowired
private DataSourcesRemote dataSourcesRemote;
@Override
public DataSources queryById(Long id) {
return dataSourcesRemote.queryById(id).getData();
}
}

View File

@ -0,0 +1,178 @@
package com.muyu.client.mysql;
import com.muyu.client.basic.DataSourceConfig;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.SpringUtils;
import com.muyu.common.data.base.BaseDataAbsSource;
import com.muyu.common.domain.DataSources;
import com.muyu.etl.domain.DataValue;
import com.muyu.etl.enums.DataType;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.sql.*;
import java.util.concurrent.ConcurrentHashMap;
@Log4j2
@Component
public class MySqlDataSource extends BaseDataAbsSource {
@Autowired
private DataSourceConfig dataSourcesRemote;
@Override
public DataValue getDataValue() {
return null;
}
@Override
public DataValue[] getRow () {
// MySqlQuery query = getQuery();
// String sql = query.getSql();
// Long dataSourceId = query.getDataSourceId();
// ConcurrentHashMap<Integer, DataValue> map = new ConcurrentHashMap<>();
//
// DataSources dataSources = dataSourcesService.getById(dataSourceId);
//
// HikariConfig hikariConfig = new HikariConfig();
// hikariConfig.setPoolName("HikariCP 连接池");
// hikariConfig.setDriverClassName(dataSources.getDriverName());
// hikariConfig.setJdbcUrl(dataSources.getUrl(dataSources)); // 修正这里
// hikariConfig.setUsername(dataSources.getUserName());
// hikariConfig.setPassword(dataSources.getUserPwd());
// hikariConfig.setMinimumIdle(2);
// hikariConfig.setMaximumPoolSize(10);
//
// HikariDataSource hikariDataSource = new HikariDataSource(hikariConfig);
//
// DataValue[] dataValues = null;
//
// try {
// PreparedStatement preparedStatement = conn.prepareStatement(sql);
// ResultSet resultSet = preparedStatement.executeQuery();
// ResultSetMetaData metaData = resultSet.getMetaData();
// int columnCount = metaData.getColumnCount();
// if (resultSet.next()){
// for (int i = 1; i < columnCount; i++) {
// if (resultSet.isFirst()){
// String columnTypeName = metaData.getColumnTypeName(i);
// DatabaseMetaData metadataColumns = conn.getMetaData();
// ResultSet columns = metadataColumns.getColumns(null, null, metaData.getTableName(i), metaData.getColumnName(i));
// String remarks =null;
// while (columns.next()){
// remarks = columns.getString("REMARKS");
// log.info("字段备注:"+remarks);
// }
// DataValue build = DataValue.builder()
// .key(metaData.getColumnName(i))
// .label(remarks)
// .value(resultSet.getObject(i, DataType.convertType(columnTypeName)))
// .type(DataType.findBySqlType(columnTypeName))
// .build();
// map.put(i,build);
// dataValues[i-1]=build;
// }
// }
// }
//
//
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// return dataValues;
return null;
}
@Override
public DataValue[][] getRows () {
MySqlQuery query = getQuery();
Integer one = Math.toIntExact(query.getOne());
Integer two = query.getTwo();
String sql = query.getSql();
Long dataSourceId = query.getDataSourceId();
ConcurrentHashMap<Integer, DataValue> map = new ConcurrentHashMap<>();
DataSources dataSources = dataSourcesRemote.queryById(dataSourceId);
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setPoolName("HikariCP 连接池");
hikariConfig.setDriverClassName(dataSources.getDriverName());
hikariConfig.setJdbcUrl(dataSources.getUrl(dataSources)); // 修正这里
hikariConfig.setUsername(dataSources.getUserName());
hikariConfig.setPassword(dataSources.getUserPwd());
hikariConfig.setMinimumIdle(2);
hikariConfig.setMaximumPoolSize(10);
DataValue[][] dataValues = new DataValue[one][two];
HikariDataSource hikariDataSource = new HikariDataSource(hikariConfig);
try {
Connection conn = hikariDataSource.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(sql);
ResultSet resultSet = preparedStatement.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
int c = 0;
while (resultSet.next()){
for (int i = 1; i <= columnCount; i++) {
if (resultSet.isFirst()){
String columnTypeName = metaData.getColumnTypeName(i);
DatabaseMetaData metaDataColumns = conn.getMetaData();
ResultSet columns = metaDataColumns.getColumns(null, null, metaData.getTableName(i), metaData.getColumnName(i));
String remarks =null;
while (columns.next()){
remarks = columns.getString("REMARKS");
log.info("字段备注:"+remarks);
}
DataValue build = DataValue.builder()
.key(metaData.getColumnName(i))
.label(remarks)
.value(resultSet.getObject(i, DataType.convertType(columnTypeName)))
.type(DataType.findBySqlType(columnTypeName))
.build();
map.put(i,build);
dataValues[c][i-1]=build;
}else {
DataValue build = DataValue.builder()
.key(metaData.getColumnName(i))
.label(map.get(i).getLabel())
.value(resultSet.getObject(i, map.get(i).getType().getTargetType()))
.type(map.get(i).getType())
.build();
dataValues[c][i-1]=build;
}
}
c++;
}
} catch (SQLException e) {
throw new RuntimeException(e);
}finally {
close(hikariDataSource); // 关闭数据源
}
return dataValues;
}
private static void close(HikariDataSource dataSource) {
if (dataSource != null) {
dataSource.close();
}
}
}

View File

@ -0,0 +1,25 @@
package com.muyu.client.mysql;
import com.muyu.common.data.base.BaseQuery;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
@EqualsAndHashCode(callSuper = true)
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class MySqlQuery extends BaseQuery {
private String sql;
private String params;
private Long one;
private Integer two;
}

View File

@ -0,0 +1,2 @@
com.muyu.client.mysql.MySqlDataSource
com.muyu.client.basic.impl.DataSourceConfigImpl

View File

@ -0,0 +1,42 @@
<?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>cloud-etl-datasources</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>cloud-datasources-common</artifactId>
<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>cloud-common-core</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-etl</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,21 @@
package com.muyu.common.data.base;
/**
* @Authorzhangzhihao
* @nameBaseDataAbsSource
* @Date2024/8/28 19:07
*
*/
public abstract class BaseDataAbsSource implements BaseDataSource{
@Override
public void setQuery(BaseQuery baseQuery){
BaseQueryHandler.set(baseQuery);
}
@Override
public <T> T getQuery(){
return BaseQueryHandler.get();
}
}

View File

@ -0,0 +1,28 @@
package com.muyu.common.data.base;
/**
* @Authorzhangzhihao
* @nameBaseDataSource
* @Date2024/8/28 18:50
*
*/
import com.muyu.etl.domain.DataValue;
/**
*
*/
public interface BaseDataSource {
public void setQuery(BaseQuery baseQuery);
public <T> T getQuery();
public DataValue getDataValue();
DataValue[] getRow();
DataValue[][] getRows();
}

View File

@ -0,0 +1,20 @@
package com.muyu.common.data.base;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* @Authorzhangzhihao
* @nameBaseQuery
* @Date2024/8/28 18:54
*
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class BaseQuery {
private Long dataSourceId;
}

View File

@ -0,0 +1,24 @@
package com.muyu.common.data.base;
/**
* @Authorzhangzhihao
* @nameBaseQueryHandler
* @Date2024/8/28 19:02
*
*/
/**
*
*/
public class BaseQueryHandler {
private static final ThreadLocal<BaseQuery> BASE_QUERY_THREAD_LOCAL = new ThreadLocal<>();
public static void set(BaseQuery baseQuery){
BASE_QUERY_THREAD_LOCAL.set(baseQuery);
}
public static <T> T get(){
return (T) BASE_QUERY_THREAD_LOCAL.get();
}
}

View File

@ -0,0 +1,23 @@
package com.muyu.common.data.redis;
import com.muyu.common.data.base.BaseDataAbsSource;
import com.muyu.etl.domain.DataValue;
public class RedisDataSource extends BaseDataAbsSource {
@Override
public DataValue getDataValue () {
return null;
}
@Override
public DataValue[] getRow () {
return new DataValue[0];
}
@Override
public DataValue[][] getRows () {
return new DataValue[0][];
}
}

View File

@ -0,0 +1,8 @@
package com.muyu.common.data.redis;
import com.muyu.common.data.base.BaseQuery;
public class RedisQuery extends BaseQuery {
}

View File

@ -0,0 +1,57 @@
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 lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* @Authorzhangzhihao
* @nameassetAccredit
* @Date2024/8/30 9:29
*
*/
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@TableName(value="asset_accredit")
public class AssetAccredit extends BaseEntity {
/**
*
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* id
*/
@Excel(name = "数据源ID")
private Long basicId;
/**
* id
*/
@Excel(name = "表ID")
private Long tableId;
/**
* id
*/
@Excel(name = "部门ID")
private Long deptId;
/**
* id
*/
@Excel(name = "用户ID")
private Long userId;
}

View File

@ -0,0 +1,119 @@
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.pool.base.BaseConfig;
import com.muyu.common.core.web.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* ;
* @author : http://www.chiner.pro
* @date : 2024-8-21
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@TableName(value="data_sources")
public class DataSources extends BaseEntity {
/** id */
@TableId(type = IdType.AUTO)
private Long id ;
/** 数据来源类型 */
@Excel(name = "数据来源类型")
private String type ;
/** 数据来源名称 */
@Excel(name = "数据来源名称")
private String name ;
/** 数据来源地址ip */
@Excel(name = "数据来源地址ip")
private String ip ;
/** 来源地址端口号 */
@Excel(name = "来源地址端口号")
private String port ;
/** 存放数据库名称 */
@Excel(name = "存放数据库名称")
private String databaseName ;
/** 数据库登录名 */
@Excel(name = "数据库登录名")
private String userName ;
/** 数据库登录密码 */
@Excel(name = "数据库登录密码")
private String userPwd ;
/** 参数 */
@Excel(name = "连接参数配置")
private String param ;
/** 状态 1初始化 2不初始化 */
@Excel(name = "是否初始化:1初始化,2不初始化")
private Integer status ;
/** 初始连接数量 */
@Excel(name = "初始连接数量")
private Integer initCount;
/** 最大连接数量 */
@Excel(name = "最大连接数量")
private Integer maxCount;
/** 最大等待时间 */
@Excel(name = "最大等待时间")
private Integer maxTime;
/** 最大等待次数 */
@Excel(name = "最大等待次数")
private Integer maxFrequency;
/** 驱动 com.mysql.cj.jdbc.Driver */
@Excel(name = "连接驱动")
private String driverName;
/**
* mysql
* @return
*/
public String getUrl(DataSources dataSources){
StringBuilder urlSb = new StringBuilder(BaseConfig.MYSQLJDBCPRO);
urlSb.append(dataSources.ip);//拼接ip
urlSb.append(":");
urlSb.append(dataSources.port); //拼接端口
urlSb.append("/");
urlSb.append(dataSources.databaseName);//拼接数据库
urlSb.append("?");
urlSb.append(dataSources.param);//useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
return urlSb.toString();
}
/**
* mysql
* @return
*/
public String getOracleUrl(DataSources dataSources){
StringBuilder urlSb = new StringBuilder(BaseConfig.ORACLEJDBCPRO);
urlSb.append(dataSources.ip);//拼接ip
urlSb.append(":");
urlSb.append(dataSources.port); //拼接端口
urlSb.append(":");
urlSb.append(dataSources.getParam());//PDB
return urlSb.toString();
}
}

View File

@ -0,0 +1,50 @@
package com.muyu.common.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* @Authorzhangzhihao
* @nameDictionaryData
* @Date2024/8/25 9:39
*
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@TableName(value="dictionary_data")
public class DictionaryData extends BaseEntity {
/**
* id
* */
@Excel(name = "主键ID")
private Long id;
/**
* id
* */
@Excel(name = "字典表ID")
private Long dictionaryId;
/**
*
* */
@Excel(name = "字典标签")
private String label;
/**
*
* */
@Excel(name = "字典值")
private String val;
@Excel(name = "是否修改")
private Boolean isEdit=false;
}

View File

@ -0,0 +1,35 @@
package com.muyu.common.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.muyu.common.core.annotation.Excel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* @Authorzhangzhihao
* @nameaddInvoke
* @Date2024/9/4 20:26
*
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class InvokeLog {
@Excel(name = "主键")
@TableId
private Long id;
@Excel(name = "用户ID")
private Long userId;
@Excel(name = "调用方法")
private String methodName;
@Excel(name = "调用时间")
private Date time;
}

View File

@ -0,0 +1,78 @@
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 lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@TableName(value ="structure",autoResultMap = true) //数据库表相关
public class Structure extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/** 表id */
@Excel(name = "表id")
private Long tableId;
/** 字段名称 */
@Excel(name = "字段名称")
private String columnName;
/** 字段注释 */
@Excel(name = "字段注释")
private String columnRemark;
/** 是否主键 'Y'是主键 'N'不是主键 */
@Excel(name = "是否主键 'Y'是主键 'N'不是主键")
private String isPrimary;
/** 数据类型 */
@Excel(name = "数据类型")
private String columnType;
/** 映射类型 */
@Excel(name = "映射类型")
private String javaType;
/** 字段长度 */
@Excel(name = "字段长度")
private String columnLength;
/** 小数位数 */
@Excel(name = "小数位数")
private String columnDecimals;
/** 是否为空 'Y'是 'N'不是 */
@Excel(name = "是否为空 'Y'是 'N'不是")
private String isNull;
/** 默认值 */
@Excel(name = "默认值")
private String defaultValue;
/** 是否字典 'Y'是 'N'不是 */
@Excel(name = "是否字典 'Y'是 'N'不是")
private String isDictionary;
/** 映射字典 */
@Excel(name = "映射字典")
private String dictionaryTable;
}

View File

@ -0,0 +1,67 @@
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.common.domain.resp.TableInfoResp;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@TableName(value ="table_info") //数据库表相关
public class TableInfo extends BaseEntity {
/** 主键 */
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@Excel(name = "数据源ID")
private Long basicId;
/** 表名称/数据库 */
@Excel(name = "表名称/数据库")
private String tableName;
/** 表备注 */
@Excel(name = "表备注")
private String tableRemark;
/** 表备注 */
@Excel(name = "数据来源类型")
private String type;
/** 数据量 */
@Excel(name = "数据量")
private Long dataNum;
/** 是否核心 'Y'是 'N'不是 */
@Excel(name = "是否核心 'Y'是 'N'不是")
private String isCenter;
@Excel(name = "父ID")
private Long parentId;
public static TableInfoResp toTableInfoResp(TableInfo tableInfo) {
return TableInfoResp.builder()
.id(tableInfo.id)
.basicId(tableInfo.basicId)
.tableName(tableInfo.tableName)
.tableRemark(tableInfo.tableRemark)
.isCenter(tableInfo.isCenter)
.dataNum(tableInfo.dataNum)
.build();
}
}

View File

@ -0,0 +1,38 @@
package com.muyu.common.domain.req;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* @Authorzhangzhihao
* @nameassetAccreditReq
* @Date2024/8/30 9:31
*
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class AssetAccreditReq {
/**
* id
*/
private Long basicId;
/**
* id
*/
private Long tableId;
/**
* id
*/
private Long deptId;
/**
* id
*/
private Long userId;
}

View File

@ -0,0 +1,103 @@
package com.muyu.common.domain.req;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.common.domain.DictionaryData;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameAssetModel
* @Date2024/8/25 9:36
*
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@TableName(value="asset_model")
public class AssetModel extends BaseEntity {
/**
*
*
* **/
private Long id;
/**
*id
*
* **/
private Long dataAssetId;
/**
*
*
* **/
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 isDict;
/**
*
*
* **/
private String defaultValue;
/**
*key
*
* **/
private String dictKey;
/**
*
* key
* */
private Long dictionaryId;
/**
*
* */
private List<DictionaryData> dictionaryDataList;
}

View File

@ -0,0 +1,28 @@
package com.muyu.common.domain.req;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Authorzhangzhihao
* @nameDataSourcesReq
* @Date2024/8/21 20:55
*
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DataSourcesReq {
/** 数据来源名称 */
private String name ;
/** 存放数据库名称 */
private String databaseName ;
private Integer pageNum=1;
private Integer pageSize=3;
}

View File

@ -0,0 +1,28 @@
package com.muyu.common.domain.resp;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Authorzhangzhihao
* @nameAssetAccreditResp
* @Date2024/8/31 19:02
*
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AssetAccreditResp {
private Long basicId;
private Long tableId;
}

View File

@ -0,0 +1,47 @@
package com.muyu.common.domain.resp;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.domain.TableInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TableInfoResp {
/**
* id
*/
private Long id;
private Long basicId;
/**
* /
*/
private String tableName;
/**
*
*/
private String tableRemark;
/** 数据量 */
private Long dataNum;
/** 是否核心 'Y'是 'N'不是 */
private String isCenter;
/**
*
*/
private List<TableInfoResp> children;
}

View File

@ -0,0 +1,43 @@
package com.muyu.common.pool;
/**
* @Authorzhangzhihao
* @nameBasePool
* @Date2024/8/22 17:42
*
*
*/
public interface BasePool<T> {
/**
*
*/
public void init();
/**
*
* @return
*/
public T getConn();
/**
*
* @param conn
*/
public void replease(T conn);
/**
*
* @return
*/
public T createConn();
/**
*
*/
public void closeConn();
}

View File

@ -0,0 +1,30 @@
package com.muyu.common.pool;
import com.muyu.common.domain.DataSources;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import jakarta.validation.constraints.NotNull;
//连接池供所有连接是调用
public class HikariPool {
public static HikariDataSource instance = null;
@NotNull
public static synchronized HikariDataSource getHikariDataSource(DataSources dataSources) {
if(instance == null) {
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setPoolName("HikariCP 连接池");
hikariConfig.setDriverClassName(dataSources.getDriverName());
hikariConfig.setJdbcUrl(dataSources.getUrl(dataSources));
hikariConfig.setUsername(dataSources.getUserName());
hikariConfig.setPassword(dataSources.getUserPwd());
hikariConfig.setMaximumPoolSize(10);
hikariConfig.setMinimumIdle(2);
hikariConfig.setConnectionTimeout(60000); // 连接超时时间(毫秒)
hikariConfig.setIdleTimeout(600000);
instance = new HikariDataSource(hikariConfig);
}
return instance;
}
}

View File

@ -0,0 +1,218 @@
package com.muyu.common.pool;
import com.muyu.common.domain.DataSources;
import com.muyu.common.pool.base.BaseConfig;
import com.muyu.common.pool.exeption.MysqlConnException;
import lombok.extern.log4j.Log4j2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @Authorzhangzhihao
* @nameMysqlPool
* @Date2024/8/22 17:21
*
* Mysql
*/
@Log4j2
public class MysqlPool implements BasePool<Connection> {
/**
*
*/
private Queue<Connection> mysqlConnQueue = null;
/**
*
*/
private Queue<Connection> activeMysqlConnQueue =null;
/**
*
*/
private AtomicInteger count = new AtomicInteger();
/**
* mysql
*/
public DataSources dataSources;
/**
* ,
* @param dataSources
*/
public MysqlPool(DataSources dataSources){
log.info("MySQL连接池实例化完成");
this.dataSources=dataSources;
BaseConfig.driver(dataSources.getDriverName());
}
/**
*
*/
@Override
public void init() {
Integer maxCount = this.dataSources.getMaxCount();
Integer initCount = this.dataSources.getInitCount();
this.mysqlConnQueue = new LinkedBlockingQueue<Connection>(maxCount);
this.activeMysqlConnQueue=new LinkedBlockingQueue<Connection>(maxCount);
for (Integer i = 0; i < initCount; i++) {
this.mysqlConnQueue.offer(createConn());
count.incrementAndGet();
}
log.info("MySQL连接池初始化完成");
}
/**
*1.
* 2.
* 3
* 4
* 5()
* 6
* 7使
* 8
* @return
*/
@Override
public Connection getConn() {
long startTime = System.currentTimeMillis();
while (true){
//从空闲队列当中取出放入活动队列
Connection conn = this.mysqlConnQueue.poll();
if (conn!=null){
this.activeMysqlConnQueue.offer(conn);
return conn;
}
//如果当前的连接数量小于最大的连接数量的时候就进行创建新的连接
if (count.get() < dataSources.getMaxCount()){
Connection mysqlConn = createConn();
this.activeMysqlConnQueue.offer(mysqlConn);
count.incrementAndGet();
return mysqlConn;
}
if ((System.currentTimeMillis() - startTime)>this.dataSources.getMaxTime()){
throw new MysqlConnException("连接超时!");
}
// 等待一段时间再尝试
try {
TimeUnit.MILLISECONDS.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("等待连接时中断", e);
}
}
}
/**
*
* @param conn
*/
@Override
public void replease(Connection conn) {
//删除活动队列当中的连接
if (this.activeMysqlConnQueue.remove(conn)){
//把这个连接放入到空闲队列当中
this.mysqlConnQueue.offer(conn);
}
}
/**
* mysql
* @return
*/
@Override
public Connection createConn(){
String url = this.dataSources.getUrl(dataSources);
String userName = this.dataSources.getUserName();
String userPwd = this.dataSources.getUserPwd();
Connection mysqlConn=null;
try {
mysqlConn = DriverManager.getConnection(url, userName, userPwd);
} catch (SQLException e) {
throw new RuntimeException(e);
}
log.info("初始化了一个数据库连接:{ip:"+this.dataSources.getIp()+" port:"+this.dataSources.getPort()+"databaseName"+this.dataSources.getDatabaseName()+" }");
return mysqlConn;
}
@Override
public void closeConn() {
closeBaseConn();
closeActiveConn();
}
/**
*
*/
public void closeBaseConn() {
//从空闲连接当中拿出一个连接 准备进行关闭
//如何拿出的这个链接为null 表示以列当中没有连接信息
Connection poll = this.mysqlConnQueue.poll();
if (poll!=null){
try {
poll.close();
} catch (SQLException e) {
try {
//判断这个接是否被关闭了,如果连接被关闭则不需要放入队列当中
//如何这个链接没有被关闭 则放入队列当中 尝试下次关闭
if (!poll.isClosed()){
this.mysqlConnQueue.offer(poll);
}
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
throw new RuntimeException(e);
}finally {
closeBaseConn();
}
}
}
/**
*
*/
public void closeActiveConn() {
//从空闲连接当中拿出一个连接 准备进行关闭
//如何拿出的这个链接为null 表示以列当中没有连接信息
Connection poll = this.activeMysqlConnQueue.poll();
if (poll!=null){
try {
poll.close();
} catch (SQLException e) {
try {
//判断这个接是否被关闭了,如果连接被关闭则不需要放入队列当中
//如何这个链接没有被关闭 则放入队列当中 尝试下次关闭
if (!poll.isClosed()){
this.activeMysqlConnQueue.offer(poll);
}
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
throw new RuntimeException(e);
}finally {
closeActiveConn();
}
}
}
}

View File

@ -0,0 +1,211 @@
package com.muyu.common.pool;
import com.muyu.common.domain.DataSources;
import com.muyu.common.pool.base.BaseConfig;
import com.muyu.common.pool.exeption.OracleConnException;
import lombok.extern.log4j.Log4j2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @Authorzhangzhihao
* @nameOraclePool
* @Date2024/8/22 17:21
*
* Oracle
*/
@Log4j2
public class OraclePool implements BasePool<Connection> {
/**
*
*/
private Queue<Connection> oracleConnQueue = null;
/**
*
*/
private Queue<Connection> activeOracleConnQueue =null;
/**
*
*/
private AtomicInteger count = new AtomicInteger();
/**
* oracle
*/
public DataSources dataSources;
/**
* ,
* @param dataSources
*/
public OraclePool(DataSources dataSources){
log.info("oracle连接池实例化完成");
this.dataSources=dataSources;
BaseConfig.driver(dataSources.getDriverName());
}
/**
*
*/
@Override
public void init() {
Integer maxCount = this.dataSources.getMaxCount();
Integer initCount = this.dataSources.getInitCount();
this.oracleConnQueue = new LinkedBlockingQueue<Connection>(maxCount);
this.activeOracleConnQueue=new LinkedBlockingQueue<Connection>(maxCount);
for (Integer i = 0; i < initCount; i++) {
this.oracleConnQueue.offer(createConn());
count.incrementAndGet();
}
log.info("oracle连接池初始化完成");
}
/**
*1.
* 2.
* 3
* 4
* 5()
* 6
* 7使
* 8
* @return
*/
@Override
public Connection getConn() {
long startTime = System.currentTimeMillis();
while (true){
//从空闲队列当中取出放入活动队列
Connection conn = this.oracleConnQueue.poll();
if (conn!=null){
this.activeOracleConnQueue.offer(conn);
return conn;
}
//如果当前的连接数量小于最大的连接数量的时候就进行创建新的连接
if (count.get() < dataSources.getMaxCount()){
Connection oracleConn = createConn();
this.activeOracleConnQueue.offer(oracleConn);
count.incrementAndGet();
return oracleConn;
}
if ((System.currentTimeMillis() - startTime)>this.dataSources.getMaxTime()){
throw new OracleConnException("连接超时!");
}
}
}
/**
*
* @param conn
*/
@Override
public void replease(Connection conn) {
//删除活动队列当中的连接
if (this.activeOracleConnQueue.remove(conn)){
//把这个连接放入到空闲队列当中
this.oracleConnQueue.offer(conn);
}
}
/**
* oracle
* @return
*/
@Override
public Connection createConn(){
String url = this.dataSources.getOracleUrl(dataSources);
String userName = this.dataSources.getUserName();
String userPwd = this.dataSources.getUserPwd();
Connection oracleConn=null;
try {
oracleConn = DriverManager.getConnection(url, userName, userPwd);
} catch (SQLException e) {
throw new RuntimeException(e);
}
log.info("初始化了一个数据库连接:{ip:"+this.dataSources.getIp()+" port:"+this.dataSources.getPort()+"databaseName"+this.dataSources.getDatabaseName()+" }");
return oracleConn;
}
@Override
public void closeConn() {
closeBaseConn();
closeActiveConn();
}
/**
*
*/
public void closeBaseConn() {
//从空闲连接当中拿出一个连接 准备进行关闭
//如何拿出的这个链接为null 表示以列当中没有连接信息
Connection poll = this.oracleConnQueue.poll();
if (poll!=null){
try {
poll.close();
} catch (SQLException e) {
try {
//判断这个接是否被关闭了,如果连接被关闭则不需要放入队列当中
//如何这个链接没有被关闭 则放入队列当中 尝试下次关闭
if (!poll.isClosed()){
this.oracleConnQueue.offer(poll);
}
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
throw new RuntimeException(e);
}finally {
closeBaseConn();
}
}
}
/**
*
*/
public void closeActiveConn() {
//从空闲连接当中拿出一个连接 准备进行关闭
//如何拿出的这个链接为null 表示以列当中没有连接信息
Connection poll = this.activeOracleConnQueue.poll();
if (poll!=null){
try {
poll.close();
} catch (SQLException e) {
try {
//判断这个接是否被关闭了,如果连接被关闭则不需要放入队列当中
//如何这个链接没有被关闭 则放入队列当中 尝试下次关闭
if (!poll.isClosed()){
this.activeOracleConnQueue.offer(poll);
}
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
throw new RuntimeException(e);
}finally {
closeActiveConn();
}
}
}
}

View File

@ -0,0 +1,156 @@
package com.muyu.common.pool;
import com.muyu.common.domain.DataSources;
import com.muyu.common.pool.exeption.RedisConnException;
import lombok.extern.log4j.Log4j2;
import redis.clients.jedis.Jedis;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @Authorzhangzhihao
* @nameRedisPool
* @Date2024/8/24 18:37
*
*/
@Log4j2
public class RedisPool implements BasePool<Jedis>{
/**
*
*/
private Queue<Jedis> jedisBaseConnQueue = null;
/**
*
*/
private Queue<Jedis> jedisActiveConnQueue = null;
/**
*
*/
private AtomicInteger count=null;
/**
* redisPoolConfig
*/
private DataSources dataSources=null;
/**
*
* @param dataSources
*/
public RedisPool(DataSources dataSources) {
log.info("redis连接池实例化完成");
this.dataSources = dataSources;
}
@Override
public void init() {
Integer maxCount = this.dataSources.getMaxCount();
this.jedisBaseConnQueue = new LinkedBlockingQueue<Jedis>(maxCount);
this.jedisActiveConnQueue = new LinkedBlockingQueue<Jedis>(maxCount);
this.count = new AtomicInteger();
Integer initCount = this.dataSources.getInitCount();
for (Integer i = 0; i < initCount; i++) {
this.jedisBaseConnQueue.offer(createConn());
count.incrementAndGet();
}
log.info("redis连接池初始化完成!");
}
@Override
public Jedis getConn() {
long startTime = System.currentTimeMillis();
while (true){
Jedis jedis = this.jedisBaseConnQueue.poll();
if (jedis!=null){
this.jedisActiveConnQueue.offer(jedis);
return jedis;
}
if (count.get()<this.dataSources.getMaxCount()){
jedis = createConn();
this.jedisActiveConnQueue.offer(jedis);
count.incrementAndGet();
return jedis;
}
if (System.currentTimeMillis() -startTime > this.dataSources.getMaxTime()){
throw new RedisConnException("redis获取连接超时!");
}
}
}
@Override
public void replease(Jedis conn) {
if (this.jedisActiveConnQueue.remove(conn)){
this.jedisBaseConnQueue.offer(conn);
}else {
count.decrementAndGet();
}
}
@Override
public Jedis createConn() {
String ip = this.dataSources.getIp();
String port = this.dataSources.getPort();
Jedis jedis = new Jedis(ip, Integer.parseInt(port));
log.info("初始化了一个redis的连接,{ip:"+ip+" port:"+port+"}");
return jedis;
}
@Override
public void closeConn() {
closeJedisBaseConn();
closeJedisActiveConn();
}
public void closeJedisBaseConn(){
Jedis jedis = this.jedisBaseConnQueue.poll();
if (jedis!=null){
try {
jedis.close();
} catch (Exception e) {
if (!jedis.isConnected()){
this.jedisBaseConnQueue.offer(jedis);
}
throw new RuntimeException(e);
}finally {
closeJedisBaseConn();
}
}
}
public void closeJedisActiveConn(){
Jedis jedis = this.jedisActiveConnQueue.poll();
if (jedis!=null){
try {
jedis.close();
} catch (Exception e) {
if (!jedis.isConnected()){
this.jedisActiveConnQueue.offer(jedis);
}
throw new RuntimeException(e);
}finally {
closeJedisActiveConn();
}
}
}
}

View File

@ -0,0 +1,33 @@
package com.muyu.common.pool.base;
/**
* @Authorzhangzhihao
* @nameBaseConfig
* @Date2024/8/22 17:03
*
*/
public class BaseConfig {
/**
* mysql
*/
public static final String MYSQLJDBCPRO="jdbc:mysql://";
public static final String ORACLEJDBCPRO="jdbc:oracle:thin:@";
public static final String SHOWTABLES="show TABLES";
public static final String SELECTCOUNT="SELECT count(1) as count FROM ";
public static final String SHOW_FULL_FIELDS_FROM="SHOW FULL FIELDS FROM ";
public static final String SELECT="select ";
public static final String SELECTALL="select * from ";
public static final String FROM=" from ";
public static void driver(String driverName){
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,13 @@
package com.muyu.common.pool.exeption;
/**
* @Authorzhangzhihao
* @nameMysqlConnException
* @Date2024/8/22 19:04
*
*/
public class MysqlConnException extends RuntimeException{
public MysqlConnException(String message) {
super(message);
}
}

View File

@ -0,0 +1,13 @@
package com.muyu.common.pool.exeption;
/**
* @Authorzhangzhihao
* @nameMysqlConnException
* @Date2024/8/22 19:04
*
*/
public class OracleConnException extends RuntimeException{
public OracleConnException(String message) {
super(message);
}
}

View File

@ -0,0 +1,13 @@
package com.muyu.common.pool.exeption;
/**
* @Authorzhangzhihao
* @nameMysqlConnException
* @Date2024/8/22 19:04
*
*/
public class RedisConnException extends RuntimeException{
public RedisConnException(String message) {
super(message);
}
}

View File

@ -0,0 +1,37 @@
<?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>cloud-etl-datasources</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>cloud-datasources-remote</artifactId>
<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>cloud-datasources-common</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-etl</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,22 @@
package com.muyu.remote;
import com.muyu.common.core.domain.Result;
import com.muyu.common.domain.DataSources;
import com.muyu.etl.domain.DataValue;
import com.muyu.remote.factory.DataSourcesFactory;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author Administrator
*/
@EnableFeignClients
@FeignClient(value = "cloud-etl-datasources",fallbackFactory = DataSourcesFactory.class )
public interface DataSourcesRemote {
@GetMapping("datasources/{id}")
public Result<DataSources> queryById(@PathVariable("id") Long id);
}

View File

@ -0,0 +1,20 @@
package com.muyu.remote.factory;
import com.muyu.common.core.domain.Result;
import com.muyu.common.domain.DataSources;
import com.muyu.remote.DataSourcesRemote;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
@Component
public class DataSourcesFactory implements FallbackFactory<DataSourcesRemote> {
@Override
public DataSourcesRemote create(Throwable cause) {
return new DataSourcesRemote() {
@Override
public Result<DataSources> queryById(Long id) {
return null;
}
};
}
}

View File

@ -0,0 +1,2 @@
com.muyu.remote.factory.DataSourcesFactory
com.muyu.remote.DataSourcesRemote

View File

@ -0,0 +1,148 @@
<?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>cloud-etl-datasources</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>cloud-datasources-server</artifactId>
<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>cloud-datasources-client</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- MuYu Common DataSource -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-datasource</artifactId>
</dependency>
<!-- MuYu Common DataScope -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-datascope</artifactId>
</dependency>
<!-- MuYu Common Log -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-log</artifactId>
</dependency>
<!-- 接口模块 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-api-doc</artifactId>
</dependency>
<!-- XllJob定时任务 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-xxl</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-rabbit</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-datasources-common</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-nacos-api</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-etl</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>cloud-datasources</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 加入maven deploy插件当在deploy时忽略些model-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,24 @@
package com.muyu.datasources;
import com.muyu.common.security.annotation.EnableCustomConfig;
import com.muyu.common.security.annotation.EnableMyFeignClients;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
/**
* @Authorzhangzhihao
* @nameDataSourcesApplication
* @Date2024/8/21 14:37
*
*/
@EnableCustomConfig
@EnableMyFeignClients
@SpringBootApplication
//@ComponentScan(basePackages = {"com.muyu", "com.muyu.datasources.mysql"})
public class DataSourcesApplication {
public static void main(String[] args) {
SpringApplication.run(DataSourcesApplication.class);
}
}

View File

@ -0,0 +1,118 @@
package com.muyu.datasources.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.utils.bean.BeanUtils;
import com.muyu.common.domain.AssetAccredit;
import com.muyu.common.domain.req.AssetAccreditReq;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.common.system.domain.SysDept;
import com.muyu.datasources.service.AssetAccreditService;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameassetAccreditController
* @Date2024/8/30 9:37
*
*/
@RestController
@RequestMapping("assetAccredit")
public class AssetAccreditController {
@Autowired
private AssetAccreditService assetAccreditService;
@PostMapping("/findUserIdList")
public Result findUserIdList(@RequestBody AssetAccreditReq req){
List<Long> list = assetAccreditService.findUserIdList(req);
return Result.success(list);
}
/**
*
* @param req
* @return
*/
@Log(title = "添加用户权限",businessType = BusinessType.INSERT)
@PostMapping("/addUserAssetAccredit")
public Result addUserAssetAccredit(@RequestBody AssetAccreditReq req){
AssetAccredit assetAccredit = new AssetAccredit();
assetAccredit.setUserId(req.getUserId());
assetAccredit.setTableId(req.getTableId());
assetAccredit.setBasicId(req.getBasicId());
boolean save = assetAccreditService.save(assetAccredit);
return save?Result.success():Result.error();
}
/**
*
* @param req
* @return
*/
@Log(title = "删除用户权限",businessType = BusinessType.DELETE)
@PostMapping("/delUserAssetAccredit")
public Result delUserAssetAccredit(@RequestBody AssetAccreditReq req){
int i = assetAccreditService.delUserAssetAccredit(req);
return i>0?Result.success():Result.error();
};
@PostMapping("/findDeptIdList")
public Result findDeptIdList(@RequestBody AssetAccreditReq req){
List<Long> list = assetAccreditService.findDeptIdList(req);
return Result.success(list);
}
/**
*
* @param req
* @return
*/
@Log(title = "添加部门权限",businessType = BusinessType.INSERT)
@PostMapping("/addDeptAssetAccredit")
public Result addDeptAssetAccredit(@RequestBody AssetAccreditReq req){
AssetAccredit assetAccredit = new AssetAccredit();
assetAccredit.setDeptId(req.getDeptId());
assetAccredit.setTableId(req.getTableId());
assetAccredit.setBasicId(req.getBasicId());
boolean save = assetAccreditService.save(assetAccredit);
return save?Result.success():Result.error();
}
/**
*
* @param req
* @return
*/
@Log(title = "删除部门权限",businessType = BusinessType.DELETE)
@PostMapping("/delDeptAssetAccredit")
public Result delDeptAssetAccredit(@RequestBody AssetAccreditReq req){
int i = assetAccreditService.delDeptAssetAccredit(req);
return i>0?Result.success():Result.error();
};
}

View File

@ -0,0 +1,192 @@
package com.muyu.datasources.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.domain.DataSources;
import com.muyu.common.domain.req.DataSourcesReq;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.datasources.service.DataSourcesService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.sql.*;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameDataSourcesController
* @Date2024/8/21 14:47
*
*/
@RestController
@RequestMapping("datasources")
public class DataSourcesController {
@Autowired
private DataSourcesService dataSourcesService;
/**
* ID
* @param id
* @return
*/
@GetMapping("/{id}")
public Result<DataSources> queryById(@PathVariable("id") Long id){
return Result.success(dataSourcesService.getById(id));
}
/**
*
* @param req
* @return
*/
@PostMapping("/all")
public Result<Page<DataSources>> all(@RequestBody DataSourcesReq req){
Page<DataSources> dataSourcesPage = dataSourcesService.selectList(req);
return Result.success(dataSourcesPage);
}
/**
*
* @param dataSources
* @return
*/
@Log(title = "新增数据来源",businessType = BusinessType.INSERT)
@PostMapping("/addDataSources")
public Result<DataSources> add(@RequestBody DataSources dataSources){
dataSourcesService.save(dataSources);
return Result.success();
}
/**
*
*
* @param dataSources
* @return
*/
@Log(title = "更新数据来源配置",businessType = BusinessType.UPDATE)
@PutMapping("/updateDataSources")
public Result<DataSources> edit(@RequestBody DataSources dataSources){
dataSourcesService.updateById(dataSources);
return Result.success();
}
/**
*
*
* @param id
* @return
*/
@Log(title = "删除数据来源",businessType = BusinessType.DELETE)
@DeleteMapping("/{id}")
public Result<Boolean> deleteById(@PathVariable("id") Long id){
return Result.success(dataSourcesService.removeById(id));
}
/**
*
* @param dataSources
* @return
*/
@PostMapping("/connectDataSources")
public Result connectDataSources(@RequestBody DataSources dataSources){
int i= dataSourcesService.connectDataSources(dataSources);
return i>0?Result.success():Result.error();
}
/**
*
* @param dataSources
* @return
*/
@Log(title = "同步数据结构",businessType = BusinessType.INSERT)
@PostMapping("/syncAssetStructure")
public Result syncAssetStructure(@RequestBody DataSources dataSources){
Integer i = dataSourcesService.syncAssetStructure(dataSources);
return Result.success(i);
}
/**
*
* @param response
*/
@PostMapping("/export")
public void export(HttpServletResponse response){
List<DataSources> list = dataSourcesService.list();
ExcelUtil<DataSources> util = new ExcelUtil<>(DataSources.class);
util.exportExcel(response,list,"连接数据库配置");
}
// @PostMapping("/test")
// public Result test() {
// // Oracle数据库的JDBC URL
// String jdbcUrl = "jdbc:oracle:thin:@LAPTOP-A6NCJEU3:1521:XE";
//
//
// String username = "zzh";
// String password = "123456";
//
// Connection conn = null;
// Statement stmt = null;
// ResultSet rs = null;
// String str="";
// try {
// // 加载Oracle JDBC驱动
// Class.forName("oracle.jdbc.driver.OracleDriver");
//
// // 建立数据库连接
// conn = DriverManager.getConnection(jdbcUrl, username, password);
//
// // 创建Statement对象
// stmt = conn.createStatement();
//
// // 编写SQL查询语句从ZZH模式的T_USER表中查询NAME字段
// String sql = "SELECT TABLE_NAME FROM DBA_TABLES WHERE OWNER = 'ZZH'";
//
// // 执行查询
// rs = stmt.executeQuery(sql);
//
//
// // 遍历ResultSet对象获取NAME字段的值
// while (rs.next()) {
// String name = rs.getString(1);
// str+=name;
// System.out.println("NAME: " + name);
// }
//
// }catch (ClassNotFoundException e) {
// System.out.println("Oracle JDBC Driver类未找到");
// e.printStackTrace();
// } catch (SQLException e) {
// System.out.println("数据库连接失败或SQL查询出错");
// e.printStackTrace();
// } finally {
// // 关闭资源
// try {
// if (rs != null) {
// rs.close();
// }
// if (stmt != null) {
// stmt.close();
// }
// if (conn != null) {
// conn.close();
// }
// } catch (SQLException e) {
// e.printStackTrace();
// }
// }
//
// return Result.success(str);
// }
}

View File

@ -0,0 +1,118 @@
package com.muyu.datasources.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.datasources.service.DataValueService;
import com.muyu.etl.domain.DataValue;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameDataKltvController
* @Date2024/8/27 22:17
*
*/
@Log4j2
@RestController
@RequestMapping("dataValue")
public class DataValueController {
@Autowired
private DataValueService dataValueService;
/**
*
* @param basicId
* @param sql
* @return
*/
@PostMapping("/findTableValue")
public Result<List<List<DataValue>>> findTableValue(@RequestParam("basicId") Long basicId, @RequestParam("sql") String sql){
long l = System.currentTimeMillis();
List<List<DataValue>> list = dataValueService.findTableValue(basicId,sql);
long x = System.currentTimeMillis();
long l1 = x - l;
log.info("耗时:"+l1);
return Result.success(list);
}
/**
*
* @param basicId
* @param tableName
* @return
*/
@PostMapping("/findTableValueByTableName")
public Result findTableValueByTableName(@RequestParam("basicId") Long basicId,@RequestParam("tableName") String tableName){
List<DataValue> list = dataValueService.findTableValueByTableName(basicId,tableName);
return Result.success(list);
}
@PostMapping("/findTableValueContributionRule")
public Result<List<List<DataValue>>> findTableValueContributionRule(@RequestParam("basicId") Long basicId,@RequestParam("tableId") Long tableId){
List<List<DataValue>> list = dataValueService.findTableValueContributionRule(basicId,tableId);
return Result.success(list);
}
@PostMapping("/findCount")
public Result<Long> findCount(@RequestParam("basicId") Long basicId,@RequestParam("sql") String sql){
Long count = dataValueService.findCount(basicId,sql);
return Result.success(count);
}
/**
*
* @param basicId
* @param sql
* @return
*/
@PostMapping("/findTableValueToArray")
public Result<DataValue[][]> findTableValueToArray(@RequestParam("basicId") Long basicId,
@RequestParam("sql") String sql,
@RequestParam("one") Long one,
@RequestParam("two") Integer two){
long begin = System.currentTimeMillis();
DataValue[][] list = dataValueService.findTableValueToArray(basicId,sql,one,two);
long end = System.currentTimeMillis();
long time = end - begin;
log.info("耗时:"+time);
return Result.success(list);
}
/**
*
*/
// @PostMapping("/test")
// public static void test() {
// MySqlQuery mySqlQuery = new MySqlQuery();
// String sql="select id,table_id from asset_accredit";
// mySqlQuery.setSql(sql);
// mySqlQuery.setDataSourceId(1L);
// BaseQueryHandler.set(mySqlQuery);
//
//
// MySqlDataSource mySqlDataSource = new MySqlDataSource();
// DataValue[][] rows = mySqlDataSource.getRows();
// System.out.println(rows);
// }
}

View File

@ -0,0 +1,39 @@
package com.muyu.datasources.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.datasources.service.ProductService;
import com.muyu.etl.domain.DataValue;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @Authorzhangzhihao
* @nameProductController
* @Date2024/9/2 21:12
*
*/
@Log4j2
@RestController
@RequestMapping("/product")
public class ProductController {
@Autowired
private ProductService productService;
@PostMapping("/addProduct")
public Result addProduct(@RequestParam("basicId") Long basicId, @RequestParam("tableId") Long tableId, @RequestBody DataValue[][] listList){
long begin = System.currentTimeMillis();
int i = productService.addProduct(basicId,tableId,listList);
long end = System.currentTimeMillis();
long allTime = end - begin;
log.info("添加到产品数据库耗时:"+allTime);
return Result.success(i);
}
}

View File

@ -0,0 +1,41 @@
package com.muyu.datasources.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.common.domain.Structure;
import com.muyu.datasources.service.StructureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameStructureController
* @Date2024/8/26 20:43
*
*/
@RestController
@RequestMapping("structure")
public class StructureController {
@Autowired
private StructureService structureService;
/**
*
* @param id
* @return
*/
@GetMapping("/findStructureByTableId/{id}")
public Result findStructureByTableId(@PathVariable("id") Long id){
List<Structure> list = structureService.findStructureByTableId(id);
return Result.success(list);
}
}

View File

@ -0,0 +1,147 @@
package com.muyu.datasources.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.common.core.domain.Result;
import com.muyu.common.domain.TableInfo;
import com.muyu.common.domain.resp.AssetAccreditResp;
import com.muyu.common.domain.resp.TableInfoResp;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.common.system.domain.SysUser;
import com.muyu.datasources.service.AssetAccreditService;
import com.muyu.datasources.service.DataSourcesService;
import com.muyu.datasources.service.SysUserService;
import com.muyu.datasources.service.TableInfoService;
import jakarta.servlet.http.HttpServletRequest;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Stream;
@RestController
@RequestMapping("tableInfo")
public class TableInfoController {
@Autowired
private TableInfoService tableInfoService;
@Autowired
private SysUserService sysUserService;
@Autowired
private AssetAccreditService assetAccreditService;
@Autowired
private HttpServletRequest request;
@GetMapping("/findAsset")
public Result findAsset(){
List<TableInfo> list = tableInfoService.list();
List<TableInfoResp> respList = list.stream().filter(tableInfo -> tableInfo.getParentId()==0).map(tableInfo -> {
TableInfoResp tableInfoResp = TableInfo.toTableInfoResp(tableInfo);
tableInfoResp.setChildren(getAssetChildren(tableInfo, list));
return tableInfoResp;
}).toList();
return Result.success(respList);
}
/**
*
* @return
*/
@GetMapping
public Result findByTableName() {
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser sysUser = loginUser.getSysUser();
Long userId = sysUser.getUserId();
Long deptId = sysUser.getDeptId();
List<AssetAccreditResp> idList = assetAccreditService.findTableIdAndBasicIdByUserId(userId);
List<AssetAccreditResp> deptIdList = assetAccreditService.findTableIdAndBasicIdByDeptId(deptId);
HashSet<TableInfo> set = new HashSet<>();
for (AssetAccreditResp assetAccreditResp : idList) {
Long basicId = assetAccreditResp.getBasicId();
Long tableId = assetAccreditResp.getTableId();
if (null!=basicId){
LambdaQueryWrapper<TableInfo> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(TableInfo::getBasicId,basicId);
List<TableInfo> tableInfoList = tableInfoService.list(wrapper);
set.addAll(tableInfoList);
}
if (null!=tableId){
TableInfo tableInfo = tableInfoService.getById(tableId);
set.add(tableInfo);
Long parentId = tableInfo.getParentId();
TableInfo dataSource = tableInfoService.getById(parentId);
set.add(dataSource);
}
}
for (AssetAccreditResp assetAccreditResp : deptIdList) {
Long basicId = assetAccreditResp.getBasicId();
Long tableId = assetAccreditResp.getTableId();
if (null!=basicId){
LambdaQueryWrapper<TableInfo> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(TableInfo::getBasicId,basicId);
List<TableInfo> tableInfoList = tableInfoService.list(wrapper);
set.addAll(tableInfoList);
}
if (null!=tableId){
TableInfo tableInfo = tableInfoService.getById(tableId);
set.add(tableInfo);
Long parentId = tableInfo.getParentId();
TableInfo dataSource = tableInfoService.getById(parentId);
set.add(dataSource);
}
}
List<TableInfoResp> respList = set.stream().filter(tableInfo -> tableInfo.getParentId()==0).map(tableInfo -> {
TableInfoResp tableInfoResp = TableInfo.toTableInfoResp(tableInfo);
tableInfoResp.setChildren(getChildren(tableInfo, set));
return tableInfoResp;
}).toList();
return Result.success(respList);
}
@NotNull
private static List<TableInfoResp> getChildren(TableInfo tableInfo, HashSet<TableInfo> list) {
return list.stream().filter(tableInfo1 -> tableInfo1.getParentId().equals(tableInfo.getId())).map(
tableInfo2 -> TableInfo.toTableInfoResp(tableInfo2)
).toList();
}
@NotNull
private static List<TableInfoResp> getAssetChildren(TableInfo tableInfo, List<TableInfo> list) {
return list.stream().filter(tableInfo1 -> tableInfo1.getParentId().equals(tableInfo.getId())).map(
tableInfo2 -> TableInfo.toTableInfoResp(tableInfo2)
).toList();
}
/**
* id
* @param id
* @return
*/
@PostMapping("/findTableName")
public Result findTableName(@RequestParam("id") Long id){
TableInfo table = tableInfoService.getById(id);
return Result.success(table);
}
}

View File

@ -0,0 +1,31 @@
package com.muyu.datasources.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.common.domain.AssetAccredit;
import com.muyu.common.domain.req.AssetAccreditReq;
import com.muyu.common.domain.resp.AssetAccreditResp;
import com.muyu.common.system.domain.SysDept;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameAssetAccreditMapper
* @Date2024/8/30 9:40
*
*/
@Mapper
public interface AssetAccreditMapper extends BaseMapper<AssetAccredit> {
List<Long> findUserIdList(AssetAccreditReq req);
List<Long> findDeptIdList(AssetAccreditReq req);
List<AssetAccreditResp> findTableIdAndBasicIdByUserId(@Param("userId") Long userId);
List<AssetAccreditResp> findTableIdAndBasicIdByDeptId(@Param("deptId") Long deptId);
}

View File

@ -0,0 +1,19 @@
package com.muyu.datasources.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.common.domain.DataSources;
import org.apache.ibatis.annotations.Mapper;
/**
* @Authorzhangzhihao
* @nameDataSourcesMapper
* @Date2024/8/21 14:40
*
*/
@Mapper
public interface DataSourcesMapper extends BaseMapper<DataSources> {
}

View File

@ -0,0 +1,15 @@
package com.muyu.datasources.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.etl.domain.DataValue;
import org.apache.ibatis.annotations.Mapper;
/**
* @Authorzhangzhihao
* @nameDataKltvMapper
* @Date2024/8/27 15:38
*
*/
@Mapper
public interface DataValueMapper extends BaseMapper<DataValue> {
}

View File

@ -0,0 +1,15 @@
package com.muyu.datasources.mapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @Authorzhangzhihao
* @nameProductMapper
* @Date2024/9/2 21:13
*
*/
@Mapper
public interface ProductMapper {
}

View File

@ -0,0 +1,15 @@
package com.muyu.datasources.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.common.domain.Structure;
import org.apache.ibatis.annotations.Mapper;
/**
* @Authorzhangzhihao
* @nameStructureMapper
* @Date2024/8/25 16:49
*
*/
@Mapper
public interface StructureMapper extends BaseMapper<Structure> {
}

View File

@ -0,0 +1,17 @@
package com.muyu.datasources.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.common.system.domain.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* @Authorzhangzhihao
* @nameSysUserMapper
* @Date2024/8/31 18:49
*
*/
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {
SysUser findUserById(@Param("userId") Long userId);
}

View File

@ -0,0 +1,19 @@
package com.muyu.datasources.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.common.domain.TableInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameTableInfoMapper
* @Date2024/8/25 11:39
*
*/
@Mapper
public interface TableInfoMapper extends BaseMapper<TableInfo> {
List<Long> findTableIdByParentId(@Param("basicId") Long basicId);
}

View File

@ -0,0 +1,32 @@
package com.muyu.datasources.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.domain.AssetAccredit;
import com.muyu.common.domain.req.AssetAccreditReq;
import com.muyu.common.domain.resp.AssetAccreditResp;
import com.muyu.common.system.domain.SysDept;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameassetAccreditService
* @Date2024/8/30 9:38
*
*/
public interface AssetAccreditService extends IService<AssetAccredit> {
List<Long> findUserIdList(AssetAccreditReq req);
int delUserAssetAccredit(AssetAccreditReq req);
int delDeptAssetAccredit(AssetAccreditReq req);
List<Long> findDeptIdList(AssetAccreditReq req);
List<AssetAccreditResp> findTableIdAndBasicIdByUserId(Long userId);
List<AssetAccreditResp> findTableIdAndBasicIdByDeptId(Long deptId);
}

View File

@ -0,0 +1,32 @@
package com.muyu.datasources.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.domain.DataSources;
import com.muyu.common.domain.req.DataSourcesReq;
/**
* @Authorzhangzhihao
* @nameDataSourcesService
* @Date2024/8/21 14:35
*
*/
public interface DataSourcesService extends IService<DataSources> {
/**
*
* @param req
* @return
*/
Page<DataSources> selectList(DataSourcesReq req);
int connectDataSources(DataSources dataSources);
Integer syncAssetStructure(DataSources dataSources);
}

View File

@ -0,0 +1,25 @@
package com.muyu.datasources.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.etl.domain.DataValue;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameDataKltvService
* @Date2024/8/27 15:33
*
*/
public interface DataValueService extends IService<DataValue> {
List<List<DataValue>> findTableValue(Long basicId, String sql);
List<DataValue> findTableValueByTableName(Long basicId, String tableName);
List<List<DataValue>> findTableValueContributionRule(Long basicId, Long tableId);
Long findCount(Long basicId, String sql);
DataValue[][] findTableValueToArray(Long basicId, String sql, Long one, Integer two);
}

View File

@ -0,0 +1,13 @@
package com.muyu.datasources.service;
import com.muyu.etl.domain.DataValue;
/**
* @Authorzhangzhihao
* @nameProductControllerService
* @Date2024/9/2 21:12
*
*/
public interface ProductService {
int addProduct(Long basicId, Long tableId, DataValue[][] listList);
}

View File

@ -0,0 +1,16 @@
package com.muyu.datasources.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.domain.Structure;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameStructureService
* @Date2024/8/25 16:48
*
*/
public interface StructureService extends IService<Structure> {
List<Structure> findStructureByTableId(Long id);
}

View File

@ -0,0 +1,14 @@
package com.muyu.datasources.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.system.domain.SysUser;
/**
* @Authorzhangzhihao
* @nameSysUserService
* @Date2024/8/31 18:48
*
*/
public interface SysUserService extends IService<SysUser> {
SysUser findUserById(Long userId);
}

View File

@ -0,0 +1,18 @@
package com.muyu.datasources.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.domain.TableInfo;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameTableInfoService
* @Date2024/8/25 11:35
*
*/
public interface TableInfoService extends IService<TableInfo> {
TableInfo selectTableInfoByName(TableInfo tableInfoInsert);
List<Long> findTableIdByParentId(Long basicId);
}

View File

@ -0,0 +1,88 @@
package com.muyu.datasources.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.domain.AssetAccredit;
import com.muyu.common.domain.req.AssetAccreditReq;
import com.muyu.common.domain.resp.AssetAccreditResp;
import com.muyu.common.system.domain.SysDept;
import com.muyu.datasources.mapper.AssetAccreditMapper;
import com.muyu.datasources.service.AssetAccreditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameAssetAccreditServiceImpl
* @Date2024/8/30 9:39
*
*/
@Service
public class AssetAccreditServiceImpl extends ServiceImpl<AssetAccreditMapper, AssetAccredit> implements AssetAccreditService {
@Autowired
private AssetAccreditMapper assetAccreditMapper;
@Override
public List<Long> findUserIdList(AssetAccreditReq req) {
List<Long> userIdList = assetAccreditMapper.findUserIdList(req);
return userIdList;
}
@Override
public int delUserAssetAccredit(AssetAccreditReq req) {
LambdaQueryWrapper<AssetAccredit> queryWrapper = new LambdaQueryWrapper<>();
if (null==req.getBasicId()){
queryWrapper.eq(AssetAccredit::getUserId,req.getUserId())
.eq(AssetAccredit::getTableId,req.getTableId());
}else if (null==req.getTableId()){
queryWrapper.eq(AssetAccredit::getUserId,req.getUserId())
.eq(AssetAccredit::getBasicId,req.getBasicId());
}
int delete = assetAccreditMapper.delete(queryWrapper);
return delete;
}
@Override
public int delDeptAssetAccredit(AssetAccreditReq req) {
LambdaQueryWrapper<AssetAccredit> queryWrapper = new LambdaQueryWrapper<>();
if (null==req.getBasicId()){
queryWrapper.eq(AssetAccredit::getDeptId,req.getDeptId())
.eq(AssetAccredit::getTableId,req.getTableId());
}else if (null==req.getTableId()){
queryWrapper.eq(AssetAccredit::getDeptId,req.getDeptId())
.eq(AssetAccredit::getBasicId,req.getBasicId());
}
int delete = assetAccreditMapper.delete(queryWrapper);
return delete;
}
@Override
public List<Long> findDeptIdList(AssetAccreditReq req) {
List<Long> deptIdList = assetAccreditMapper.findDeptIdList(req);
return deptIdList;
}
@Override
public List<AssetAccreditResp> findTableIdAndBasicIdByUserId(Long userId) {
List<AssetAccreditResp> list = assetAccreditMapper.findTableIdAndBasicIdByUserId(userId);
return list;
}
@Override
public List<AssetAccreditResp> findTableIdAndBasicIdByDeptId(Long deptId) {
List<AssetAccreditResp> list = assetAccreditMapper.findTableIdAndBasicIdByDeptId(deptId);
return list;
}
}

View File

@ -0,0 +1,22 @@
package com.muyu.datasources.service.impl;
import com.muyu.client.basic.DataSourceConfig;
import com.muyu.common.core.domain.Result;
import com.muyu.common.domain.DataSources;
import com.muyu.datasources.service.DataSourcesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
@Service
@Primary
public class DataSourceConfigLocalImpl implements DataSourceConfig {
@Autowired
private DataSourcesService dataSourcesService;
@Override
public DataSources queryById(Long id) {
return dataSourcesService.getById(id);
}
}

View File

@ -0,0 +1,547 @@
package com.muyu.datasources.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.domain.DataSources;
import com.muyu.common.domain.Structure;
import com.muyu.common.domain.TableInfo;
import com.muyu.common.domain.req.DataSourcesReq;
import com.muyu.common.pool.MysqlPool;
import com.muyu.common.pool.OraclePool;
import com.muyu.common.pool.RedisPool;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.datasources.mapper.DataSourcesMapper;
import com.muyu.datasources.service.DataSourcesService;
import com.muyu.datasources.service.StructureService;
import com.muyu.datasources.service.TableInfoService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import java.sql.*;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import static com.muyu.common.pool.base.BaseConfig.*;
/**
* @Authorzhangzhihao
* @nameDataSourcesServiceImpl
* @Date2024/8/21 14:35
*
*/
@Log4j2
@Service
public class DataSourcesServiceImpl extends ServiceImpl<DataSourcesMapper, DataSources> implements DataSourcesService {
@Autowired
private DataSourcesMapper dataSourcesMapper;
@Autowired
private TableInfoService tableInfoService;
@Autowired
private StructureService structureService;
private static final Long PARENTID =0L;
private static final String DRIVERNAME ="com.mysql.cj.jdbc.Driver";
private static final String DRIVERORACLENAME ="oracle.jdbc.driver.OracleDriver";
private static final String MYSQL ="mysql";
private static final String ORACLE ="oracle";
private static final String REDIS ="redis";
/**
*
* @param dataSources
* @return
*/
@Override
public boolean save(DataSources dataSources) {
String type = dataSources.getType();
if (type.equals(MYSQL)){
dataSources.setDriverName(DRIVERNAME);
}
if (type.equals(ORACLE)){
dataSources.setDriverName(DRIVERORACLENAME);
}
return super.save(dataSources);
}
/**
*
* @param req
* @return
*/
@Override
public Page<DataSources> selectList(DataSourcesReq req) {
LambdaQueryWrapper<DataSources> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.like(StringUtils.isNotEmpty(req.getName()), DataSources::getName,req.getName());
queryWrapper.like(StringUtils.isNotEmpty(req.getDatabaseName()), DataSources::getDatabaseName,req.getDatabaseName());
Page<DataSources> page = new Page<>(req.getPageNum(), req.getPageSize());
Page<DataSources> pageList = dataSourcesMapper.selectPage(page, queryWrapper);
return pageList;
}
/**
*
* @param dataSources
*/
@Override
public int connectDataSources(DataSources dataSources) {
if (dataSources.getType().equals(MYSQL)){
MysqlPool mysqlPool = new MysqlPool(dataSources);
mysqlPool.init();
Connection conn = mysqlPool.getConn();
mysqlPool.replease(conn);
mysqlPool.closeConn();
return 1;
}else if (dataSources.getType().equals(REDIS)){
RedisPool redisPool = new RedisPool(dataSources);
redisPool.init();
Jedis conn = redisPool.getConn();
redisPool.replease(conn);
redisPool.closeConn();
return 1;
}
return 0;
}
private static final ExecutorService threadPool = Executors.newCachedThreadPool();
@Override
public Integer syncAssetStructure(DataSources dataSources) {
try {
if (dataSources.getType().equals(MYSQL)) {
MysqlPool mysqlPool = new MysqlPool(dataSources);
mysqlPool.init();
Connection conn = mysqlPool.getConn();
TableInfo tableInfoInsert = TableInfo.builder()
.basicId(dataSources.getId())
.parentId(PARENTID)
.tableRemark("")
.isCenter("Y")
.type("dataSource")
.tableName(dataSources.getDatabaseName())
.createBy(SecurityUtils.getUsername())
.createTime(new Date())
.build();
//添加数据库table_info表
tableInfoService.saveOrUpdate(tableInfoInsert,new LambdaUpdateWrapper<TableInfo>(TableInfo.class){{
eq(TableInfo::getTableName,tableInfoInsert.getTableName());
eq(TableInfo::getBasicId,dataSources.getId());
}});
//根据数据库id和数据库名称或表名称查询
TableInfo tableInfo = tableInfoService.selectTableInfoByName(tableInfoInsert);
// 查询所有表信息
DatabaseMetaData metaData = conn.getMetaData();
ResultSet rs = metaData.getTables(dataSources.getDatabaseName(), null, "%", new String[]{"TABLE"});
while (rs.next()) {
String tableName = rs.getString("TABLE_NAME");
String tableRemark = rs.getString("REMARKS");
try (PreparedStatement preparedStatement = conn.prepareStatement(SELECTCOUNT + tableName)) {
ResultSet resultSet = preparedStatement.executeQuery();
long count = 0L;
if (resultSet.next()) {
count = resultSet.getLong("count");
}
TableInfo build = TableInfo.builder()
.basicId(dataSources.getId())
.tableName(tableName)
.tableRemark(tableRemark != null ? tableRemark : "")
.parentId(tableInfo.getId())
.type("dataTable")
.isCenter("Y")
.updateBy(SecurityUtils.getUsername())
.dataNum(count)
.updateTime(new Date())
.build();
tableInfoService.saveOrUpdate(build, new LambdaUpdateWrapper<>(TableInfo.class) {{
eq(TableInfo::getTableName, build.getTableName());
eq(TableInfo::getBasicId, dataSources.getId());
}});
TableInfo table = tableInfoService.selectTableInfoByName(build);
threadPool.submit(() -> {
syncData(conn, dataSources.getDatabaseName(), table);
});
} catch (SQLException e) {
log.error("查询计数失败", e);
}
}
try {
Thread.sleep(1000);
conn.close();
mysqlPool.closeConn();
} catch (SQLException e) {
log.error("关闭数据库连接失败", e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} else if (dataSources.getType().equals(ORACLE)) {
OraclePool oraclePool = new OraclePool(dataSources);
oraclePool.init();
Connection conn = oraclePool.getConn();
TableInfo tableInfoInsert = TableInfo.builder()
.basicId(dataSources.getId())
.parentId(PARENTID)
.tableRemark("")
.isCenter("Y")
.type("dataSource")
.tableName(dataSources.getDatabaseName())
.createBy(SecurityUtils.getUsername())
.createTime(new Date())
.build();
// 添加数据库 table_info 表
tableInfoService.saveOrUpdate(tableInfoInsert, new LambdaUpdateWrapper<>(TableInfo.class) {{
eq(TableInfo::getTableName, tableInfoInsert.getTableName());
eq(TableInfo::getBasicId, dataSources.getId());
}});
// 根据数据库 id 和数据库名称查询
TableInfo tableInfo = tableInfoService.selectTableInfoByName(tableInfoInsert);
DatabaseMetaData metaData = conn.getMetaData();
// 编写 SQL 查询语句,从 ZZH 模式的 T_USER 表中查询 NAME 字段
String sql = "SELECT TABLE_NAME FROM DBA_TABLES WHERE OWNER = '" + dataSources.getDatabaseName() + "'";
// 执行查询
PreparedStatement prepared = conn.prepareStatement(sql);
ResultSet rs = prepared.executeQuery();
// 遍历 ResultSet 对象,获取 NAME 字段的值
while (rs.next()) {
String tableName = rs.getString(1);
try (PreparedStatement preparedStatement = conn.prepareStatement(SELECTCOUNT + tableName)) {
ResultSet resultSet = preparedStatement.executeQuery();
long count = 0L;
if (resultSet.next()) {
count = resultSet.getLong("count");
}
TableInfo build = TableInfo.builder()
.basicId(dataSources.getId())
.tableName(tableName)
.tableRemark("")
.parentId(tableInfo.getId())
.type("dataTable")
.isCenter("Y")
.updateBy(SecurityUtils.getUsername())
.dataNum(count)
.updateTime(new Date())
.build();
tableInfoService.saveOrUpdate(build, new LambdaUpdateWrapper<>(TableInfo.class) {{
eq(TableInfo::getTableName, build.getTableName());
eq(TableInfo::getBasicId, dataSources.getId());
}});
TableInfo table = tableInfoService.selectTableInfoByName(build);
threadPool.submit(() -> {
syncOracleData(conn, dataSources.getDatabaseName(), table);
});
} catch (SQLException e) {
log.error("查询计数失败", e);
}
}
try {
Thread.sleep(1000);
conn.close();
oraclePool.closeConn();
} catch (SQLException e) {
log.error("关闭数据库连接失败", e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
} catch (SQLException e) {
log.error("数据库操作失败", e);
throw new RuntimeException(e);
}
return 1;
}
/**
*
*
* @param conn
* @param databaseName
* @param table ID
*/
public void syncData(Connection conn, String databaseName, TableInfo table) {
// 创建一个单线程执行器,用于提交保存或更新结构信息的任务
ExecutorService threadPool = Executors.newSingleThreadExecutor();
// 准备SQL查询语句用于获取指定数据库表的列信息
String sql = "SELECT\n" +
" COLUMN_NAME,\n" +
" COLUMN_COMMENT,\n" +
" CASE WHEN COLUMN_KEY = 'PRI' THEN '是' ELSE '否' END AS IS_PRIMARY_KEY,\n" +
" CASE\n" +
" WHEN DATA_TYPE = 'int' THEN 'Integer'\n" +
" WHEN DATA_TYPE = 'bigint' THEN 'Long'\n" +
" WHEN DATA_TYPE = 'varchar' THEN 'String'\n" +
" WHEN DATA_TYPE = 'decimal' THEN 'BigDecimal'\n" +
" WHEN DATA_TYPE = 'tinyint' AND COLUMN_TYPE = 'tinyint(1)' THEN 'Boolean'\n" +
" ELSE DATA_TYPE\n" +
" END AS GENERIC_DATA_TYPE,\n" +
" DATA_TYPE AS ORIGINAL_DATA_TYPE,\n" +
" COLUMN_TYPE AS DETAILED_DATA_TYPE,\n" +
" CHARACTER_MAXIMUM_LENGTH,\n" +
" NUMERIC_SCALE,\n" +
" IS_NULLABLE,\n" +
" COLUMN_DEFAULT\n" +
"FROM\n" +
" INFORMATION_SCHEMA.COLUMNS\n" +
"WHERE\n" +
" TABLE_SCHEMA = ?\n" +
" AND TABLE_NAME = ?;";
// 创建PreparedStatement对象用于执行SQL查询
PreparedStatement ps = null;
// 创建ResultSet对象用于存储查询结果
ResultSet resultSet = null;
try {
// 准备SQL语句并设置参数
ps = conn.prepareStatement(sql);
ps.setString(1, databaseName);
ps.setString(2, table.getTableName());
// 执行查询并处理结果
resultSet = ps.executeQuery();
while (resultSet.next()) {
// 获取列信息并构建Structure对象
Structure build = Structure.builder()
.tableId(table.getId())
.columnName(resultSet.getString(1))
.columnRemark(resultSet.getString(2))
.isPrimary("是".equals(resultSet.getString(3)) ? "Y" : "N")
.javaType(resultSet.getString(4))
.columnType(resultSet.getString(6))
.columnLength(String.valueOf(resultSet.getInt(7)))
.columnDecimals(String.valueOf(resultSet.getInt(8)))
.isNull("YES".equals(resultSet.getString(9)) ? "Y" : "N")
.defaultValue(resultSet.getString(10))
.build();
// 提交保存或更新结构信息的任务到线程池
threadPool.submit(() -> {
try {
structureService.saveOrUpdate(build, new LambdaUpdateWrapper<Structure>() {{
eq(Structure::getTableId, build.getTableId());
eq(Structure::getColumnName, build.getColumnName());
eq(Structure::getColumnRemark, build.getColumnRemark());
}});
} catch (Exception e) {
log.error("保存或更新结构信息失败", e);
}
});
}
// 关闭线程池并等待所有任务完成
threadPool.shutdown();
threadPool.awaitTermination(1, TimeUnit.MINUTES);
} catch (SQLException e) {
throw new RuntimeException("Error executing SQL query: " + e.getMessage(), e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("Thread interrupted", e);
} finally {
// 安静地关闭资源
closeQuietly(ps);
closeQuietly(resultSet);
if (!threadPool.isTerminated()) {
threadPool.shutdownNow(); // 强制关闭线程池
}
}
}
/**
*
*
* @param closeable
*/
private void closeQuietly(AutoCloseable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (Exception e) {
log.error("关闭资源时发生异常", e);
}
}
}
/**
* Oracle
*
* @param conn
* @param databaseName
* @param table
*/
public void syncOracleData(Connection conn, String databaseName, TableInfo table) {
// 创建一个可缓存线程池,用于提交结构更新任务
ExecutorService threadPool = Executors.newCachedThreadPool();
// 准备执行SQL的PreparedStatement对象
PreparedStatement ps = null;
try {
// 创建SQL用于查询表的列信息包括列名、数据类型等
String sql = "SELECT \n" +
" COLUMN_NAME, \n" +
" NULL AS COLUMN_COMMENT, \n" +
" CASE \n" +
" WHEN DATA_TYPE = 'NUMBER' AND DATA_PRECISION IS NOT NULL AND DATA_SCALE = 0 THEN 'Integer' \n" +
" WHEN DATA_TYPE = 'NUMBER' THEN 'BigDecimal' \n" +
" WHEN DATA_TYPE = 'VARCHAR2' THEN 'String' \n" +
" WHEN DATA_TYPE = 'CHAR' THEN 'String'\n" +
" WHEN DATA_TYPE = 'BINARY_FLOAT' OR DATA_TYPE = 'BINARY_DOUBLE' THEN 'Double' -- \n" +
" WHEN DATA_TYPE = 'NUMBER' AND DATA_SCALE = 1 AND COLUMN_NAME LIKE '%IS_ACTIVE%' THEN 'Boolean' -- \n" +
" ELSE DATA_TYPE \n" +
" END AS GENERIC_DATA_TYPE, \n" +
" DATA_TYPE AS ORIGINAL_DATA_TYPE, \n" +
" DATA_TYPE || '(' || CASE WHEN DATA_LENGTH IS NULL THEN NULL ELSE TO_CHAR(DATA_LENGTH) END \n" +
" || CASE WHEN DATA_SCALE IS NULL THEN NULL ELSE ', ' || TO_CHAR(DATA_SCALE) END || ')' AS DETAILED_DATA_TYPE, \n" +
" CASE WHEN DATA_TYPE IN ('VARCHAR2', 'CHAR') THEN DATA_LENGTH ELSE NULL END AS CHARACTER_MAXIMUM_LENGTH, \n" +
" NULLABLE AS IS_NULLABLE, \n" +
" DATA_DEFAULT AS COLUMN_DEFAULT \n" +
"FROM \n" +
" ALL_TAB_COLUMNS \n" +
"WHERE \n" +
" OWNER = UPPER(?) \n" +
" AND TABLE_NAME = UPPER(?)";
// 使用数据库连接预编译SQL
ps = conn.prepareStatement(sql);
// 设置SQL参数数据库名称和表名
ps.setString(1, databaseName);
ps.setString(2, table.getTableName());
// 执行查询并获取结果集
ResultSet resultSet = ps.executeQuery();
// 遍历结果集,处理每一行数据
while (resultSet.next()) {
// 从结果集中提取列信息
String columnName = resultSet.getString(1);
String columnComment = resultSet.getString(2);
String javaType = resultSet.getString(3);
String columnType = resultSet.getString(4);
String isNullable = resultSet.getString(7);
String columnDefault = resultSet.getString(8);
// 构建表结构信息对象
Structure build = Structure.builder()
.tableId(table.getId())
.columnName(columnName)
.columnRemark(columnComment)
.isPrimary("N")
.javaType(javaType)
.columnType(columnType)
.isNull("YES".equals(isNullable) ? "Y" : "N")
.defaultValue(columnDefault)
.build();
// 提交任务到线程池,异步更新本地表结构信息
threadPool.submit(() -> {
// 复制结构信息对象,准备更新
Structure buildCopy = Structure.builder()
.tableId(build.getTableId())
.columnName(build.getColumnName())
.columnRemark(build.getColumnRemark())
.isPrimary(build.getIsPrimary())
.javaType(build.getJavaType())
.columnType(build.getColumnType())
.isNull(build.getIsNull())
.defaultValue(build.getDefaultValue())
.build();
// 使用服务保存或更新结构信息
structureService.saveOrUpdate(buildCopy, new LambdaUpdateWrapper<Structure>() {{
eq(Structure::getTableId, buildCopy.getTableId());
eq(Structure::getColumnName, buildCopy.getColumnName());
eq(Structure::getColumnRemark, buildCopy.getColumnRemark());
}});
});
}
} catch (SQLException e) {
// 记录并抛出SQL异常
log.error("同步Oracle数据时发生错误", e);
throw new RuntimeException("同步Oracle数据时发生错误", e);
} finally {
// 关闭资源先关闭PreparedStatement然后关闭线程池
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
log.error("关闭PreparedStatement出错", e);
}
}
threadPool.shutdown();
}
}
// else if (dataSources.getType().equals(REDIS)){
// RedisPool redisPool = new RedisPool(dataSources);
// redisPool.init();
// Jedis jedis = redisPool.getConn();
// String cursor = ScanParams.SCAN_POINTER_START;
// ScanParams scanParams = new ScanParams().count(100);
// HashMap<String, String> map = new HashMap<>();
// while (true){
// ScanResult<String> scanResult = jedis.scan(cursor, scanParams);
// List<String> keys = scanResult.getResult();
// for (String key : keys) {
// String value = jedis.get(key);
// if (value!=null){
// map.put(key,value);
// }
// }
// cursor = scanResult.getCursor();
// if (cursor.equals(ScanParams.SCAN_POINTER_START)){
// break;
// }
// }
// System.out.println(map);
// redisPool.replease(jedis);
// redisPool.closeConn();
// }
}

View File

@ -0,0 +1,323 @@
package com.muyu.datasources.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.client.mysql.MySqlDataSource;
import com.muyu.client.mysql.MySqlQuery;
import com.muyu.common.data.base.BaseQueryHandler;
import com.muyu.common.domain.DataSources;
import com.muyu.common.domain.TableInfo;
import com.muyu.common.pool.MysqlPool;
import com.muyu.datasources.mapper.DataValueMapper;
import com.muyu.datasources.service.DataValueService;
import com.muyu.datasources.service.DataSourcesService;
import com.muyu.datasources.service.TableInfoService;
import com.muyu.etl.domain.DataValue;
import com.muyu.etl.enums.DataType;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import static com.muyu.common.pool.base.BaseConfig.SELECTALL;
/**
* @Authorzhangzhihao
* @nameDataKltvServiceImpl
* @Date2024/8/27 15:37
*
*/
@Log4j2
@Service
public class DataValueServiceImpl extends ServiceImpl<DataValueMapper, DataValue> implements DataValueService {
@Autowired
private DataSourcesService dataSourcesService;
@Autowired
private TableInfoService tableInfoService;
@Override
/**
* IDSQL
*
* @param basicId ID
* @param sql SQL
* @return
*/
public List<List<DataValue>> findTableValue(Long basicId, String sql) {
// 根据数据库ID获取数据库配置信息
DataSources dataSources = dataSourcesService.getById(basicId);
// 创建MySQL连接池并初始化
MysqlPool mysqlPool = new MysqlPool(dataSources);
mysqlPool.init();
// 获取数据库连接
Connection conn = mysqlPool.getConn();
// 创建列表用于存储查询结果
List<List<DataValue>> list = new ArrayList<>();
// 使用try-with-resources确保连接最终被关闭
try (conn; PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
// 执行查询并获取结果集
ResultSet resultSet = preparedStatement.executeQuery();
// 获取结果集的元数据
ResultSetMetaData metaData = resultSet.getMetaData();
// 获取列数
int columnCount = metaData.getColumnCount();
// 使用ConcurrentHashMap存储列索引与DataValue对象的映射
ConcurrentHashMap<Integer, DataValue> map = new ConcurrentHashMap<>();
// 遍历结果集中的每一行
while (resultSet.next()) {
// 创建列表存储当前行的数据值
ArrayList<DataValue> dataValues = new ArrayList<>();
// 遍历每一列
for (int i = 1; i <= columnCount; i++) {
// 如果是结果集的第一行初始化DataValue对象
if (resultSet.isFirst()) {
// 获取列的类型名称
String columnTypeName = metaData.getColumnTypeName(i);
// 获取数据库元数据
DatabaseMetaData metaDataColumns = conn.getMetaData();
// 获取列的详细信息
ResultSet columns = metaDataColumns.getColumns(null, null, metaData.getTableName(i), metaData.getColumnName(i));
// 初始化备注信息
String remarks = null;
// 从列的详细信息中获取备注
while (columns.next()) {
remarks = columns.getString("REMARKS");
log.info("字段备注: " + remarks);
}
// 构建DataValue对象并添加到列表中
DataValue build = DataValue.builder()
.key(metaData.getColumnName(i))
.label(remarks)
.value(resultSet.getObject(i, DataType.convertType(columnTypeName)))
.type(DataType.findBySqlType(columnTypeName))
.build();
dataValues.add(build);
map.put(i, build);
} else {
// 非第一行时使用已有的DataValue对象更新数据值
DataValue build = DataValue.builder()
.key(metaData.getColumnName(i))
.label(map.get(i).getLabel())
.value(resultSet.getObject(i, map.get(i).getType().getTargetType()))
.type(map.get(i).getType())
.build();
dataValues.add(build);
}
}
// 将当前行的数据值列表添加到结果列表中
list.add(dataValues);
}
} catch (SQLException e) {
// 记录数据库操作日志并抛出运行时异常
log.error("数据库操作失败", e);
throw new RuntimeException("数据库操作失败", e);
} finally {
// 释放数据库连接并关闭连接池
mysqlPool.replease(conn);
mysqlPool.closeConn();
}
// 返回查询结果列表
return list;
}
@Override
public List<DataValue> findTableValueByTableName(Long basicId, String tableName) {
ConcurrentHashMap<Integer, DataValue> map = new ConcurrentHashMap<>();
DataSources dataSources = dataSourcesService.getById(basicId);
MysqlPool mysqlPool = new MysqlPool(dataSources);
mysqlPool.init();
Connection conn = mysqlPool.getConn();
List<DataValue> list = new ArrayList<>();
try {
PreparedStatement preparedStatement = conn.prepareStatement(SELECTALL+tableName+" LIMIT 10");
ResultSet resultSet = preparedStatement.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
while (resultSet.next()){
for (int i = 1; i <= columnCount; i++) {
if (resultSet.isFirst()){
String columnTypeName = metaData.getColumnTypeName(i);
DatabaseMetaData metaDataColumns = conn.getMetaData();
ResultSet columns = metaDataColumns.getColumns(null, null, metaData.getTableName(i), metaData.getColumnName(i));
String remarks =null;
while (columns.next()){
remarks = columns.getString("REMARKS");
log.info("字段备注:"+remarks);
}
DataValue build = DataValue.builder()
.key(metaData.getColumnName(i))
.label(remarks)
.value(resultSet.getObject(i, DataType.convertType(columnTypeName)))
.type(DataType.findBySqlType(columnTypeName))
.build();
map.put(i,build);
list.add(build);
}else {
DataValue build = DataValue.builder()
.key(metaData.getColumnName(i))
.label(map.get(i).getLabel())
.value(resultSet.getObject(i, map.get(i).getType().getTargetType()))
.type(map.get(i).getType())
.build();
list.add(build);
}
}
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
mysqlPool.replease(conn);
mysqlPool.closeConn();
return list;
}
@Override
public List<List<DataValue>> findTableValueContributionRule(Long basicId, Long tableId) {
ConcurrentHashMap<Integer, DataValue> map = new ConcurrentHashMap<>();
TableInfo dataSourceTableInfo = tableInfoService.getById(basicId);
DataSources dataSources = dataSourcesService.getById(dataSourceTableInfo.getBasicId());
TableInfo tableInfo = tableInfoService.getById(tableId);
String tableName = tableInfo.getTableName();
MysqlPool mysqlPool = new MysqlPool(dataSources);
mysqlPool.init();
Connection conn = mysqlPool.getConn();
List<List<DataValue>> list = new ArrayList<>();
try {
PreparedStatement preparedStatement = conn.prepareStatement(SELECTALL+tableName);
ResultSet resultSet = preparedStatement.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
while (resultSet.next()){
ArrayList<DataValue> dataValues = new ArrayList<>();
for (int i = 1; i <= columnCount; i++) {
if (resultSet.isFirst()){
String columnTypeName = metaData.getColumnTypeName(i);
DatabaseMetaData metaDataColumns = conn.getMetaData();
ResultSet columns = metaDataColumns.getColumns(null, null, metaData.getTableName(i), metaData.getColumnName(i));
String remarks =null;
while (columns.next()){
remarks = columns.getString("REMARKS");
log.info("字段备注:"+remarks);
}
DataValue build = DataValue.builder()
.key(metaData.getColumnName(i))
.label(remarks)
.value(resultSet.getObject(i, DataType.convertType(columnTypeName)))
.type(DataType.findBySqlType(columnTypeName))
.build();
dataValues.add(build);
map.put(i,build);
}else {
DataValue build = DataValue.builder()
.key(metaData.getColumnName(i))
.label(map.get(i).getLabel())
.value(resultSet.getObject(i, map.get(i).getType().getTargetType()))
.type(map.get(i).getType())
.build();
dataValues.add(build);
}
}
list.add(dataValues);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
mysqlPool.replease(conn);
mysqlPool.closeConn();
return list;
}
@Override
public Long findCount(Long basicId, String sql) {
DataSources dataSources = dataSourcesService.getById(basicId);
MysqlPool mysqlPool = new MysqlPool(dataSources);
mysqlPool.init();
Connection conn = mysqlPool.getConn();
Long count=0L;
try {
PreparedStatement preparedStatement = conn.prepareStatement(sql);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()){
count = resultSet.getLong(1);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}finally {
try {
conn.close();
mysqlPool.closeConn();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return count;
}
@Override
public DataValue[][] findTableValueToArray(Long basicId, String sql, Long one, Integer two) {
MySqlQuery mySqlQuery = new MySqlQuery();
mySqlQuery.setSql(sql);
mySqlQuery.setDataSourceId(basicId);
mySqlQuery.setOne(one);
mySqlQuery.setTwo(two);
BaseQueryHandler.set(mySqlQuery);
MySqlDataSource mySqlDataSource = new MySqlDataSource();
DataValue[][] rows = mySqlDataSource.getRows();
return rows;
}
}

View File

@ -0,0 +1,225 @@
package com.muyu.datasources.service.impl;
import com.muyu.common.domain.DataSources;
import com.muyu.common.domain.TableInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.datasources.service.DataSourcesService;
import com.muyu.datasources.service.ProductService;
import com.muyu.datasources.service.TableInfoService;
import com.muyu.etl.domain.DataValue;
import com.muyu.etl.enums.DataType;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @Authorzhangzhihao
* @nameProductServiceImpl
* @Date2024/9/2 21:12
*
*/
@Log4j2
@Service
public class ProductServiceImpl implements ProductService {
@Autowired
private DataSourcesService dataSourcesService;
@Autowired
private TableInfoService tableInfoService;
/**
*
* @param basicId
* @param tableId
* @param listList
* @return
*/
@Log(title = "添加产品数据库", businessType = BusinessType.INSERT)
@Override
public int addProduct(Long basicId, Long tableId, DataValue[][] listList) {
TableInfo tableInfoDataSources = tableInfoService.getById(basicId);
Long basicId1 = tableInfoDataSources.getBasicId();
DataSources dataSources = dataSourcesService.getById(basicId1);
TableInfo tableInfo = tableInfoService.getById(tableId);
String tableName = tableInfo.getTableName();
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setPoolName("HikariCP 连接池");
hikariConfig.setDriverClassName(dataSources.getDriverName());
hikariConfig.setJdbcUrl(dataSources.getUrl(dataSources));
hikariConfig.setUsername(dataSources.getUserName());
hikariConfig.setPassword(dataSources.getUserPwd());
hikariConfig.setMinimumIdle(2);
hikariConfig.setMaximumPoolSize(10);
hikariConfig.setMaxLifetime(300000); // 5 minutes
hikariConfig.setConnectionTimeout(30000); // 30 seconds
HikariDataSource hikariDataSource = new HikariDataSource(hikariConfig);
ExecutorService executorService = Executors.newFixedThreadPool(6);
AtomicInteger addCount = new AtomicInteger();
// 分割数据为较小的批次
List<DataValue[][]> batches = splitData(listList, 5000);
try (Connection conn = hikariDataSource.getConnection()) {
conn.setAutoCommit(false); // 开启事务
for (DataValue[][] batch : batches) {
executorService.submit(() -> {
try (Statement stmt = conn.createStatement()) {
String sql = buildBatchInsertSQL(tableName, batch);
stmt.executeUpdate(sql);
addCount.addAndGet(batch.length);
} catch (SQLException e) {
log.error("SQLException异常发生", e);
try {
conn.rollback(); // 回滚事务
} catch (SQLException ex) {
log.error("回滚事务失败", ex);
throw new RuntimeException(ex);
}
throw new RuntimeException(e);
} catch (Exception e) {
log.error("其他异常发生", e);
try {
conn.rollback(); // 回滚事务
} catch (SQLException ex) {
log.error("回滚事务失败", ex);
throw new RuntimeException(ex);
}
throw new RuntimeException(e);
}
});
}
executorService.shutdown();
if (!executorService.awaitTermination(1, TimeUnit.HOURS)) {
log.warn("Executor service did not terminate within the timeout.");
executorService.shutdownNow();
}
conn.commit(); // 提交事务
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
close(hikariDataSource); // 关闭数据源
}
return addCount.get();
}
private String buildBatchInsertSQL(String tableName, DataValue[][] batch) {
StringBuilder columns = new StringBuilder("(");
StringBuilder values = new StringBuilder("VALUES ");
// 构建字段名
for (DataValue dataValue : batch[0]) {
String key = dataValue.getKey();
columns.append(key).append(", ");
}
// 删除最后一个逗号和空格
columns.delete(columns.length() - 2, columns.length());
// 构建值部分
for (DataValue[] dataValueList : batch) {
values.append("(");
for (DataValue dataValue : dataValueList) {
Object value = dataValue.getValue();
values.append(formatValue(dataValue.getType(), value)).append(", ");
}
values.delete(values.length() - 2, values.length());
values.append("), ");
}
// 删除最后一个逗号
values.delete(values.length() - 2, values.length());
// 完成 SQL 插入语句
String sql = "INSERT INTO " + tableName + " " + columns.toString() + ") " + values.toString();
return sql;
}
private String formatValue(DataType type, Object value) {
if (value == null) {
// 根据业务需求处理 null 值
return "NULL"; // 或者其他默认值
}
if (type == DataType.VARCHAR || type == DataType.TEXT) {
return "'" + value.toString().replace("'", "''") + "'";
} else if (type == DataType.BIGINT) {
return value.toString();
} else if (type == DataType.INT) {
return value.toString();
} else if (type == DataType.DECIMAL) {
return value.toString();
} else if (type == DataType.DATETIME) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return "'" + sdf.format((Date) value) + "'";
} else if (type == DataType.DOUBLE) {
return value.toString();
} else {
return "'" + value.toString() + "'";
}
}
// 分割数据为较小的批次
private List<DataValue[][]> splitData(DataValue[][] listList, int batchSize) {
List<DataValue[][]> batches = new ArrayList<>();
int totalRows = listList.length;
int totalBatches = (int) Math.ceil((double) totalRows / batchSize);
for (int i = 0; i < totalBatches; i++) {
int start = i * batchSize;
int end = Math.min(start + batchSize, totalRows);
DataValue[][] batch = Arrays.copyOfRange(listList, start, end);
batches.add(batch);
}
return batches;
}
// 关闭数据源
private void close(HikariDataSource dataSource) {
dataSource.close();
}
// private void closeConnection(Connection conn, MysqlPool mysqlPool) {
// try {
// if (conn != null && !conn.isClosed()) {
// conn.close();
// mysqlPool.closeConn();
// }
// } catch (SQLException e) {
// e.printStackTrace();
// }
// }
}

View File

@ -0,0 +1,33 @@
package com.muyu.datasources.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.domain.Structure;
import com.muyu.datasources.mapper.StructureMapper;
import com.muyu.datasources.service.StructureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameStructureServiceImpl
* @Date2024/8/25 16:49
*
*/
@Service
public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure> implements StructureService {
@Autowired
private StructureMapper structureMapper;
@Override
public List<Structure> findStructureByTableId(Long id) {
LambdaQueryWrapper<Structure> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Structure::getTableId,id);
List<Structure> list = structureMapper.selectList(queryWrapper);
return list;
}
}

View File

@ -0,0 +1,25 @@
package com.muyu.datasources.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.system.domain.SysUser;
import com.muyu.datasources.mapper.SysUserMapper;
import com.muyu.datasources.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @Authorzhangzhihao
* @nameSysUserServiceImpl
* @Date2024/8/31 18:48
*
*/
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
@Autowired
private SysUserMapper userMapper;
@Override
public SysUser findUserById(Long userId) {
return userMapper.findUserById(userId);
}
}

View File

@ -0,0 +1,42 @@
package com.muyu.datasources.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.domain.TableInfo;
import com.muyu.datasources.mapper.TableInfoMapper;
import com.muyu.datasources.service.TableInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Authorzhangzhihao
* @nameTableInfoServiceImpl
* @Date2024/8/25 11:37
*
*/
@Service
public class TableInfoServiceImpl extends ServiceImpl<TableInfoMapper, TableInfo> implements TableInfoService {
@Autowired
private TableInfoMapper tableInfoMapper;
@Override
public TableInfo selectTableInfoByName(TableInfo tableInfoInsert) {
LambdaQueryWrapper<TableInfo> tableInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
tableInfoLambdaQueryWrapper.eq(TableInfo::getBasicId, tableInfoInsert.getBasicId())
.eq(TableInfo::getTableName, tableInfoInsert.getTableName())
.eq(TableInfo::getParentId, tableInfoInsert.getParentId());
return this.tableInfoMapper.selectOne(tableInfoLambdaQueryWrapper);
}
@Override
public List<Long> findTableIdByParentId(Long basicId) {
return tableInfoMapper.findTableIdByParentId(basicId);
}
}

View File

@ -0,0 +1,2 @@
Spring Boot Version: ${spring-boot.version}
Spring Application Name: ${spring.application.name}

View File

@ -0,0 +1,56 @@
# Tomcat
server:
port: 12000
# nacos线上地址
nacos:
addr: 12.2.0.252:8848
user-name: nacos
password: nacos
namespace: muyu-cloud
# Spring
spring:
main:
allow-bean-definition-overriding: true
application:
# 应用名称
name: cloud-etl-datasources
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: ${nacos.addr}
# nacos用户名
username: ${nacos.user-name}
# nacos密码
password: ${nacos.password}
# 命名空间
namespace: ${nacos.namespace}
config:
# 服务注册地址
server-addr: ${nacos.addr}
# nacos用户名
username: ${nacos.user-name}
# nacos密码
password: ${nacos.password}
# 命名空间
namespace: ${nacos.namespace}
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
# 系统共享配置
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# 系统环境Config共享配置
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# xxl-job 配置文件
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# rabbit 配置文件
- application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
logging:
level:
com.muyu.system.mapper: DEBUG

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="logs/cloud-etl"/>
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.muyu" level="info"/>
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn"/>
<root level="info">
<appender-ref ref="console"/>
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info"/>
<appender-ref ref="file_error"/>
</root>
</configuration>

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="logs/cloud-etl"/>
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.sky.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 使用gRpc将日志发送到skywalking服务端 -->
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<Pattern>${log.sky.pattern}</Pattern>
</layout>
</encoder>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.muyu" level="info"/>
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn"/>
<root level="info">
<appender-ref ref="GRPC_LOG"/>
<appender-ref ref="console"/>
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info"/>
<appender-ref ref="file_error"/>
</root>
</configuration>

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="logs/cloud-etl"/>
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.sky.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 使用gRpc将日志发送到skywalking服务端 -->
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<Pattern>${log.sky.pattern}</Pattern>
</layout>
</encoder>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.muyu" level="info"/>
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn"/>
<root level="info">
<appender-ref ref="GRPC_LOG"/>
<appender-ref ref="console"/>
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info"/>
<appender-ref ref="file_error"/>
</root>
</configuration>

View File

@ -0,0 +1,65 @@
<?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">
<mapper namespace="com.muyu.datasources.mapper.AssetAccreditMapper">
<select id="findUserIdList" resultType="java.lang.Long">
SELECT
su.user_id
FROM
sys_user su
LEFT JOIN asset_accredit aa ON su.user_id = aa.user_id
<where>
<if test="tableId!=null">
and aa.table_id = #{tableId}
</if>
<if test="basicId!=null">
and aa.basic_id = #{basicId}
</if>
</where>
</select>
<select id="findDeptIdList" resultType="java.lang.Long">
SELECT
sd.dept_id
FROM
sys_dept sd
LEFT JOIN asset_accredit aa on sd.dept_id = aa.dept_id
<where>
<if test="tableId!=null">
and aa.table_id = #{tableId}
</if>
<if test="basicId!=null">
and aa.basic_id = #{basicId}
</if>
</where>
</select>
<select id="findTableIdAndBasicIdByUserId" resultType="com.muyu.common.domain.resp.AssetAccreditResp">
SELECT
basic_id,
table_id
FROM
asset_accredit
<where>
<if test="userId!=null">
and user_id = #{userId}
</if>
</where>
</select>
<select id="findTableIdAndBasicIdByDeptId" resultType="com.muyu.common.domain.resp.AssetAccreditResp">
SELECT
basic_id,
table_id
FROM
asset_accredit
<where>
<if test="deptId!=null">
and dept_id = #{deptId}
</if>
</where>
</select>
</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">
<mapper namespace="com.muyu.datasources.mapper.SysUserMapper">
<select id="findUserById" resultType="com.muyu.common.system.domain.SysUser">
select * from sys_user where user_id=#{userId}
</select>
</mapper>

View File

@ -0,0 +1,19 @@
<?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">
<mapper namespace="com.muyu.datasources.mapper.TableInfoMapper">
<select id="findTableIdByParentId" resultType="java.lang.Long">
SELECT
id
FROM
table_info
<where>
<if test="basicId!=null">
and parent_id = #{basicId}
</if>
</where>
</select>
</mapper>

28
pom.xml 100644
View File

@ -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>cloud-server-parent</artifactId>
<version>3.6.4</version>
</parent>
<artifactId>cloud-etl-datasources</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>cloud-datasources-common</module>
<module>cloud-datasources-remote</module>
<module>cloud-datasources-server</module>
<module>cloud-datasources-client</module>
</modules>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>