feat:完善规则引擎版本测试
parent
f47588e658
commit
7615d0401c
|
@ -0,0 +1,16 @@
|
||||||
|
package com.muyu.data.source.client.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据接入客户端配置类
|
||||||
|
*
|
||||||
|
* @author CHX
|
||||||
|
* on 2024/5/9 星期四
|
||||||
|
*/
|
||||||
|
@ComponentScan
|
||||||
|
@Import(value = {SourceClientRunner.class})
|
||||||
|
public class SourceClientConfig {
|
||||||
|
|
||||||
|
}
|
|
@ -1,12 +1,15 @@
|
||||||
package com.muyu.data.source.client.config;
|
package com.muyu.data.source.client.config;
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.data.source.client.jdbcUtils.JDBCConcreteClass;
|
||||||
import com.muyu.data.source.config.DataSourceConfig;
|
import com.muyu.data.source.config.DataSourceConfig;
|
||||||
import com.muyu.data.source.domain.DataSource;
|
import com.muyu.data.source.domain.DataSource;
|
||||||
import com.muyu.data.source.domain.DatabaseType;
|
import com.muyu.data.source.domain.DatabaseType;
|
||||||
import com.muyu.data.source.remote.RemoteDataSourceService;
|
import com.muyu.data.source.remote.RemoteDataSourceService;
|
||||||
import com.muyu.data.source.remote.RemoteDataTypeService;
|
import com.muyu.data.source.remote.RemoteDataTypeService;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.ResultSetMetaData;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -44,10 +47,19 @@ public class SourceClientRunner implements ApplicationRunner {
|
||||||
log.info("查看连接池");
|
log.info("查看连接池");
|
||||||
DataSourceConfig.size(key);
|
DataSourceConfig.size(key);
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
log.info("取出一个链接,查看连接池");
|
log.info("取出一个连接,查看连接池");
|
||||||
Connection connection = DataSourceConfig.getConnection(key);
|
Connection connection = DataSourceConfig.getConnection(key);
|
||||||
DataSourceConfig.size(key);
|
DataSourceConfig.size(key);
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
|
JDBCConcreteClass jdbcConcreteClass = new JDBCConcreteClass();
|
||||||
|
ResultSet resultSet = jdbcConcreteClass.getResultSet(connection, "select * from engine_maintenance");
|
||||||
|
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||||
|
for (int i = 1; i <= metaData.getColumnCount(); i++) {
|
||||||
|
log.info("字段名称:{}",metaData.getColumnClassName(i));
|
||||||
|
log.info("数据库类型:{}",metaData.getColumnTypeName(i));
|
||||||
|
log.info("java类型:{}",metaData.getColumnClassName(i));
|
||||||
|
}
|
||||||
|
|
||||||
log.info("返回一个连接,查看连接池");
|
log.info("返回一个连接,查看连接池");
|
||||||
DataSourceConfig.returnConn(connection);
|
DataSourceConfig.returnConn(connection);
|
||||||
DataSourceConfig.size(key);
|
DataSourceConfig.size(key);
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.muyu.data.source.client.jdbcUtils;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* jdbc抽象类
|
||||||
|
*
|
||||||
|
* @author HuFangMing
|
||||||
|
* @ClassName: JDBCAbstractClass
|
||||||
|
* @createTime: 2024/5/13 14:40
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class JDBCAbstractClass {
|
||||||
|
public abstract ResultSet getResultSet(Connection connection,String sql);
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.muyu.data.source.client.jdbcUtils;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* jdbc实体类
|
||||||
|
*
|
||||||
|
* @author HuFangMing
|
||||||
|
* @ClassName: JDBCConcreteClass
|
||||||
|
* @createTime: 2024/5/13 14:42
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public class JDBCConcreteClass extends JDBCAbstractClass{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResultSet getResultSet(Connection connection, String sql) {
|
||||||
|
|
||||||
|
PreparedStatement ps=null;
|
||||||
|
try {
|
||||||
|
ps=connection.prepareStatement(sql);
|
||||||
|
ResultSet resultSet = ps.executeQuery();
|
||||||
|
return resultSet;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,8 +18,9 @@ import org.springframework.stereotype.Component;
|
||||||
* @createTime: 2024/5/13 15:25
|
* @createTime: 2024/5/13 15:25
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Component
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
|
@Component
|
||||||
public class DataSourceConfig {
|
public class DataSourceConfig {
|
||||||
private static HashMap<Long, DruidDataSource> dataSourceMap=new HashMap<>();
|
private static HashMap<Long, DruidDataSource> dataSourceMap=new HashMap<>();
|
||||||
|
|
||||||
|
@ -63,6 +64,6 @@ public class DataSourceConfig {
|
||||||
DruidDataSource druidDataSource=dataSourceMap.get(key);
|
DruidDataSource druidDataSource=dataSourceMap.get(key);
|
||||||
int activeCount = druidDataSource.getActiveCount();
|
int activeCount = druidDataSource.getActiveCount();
|
||||||
int poolingCount = druidDataSource.getPoolingCount();
|
int poolingCount = druidDataSource.getPoolingCount();
|
||||||
log.info(key+"连接池正在使用连接"+activeCount+"个,线程池中线程数量"+poolingCount+"个");
|
log.info(key+"连接池正在使用连接"+activeCount+"个,连接池中连接数量"+poolingCount+"个");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
com.muyu.source.remote.factory.RemoteDataSourceFactory
|
com.muyu.data.source.remote.factory.RemoteDataSourceFactory
|
||||||
com.muyu.source.remote.factory.RemoteDataTypeFactory
|
com.muyu.data.source.remote.factory.RemoteDataTypeFactory
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.muyu.data.source.domain.AssetDataSource;
|
||||||
import com.muyu.data.source.domain.Children;
|
import com.muyu.data.source.domain.Children;
|
||||||
import com.muyu.data.source.domain.TableData;
|
import com.muyu.data.source.domain.TableData;
|
||||||
import com.muyu.data.source.domain.resp.CountResp;
|
import com.muyu.data.source.domain.resp.CountResp;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
@ -202,4 +203,12 @@ public class DataSourceController extends BaseController {
|
||||||
return Result.success(countResp);
|
return Result.success(countResp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据实例集合
|
||||||
|
*/
|
||||||
|
@GetMapping("/getDataModel/{id}")
|
||||||
|
public Result getDataModel(@PathVariable("id")Long id){
|
||||||
|
List<HashMap<String, Object>> dataModelMapList= dataSourceService.getDataModel(id);
|
||||||
|
return Result.success(dataModelMapList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.muyu.data.source.domain.AssetDataSource;
|
||||||
import com.muyu.data.source.domain.Children;
|
import com.muyu.data.source.domain.Children;
|
||||||
import com.muyu.data.source.domain.TableData;
|
import com.muyu.data.source.domain.TableData;
|
||||||
import com.muyu.data.source.domain.resp.CountResp;
|
import com.muyu.data.source.domain.resp.CountResp;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.muyu.data.source.domain.DataSource;
|
import com.muyu.data.source.domain.DataSource;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
@ -43,4 +44,6 @@ public interface DataSourceService extends IService<DataSource> {
|
||||||
CountResp getTableDataCount(Long id);
|
CountResp getTableDataCount(Long id);
|
||||||
|
|
||||||
Result updTableData(TableData tableData);
|
Result updTableData(TableData tableData);
|
||||||
|
|
||||||
|
List<HashMap<String, Object>> getDataModel(Long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -479,6 +479,53 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
||||||
return Result.success(tableDataService.updateById(tableData));
|
return Result.success(tableDataService.updateById(tableData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<HashMap<String, Object>> getDataModel(Long id) {
|
||||||
|
List<HashMap<String, Object>> list = new ArrayList<>();
|
||||||
|
Children children = childrenService.getOne(new LambdaQueryWrapper<>() {{
|
||||||
|
eq(Children::getId, id);
|
||||||
|
}});
|
||||||
|
DataSource dataSource = this.getOne(new LambdaQueryWrapper<>() {{
|
||||||
|
eq(DataSource::getId, children.getAssetId());
|
||||||
|
}});
|
||||||
|
DatabaseType databaseType = databaseTypeService.getOne(new LambdaQueryWrapper<>() {{
|
||||||
|
eq(DatabaseType::getDatabaseName, dataSource.getDataType());
|
||||||
|
}});
|
||||||
|
List<TableData> tableDataList = tableDataService.list(new LambdaQueryWrapper<>() {{
|
||||||
|
eq(TableData::getChildrenId, id);
|
||||||
|
}});
|
||||||
|
String sql="";
|
||||||
|
String query="";
|
||||||
|
String url=databaseType.getUrlPre()+dataSource.getHost()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName()+"?"+dataSource.getConnectionParam();
|
||||||
|
for (TableData tableData : tableDataList) {
|
||||||
|
query+=tableData.getName()+",";
|
||||||
|
}
|
||||||
|
query=query.substring(0,query.length()-1);
|
||||||
|
if ("mysql".equals(dataSource.getDataType())){
|
||||||
|
sql="select"+query+"from"+children.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName(databaseType.getDriverManager());
|
||||||
|
Connection connection=DriverManager.getConnection(url,dataSource.getUser(),dataSource.getPassword());
|
||||||
|
Statement statement = connection.createStatement();
|
||||||
|
ResultSet rs = statement.executeQuery(sql);
|
||||||
|
ResultSetMetaData metaData = rs.getMetaData();
|
||||||
|
while (rs.next()){
|
||||||
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
|
for (int i = 1; i <= metaData.getColumnCount(); i++) {
|
||||||
|
String columnName = metaData.getColumnName(i);
|
||||||
|
Object value = rs.getObject(i);
|
||||||
|
map.put(columnName, value);
|
||||||
|
}
|
||||||
|
list.add(map);
|
||||||
|
}
|
||||||
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getJavaType(String driveClass, String jdbcUrl, DataSource dataSource, String tableName,
|
public static String getJavaType(String driveClass, String jdbcUrl, DataSource dataSource, String tableName,
|
||||||
String columnName) {
|
String columnName) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.muyu.rule.client.config;
|
package com.muyu.ruleEngine.client.config;
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.muyu.ruleEngine.client.config;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.ruleEngine.domain.EngineMaintenance;
|
||||||
|
|
||||||
|
import com.muyu.ruleEngine.remote.RemoteEngineMaintenanceService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化加载
|
||||||
|
*
|
||||||
|
* @author CHX
|
||||||
|
* on 2024/5/9 星期四
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
public class RuleEngineClientRunner implements ApplicationRunner {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RemoteEngineMaintenanceService engineMaintenanceService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
|
Result<List<EngineMaintenance>> maintenanceList = engineMaintenanceService.getMaintenanceList();
|
||||||
|
|
||||||
|
log.info(maintenanceList);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1 @@
|
||||||
com.muyu.rule.engine.client.config.RuleEngineClientConfig
|
com.muyu.ruleEngine.client.config.RuleEngineClientConfig
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
package com.muyu.ruleEngine.context;
|
||||||
|
|
||||||
import com.muyu.ruleEngine.engine.scope.scope_engine;
|
import com.muyu.ruleEngine.engine.scope.scope_engine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue