fase()线程池查找随机字段值
parent
6044eaa915
commit
28b252bb66
|
@ -1,13 +0,0 @@
|
|||
package muyu.data.range.config;
|
||||
|
||||
import muyu.data.range.config.runner.DataRangeConfigRunner;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* 规则引擎客户端配置类
|
||||
*/
|
||||
@ComponentScan
|
||||
@Import(value = DataRangeConfigRunner.class)
|
||||
public class DataRangeConfig {
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package muyu.data.range.config.runner;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.edition.domain.RuleEngine;
|
||||
import com.muyu.goods.edition.remote.RemoteDataManagerService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Log4j2
|
||||
@Component
|
||||
@Configuration
|
||||
public class DataGoodsConfigRunner implements ApplicationRunner {
|
||||
@Autowired
|
||||
private RemoteDataManagerService remoteDataManagerService;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
Result<List<RuleEngine>> list = remoteDataManagerService.list();
|
||||
List<RuleEngine> rows = list.getData();
|
||||
log.info("远程调用成功:{}",rows);
|
||||
}
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
muyu.data.range.config.DataGoodsConfig
|
||||
muyu.data.range.config.DataRangeConfig
|
|
@ -1,20 +0,0 @@
|
|||
package muyu.data.range;
|
||||
|
||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@EnableAsync
|
||||
public class DataRangesApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DataRangesApplication.class);
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package muyu.data.range.controller;
|
||||
|
||||
import com.data.ranges.clinet.config.runner.DataGoodsConfigRunner;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/range")
|
||||
@Log4j2
|
||||
public class RangesController {
|
||||
|
||||
@PostMapping("sel")
|
||||
private static void sel(){
|
||||
DataGoodsConfigRunner dataGoodsConfigRunner = new DataGoodsConfigRunner();
|
||||
System.out.println(dataGoodsConfigRunner.toString());
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9511
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: muyu-range
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 129.211.23.219:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 129.211.23.219:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
logging:
|
||||
level:
|
||||
com.muyu.edition.mapper: DEBUG
|
|
@ -1,27 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-data-range</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>muyu-data-range-server</module>
|
||||
<module>muyu-data-range-common</module>
|
||||
<module>muyu-data-range-clinet</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>
|
|
@ -1,15 +1,16 @@
|
|||
<?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"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-data-range</artifactId>
|
||||
<artifactId>muyu</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<relativePath>../../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-data-range-clinet</artifactId>
|
||||
<artifactId>muyu-data-test-client</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
|
@ -17,35 +18,22 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-modules-system</artifactId>
|
||||
<artifactId>muyu-goods-edition-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-goods-edition</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<artifactId>muyu-common-system</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-data-range-common</artifactId>
|
||||
<artifactId>muyu-data-test-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-goods-edition</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-goods-edition-remote</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,11 @@
|
|||
package muyu.data.test.clinet;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DataClientApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DataClientApplication.class);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package muyu.data.range.config;
|
||||
package muyu.data.test.clinet.config;
|
||||
|
||||
import muyu.data.range.config.runner.DataGoodsConfigRunner;
|
||||
import muyu.data.test.clinet.config.runner.AccessConfigRunner;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
|
@ -8,6 +8,6 @@ import org.springframework.context.annotation.Import;
|
|||
* 规则引擎客户端配置类
|
||||
*/
|
||||
@ComponentScan
|
||||
@Import(value = DataGoodsConfigRunner.class)
|
||||
public class DataGoodsConfig {
|
||||
@Import(value = AccessConfigRunner.class)
|
||||
public class AccessConfig {
|
||||
}
|
|
@ -1,16 +1,13 @@
|
|||
package muyu.data.range.config.runner;
|
||||
package muyu.data.test.clinet.config.runner;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.edition.dataSoutce.DataSourceConfig;
|
||||
import com.muyu.system.domain.DataAccess;
|
||||
import com.muyu.system.remote.RemoteSystemManageService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import muyu.data.test.common.dataSoutce.DataSourceConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
@ -24,15 +21,15 @@ import java.util.List;
|
|||
@Log4j2
|
||||
@Component
|
||||
@Configuration
|
||||
public class DataRangeConfigRunner implements ApplicationRunner {
|
||||
public class AccessConfigRunner implements ApplicationRunner {
|
||||
@Autowired
|
||||
private RemoteSystemManageService remoteSystemManageService;// 远程调用
|
||||
@Autowired
|
||||
private DataSourceConfig dataSourceConfig;
|
||||
private RemoteSystemManageService remoteSystemManageService;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
//远程调用
|
||||
Result<List<DataAccess>> lists = remoteSystemManageService.lists();
|
||||
log.info("数据源调用状态:{}",lists);
|
||||
//判断非空
|
||||
if (lists.getData() == null || lists.getData().isEmpty()){
|
||||
log.error("数据为空");
|
||||
|
@ -40,7 +37,7 @@ public class DataRangeConfigRunner implements ApplicationRunner {
|
|||
}
|
||||
//获取数据源集合
|
||||
List<DataAccess> listResultData = lists.getData();
|
||||
// log.info("远程调用:{}",listResultData);
|
||||
log.info("远程调用:{}",listResultData);
|
||||
//存入map
|
||||
//创建map
|
||||
HashMap<Long, DataAccess> frimaryVoHashMap = new HashMap<>();
|
||||
|
@ -50,35 +47,26 @@ public class DataRangeConfigRunner implements ApplicationRunner {
|
|||
});
|
||||
//遍历添加到hashMap
|
||||
for (DataAccess listResultDatum : listResultData) {
|
||||
if (listResultDatum.getType() == "MySql"){
|
||||
if (listResultDatum.getType().equals("MySql")){
|
||||
//记录线程池
|
||||
dataSourceConfig.index(listResultDatum);
|
||||
DataSourceConfig.index(listResultDatum);
|
||||
}
|
||||
}
|
||||
//连接上线程池
|
||||
DataAccess dataAccess = listResultData.get(0);
|
||||
System.out.println(dataAccess);
|
||||
dataSourceConfig.verify(dataAccess.getId());
|
||||
DataSourceConfig.verify(dataAccess.getId());
|
||||
//获取一个线程池
|
||||
Connection connection = dataSourceConfig.getConnection(dataAccess.getId());
|
||||
log.info("获取线程:{}",connection);
|
||||
//查看线程
|
||||
System.out.println("查看线程");
|
||||
dataSourceConfig.verify(dataAccess.getId());
|
||||
Connection connection = DataSourceConfig.getConnection(dataAccess.getId());
|
||||
log.info("获取一个线程:{}",connection);
|
||||
DataSourceConfig.verify(dataAccess.getId());
|
||||
//归还线程池
|
||||
System.out.println("归还线程池");
|
||||
dataSourceConfig.returnConnection(connection);
|
||||
//查看线程
|
||||
System.out.println("查看线程");
|
||||
dataSourceConfig.verify(dataAccess.getId());
|
||||
DataSourceConfig.returnConnection(connection);
|
||||
DataSourceConfig.verify(dataAccess.getId());
|
||||
//将对象传入Spring
|
||||
//SpringHashMap(hashMap);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HashMap<Long, DruidDataSource> SpringHashMap(HashMap<Long,DruidDataSource> hashMap) {
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
muyu.data.test.clinet.config.AccessConfig
|
|
@ -1,27 +1,27 @@
|
|||
<?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"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-data-range</artifactId>
|
||||
<artifactId>muyu-data-test</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-data-range-common</artifactId>
|
||||
<artifactId>muyu-data-test-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>muyu-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-modules-system</artifactId>
|
||||
|
@ -29,5 +29,4 @@
|
|||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,93 @@
|
|||
package muyu.data.test.common.dataSoutce;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.muyu.system.domain.DataAccess;
|
||||
import lombok.Data;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 线程池配置
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@Configuration
|
||||
@Log4j2
|
||||
public class DataSourceConfig {
|
||||
|
||||
private static HashMap<Long,DruidDataSource> hashMap = new HashMap<>();
|
||||
/**
|
||||
* 添加线程池
|
||||
* 线程池初始化
|
||||
*/
|
||||
public static void index(DataAccess dataAccess) throws SQLException {
|
||||
//主机地址
|
||||
String host = dataAccess.getHost();
|
||||
//端口号
|
||||
String port = dataAccess.getPort();
|
||||
//数据库名
|
||||
String databaseName = dataAccess.getDatabaseName();
|
||||
// url
|
||||
String url = String.format("jdbc:mysql://"+ host+":"+port+"/"+databaseName);
|
||||
log.info("集成化的url:{}",url);
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
//初始化链接池数量
|
||||
dataSource.setInitialSize(dataAccess.getInitNum().intValue());
|
||||
//最大线程池
|
||||
dataSource.setMaxActive(dataAccess.getMaxNum().intValue());
|
||||
//最大等待时间
|
||||
dataSource.setMaxWait(dataAccess.getMaxWaitTime());
|
||||
//配置数据库的基本信息
|
||||
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
|
||||
//数据库连接池
|
||||
dataSource.setUrl(url);
|
||||
//数据库用户名
|
||||
dataSource.setUsername(dataAccess.getUsername());
|
||||
//数据库密码
|
||||
dataSource.setPassword(dataAccess.getPassword());
|
||||
dataSource.init();// 初始化
|
||||
hashMap.put(dataAccess.getId(),dataSource);
|
||||
log.info("储存线程池:{}",hashMap);
|
||||
// HashMap<Long, DruidDataSource> dataSourceHashMap = SpringHashMap(hashMap);
|
||||
// log.info("hashmap存储",dataSourceHashMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取出线程池
|
||||
*/
|
||||
public static Connection getConnection(Long key){
|
||||
DruidDataSource dataSource = hashMap.get(key);
|
||||
try {
|
||||
DruidPooledConnection connection = dataSource.getConnection();
|
||||
return connection;
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 归还线程池
|
||||
*/
|
||||
public static void returnConnection(Connection connection){
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 连接线程池
|
||||
* 验证线程池
|
||||
*/
|
||||
public static DruidDataSource verify(Long key) throws SQLException {
|
||||
DruidDataSource dataSource = hashMap.get(key);
|
||||
// 获取连接
|
||||
log.info("查看连接上的线程池:{}",dataSource);
|
||||
return dataSource;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package muyu.data.test.common.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
public class Table {
|
||||
public String key;
|
||||
public Object val;
|
||||
}
|
|
@ -1,15 +1,15 @@
|
|||
<?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"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-data-range</artifactId>
|
||||
<artifactId>muyu-data-test</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-data-range-server</artifactId>
|
||||
<artifactId>muyu-data-test-server</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
|
@ -17,22 +17,31 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-data-test-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-data-test-client</artifactId>
|
||||
<version>3.6.3</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>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
@ -82,17 +91,6 @@
|
|||
<artifactId>muyu-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Sql Server 驱动 -->
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
<version>9.4.0.jre8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-goods-edition-clinet</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -117,13 +115,6 @@
|
|||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<mainClass>com.muyu.ruleEngine.GtlRuleEngineApplication</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -5,20 +5,16 @@ import com.muyu.common.security.annotation.EnableMyFeignClients;
|
|||
import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
/**
|
||||
* 测试启动类
|
||||
*
|
||||
*/
|
||||
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
|
||||
@SpringBootApplication
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@EnableAsync
|
||||
public class MuyuGoodsTestApplication {
|
||||
public class DataTestApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MuyuGoodsTestApplication.class);
|
||||
SpringApplication.run(DataTestApplication.class,args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package com.data.test.common;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import muyu.data.test.common.dataSoutce.DataSourceConfig;
|
||||
import muyu.data.test.common.domain.Table;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/data")
|
||||
public class TestController extends BaseController {
|
||||
/**
|
||||
* 随机字段
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("randomField")
|
||||
public Result randomField(Long id,String tableName) throws SQLException {
|
||||
System.out.println("id="+id);
|
||||
Connection connection = DataSourceConfig.getConnection(id);
|
||||
DruidDataSource verify = DataSourceConfig.verify(id);
|
||||
System.out.println(verify.getUrl());
|
||||
log.info("获取一个线程池:{}",connection);
|
||||
//运行sql语句
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery("select * from " + tableName);
|
||||
//获取meteData
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
//总数量
|
||||
int columnCount = metaData.getColumnCount();
|
||||
//随机数
|
||||
Random random = new Random();
|
||||
List<Table> list = new ArrayList<>();
|
||||
int i = random.nextInt(columnCount)+1;
|
||||
System.out.println("随机数"+i);
|
||||
while (resultSet.next()){
|
||||
for (int i1 = 1; i1 <= columnCount; i1++) {
|
||||
String s = metaData.getColumnName(i1);
|
||||
Object o = resultSet.getObject(i1);
|
||||
System.out.println(s);
|
||||
System.out.println(o);
|
||||
Table build = Table.builder()
|
||||
.key(s)
|
||||
.val(o)
|
||||
.build();
|
||||
list.add(build);
|
||||
}
|
||||
}
|
||||
if (list.size()==0){
|
||||
return null;
|
||||
}
|
||||
int qu = list.size()/columnCount;
|
||||
System.out.println("区间数:"+qu);
|
||||
int in = i*qu;
|
||||
System.out.println("字段长度"+columnCount);
|
||||
System.out.println("新数"+in);
|
||||
System.out.println(list);
|
||||
System.out.println("长度"+list.size());
|
||||
List<Table> tables = new ArrayList<>();
|
||||
for (int idd = i*columnCount-columnCount; idd < i*columnCount; idd++) {
|
||||
System.out.println(idd);
|
||||
tables.add(list.get(idd));
|
||||
}
|
||||
System.out.println(tables);
|
||||
DataSourceConfig.returnConnection(connection);
|
||||
return success(tables);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.data.test.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface TestMapper {
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.data.test.server;
|
||||
|
||||
public interface TestService {
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.data.test.server.impl;
|
||||
|
||||
import com.data.test.server.TestService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class TestServiceImpl implements TestService {
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9515
|
||||
port: 9509
|
||||
|
||||
# Spring
|
||||
spring:
|
|
@ -1,6 +1,6 @@
|
|||
<?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"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>
|
||||
|
@ -11,98 +11,17 @@
|
|||
</parent>
|
||||
|
||||
<artifactId>muyu-data-test</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>muyu-data-test-common</module>
|
||||
<module>muyu-data-test-client</module>
|
||||
<module>muyu-data-test-server</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>
|
||||
<dependencies>
|
||||
<!-- 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>
|
||||
|
||||
<!-- Swagger UI -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataSource -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-datascope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common Swagger -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</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>
|
||||
|
|
|
@ -45,6 +45,8 @@ import java.util.stream.Stream;
|
|||
@Configuration
|
||||
public class AccessConfigRunner implements ApplicationRunner {
|
||||
// @Autowired
|
||||
// private RemoteSystemManageService remoteSystemManageService;
|
||||
// @Autowired
|
||||
// private RemoteSystemManageService remoteSystemManageService;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package muyu.data.range.common.domain.dataSoutce;
|
||||
package com.muyu.edition.dataSoutce;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
|
@ -35,7 +35,7 @@ public class DataSourceConfig {
|
|||
//数据库名
|
||||
String databaseName = dataAccess.getDatabaseName();
|
||||
// url
|
||||
String url = String.format("jdbc:mysql://"+ host+":"+port+":"+databaseName);
|
||||
String url = String.format("jdbc:mysql://"+ host+":"+port+"/"+databaseName);
|
||||
log.info("集成化的url:{}",url);
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
//初始化链接池数量
|
||||
|
@ -45,20 +45,18 @@ public class DataSourceConfig {
|
|||
//最大等待时间
|
||||
dataSource.setMaxWait(dataAccess.getMaxWaitTime());
|
||||
//配置数据库的基本信息
|
||||
dataSource.setDriverClassName("com.mysql/jdbc.Driver");
|
||||
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
|
||||
//数据库连接池
|
||||
dataSource.setUrl("jdbc:mysql://"+host+":"+port+":"+databaseName);
|
||||
dataSource.setUrl(url);
|
||||
//数据库用户名
|
||||
dataSource.setUsername(dataAccess.getUsername());
|
||||
//数据库密码
|
||||
dataSource.setPassword(dataAccess.getPassword());
|
||||
try {
|
||||
dataSource.init();// 初始化
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
hashMap.put(dataAccess.getId(),dataSource);
|
||||
SpringHashMap(hashMap);
|
||||
log.info("储存线程池:{}",hashMap);
|
||||
// HashMap<Long, DruidDataSource> dataSourceHashMap = SpringHashMap(hashMap);
|
||||
// log.info("hashmap存储",dataSourceHashMap);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,12 +88,11 @@ public class DataSourceConfig {
|
|||
public static void verify(Long key) throws SQLException {
|
||||
DruidDataSource dataSource = hashMap.get(key);
|
||||
// 获取连接
|
||||
DruidPooledConnection connection = dataSource.getConnection();
|
||||
log.info("连接上线程池:{}",connection);
|
||||
log.info("查看连接上的线程池:{}",dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static HashMap<Long,DruidDataSource> SpringHashMap(HashMap<Long, DruidDataSource> hashMap) {
|
||||
return hashMap;
|
||||
}
|
||||
// @Bean
|
||||
// public static HashMap<Long,DruidDataSource> SpringHashMap(HashMap<Long, DruidDataSource> hashMap) {
|
||||
// return hashMap;
|
||||
// }
|
||||
}
|
|
@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("accredit")
|
||||
|
@ -189,6 +190,18 @@ public class AccreditController extends BaseController {
|
|||
return success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父类集主键获取子类集
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/selectTableList/{id}")
|
||||
public Result<List<TableList>> selectTableList(@PathVariable Long id){
|
||||
List<FrimaryVo> collect = selectFrimary().getData().stream().filter(i -> i.getId().equals(id)).collect(Collectors.toList());
|
||||
List<TableList> tableLists = collect.get(0).getTableLists();
|
||||
return success(tableLists);
|
||||
}
|
||||
|
||||
@PostMapping("/selStatus")
|
||||
public Result<Status> selStatus(String databaseName, String tableName) {
|
||||
return success(service.selStatus(databaseName,tableName));
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.system.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.system.domain.vo.DataModel;
|
||||
import com.muyu.system.service.TestSystemService;
|
||||
import com.mysql.cj.x.protobuf.MysqlxCrud;
|
||||
import org.apache.poi.util.Internal;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("extract")
|
||||
public class TestSystemController extends BaseController {
|
||||
@Autowired
|
||||
private TestSystemService testSystemService;
|
||||
|
||||
@GetMapping("/getRandomDate")
|
||||
public Result<List<List<DataModel>>> getRandomDate(Long id,String tableName,Integer cope){
|
||||
return success(testSystemService.getRandomDate(id,tableName,cope));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.muyu.system.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
public class DataModel {
|
||||
private String key;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.muyu.system.service;
|
||||
|
||||
public interface TestSystemService {
|
||||
String getRandomDate(Long id, String tableName, Integer cope);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.system.service.impl;
|
||||
|
||||
import com.muyu.system.domain.vo.FrimaryVo;
|
||||
import com.muyu.system.service.AccreditService;
|
||||
import com.muyu.system.service.TestSystemService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class TestSystemServiceImpl implements TestSystemService {
|
||||
@Autowired
|
||||
private AccreditService accreditService;
|
||||
|
||||
@Override
|
||||
public String getRandomDate(Long id, String tableName, Integer cope) {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -14,7 +14,6 @@
|
|||
<module>muyu-job</module>
|
||||
<module>muyu-file</module>
|
||||
<module>muyu-goods</module>
|
||||
<module>muyu-goods</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>muyu-modules</artifactId>
|
||||
|
|
Loading…
Reference in New Issue