fix() 修改测试数据的展示
parent
2a13586cf7
commit
28f98b4e9c
|
@ -35,7 +35,7 @@ public class DataAccessClientRunner implements ApplicationRunner {
|
||||||
MyDataSource.size(key);
|
MyDataSource.size(key);
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
System.out.println("取出一个链接,查看连接池:");
|
System.out.println("取出一个链接,查看连接池:");
|
||||||
Connection con = MyDataSource.getCon(key);
|
Connection con = MyDataSource.getConnection(key);
|
||||||
MyDataSource.size(key);
|
MyDataSource.size(key);
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
System.out.println("返回一个链接,查看连接池:");
|
System.out.println("返回一个链接,查看连接池:");
|
||||||
|
|
|
@ -1,19 +1,24 @@
|
||||||
package com.muyu.etl.datasource;
|
package com.muyu.etl.datasource;
|
||||||
|
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import com.muyu.common.log.annotation.Log;
|
||||||
import com.muyu.etl.domain.DataSource;
|
import com.muyu.etl.domain.DataSource;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.sql.SQLFeatureNotSupportedException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName MyDataSource
|
* @ClassName MyDataSource
|
||||||
* @Description 描述
|
* @Description 数据库连接池管理
|
||||||
* @Author Peng.Jiang
|
* @Author Xin.Yao
|
||||||
* @Date 2024/5/9 19:36
|
* @Date 2024/5/9 19:36
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
|
@ -21,13 +26,16 @@ import java.util.List;
|
||||||
public class MyDataSource {
|
public class MyDataSource {
|
||||||
private static HashMap<String, DruidDataSource> pools = new HashMap<>();
|
private static HashMap<String, DruidDataSource> pools = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总数据库连接池初始化
|
||||||
|
* @param dataSourceList
|
||||||
|
*/
|
||||||
public static void info(List<DataSource> dataSourceList){
|
public static void info(List<DataSource> dataSourceList){
|
||||||
dataSourceList.stream().forEach(dataSource -> {
|
dataSourceList.stream().forEach(dataSource -> {
|
||||||
String jdbcUrl = "jdbc:"+dataSource.getType().toLowerCase()+"://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
String jdbcUrl = "jdbc:"+dataSource.getType().toLowerCase()+"://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
||||||
String key = dataSource.getDataSourceName() + "-" + dataSource.getId();
|
String key = dataSource.getDataSourceName()+"_"+dataSource.getId();
|
||||||
// 创建德鲁伊数据源
|
// 创建德鲁伊数据源
|
||||||
DruidDataSource druidSource = new DruidDataSource();
|
DruidDataSource druidSource = new DruidDataSource();
|
||||||
|
|
||||||
// 配置数据库连接信息
|
// 配置数据库连接信息
|
||||||
druidSource.setUrl(jdbcUrl);
|
druidSource.setUrl(jdbcUrl);
|
||||||
druidSource.setUsername(dataSource.getUsername());
|
druidSource.setUsername(dataSource.getUsername());
|
||||||
|
@ -41,18 +49,28 @@ public class MyDataSource {
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
pools.put(dataSource.getDataSourceName()+"_"+dataSource.getId(),druidSource);
|
addDataSource(key,druidSource);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加新的连接池
|
/**
|
||||||
|
* 添加新的连接池
|
||||||
|
* @param key
|
||||||
|
* @param druidDataSource
|
||||||
|
*/
|
||||||
public static void addDataSource(String key,DruidDataSource druidDataSource){
|
public static void addDataSource(String key,DruidDataSource druidDataSource){
|
||||||
if(!pools.containsKey(key)){
|
if (!pools.containsKey(key)){
|
||||||
pools.put(key,druidDataSource);
|
pools.put(key,druidDataSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Connection getCon(String key) {
|
/**
|
||||||
|
* 根据 key 获取连接池中的连接
|
||||||
|
* @param key
|
||||||
|
* @return Connection
|
||||||
|
*/
|
||||||
|
public static Connection getConnection(String key){
|
||||||
try {
|
try {
|
||||||
//根据key获取连接池
|
//根据key获取连接池
|
||||||
DruidDataSource druidDataSource = pools.get(key);
|
DruidDataSource druidDataSource = pools.get(key);
|
||||||
|
@ -63,7 +81,11 @@ public class MyDataSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4 提供非静态方法,用来归还链接
|
/**
|
||||||
|
* 归还连接池中的连接
|
||||||
|
* @param connection
|
||||||
|
*/
|
||||||
|
|
||||||
public static void addBack(Connection connection){
|
public static void addBack(Connection connection){
|
||||||
try {
|
try {
|
||||||
connection.close();
|
connection.close();
|
||||||
|
@ -72,7 +94,15 @@ public class MyDataSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 key 查看连接池连接信息
|
||||||
|
* @param key
|
||||||
|
*/
|
||||||
public static void size(String key){
|
public static void size(String key){
|
||||||
|
for (String s : pools.keySet()) {
|
||||||
|
log.info("连接池名称: "+s);
|
||||||
|
}
|
||||||
|
|
||||||
//根据key获取连接池
|
//根据key获取连接池
|
||||||
DruidDataSource druidDataSource = pools.get(key);
|
DruidDataSource druidDataSource = pools.get(key);
|
||||||
//获取正在使用的连接数量
|
//获取正在使用的连接数量
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.muyu.etl;
|
||||||
|
|
||||||
|
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
|
import com.muyu.etl.domain.AssetModel;
|
||||||
|
import com.muyu.etl.factory.DataAccessFallbackFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
@FeignClient(contextId = "remoteAssetModelService",
|
||||||
|
value = ServiceNameConstants.DATA_ACCESS_SERVICE,
|
||||||
|
fallbackFactory = DataAccessFallbackFactory.class)
|
||||||
|
public interface RemoteAssetModelService {
|
||||||
|
@PostMapping("/model/list")
|
||||||
|
public Result<TableDataInfo<AssetModel>> list(@RequestBody AssetModel assetModel);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.muyu.etl.factory;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
|
import com.muyu.etl.RemoteAssetModelService;
|
||||||
|
import com.muyu.etl.domain.AssetModel;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
|
||||||
|
public class AssetModelFallbackFactory implements FallbackFactory<RemoteAssetModelService> {
|
||||||
|
@Override
|
||||||
|
public RemoteAssetModelService create(Throwable cause) {
|
||||||
|
return new RemoteAssetModelService() {
|
||||||
|
@Override
|
||||||
|
public Result<TableDataInfo<AssetModel>> list(AssetModel assetModel) {
|
||||||
|
return Result.error("获取数据模型列表失败");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,6 +24,18 @@
|
||||||
<version>3.6.3</version>
|
<version>3.6.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>muyu-engine-common</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>muyu-data-access-client</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>muyu-modules-system</artifactId>
|
<artifactId>muyu-modules-system</artifactId>
|
||||||
|
|
|
@ -30,8 +30,8 @@ public class AssetModelController extends BaseController
|
||||||
/**
|
/**
|
||||||
* 查询【请填写功能名称】列表
|
* 查询【请填写功能名称】列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list")
|
@PostMapping("/list")
|
||||||
public Result<TableDataInfo<AssetModel>> list(AssetModel assetModel)
|
public Result<TableDataInfo<AssetModel>> list(@RequestBody AssetModel assetModel)
|
||||||
{
|
{
|
||||||
startPage();
|
startPage();
|
||||||
List<AssetModel> list = assetModelService.selectAssetModelList(assetModel);
|
List<AssetModel> list = assetModelService.selectAssetModelList(assetModel);
|
||||||
|
|
|
@ -77,9 +77,9 @@ public class DataSourceController extends BaseController
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/StructureList")
|
@PostMapping("/StructureList")
|
||||||
public Result structureList(@RequestBody DataSource dataSource)
|
public Result structureList(@RequestBody DataAsset dataAsset)
|
||||||
{
|
{
|
||||||
return dataSourceService.structureList(dataSource);
|
return dataSourceService.structureList(dataAsset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -66,7 +66,7 @@ public interface IDataSourceService
|
||||||
|
|
||||||
Result assetsList(DataSource dataSource);
|
Result assetsList(DataSource dataSource);
|
||||||
|
|
||||||
Result structureList(DataSource dataSource);
|
Result structureList(DataAsset dataAsset);
|
||||||
|
|
||||||
Result synchronousData(DataSource dataSource);
|
Result synchronousData(DataSource dataSource);
|
||||||
|
|
||||||
|
|
|
@ -251,8 +251,8 @@ public class DataSourceServiceImpl implements IDataSourceService
|
||||||
* @return AssetsModule 包含查询结果和列信息的模块化对象。
|
* @return AssetsModule 包含查询结果和列信息的模块化对象。
|
||||||
*/
|
*/
|
||||||
//获取数据模型的数据(KVT结构)
|
//获取数据模型的数据(KVT结构)
|
||||||
public AssetsModule getStructure(DataSource dataSource){
|
public AssetsModule getStructure(DataAsset dataAsset){
|
||||||
|
DataSource dataSource = dataSourceMapper.selectDataSourceById(dataAsset.getDataSourceId());
|
||||||
String jdbcUrl = "jdbc:"+dataSource.getType().toLowerCase()+"://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
String jdbcUrl = "jdbc:"+dataSource.getType().toLowerCase()+"://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
||||||
if (dataSource.getConnectionParam()!=null && dataSource.getConnectionParam()!=""){
|
if (dataSource.getConnectionParam()!=null && dataSource.getConnectionParam()!=""){
|
||||||
jdbcUrl = jdbcUrl+"?"+dataSource.getConnectionParam();
|
jdbcUrl = jdbcUrl+"?"+dataSource.getConnectionParam();
|
||||||
|
@ -287,7 +287,8 @@ public class DataSourceServiceImpl implements IDataSourceService
|
||||||
for (int i = 1; i <= columnCount; i++) {
|
for (int i = 1; i <= columnCount; i++) {
|
||||||
// 获取列名和类型,并封装数据
|
// 获取列名和类型,并封装数据
|
||||||
String columnName = rsd.getColumnName(i);
|
String columnName = rsd.getColumnName(i);
|
||||||
String type = map.get(columnName);
|
String[] split = rsd.getColumnClassName(i).split("\\.");
|
||||||
|
String type = split[split.length-1];
|
||||||
Object value = resultSet.getObject(i);
|
Object value = resultSet.getObject(i);
|
||||||
if (value==null){
|
if (value==null){
|
||||||
stringVTClassHashMap.put(columnName,new VTClass("",type));
|
stringVTClassHashMap.put(columnName,new VTClass("",type));
|
||||||
|
@ -438,8 +439,8 @@ public class DataSourceServiceImpl implements IDataSourceService
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public Result structureList(DataSource dataSource) {
|
public Result structureList(DataAsset dataAsset) {
|
||||||
AssetsModule kvt = getStructure(dataSource);
|
AssetsModule kvt = getStructure(dataAsset);
|
||||||
return Result.success(kvt);
|
return Result.success(kvt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,11 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>muyu-data-access-common</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</dependency>
|
||||||
<!-- SpringCloud Alibaba Nacos -->
|
<!-- SpringCloud Alibaba Nacos -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.muyu.rule.engine.req;
|
||||||
|
|
||||||
|
import com.muyu.etl.domain.DataAsset;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.apache.poi.poifs.nio.DataSource;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class DataSourceAssetModelReq {
|
||||||
|
|
||||||
|
private DataSource dataSource;
|
||||||
|
|
||||||
|
private DataAsset dataAsset;
|
||||||
|
|
||||||
|
}
|
|
@ -6,11 +6,11 @@ import lombok.Data;
|
||||||
public class RecordModel {
|
public class RecordModel {
|
||||||
|
|
||||||
private RecordModel(int dataModelLength){
|
private RecordModel(int dataModelLength){
|
||||||
dataModelArr = new DataModel[dataModelLength];
|
this.dataModelArr = new DataModel[dataModelLength];
|
||||||
}
|
}
|
||||||
|
|
||||||
private RecordModel(DataModel[] dataModelArr){
|
private RecordModel(DataModel[] dataModelArr){
|
||||||
dataModelArr = dataModelArr;
|
this.dataModelArr = dataModelArr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataModel[] dataModelArr = null;
|
private DataModel[] dataModelArr = null;
|
||||||
|
|
|
@ -1,19 +1,32 @@
|
||||||
package com.muyu.rule.scope;
|
package com.muyu.rule.scope;
|
||||||
|
|
||||||
import com.muyu.rule.scope.model.DataProcessModel;
|
import com.muyu.rule.scope.model.DataProcessModel;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class DataModelContext implements ScopeContext <DataProcessModel>{
|
public class DataModelContext implements ScopeContext <DataProcessModel>{
|
||||||
|
|
||||||
private static final ThreadLocal<DataProcessModel> THREAD_LOCAL = new ThreadLocal<>();
|
private static final ThreadLocal<DataProcessModel> THREAD_LOCAL = new ThreadLocal<>();
|
||||||
|
|
||||||
private final DataSetContext dataSetContext;
|
private final RecordContext recordContext;
|
||||||
|
|
||||||
public DataModelContext (DataSetContext dataSetContext) {
|
public DataModelContext (RecordContext recordContext) {
|
||||||
this.dataSetContext = dataSetContext;
|
this.recordContext = recordContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataProcessModel get () {
|
public DataProcessModel get () {
|
||||||
return THREAD_LOCAL.get();
|
return THREAD_LOCAL.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(DataProcessModel dataProcessModel){
|
||||||
|
THREAD_LOCAL.set(dataProcessModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear(){
|
||||||
|
THREAD_LOCAL.remove();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,25 @@ public class DataSetContext implements ScopeContext <DataSetProcessModel>{
|
||||||
|
|
||||||
private static final ThreadLocal<DataSetProcessModel> THREAD_LOCAL = new ThreadLocal<>();
|
private static final ThreadLocal<DataSetProcessModel> THREAD_LOCAL = new ThreadLocal<>();
|
||||||
|
|
||||||
private final RecordContext recordContext;
|
private final TaskContext taskContext;
|
||||||
|
|
||||||
public DataSetContext (RecordContext recordContext) {
|
public DataSetContext (TaskContext taskContext) {
|
||||||
this.recordContext = recordContext;
|
this.taskContext = taskContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataSetProcessModel get() {
|
public DataSetProcessModel get() {
|
||||||
return THREAD_LOCAL.get();
|
return THREAD_LOCAL.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear(){
|
||||||
|
THREAD_LOCAL.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(DataSetProcessModel dataSetProcessModel){
|
||||||
|
THREAD_LOCAL.set(dataSetProcessModel);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,29 @@ import com.muyu.rule.scope.model.RecordProcessModel;
|
||||||
* @Description: 记录/资产模型
|
* @Description: 记录/资产模型
|
||||||
* @Version: 1.0
|
* @Version: 1.0
|
||||||
*/
|
*/
|
||||||
public class RecordContext {
|
public class RecordContext implements ScopeContext<RecordProcessModel>{
|
||||||
|
|
||||||
private static final ThreadLocal<RecordProcessModel> THREAD_LOCAL = new ThreadLocal<>();
|
private static final ThreadLocal<RecordProcessModel> THREAD_LOCAL = new ThreadLocal<>();
|
||||||
|
|
||||||
private final TaskContext taskContext;
|
private final DataSetContext dataSetContext;
|
||||||
|
|
||||||
private RecordContext (TaskContext taskContext) {
|
private RecordContext (DataSetContext dataSetContext) {
|
||||||
this.taskContext = taskContext;
|
this.dataSetContext = dataSetContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecordProcessModel get() {
|
||||||
|
return THREAD_LOCAL.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
THREAD_LOCAL.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(RecordProcessModel recordProcessModel) {
|
||||||
|
THREAD_LOCAL.set(recordProcessModel);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,4 +9,7 @@ package com.muyu.rule.scope;
|
||||||
public interface ScopeContext<V> {
|
public interface ScopeContext<V> {
|
||||||
|
|
||||||
V get();
|
V get();
|
||||||
|
void clear();
|
||||||
|
void set(V v);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,12 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>muyu-data-access-client</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>muyu-engine-common</artifactId>
|
<artifactId>muyu-engine-common</artifactId>
|
||||||
|
|
|
@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import com.muyu.common.log.annotation.Log;
|
import com.muyu.common.log.annotation.Log;
|
||||||
import com.muyu.common.log.enums.BusinessType;
|
import com.muyu.common.log.enums.BusinessType;
|
||||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
|
||||||
import com.muyu.rule.engine.domain.EngineMaintenance;
|
import com.muyu.rule.engine.domain.EngineMaintenance;
|
||||||
import com.muyu.rule.engine.service.IEngineMaintenanceService;
|
import com.muyu.rule.engine.service.IEngineMaintenanceService;
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import com.muyu.rule.engine.domain.EngineMaintenance;
|
import com.muyu.rule.engine.domain.EngineMaintenance;
|
||||||
|
import com.muyu.rule.engine.req.DataSourceAssetModelReq;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import com.muyu.common.log.annotation.Log;
|
import com.muyu.common.log.annotation.Log;
|
||||||
|
@ -81,6 +82,14 @@ public class EngineVersionController extends BaseController
|
||||||
return toAjax(engineVersionService.updateEngineVersion(engineVersion));
|
return toAjax(engineVersionService.updateEngineVersion(engineVersion));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据域列表
|
||||||
|
*/
|
||||||
|
@PostMapping("/GetDataRegionList")
|
||||||
|
public Result getDataRegionList(@RequestBody DataSourceAssetModelReq dataSourceAssetModelReq){
|
||||||
|
return engineVersionService.getDataRegionList(dataSourceAssetModelReq);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成规则版本代码
|
* 生成规则版本代码
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.rule.engine.service;
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.rule.engine.domain.EngineVersion;
|
import com.muyu.rule.engine.domain.EngineVersion;
|
||||||
|
import com.muyu.rule.engine.req.DataSourceAssetModelReq;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -65,4 +66,6 @@ public interface IEngineVersionService
|
||||||
|
|
||||||
Result initializeRuleEngine(EngineVersion engineVersion);
|
Result initializeRuleEngine(EngineVersion engineVersion);
|
||||||
|
|
||||||
|
Result getDataRegionList(DataSourceAssetModelReq dataSourceAssetModelReq);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,19 @@ package com.muyu.rule.engine.service.impl;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.util.Arrays;
|
import java.sql.*;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.utils.DateUtils;
|
import com.muyu.common.core.utils.DateUtils;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
|
import com.muyu.etl.datasource.MyDataSource;
|
||||||
|
import com.muyu.etl.domain.custom.VTClass;
|
||||||
import com.muyu.rule.engine.constant.GenerateConstant;
|
import com.muyu.rule.engine.constant.GenerateConstant;
|
||||||
import com.muyu.rule.engine.constant.PathConstant;
|
import com.muyu.rule.engine.constant.PathConstant;
|
||||||
import com.muyu.rule.engine.domain.EngineMaintenance;
|
import com.muyu.rule.engine.domain.EngineMaintenance;
|
||||||
import com.muyu.rule.engine.mapper.EngineMaintenanceMapper;
|
import com.muyu.rule.engine.mapper.EngineMaintenanceMapper;
|
||||||
|
import com.muyu.rule.engine.req.DataSourceAssetModelReq;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -118,10 +121,17 @@ public class EngineVersionServiceImpl implements IEngineVersionService
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result generatedCode(EngineVersion engineVersion) {
|
public Result generatedCode(EngineVersion engineVersion) {
|
||||||
|
// //根据引擎ID获取规则引擎信息
|
||||||
|
// EngineMaintenance engineMaintenance = engineMaintenanceMapper.selectEngineMaintenanceById(engineVersion.getEngineMaintenanceId());
|
||||||
|
// //生成规则版本类名
|
||||||
|
// engineVersion.setVersionCode(engineMaintenance.getEngineCode()+"_"+engineVersion.getCode());
|
||||||
|
// //生成规则版本代码
|
||||||
|
// engineVersion.setCodeIng(GenerateConstant.generateConstant(engineMaintenance,engineVersion));
|
||||||
|
// return Result.success(engineVersion);
|
||||||
//根据引擎ID获取规则引擎信息
|
//根据引擎ID获取规则引擎信息
|
||||||
EngineMaintenance engineMaintenance = engineMaintenanceMapper.selectEngineMaintenanceById(engineVersion.getEngineMaintenanceId());
|
EngineMaintenance engineMaintenance = engineMaintenanceMapper.selectEngineMaintenanceById(engineVersion.getEngineMaintenanceId());
|
||||||
//生成规则版本类名
|
//生成规则版本类名
|
||||||
engineVersion.setVersionCode(engineMaintenance.getEngineCode()+"_"+engineVersion.getCode());
|
engineVersion.setVersionCode(engineMaintenance.getEngineCode()+"-"+engineVersion.getCode());
|
||||||
//生成规则版本代码
|
//生成规则版本代码
|
||||||
engineVersion.setCodeIng(GenerateConstant.generateConstant(engineMaintenance,engineVersion));
|
engineVersion.setCodeIng(GenerateConstant.generateConstant(engineMaintenance,engineVersion));
|
||||||
return Result.success(engineVersion);
|
return Result.success(engineVersion);
|
||||||
|
@ -178,4 +188,42 @@ public class EngineVersionServiceImpl implements IEngineVersionService
|
||||||
}
|
}
|
||||||
return Result.error("初始化失败");
|
return Result.error("初始化失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result getDataRegionList(DataSourceAssetModelReq dataSourceAssetModelReq) {
|
||||||
|
ArrayList<Map<String, VTClass>> kvtList = new ArrayList<>();
|
||||||
|
log.info("数据源: "+dataSourceAssetModelReq.getDataSource().toString());
|
||||||
|
try {
|
||||||
|
String sql = "select * from "+(dataSourceAssetModelReq.getDataSource().getModeName() == null ? "" : dataSourceAssetModelReq.getDataSource().getModeName()+".")+dataSourceAssetModelReq.getDataAsset().getTableName() +" limit 5";
|
||||||
|
Connection connection = MyDataSource.getConnection(dataSourceAssetModelReq.getDataSource().getDataSourceName() + "_" + dataSourceAssetModelReq.getDataSource().getId());
|
||||||
|
PreparedStatement pst = connection.prepareStatement(sql);
|
||||||
|
ResultSet resultSet = pst.executeQuery();
|
||||||
|
ResultSetMetaData rsd = resultSet.getMetaData();
|
||||||
|
|
||||||
|
int columnCount = rsd.getColumnCount();
|
||||||
|
// 遍历查询结果,将每行数据转换为 Map 形式存储
|
||||||
|
while (resultSet.next()){
|
||||||
|
Map<String, VTClass> stringVTClassHashMap = new HashMap<>();
|
||||||
|
for (int i = 1; i <= columnCount; i++) {
|
||||||
|
// 获取列名和类型,并封装数据
|
||||||
|
String columnName = rsd.getColumnName(i);
|
||||||
|
String[] split = rsd.getColumnClassName(i).split("\\.");
|
||||||
|
String type = split[split.length-1];
|
||||||
|
Object value = resultSet.getObject(i);
|
||||||
|
if (value==null){
|
||||||
|
stringVTClassHashMap.put(columnName,new VTClass("",type));
|
||||||
|
}else{
|
||||||
|
stringVTClassHashMap.put(columnName,new VTClass(value.toString(),type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kvtList.add(stringVTClassHashMap);
|
||||||
|
}
|
||||||
|
// 关闭资源
|
||||||
|
pst.close();
|
||||||
|
MyDataSource.addBack(connection);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return Result.success(kvtList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue