feat: 连接池以及jdbc 封装
parent
6cec4b330f
commit
db1da8613d
|
@ -21,5 +21,8 @@ public class ServiceNameConstants {
|
||||||
* 文件服务的serviceid
|
* 文件服务的serviceid
|
||||||
*/
|
*/
|
||||||
public static final String FILE_SERVICE = "muyu-file";
|
public static final String FILE_SERVICE = "muyu-file";
|
||||||
|
|
||||||
public static final String MUYU_KVT = "muyu-kvt";
|
public static final String MUYU_KVT = "muyu-kvt";
|
||||||
|
|
||||||
|
public static final String MUYU_RULE_ENGINE ="muyu-rule-engine" ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +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"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>muyu-common</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>muyu-common-mysql</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>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.30</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.muyu.mysql;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mysql基本定值 MySqlConfig
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/10
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class MySqlConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mysql连接前缀
|
||||||
|
*/
|
||||||
|
public static final String MYSQLJDBCPRO="jdbc:mysql://";
|
||||||
|
|
||||||
|
public static void dirver(String dirverName)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
Class.forName(dirverName);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.mysql;
|
||||||
|
|
||||||
|
import com.muyu.mysql.confilg.MySqlConfilg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mysql提供一个连接准则 MySql
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/10
|
||||||
|
*/
|
||||||
|
public interface MySqlConnect<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取连接
|
||||||
|
*/
|
||||||
|
public T getConn(MySqlConfilg mySqlConfilg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭连接
|
||||||
|
*/
|
||||||
|
public void closeConn();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.muyu.mysql;
|
||||||
|
|
||||||
|
import com.muyu.mysql.confilg.MySqlConfilg;
|
||||||
|
import com.muyu.mysql.dto.Mysql;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mysql测试 MysqlApp
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/10
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@Log4j2
|
||||||
|
public class MysqlApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
HashMap<String, Object> hashMap = new HashMap<>();
|
||||||
|
List<Mysql> mySqlConfigs = new ArrayList<>();
|
||||||
|
|
||||||
|
Mysql mysql = new Mysql();
|
||||||
|
mysql.setId("1");
|
||||||
|
mysql.setUsername("root");
|
||||||
|
mysql.setPassword("root");
|
||||||
|
mysql.setHost("localhost");
|
||||||
|
mysql.setDatabaseName("data_basete");
|
||||||
|
mysql.setPort("3306");
|
||||||
|
mysql.setType("mysql");
|
||||||
|
mysql.setConnectionParam("useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
|
||||||
|
|
||||||
|
mySqlConfigs.add(mysql);
|
||||||
|
|
||||||
|
mySqlConfigs.forEach(mysql1 -> {
|
||||||
|
MySqlConfilg build = MySqlConfilg.builder()
|
||||||
|
.id(mysql1.getId())
|
||||||
|
.name(mysql1.getName())
|
||||||
|
.userName(mysql1.getUsername())
|
||||||
|
.password(mysql1.getPassword())
|
||||||
|
.databaseName(mysql1.getDatabaseName())
|
||||||
|
.port(mysql1.getPort())
|
||||||
|
.type(mysql1.getType())
|
||||||
|
.driverName(mysql1.getConnectionParam())
|
||||||
|
.ip(mysql1.getHost())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
MySqlConnect<Connection> mySqlConnect = new MysqlConnectionInformation(build);
|
||||||
|
Connection conn = mySqlConnect.getConn(build);
|
||||||
|
try {
|
||||||
|
Statement statement = conn.createStatement();
|
||||||
|
ResultSet resultSet = statement.executeQuery("SHOW TABLES");
|
||||||
|
while (resultSet.next()){
|
||||||
|
String string = resultSet.getString(1);
|
||||||
|
log.info("name:{}",string);
|
||||||
|
}
|
||||||
|
log.info("连接成功");
|
||||||
|
mySqlConnect.closeConn();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.muyu.mysql;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mysql超时异常 MysqlConn
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/9
|
||||||
|
*/
|
||||||
|
public class MysqlConnException extends RuntimeException {
|
||||||
|
public MysqlConnException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.muyu.mysql;
|
||||||
|
|
||||||
|
import com.muyu.mysql.confilg.MySqlConfilg;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mysql连接信息 MysqlConnectionInformation
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/10
|
||||||
|
*/
|
||||||
|
public class MysqlConnectionInformation implements MySqlConnect<Connection> {
|
||||||
|
/**
|
||||||
|
* 打印日志
|
||||||
|
*/
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(MysqlConnectionInformation.class);
|
||||||
|
|
||||||
|
public MySqlConfilg mySqlConfilg;
|
||||||
|
|
||||||
|
public MysqlConnectionInformation(MySqlConfilg mySqlConfilg) {
|
||||||
|
this.mySqlConfilg = mySqlConfilg;
|
||||||
|
MySqlConfig.dirver(this.mySqlConfilg.getDriverName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Connection getConn(MySqlConfilg mySqlConfig) {
|
||||||
|
this.mySqlConfilg = mySqlConfig;
|
||||||
|
String url = this.mySqlConfilg.getUrl();
|
||||||
|
String password = this.mySqlConfilg.getPassword();
|
||||||
|
String name = this.mySqlConfilg.getName();
|
||||||
|
Connection connection = null;
|
||||||
|
try {
|
||||||
|
connection = DriverManager.getConnection(url, name, password);
|
||||||
|
if (connection != null) {
|
||||||
|
log.info("获取数据库连接成功");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("获取数据库连接失败");
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void closeConn() {
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
//关闭连接
|
||||||
|
public void close(){
|
||||||
|
|
||||||
|
Connection conn = this.getConn(this.mySqlConfilg);
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
log.info("关闭连接");
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("关闭连接失败");
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package com.muyu.mysql.confilg;
|
||||||
|
|
||||||
|
import com.muyu.mysql.MySqlConfig;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mysql连接配置 MySqlConfilg
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/10
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@SuperBuilder
|
||||||
|
public class MySqlConfilg {
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
private String id; /**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 驱动
|
||||||
|
*/
|
||||||
|
private String driverName;
|
||||||
|
/**
|
||||||
|
* url ip 端口 数据库名 编码
|
||||||
|
*/
|
||||||
|
private String ip;
|
||||||
|
private String port;
|
||||||
|
private String databaseName;
|
||||||
|
private String param;
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String userName;
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
public String getUrl(){
|
||||||
|
StringBuffer stringBuffer = new StringBuffer(MySqlConfig.MYSQLJDBCPRO);
|
||||||
|
stringBuffer.append(this.ip);
|
||||||
|
stringBuffer.append(":");
|
||||||
|
stringBuffer.append(this.port);
|
||||||
|
stringBuffer.append("/");
|
||||||
|
stringBuffer.append(this.databaseName);
|
||||||
|
stringBuffer.append("?");
|
||||||
|
stringBuffer.append(this.param);
|
||||||
|
|
||||||
|
|
||||||
|
return stringBuffer.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.muyu.mysql.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mysql对象 Mysql
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/10
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Mysql {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
/** 接入源名称 */
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** 数据来源系统名称 */
|
||||||
|
private String systemName;
|
||||||
|
|
||||||
|
/** 主机地址 */
|
||||||
|
private String host;
|
||||||
|
private String port;
|
||||||
|
|
||||||
|
/** 用户名 */
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/** 密码 */
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/** 数据接入类型 */
|
||||||
|
private String type;
|
||||||
|
/** 数据库名称 */
|
||||||
|
private String databaseName;
|
||||||
|
|
||||||
|
/** 数据连接参数 */
|
||||||
|
private String connectionParam;
|
||||||
|
|
||||||
|
}
|
|
@ -14,7 +14,9 @@ import org.springframework.web.bind.annotation.*;
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
|
@FeignClient(contextId = "remoteUserService",
|
||||||
|
value = ServiceNameConstants.SYSTEM_SERVICE,
|
||||||
|
fallbackFactory = RemoteUserFallbackFactory.class)
|
||||||
public interface RemoteUserService {
|
public interface RemoteUserService {
|
||||||
/**
|
/**
|
||||||
* 通过用户名查询用户信息
|
* 通过用户名查询用户信息
|
||||||
|
@ -38,7 +40,7 @@ public interface RemoteUserService {
|
||||||
@PostMapping("/user/register")
|
@PostMapping("/user/register")
|
||||||
public Result<Boolean> registerUserInfo (@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
public Result<Boolean> registerUserInfo (@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
|
|
||||||
@PostMapping("/selectUserId")
|
@PostMapping("/user/selectUserId")
|
||||||
public Result<SysUser> selectUserId(@RequestParam("userId") Long userId);
|
public Result<SysUser> selectUserId(@RequestParam("userId") Long userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
<module>muyu-common-datascope</module>
|
<module>muyu-common-datascope</module>
|
||||||
<module>muyu-common-datasource</module>
|
<module>muyu-common-datasource</module>
|
||||||
<module>muyu-common-system</module>
|
<module>muyu-common-system</module>
|
||||||
|
<module>muyu-common-mysql</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>muyu-common</artifactId>
|
<artifactId>muyu-common</artifactId>
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
<version>3.6.3</version>
|
<version>3.6.3</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid</artifactId>
|
||||||
|
<version>1.2.6</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,15 +1,25 @@
|
||||||
package com.muyu.kvt.client.config;
|
package com.muyu.kvt.client.config;
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.web.page.TableDataInfo;
|
import com.muyu.kvt.client.pool.BasePool;
|
||||||
|
import com.muyu.kvt.client.pool.MysqlPool;
|
||||||
|
import com.muyu.kvt.client.pool.confilg.MysqlPoolConfig;
|
||||||
|
import com.muyu.kvt.client.pool.dto.SysDataSource;
|
||||||
import com.muyu.kvt.domain.Kvt;
|
import com.muyu.kvt.domain.Kvt;
|
||||||
import com.muyu.kvt.domain.req.KvtQueryReq;
|
|
||||||
import com.muyu.kvt.remote.RemoteDataManagerService;
|
import com.muyu.kvt.remote.RemoteDataManagerService;
|
||||||
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.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化加载 KvtCilentRunner
|
* 初始化加载 KvtCilentRunner
|
||||||
*
|
*
|
||||||
|
@ -23,9 +33,153 @@ public class KvtClientRunner implements ApplicationRunner {
|
||||||
private RemoteDataManagerService remoteDataManagerService;
|
private RemoteDataManagerService remoteDataManagerService;
|
||||||
|
|
||||||
|
|
||||||
|
static HashMap<String, Connection> map = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) throws Exception {
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
// Result<TableDataInfo<Kvt>> list = remoteDataManagerService.list(null);
|
|
||||||
log.info("list");
|
List<SysDataSource> list = new ArrayList<>();
|
||||||
|
Result<List<Kvt>> listResult = remoteDataManagerService.selectKvt();
|
||||||
|
List<Kvt> data = listResult.getData();
|
||||||
|
HashMap<String, Object> hashMap = new HashMap<>();
|
||||||
|
|
||||||
|
data.forEach(kvt -> {
|
||||||
|
|
||||||
|
MysqlPoolConfig build = MysqlPoolConfig.builder()
|
||||||
|
.id(String.valueOf(kvt.getId()))
|
||||||
|
.ip(kvt.getHost())
|
||||||
|
.port(kvt.getPort())
|
||||||
|
.databaseName(kvt.getDatabaseName())
|
||||||
|
.param(kvt.getConnectionParam())
|
||||||
|
.initTotal(Math.toIntExact(kvt.getInitNum()))
|
||||||
|
.maxTotal(Math.toIntExact(kvt.getMaxNum()))
|
||||||
|
.maxWaitTimes(kvt.getMaxWaitTime())
|
||||||
|
.userName(kvt.getUsername())
|
||||||
|
.password(kvt.getPassword())
|
||||||
|
.driverName("com.mysql.cj.jdbc.Driver")
|
||||||
|
.build();
|
||||||
|
BasePool<Connection> mysqlPool = new MysqlPool(build);
|
||||||
|
|
||||||
|
log.info("初始化开始");
|
||||||
|
|
||||||
|
mysqlPool.init();
|
||||||
|
int initNum = build.getInitTotal();
|
||||||
|
for (int i = 0; i < initNum; i++) {
|
||||||
|
Connection connection = mysqlPool.creatConnection();
|
||||||
|
map.put(String.valueOf(i), connection);
|
||||||
|
mysqlPool.returnConn(connection);
|
||||||
}
|
}
|
||||||
|
log.info("-------------------------");
|
||||||
|
mysqlPool.close();
|
||||||
|
log.info("map:{}",map);
|
||||||
|
});
|
||||||
|
Connection connection = map.get("1");
|
||||||
|
Statement statement =null;
|
||||||
|
try{
|
||||||
|
statement = connection.createStatement();
|
||||||
|
ResultSet resultSet = statement.executeQuery("SHOW Tables");
|
||||||
|
while (resultSet.next()){
|
||||||
|
String name = resultSet.getString(1);
|
||||||
|
log.info("name:{}",name);
|
||||||
|
}
|
||||||
|
log.info("连接成功");
|
||||||
|
}catch (SQLException e){
|
||||||
|
log.error("sql错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// SysDataSource sysDataSource = new SysDataSource();
|
||||||
|
// sysDataSource.setId("1");
|
||||||
|
// sysDataSource.setName("本地数据库");
|
||||||
|
// sysDataSource.setSystemName("localhost");
|
||||||
|
// sysDataSource.setHost("127.0.0.1");
|
||||||
|
// sysDataSource.setPort("3306");
|
||||||
|
// sysDataSource.setUsername("root");
|
||||||
|
// sysDataSource.setPassword("root");
|
||||||
|
// sysDataSource.setType("MySql");
|
||||||
|
// sysDataSource.setDatabaseName("damo01");
|
||||||
|
// sysDataSource.setConnectionParam("useUnicode=true&characterEncoding=utf8&allowMultiQueries=true");
|
||||||
|
// sysDataSource.setInitNum(5);
|
||||||
|
// sysDataSource.setMaxNum(10);
|
||||||
|
// sysDataSource.setMaxWaitTime(4);
|
||||||
|
// sysDataSource.setMaxWaitSize(3);
|
||||||
|
// sysDataSource.setRemark("测试");
|
||||||
|
// sysDataSource.setIsInit("Y");
|
||||||
|
//
|
||||||
|
// list.add(sysDataSource);
|
||||||
|
//
|
||||||
|
// list.forEach(sysDataSoure -> {
|
||||||
|
// MysqlPoolConfig build = MysqlPoolConfig.builder()
|
||||||
|
// .id(sysDataSoure.getId())
|
||||||
|
// .ip(sysDataSoure.getHost())
|
||||||
|
// .port(sysDataSoure.getPort())
|
||||||
|
// .databaseName(sysDataSoure.getDatabaseName())
|
||||||
|
// .param(sysDataSoure.getConnectionParam())
|
||||||
|
// .initTotal(sysDataSoure.getInitNum())
|
||||||
|
// .maxTotal(sysDataSoure.getMaxNum())
|
||||||
|
// .maxWaitTimes(sysDataSoure.getMaxWaitTime())
|
||||||
|
// .userName(sysDataSoure.getUsername())
|
||||||
|
// .password(sysDataSoure.getPassword())
|
||||||
|
// .driverName("com.mysql.cj.jdbc.Driver")
|
||||||
|
// .build();
|
||||||
|
// BasePool<Connection> mysqlPool = new MysqlPool(build);
|
||||||
|
//
|
||||||
|
// log.info("初始化开始");
|
||||||
|
//
|
||||||
|
// mysqlPool.init();
|
||||||
|
// int initNum = sysDataSoure.getInitNum();
|
||||||
|
// for (int i = 0; i < initNum; i++) {
|
||||||
|
// Connection connection = mysqlPool.creatConnection();
|
||||||
|
// map.put(String.valueOf(i), connection);
|
||||||
|
// mysqlPool.returnConn(connection);
|
||||||
|
// }
|
||||||
|
// log.info("-------------------------");
|
||||||
|
// mysqlPool.close();
|
||||||
|
// log.info("map:{}",map);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// Connection connection = map.get("1");
|
||||||
|
// Statement statement =null;
|
||||||
|
// try{
|
||||||
|
// statement = connection.createStatement();
|
||||||
|
// ResultSet resultSet = statement.executeQuery("select * from user");
|
||||||
|
// while (resultSet.next()){
|
||||||
|
// int id = resultSet.getInt(1);
|
||||||
|
// String name = resultSet.getString(2);
|
||||||
|
// log.info("id:{},name:{}",id,name);
|
||||||
|
// }
|
||||||
|
// log.info("连接成功");
|
||||||
|
// }catch (SQLException e){
|
||||||
|
// log.error("sql错误");
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// DruidDataSource dataSource = new DruidDataSource();
|
||||||
|
// dataSource.setUsername("root");
|
||||||
|
// dataSource.setPassword("wxl@123");
|
||||||
|
// dataSource.setUrl("jdbc:mysql://111.229.37.54:3306/rule_engine?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
|
||||||
|
// dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
|
||||||
|
// // 连接池最小空闲的连接数
|
||||||
|
// dataSource.setMinIdle(5);
|
||||||
|
// // 连接池最大活跃的连接数
|
||||||
|
// dataSource.setMaxActive(20);
|
||||||
|
// // 初始化连接池时创建的连接数
|
||||||
|
// dataSource.setInitialSize(10);
|
||||||
|
// MysqlPool mysqlPool = new MysqlPool();
|
||||||
|
// mysqlPool.init();
|
||||||
|
// try {
|
||||||
|
// dataSource.init();
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
// throw new RuntimeException(e);
|
||||||
|
// }
|
||||||
|
// System.out.println(dataSource);
|
||||||
|
}
|
||||||
|
// @Configuration
|
||||||
|
// class DataSourceConfig{
|
||||||
|
// @Bean
|
||||||
|
// public DataSource dataSource(){
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.muyu.kvt.client.hashMap;
|
||||||
|
|
||||||
|
import com.muyu.kvt.client.config.KvtClientRunner;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公共类HashMap HashMap
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/9
|
||||||
|
*/
|
||||||
|
@ComponentScan
|
||||||
|
@Import(value = {KvtClientRunner.class})
|
||||||
|
|
||||||
|
public class HashMapp {
|
||||||
|
public static final HashMap<String, Object> params = new HashMap<>();
|
||||||
|
|
||||||
|
public void put(String value){
|
||||||
|
params.put("params",value);
|
||||||
|
}
|
||||||
|
public static HashMap<String, Object> getParams (String id)
|
||||||
|
{
|
||||||
|
Object o = params.get(id);
|
||||||
|
return (HashMap<String, Object>) o;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.muyu.kvt.client.pool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基本定值 BaseConfig
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/9
|
||||||
|
*/
|
||||||
|
public class BaseConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mysql连接前缀
|
||||||
|
*/
|
||||||
|
public static final String MYSQLJDBCPRO="jdbc:mysql://";
|
||||||
|
|
||||||
|
public static void dirver(String dirverName){
|
||||||
|
try {
|
||||||
|
Class.forName(dirverName);
|
||||||
|
}catch (ClassNotFoundException e){
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.muyu.kvt.client.pool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供一个连接池的准则 BasePool
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/9
|
||||||
|
*/
|
||||||
|
public interface BasePool<T> {
|
||||||
|
/**
|
||||||
|
* 初始化
|
||||||
|
*/
|
||||||
|
public void init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取连接
|
||||||
|
*/
|
||||||
|
public T getConn();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 归还连接
|
||||||
|
*/
|
||||||
|
public void returnConn(T conn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建连接
|
||||||
|
*/
|
||||||
|
public T creatConnection();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭连接
|
||||||
|
*/
|
||||||
|
public void close();
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.muyu.kvt.client.pool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mysql超时异常 MysqlConn
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/9
|
||||||
|
*/
|
||||||
|
public class MysqlConnException extends RuntimeException {
|
||||||
|
public MysqlConnException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,195 @@
|
||||||
|
package com.muyu.kvt.client.pool;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import com.muyu.kvt.client.pool.confilg.MysqlPoolConfig;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mysql的连接池信息 MysqlPool
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/9
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class MysqlPool implements BasePool<Connection> {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印日志
|
||||||
|
*/
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(MysqlPool.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 等待队列 基础队列
|
||||||
|
*/
|
||||||
|
private Queue<Connection> mysqlConnQueue = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 活动队列
|
||||||
|
*/
|
||||||
|
private Queue<Connection> activeMysqlQueue = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 记录队列的连接总数
|
||||||
|
*/
|
||||||
|
private AtomicInteger count = new AtomicInteger();
|
||||||
|
|
||||||
|
public MysqlPoolConfig mysqlPoolConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进行实例化连接池 并且加载驱动
|
||||||
|
*/
|
||||||
|
public MysqlPool(MysqlPoolConfig mysqlPoolConfig) {
|
||||||
|
log.info("Mysql连接池实例化完成");
|
||||||
|
this.mysqlPoolConfig = mysqlPoolConfig;
|
||||||
|
BaseConfig.dirver(this.mysqlPoolConfig.getDriverName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进行初始化连接池
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
int maxTotal = this.mysqlPoolConfig.getMaxTotal();
|
||||||
|
int initTotal = this.mysqlPoolConfig.getInitTotal();
|
||||||
|
this.mysqlConnQueue = new LinkedBlockingQueue<>();
|
||||||
|
this.activeMysqlQueue = new LinkedBlockingQueue<>();
|
||||||
|
for (int i = 0; i < initTotal; i++) {
|
||||||
|
this.mysqlConnQueue.offer(creatConnection());
|
||||||
|
count.incrementAndGet();
|
||||||
|
}
|
||||||
|
log.info("Mysql连接池初始化完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前毫秒 用来计算连接是否超时
|
||||||
|
* 获取队列当中是否还有空闲连接
|
||||||
|
* 如果有连接我们获取连接进行返回
|
||||||
|
* 如果没有 判断是否到达最大连接数
|
||||||
|
* 如何达到最大连接数则进行等待
|
||||||
|
* 如何没有达到最大连接数额 进行创建一个连接
|
||||||
|
* 放到使用队列当中 然后进行返回
|
||||||
|
* 如果连接超时的话进行抛出异常
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Connection getConn() {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
//从空闲队列当中取出放入活动队列当中
|
||||||
|
Connection conn = this.mysqlConnQueue.poll();
|
||||||
|
if (conn == null) {
|
||||||
|
this.activeMysqlQueue.offer(conn);
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果当前连接数小于最大连接数进行创建新的连接
|
||||||
|
if (count.get() < this.mysqlPoolConfig.getMaxTotal()) {
|
||||||
|
Connection connection = creatConnection();
|
||||||
|
this.activeMysqlQueue.offer(connection);
|
||||||
|
count.incrementAndGet();
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// if (System.currentTimeMillis() - startTime > this.mysqlPoolConfig.getMaxWaitTimes()) {
|
||||||
|
// throw new MysqlConnException("连接超时");
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 归还连接
|
||||||
|
*
|
||||||
|
* @param conn
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void returnConn(Connection conn) {
|
||||||
|
//删除活动队列当中的连接
|
||||||
|
if (this.activeMysqlQueue.remove(conn)) {
|
||||||
|
//把这个连接放入空闲队列当中
|
||||||
|
this.mysqlConnQueue.offer(conn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取mysql连接信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Connection creatConnection() {
|
||||||
|
String url = this.mysqlPoolConfig.getUrl();
|
||||||
|
String userName = this.mysqlPoolConfig.getUserName();
|
||||||
|
String password = this.mysqlPoolConfig.getPassword();
|
||||||
|
Connection connection = null;
|
||||||
|
try {
|
||||||
|
connection = DriverManager.getConnection(url, userName, password);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
log.info("初始化了一个数据库连接:{ip: " + this.mysqlPoolConfig.getIp() + " port: " + this.mysqlPoolConfig.getPort() + " databaseName: " + this.mysqlPoolConfig.getDatabaseName() + "}");
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
closeBaseConn();
|
||||||
|
closeActiveConn();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭空闲连接
|
||||||
|
*/
|
||||||
|
public void closeBaseConn() {
|
||||||
|
Connection poll = this.mysqlConnQueue.poll();
|
||||||
|
if (poll != null) {
|
||||||
|
try {
|
||||||
|
poll.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
if (!poll.isClosed()) {
|
||||||
|
this.mysqlConnQueue.offer(poll);
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
closeBaseConn();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeActiveConn() {
|
||||||
|
Connection poll = this.activeMysqlQueue.poll();
|
||||||
|
if (poll != null) {
|
||||||
|
try {
|
||||||
|
poll.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
try{
|
||||||
|
if (!poll.isClosed()) {
|
||||||
|
this.activeMysqlQueue.offer(poll);
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e1){
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
closeBaseConn();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.muyu.kvt.client.pool.confilg;
|
||||||
|
|
||||||
|
import com.muyu.kvt.client.pool.BaseConfig;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mysql连接池配置 MysqlPoolConfig
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/9
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@SuperBuilder
|
||||||
|
public class MysqlPoolConfig {
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
/**
|
||||||
|
* 初始化连接数
|
||||||
|
*/
|
||||||
|
private int initTotal;
|
||||||
|
/**
|
||||||
|
* 最大连接数
|
||||||
|
*/
|
||||||
|
private int maxTotal;
|
||||||
|
/**
|
||||||
|
* 最长等待时间 毫秒
|
||||||
|
*/
|
||||||
|
private long maxWaitTimes;
|
||||||
|
/**
|
||||||
|
* 驱动
|
||||||
|
*/
|
||||||
|
private String driverName;
|
||||||
|
/**
|
||||||
|
* url ip 端口 数据库名 编码
|
||||||
|
*/
|
||||||
|
private String ip;
|
||||||
|
private String port;
|
||||||
|
private String databaseName;
|
||||||
|
private String param;
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String userName;
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据库连接
|
||||||
|
*/
|
||||||
|
public String getUrl() {
|
||||||
|
StringBuilder urlSb = new StringBuilder(BaseConfig.MYSQLJDBCPRO);
|
||||||
|
urlSb.append(this.ip);
|
||||||
|
urlSb.append(":");
|
||||||
|
urlSb.append(this.port);
|
||||||
|
urlSb.append("/");
|
||||||
|
urlSb.append(this.databaseName);
|
||||||
|
urlSb.append("?");
|
||||||
|
urlSb.append(this.param);
|
||||||
|
return urlSb.toString();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package com.muyu.kvt.client.pool.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源对象 SysDataSoure
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/9
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class SysDataSource {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 数据源密码 */
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/** 接入源名称 */
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** 数据来源系统名称 */
|
||||||
|
private String systemName;
|
||||||
|
|
||||||
|
/** 主机地址 */
|
||||||
|
private String host;
|
||||||
|
private String port;
|
||||||
|
|
||||||
|
/** 用户名 */
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/** 密码 */
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/** 数据接入类型 */
|
||||||
|
private String type;
|
||||||
|
/** 数据库名称 */
|
||||||
|
private String databaseName;
|
||||||
|
|
||||||
|
/** 数据连接参数 */
|
||||||
|
private String connectionParam;
|
||||||
|
|
||||||
|
/** 初始连接数量 */
|
||||||
|
private int initNum;
|
||||||
|
|
||||||
|
/** 最大连接数量 */
|
||||||
|
private int maxNum;
|
||||||
|
|
||||||
|
/** 最大等待时间 */
|
||||||
|
private int maxWaitTime;
|
||||||
|
|
||||||
|
/** 最大等待次数 */
|
||||||
|
private int maxWaitSize;
|
||||||
|
|
||||||
|
/** 备注 */
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** 是否初始化 */
|
||||||
|
private String isInit;
|
||||||
|
|
||||||
|
}
|
|
@ -1,22 +1,21 @@
|
||||||
package com.muyu.kvt.domain;
|
package com.muyu.kvt.domain;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.muyu.common.core.annotation.Excel;
|
||||||
|
import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
import com.muyu.kvt.domain.req.KvtEditReq;
|
import com.muyu.kvt.domain.req.KvtEditReq;
|
||||||
import com.muyu.kvt.domain.req.KvtQueryReq;
|
import com.muyu.kvt.domain.req.KvtQueryReq;
|
||||||
import com.muyu.kvt.domain.req.KvtSaveReq;
|
import com.muyu.kvt.domain.req.KvtSaveReq;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
import io.swagger.annotations.*;
|
|
||||||
import com.muyu.common.core.annotation.Excel;
|
|
||||||
|
|
||||||
import com.muyu.common.core.web.domain.BaseEntity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* kvt
|
* kvt
|
||||||
|
@ -90,13 +89,12 @@ public class Kvt extends BaseEntity {
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
@Excel(name = "最大等待时间", width = 30, dateFormat = "yyyy-MM-dd")
|
@Excel(name = "最大等待时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||||
@ApiModelProperty(name = "最大等待时间", value = "最大等待时间")
|
@ApiModelProperty(name = "最大等待时间", value = "最大等待时间")
|
||||||
private Date maxWaitTime;
|
private Long maxWaitTime;
|
||||||
|
|
||||||
/** 最大等待次数 */
|
/** 最大等待次数 */
|
||||||
@Excel(name = "最大等待次数")
|
@Excel(name = "最大等待次数")
|
||||||
@ApiModelProperty(name = "最大等待次数", value = "最大等待次数")
|
@ApiModelProperty(name = "最大等待次数", value = "最大等待次数")
|
||||||
private Long maxWaitSize;
|
private Long maxWaitSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户名
|
* 用户名
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package com.muyu.kvt.domain.req;
|
package com.muyu.kvt.domain.req;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
|
||||||
import io.swagger.annotations.*;
|
|
||||||
import com.muyu.common.core.web.domain.BaseEntity;
|
import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* kvt
|
* kvt
|
||||||
|
@ -65,7 +64,7 @@ public class KvtEditReq extends BaseEntity {
|
||||||
/** 最大等待时间 */
|
/** 最大等待时间 */
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
@ApiModelProperty(name = "最大等待时间", value = "最大等待时间")
|
@ApiModelProperty(name = "最大等待时间", value = "最大等待时间")
|
||||||
private Date maxWaitTime;
|
private Long maxWaitTime;
|
||||||
|
|
||||||
/** 最大等待次数 */
|
/** 最大等待次数 */
|
||||||
@ApiModelProperty(name = "最大等待次数", value = "最大等待次数")
|
@ApiModelProperty(name = "最大等待次数", value = "最大等待次数")
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
package com.muyu.kvt.domain.req;
|
package com.muyu.kvt.domain.req;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.muyu.common.core.annotation.Excel;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
|
||||||
import io.swagger.annotations.*;
|
|
||||||
import com.muyu.common.core.web.domain.BaseEntity;
|
import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* kvt
|
* kvt
|
||||||
|
@ -66,7 +64,7 @@ public class KvtQueryReq extends BaseEntity {
|
||||||
/** 最大等待时间 */
|
/** 最大等待时间 */
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
@ApiModelProperty(name = "最大等待时间", value = "最大等待时间")
|
@ApiModelProperty(name = "最大等待时间", value = "最大等待时间")
|
||||||
private Date maxWaitTime;
|
private Long maxWaitTime;
|
||||||
|
|
||||||
/** 最大等待次数 */
|
/** 最大等待次数 */
|
||||||
@ApiModelProperty(name = "最大等待次数", value = "最大等待次数")
|
@ApiModelProperty(name = "最大等待次数", value = "最大等待次数")
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package com.muyu.kvt.domain.req;
|
package com.muyu.kvt.domain.req;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
|
||||||
import io.swagger.annotations.*;
|
|
||||||
import com.muyu.common.core.web.domain.BaseEntity;
|
import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* kvt
|
* kvt
|
||||||
|
@ -80,7 +79,7 @@ public class KvtSaveReq extends BaseEntity {
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
|
|
||||||
@ApiModelProperty(name = "最大等待时间", value = "最大等待时间")
|
@ApiModelProperty(name = "最大等待时间", value = "最大等待时间")
|
||||||
private Date maxWaitTime;
|
private Long maxWaitTime;
|
||||||
|
|
||||||
/** 最大等待次数 */
|
/** 最大等待次数 */
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,12 @@ package com.muyu.kvt.remote;
|
||||||
|
|
||||||
import com.muyu.common.core.constant.ServiceNameConstants;
|
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.web.page.TableDataInfo;
|
|
||||||
|
|
||||||
import com.muyu.kvt.domain.Kvt;
|
import com.muyu.kvt.domain.Kvt;
|
||||||
import com.muyu.kvt.domain.req.KvtQueryReq;
|
|
||||||
|
|
||||||
import com.muyu.kvt.remote.factory.DataManagerFactory;
|
import com.muyu.kvt.remote.factory.DataManagerFactory;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RemoteUser
|
* RemoteUser
|
||||||
|
@ -25,7 +23,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||||
)
|
)
|
||||||
public interface RemoteDataManagerService {
|
public interface RemoteDataManagerService {
|
||||||
|
|
||||||
@GetMapping("/list")
|
@PostMapping("/selectKvt")
|
||||||
public Result<TableDataInfo<Kvt>> list(KvtQueryReq kvtQueryReq) ;
|
public Result<List<Kvt>> selectKvt();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,13 @@ package com.muyu.kvt.remote.factory;
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.web.page.TableDataInfo;
|
|
||||||
import com.muyu.kvt.domain.Kvt;
|
import com.muyu.kvt.domain.Kvt;
|
||||||
import com.muyu.kvt.domain.req.KvtQueryReq;
|
|
||||||
import com.muyu.kvt.remote.RemoteDataManagerService;
|
import com.muyu.kvt.remote.RemoteDataManagerService;
|
||||||
|
|
||||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户服务降级处理
|
* 用户服务降级处理
|
||||||
*
|
*
|
||||||
|
@ -21,9 +20,11 @@ public class DataManagerFactory implements FallbackFactory<RemoteDataManagerServ
|
||||||
@Override
|
@Override
|
||||||
public RemoteDataManagerService create(Throwable cause) {
|
public RemoteDataManagerService create(Throwable cause) {
|
||||||
return new RemoteDataManagerService() {
|
return new RemoteDataManagerService() {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<TableDataInfo<Kvt>> list(KvtQueryReq kvtQueryReq) {
|
public Result<List<Kvt>> selectKvt() {
|
||||||
return Result.error("获取数据失败");
|
return Result.error(cause.getMessage());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package com.muyu.kvt.controller;
|
package com.muyu.kvt.controller;
|
||||||
|
|
||||||
import java.security.Permissions;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
|
@ -23,14 +18,16 @@ import com.muyu.kvt.domain.req.KvtEditReq;
|
||||||
import com.muyu.kvt.domain.req.KvtQueryReq;
|
import com.muyu.kvt.domain.req.KvtQueryReq;
|
||||||
import com.muyu.kvt.domain.req.KvtSaveReq;
|
import com.muyu.kvt.domain.req.KvtSaveReq;
|
||||||
import com.muyu.kvt.permissions.PermissionsUser;
|
import com.muyu.kvt.permissions.PermissionsUser;
|
||||||
|
import com.muyu.kvt.service.KvtService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import com.muyu.kvt.service.KvtService;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* kvt
|
* kvt
|
||||||
|
@ -58,6 +55,13 @@ public class KvtController extends BaseController {
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//查询数据接入
|
||||||
|
@PostMapping("/selectKvt")
|
||||||
|
public Result<List<Kvt>> selectKvt(){
|
||||||
|
List<Kvt> list = kvtService.list();
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出kvt列表
|
* 导出kvt列表
|
||||||
*/
|
*/
|
||||||
|
@ -270,8 +274,8 @@ public class KvtController extends BaseController {
|
||||||
//添加权限表
|
//添加权限表
|
||||||
@PostMapping("/permissionsUserAdd")
|
@PostMapping("/permissionsUserAdd")
|
||||||
public Result permissionsUserAdd(@RequestBody PermissionsUser permissionsUser){
|
public Result permissionsUserAdd(@RequestBody PermissionsUser permissionsUser){
|
||||||
kvtService.permissionsUserAdd(permissionsUser);
|
|
||||||
return Result.success("添加成功");
|
return kvtService.permissionsUserAdd(permissionsUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除权限表
|
//删除权限表
|
||||||
|
@ -287,4 +291,17 @@ public class KvtController extends BaseController {
|
||||||
List<PermissionsUser> list= kvtService.selectPermission();
|
List<PermissionsUser> list= kvtService.selectPermission();
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//根据库名查表名
|
||||||
|
@PostMapping("/selectTable")
|
||||||
|
public Result<List<String>> selectTable(@RequestBody String databaseName){
|
||||||
|
List<String> list= kvtService.selectTable(databaseName);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/selectTableName")
|
||||||
|
public Result<List<Object>> selectTableName(@RequestBody String tableName){
|
||||||
|
List<Object> list= kvtService.selectTableName(tableName);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,5 +102,11 @@ public interface KvtMapper extends BaseMapper<Kvt> {
|
||||||
|
|
||||||
List<PermissionsUser> selectPermission();
|
List<PermissionsUser> selectPermission();
|
||||||
|
|
||||||
List<PermissionsUser> permissionsUserSelect(PermissionsUser build);
|
PermissionsUser permissionsUserSelect(PermissionsUser build);
|
||||||
|
|
||||||
|
List<Object> selectTableName(String tableName);
|
||||||
|
|
||||||
|
List<DataStructure> selectDataStructureAll();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,11 +70,14 @@ public interface KvtService extends IService<Kvt> {
|
||||||
|
|
||||||
List<DataDisplay> selectDataDisplayName(String name);
|
List<DataDisplay> selectDataDisplayName(String name);
|
||||||
|
|
||||||
void permissionsUserAdd(PermissionsUser permissionsUser);
|
Result permissionsUserAdd(PermissionsUser permissionsUser);
|
||||||
|
|
||||||
void permissionsUserDel(PermissionsUser permissionsUser);
|
void permissionsUserDel(PermissionsUser permissionsUser);
|
||||||
|
|
||||||
List<PermissionsUser> selectPermission();
|
List<PermissionsUser> selectPermission();
|
||||||
|
|
||||||
|
|
||||||
|
List<String> selectTable(String databaseName);
|
||||||
|
|
||||||
|
List<Object> selectTableName(String tableName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,9 @@
|
||||||
package com.muyu.kvt.service.impl;
|
package com.muyu.kvt.service.impl;
|
||||||
|
|
||||||
import java.sql.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.common.core.utils.ObjUtils;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.common.core.utils.ObjUtils;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.common.system.domain.SysDept;
|
import com.muyu.common.system.domain.SysDept;
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
|
@ -23,15 +15,20 @@ import com.muyu.kvt.dictionary.Diction;
|
||||||
import com.muyu.kvt.dictionary.DictionaryType;
|
import com.muyu.kvt.dictionary.DictionaryType;
|
||||||
import com.muyu.kvt.dictionary.Dictionaryy;
|
import com.muyu.kvt.dictionary.Dictionaryy;
|
||||||
import com.muyu.kvt.domain.*;
|
import com.muyu.kvt.domain.*;
|
||||||
|
import com.muyu.kvt.mapper.KvtMapper;
|
||||||
import com.muyu.kvt.permissions.PermissionsUser;
|
import com.muyu.kvt.permissions.PermissionsUser;
|
||||||
|
import com.muyu.kvt.service.KvtService;
|
||||||
import com.muyu.kvt.remote.RemoteDataManagerService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.muyu.kvt.mapper.KvtMapper;
|
|
||||||
import com.muyu.kvt.service.KvtService;
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -169,20 +166,39 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
||||||
public List<ChildrenList> selectDepartment(String databaseName) {
|
public List<ChildrenList> selectDepartment(String databaseName) {
|
||||||
List<ChildrenList> list = baseMapper.selectDepartment(databaseName);
|
List<ChildrenList> list = baseMapper.selectDepartment(databaseName);
|
||||||
// Kvt kvt = baseMapper.selectType(databaseName);
|
// Kvt kvt = baseMapper.selectType(databaseName);
|
||||||
List<ChildrenList> childrenLists = new ArrayList<>();
|
HashSet<ChildrenList> set = new HashSet<>();
|
||||||
|
|
||||||
|
Result<SysUser> sysUserResult = remoteUserSer.selectUserId(SecurityUtils.getUserId());
|
||||||
|
SysUser data = sysUserResult.getData();
|
||||||
|
List<PermissionsUser> permissionsUsers = this.selectPermission();
|
||||||
|
// ...(你可能不需要SysUser对象,除非后续有使用)
|
||||||
|
|
||||||
|
Set<String> tableNameSet = permissionsUsers.stream()
|
||||||
|
.map(PermissionsUser::getTbaleName) // 确保使用正确的方法名getTableName
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
|
||||||
for (ChildrenList childrenList : list) {
|
for (ChildrenList childrenList : list) {
|
||||||
|
boolean isInSet = false; // 标记变量,用于检查name是否在tableNameSet中
|
||||||
|
for (String s : tableNameSet) {
|
||||||
|
if (childrenList.getName().equals(s)) {
|
||||||
|
isInSet = true; // 如果找到匹配的name,则设置标记为true
|
||||||
|
break; // 跳出循环,因为我们已经找到了匹配的项
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isInSet) { // 如果name不在tableNameSet中
|
||||||
ChildrenList build = ChildrenList.builder()
|
ChildrenList build = ChildrenList.builder()
|
||||||
|
.id(childrenList.getId())
|
||||||
.name(childrenList.getName())
|
.name(childrenList.getName())
|
||||||
.dataTotal(childrenList.getDataTotal())
|
.dataTotal(childrenList.getDataTotal())
|
||||||
.as(childrenList.getAs())
|
.as(childrenList.getAs())
|
||||||
.type(Long.valueOf(2))
|
.type(Long.valueOf(2)) // 注意:这里将type硬编码为2,可能需要根据实际情况调整
|
||||||
.build();
|
.build();
|
||||||
childrenLists.add(build);
|
set.add(build); // 将新的ChildrenList对象添加到set中
|
||||||
}
|
}
|
||||||
return childrenLists;
|
}
|
||||||
|
|
||||||
|
return set.stream().distinct().collect(Collectors.toList());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,10 +217,12 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
||||||
List<DataStructure> list = baseMapper.selectDataStur(tableName);
|
List<DataStructure> list = baseMapper.selectDataStur(tableName);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void user() {
|
public void user() {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Child selectChild(String tableName) {
|
public Child selectChild(String tableName) {
|
||||||
return baseMapper.selectChild(tableName);
|
return baseMapper.selectChild(tableName);
|
||||||
|
@ -212,22 +230,45 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DataStructure> selectChildAll() {
|
public List<DataStructure> selectChildAll() {
|
||||||
Result<SysUser> sysUserResult = remoteUserSer.selectUserId(SecurityUtils.getUserId());
|
// Result<SysUser> sysUserResult = remoteUserSer.selectUserId(SecurityUtils.getUserId());
|
||||||
SysUser data = sysUserResult.getData();
|
// SysUser data = sysUserResult.getData();
|
||||||
List<PermissionsUser> permissionsUsers = this.selectPermission();
|
// List<PermissionsUser> permissionsUsers = this.selectPermission();
|
||||||
// ...(你可能不需要SysUser对象,除非后续有使用)
|
//// ...(你可能不需要SysUser对象,除非后续有使用)
|
||||||
|
//
|
||||||
|
// Set<String> tableNameSet = permissionsUsers.stream()
|
||||||
|
// .map(PermissionsUser::getTbaleName) // 确保使用正确的方法名getTableName
|
||||||
|
// .collect(Collectors.toSet());
|
||||||
|
// List<DataStructure> dataStructures = new ArrayList<>();
|
||||||
|
List<DataStructure> list = baseMapper.selectDataStructureAll();
|
||||||
|
|
||||||
Set<String> tableNameSet = permissionsUsers.stream()
|
return list;
|
||||||
.map(PermissionsUser::getTbaleName) // 确保使用正确的方法名getTableName
|
// list.forEach(dataStructure -> tableNameSet.stream().filter(s -> !dataStructure.getTableName().equals(s)).map(s -> dataStructure).forEach(dataStructures::add));
|
||||||
.collect(Collectors.toSet());
|
// List<DataStructure> collect = dataStructures.stream().distinct().collect(Collectors.toList());
|
||||||
|
// return collect;
|
||||||
|
//
|
||||||
|
// List<DataStructure> dataStructures = list.stream()
|
||||||
|
// .filter(dataStructure -> !tableNameSet.contains(dataStructure.getName()))
|
||||||
|
// .distinct() // 移除重复的DataStructure对象
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
|
||||||
List<DataStructure> list = baseMapper.selectChildAll();
|
//List<DataStructure> dataStructures = list.stream()
|
||||||
List<DataStructure> notContainingCollect = list.stream()
|
// .map(dataStructure -> {
|
||||||
.filter(dataStructure -> !tableNameSet.contains(dataStructure.getTableName())) // 使用!进行否定
|
// if (!tableNameSet.contains(dataStructure.getName())) {
|
||||||
.collect(Collectors.toList());
|
// return Optional.of(dataStructure);
|
||||||
|
// } else {
|
||||||
|
// return Optional.empty(); // 当名称匹配时返回空Optional
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .filter(Optional::isPresent) // 移除空Optional
|
||||||
|
// .map(Optional::get) // 提取非空Optional中的对象
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
//
|
||||||
|
// List<DataStructure> notContainingCollect = list.stream()
|
||||||
|
// .filter(dataStructure -> !list.contains(dataStructure.getTableName())) // 使用!进行否定
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
|
||||||
// notContainingCollect现在包含了不包含在permissionsUsers中tableName的DataStructure对象列表
|
// notContainingCollect现在包含了不包含在permissionsUsers中tableName的DataStructure对象列表
|
||||||
return notContainingCollect; // 返回不包含符合条件的数据的列表
|
// 返回不包含符合条件的数据的列表
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -327,6 +368,7 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步添加资产展示
|
* 同步添加资产展示
|
||||||
|
*
|
||||||
* @param tableName
|
* @param tableName
|
||||||
* @param connection
|
* @param connection
|
||||||
* @param kvt
|
* @param kvt
|
||||||
|
@ -376,6 +418,7 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加数据结构
|
* 添加数据结构
|
||||||
|
*
|
||||||
* @param connection
|
* @param connection
|
||||||
* @param kvt
|
* @param kvt
|
||||||
* @param tableName
|
* @param tableName
|
||||||
|
@ -506,7 +549,6 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
baseMapper.add(build);
|
baseMapper.add(build);
|
||||||
}
|
}
|
||||||
executeQuery.close();
|
executeQuery.close();
|
||||||
|
@ -519,6 +561,7 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询数据库中表的总条数 以及备注 名称
|
* 查询数据库中表的总条数 以及备注 名称
|
||||||
|
*
|
||||||
* @param connection
|
* @param connection
|
||||||
* @param kvt
|
* @param kvt
|
||||||
*/
|
*/
|
||||||
|
@ -692,7 +735,7 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void permissionsUserAdd(PermissionsUser permissionsUser) {
|
public Result permissionsUserAdd(PermissionsUser permissionsUser) {
|
||||||
|
|
||||||
PermissionsUser build = PermissionsUser.builder()
|
PermissionsUser build = PermissionsUser.builder()
|
||||||
.userId(permissionsUser.getUserId())
|
.userId(permissionsUser.getUserId())
|
||||||
|
@ -701,10 +744,13 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
||||||
.tbaleName(permissionsUser.getTbaleName())
|
.tbaleName(permissionsUser.getTbaleName())
|
||||||
.build();
|
.build();
|
||||||
//先查询表中是否有这条数据
|
//先查询表中是否有这条数据
|
||||||
if (baseMapper.permissionsUserSelect(build)!=null) {
|
PermissionsUser users = baseMapper.permissionsUserSelect(build);
|
||||||
|
if (users == null) {
|
||||||
baseMapper.permissionsUserAdd(build);
|
baseMapper.permissionsUserAdd(build);
|
||||||
|
return Result.success("添加成功");
|
||||||
} else {
|
} else {
|
||||||
baseMapper.permissionsUserDel(build);
|
baseMapper.permissionsUserDel(build);
|
||||||
|
return Result.success("删除成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -720,8 +766,19 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
||||||
return baseMapper.selectPermission();
|
return baseMapper.selectPermission();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> selectTable(String databaseName) {
|
||||||
|
return baseMapper.selectTable(databaseName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Object> selectTableName(String tableName) {
|
||||||
|
return baseMapper.selectTableName(tableName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询 根据库名跟表名查询字段信息
|
* 查询 根据库名跟表名查询字段信息
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String sql() {
|
private String sql() {
|
||||||
|
@ -750,6 +807,7 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
||||||
" INFORMATION_SCHEMA.COLUMNS\n" +
|
" INFORMATION_SCHEMA.COLUMNS\n" +
|
||||||
" WHERE\n";
|
" WHERE\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sql4() {
|
public String sql4() {
|
||||||
return "SELECT\n" +
|
return "SELECT\n" +
|
||||||
" information_schema.columns.column_name,\n" +
|
" information_schema.columns.column_name,\n" +
|
||||||
|
|
|
@ -217,6 +217,12 @@ SELECT
|
||||||
and tbale_name = #{tbaleName}
|
and tbale_name = #{tbaleName}
|
||||||
and dept_id = #{deptId}
|
and dept_id = #{deptId}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectTableName" resultType="java.lang.Object">
|
||||||
|
select * from #{tableName}
|
||||||
|
</select>
|
||||||
|
<select id="selectDataStructureAll" resultType="com.muyu.kvt.domain.DataStructure">
|
||||||
|
select * from child
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<insert id="synchronizationAdd">
|
<insert id="synchronizationAdd">
|
||||||
|
|
|
@ -16,5 +16,14 @@
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>muyu-rule-engine-remote</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.muyu.engine.client;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 规则接入开发端 EngClientConfig
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/9
|
||||||
|
*/
|
||||||
|
@ComponentScan
|
||||||
|
@Import(value = {EngClientRunner.class})
|
||||||
|
public class EngClientConfig {
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.muyu.engine.client;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.engine.domain.RuleEngine;
|
||||||
|
import com.muyu.engine.remote.RuleEngineManangerService;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化加载 EngClientRunner
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/9
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
public class EngClientRunner implements ApplicationRunner {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RuleEngineManangerService ruleEngineManangerService;;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
|
Result<List<RuleEngine>> listResult = ruleEngineManangerService.selectRuleEngine();
|
||||||
|
System.out.println("sdsssssssssssssssssssssssss"+listResult.getData());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
com.muyu.engine.client.EngClientConfig
|
|
@ -1,22 +0,0 @@
|
||||||
package com.muyu.engine.custom;
|
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.engine.action.ActionDiscard;
|
|
||||||
import com.muyu.engine.scope.DataModelEngine;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: yl
|
|
||||||
* @date: 2024/5/6
|
|
||||||
* @Description: ss-ss
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
public class engine_custom_email_ss extends DataModelEngine {
|
|
||||||
@Override
|
|
||||||
public void execution () {
|
|
||||||
Object value = getValue();
|
|
||||||
|
|
||||||
if (value == null || "".equals(value) || "null".equals(value)) {
|
|
||||||
throw new ActionDiscard();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -17,4 +17,12 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>muyu-rule-engine-common</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.muyu.engine.remote;
|
||||||
|
|
||||||
|
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.engine.domain.RuleEngine;
|
||||||
|
import com.muyu.engine.domain.req.RuleEngineQueryReq;
|
||||||
|
import com.muyu.engine.remote.factory.RuleEngineManangerServiceFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RuleEngineManangerService
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/9
|
||||||
|
*/
|
||||||
|
@FeignClient(
|
||||||
|
contextId = "RuleEngineManangerService",
|
||||||
|
value = ServiceNameConstants.MUYU_RULE_ENGINE,
|
||||||
|
fallbackFactory = RuleEngineManangerServiceFactory.class,
|
||||||
|
path = "/engine"
|
||||||
|
)
|
||||||
|
public interface RuleEngineManangerService {
|
||||||
|
@PostMapping("/selectRuleEngine")
|
||||||
|
public Result<List<RuleEngine>> selectRuleEngine();
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.muyu.engine.remote.factory;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
|
import com.muyu.engine.domain.RuleEngine;
|
||||||
|
import com.muyu.engine.domain.req.RuleEngineQueryReq;
|
||||||
|
import com.muyu.engine.remote.RuleEngineManangerService;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户服务器降级处理 RuleEngineManangerServiceFactory
|
||||||
|
*
|
||||||
|
* @author LeYang
|
||||||
|
* on 2024/5/9
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class RuleEngineManangerServiceFactory implements FallbackFactory<RuleEngineManangerService> {
|
||||||
|
@Override
|
||||||
|
public RuleEngineManangerService create(Throwable cause) {
|
||||||
|
return new RuleEngineManangerService() {
|
||||||
|
@Override
|
||||||
|
public Result<List<RuleEngine>> selectRuleEngine() {
|
||||||
|
return Result.error(cause.getMessage());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
com.muyu.engine.remote.factory.RuleEngineManangerServiceFactory
|
|
@ -18,11 +18,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class RuleEngineApplication {
|
public class RuleEngineApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
SpringApplication.run(RuleEngineApplication.class);
|
SpringApplication.run(RuleEngineApplication.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,27 @@
|
||||||
package com.muyu.engine.controller;
|
package com.muyu.engine.controller;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import com.muyu.engine.domain.RuleEngines;
|
|
||||||
import io.swagger.annotations.*;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
|
import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
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.common.security.annotation.RequiresPermissions;
|
||||||
import com.muyu.engine.domain.RuleEngine;
|
import com.muyu.engine.domain.RuleEngine;
|
||||||
|
import com.muyu.engine.domain.RuleEngines;
|
||||||
|
import com.muyu.engine.domain.req.RuleEngineEditReq;
|
||||||
import com.muyu.engine.domain.req.RuleEngineQueryReq;
|
import com.muyu.engine.domain.req.RuleEngineQueryReq;
|
||||||
import com.muyu.engine.domain.req.RuleEngineSaveReq;
|
import com.muyu.engine.domain.req.RuleEngineSaveReq;
|
||||||
import com.muyu.engine.domain.req.RuleEngineEditReq;
|
|
||||||
import com.muyu.engine.service.RuleEngineService;
|
import com.muyu.engine.service.RuleEngineService;
|
||||||
import com.muyu.common.core.web.page.TableDataInfo;
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 规则引擎Controller
|
* 规则引擎Controller
|
||||||
|
@ -145,4 +140,10 @@ public class RuleEngineController extends BaseController {
|
||||||
ruleEngineService.updateRuleEngineVersionStates(ruleEngine);
|
ruleEngineService.updateRuleEngineVersionStates(ruleEngine);
|
||||||
return Result.success("引擎状态操作成功");
|
return Result.success("引擎状态操作成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/selectRuleEngine")
|
||||||
|
public Result<List<RuleEngine>> selectRuleEngine(){
|
||||||
|
List<RuleEngine> list = ruleEngineService.list();
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
package com.muyu.engine.service.impl;
|
package com.muyu.engine.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.common.core.utils.ObjUtils;
|
||||||
|
import com.muyu.engine.domain.RuleEngine;
|
||||||
|
import com.muyu.engine.domain.RuleEngines;
|
||||||
|
import com.muyu.engine.mapper.RuleEngineMapper;
|
||||||
|
import com.muyu.engine.service.RuleEngineService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
@ -8,18 +19,6 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.common.core.utils.ObjUtils;
|
|
||||||
import com.muyu.engine.domain.RuleEngines;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import com.muyu.engine.mapper.RuleEngineMapper;
|
|
||||||
import com.muyu.engine.domain.RuleEngine;
|
|
||||||
import com.muyu.engine.service.RuleEngineService;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 规则引擎Service业务层处理
|
* 规则引擎Service业务层处理
|
||||||
|
|
|
@ -2,11 +2,9 @@ package com.muyu.engine.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.engine.domain.RuleEngine;
|
import com.muyu.engine.domain.RuleEngine;
|
||||||
import com.muyu.engine.domain.rule_engine_version.RuleEngineList;
|
import com.muyu.engine.domain.rule_engine_version.RuleEngineList;
|
||||||
import com.muyu.engine.domain.rule_engine_version.RuleEngineVersion;
|
import com.muyu.engine.domain.rule_engine_version.RuleEngineVersion;
|
||||||
import com.muyu.engine.mapper.RuleEngineMapper;
|
|
||||||
import com.muyu.engine.mapper.RuleEngineVersionMapper;
|
import com.muyu.engine.mapper.RuleEngineVersionMapper;
|
||||||
import com.muyu.engine.service.RuleEngineService;
|
import com.muyu.engine.service.RuleEngineService;
|
||||||
import com.muyu.engine.service.RuleEngineVersionService;
|
import com.muyu.engine.service.RuleEngineVersionService;
|
||||||
|
@ -15,14 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.tools.*;
|
import javax.tools.*;
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -103,7 +94,7 @@ private RuleEngineService ruleEngineService;
|
||||||
}
|
}
|
||||||
|
|
||||||
//全局变量
|
//全局变量
|
||||||
public static String url="D:\\work\\zglkh\\cloud-server\\muyu-modules\\muyu-rule-engine\\muyu-rule-engine-common\\src\\main\\java\\com\\muyu\\engine\\custom\\";
|
// public static String url="D:\\work\\zglkh\\cloud-server\\muyu-modules\\muyu-rule-engine\\muyu-rule-engine-common\\src\\main\\java\\com\\muyu\\engine\\custom\\";
|
||||||
@Override
|
@Override
|
||||||
public void RuleEngineVersionAdd(RuleEngineVersion ruleEngineVersion) {
|
public void RuleEngineVersionAdd(RuleEngineVersion ruleEngineVersion) {
|
||||||
this.save(ruleEngineVersion);
|
this.save(ruleEngineVersion);
|
||||||
|
@ -118,110 +109,110 @@ private RuleEngineService ruleEngineService;
|
||||||
.build();
|
.build();
|
||||||
this.update(build,new LambdaQueryWrapper<RuleEngineVersion>().eq(RuleEngineVersion::getId,ruleEngineVersion.getId()));
|
this.update(build,new LambdaQueryWrapper<RuleEngineVersion>().eq(RuleEngineVersion::getId,ruleEngineVersion.getId()));
|
||||||
this.writeCodeAdd(ruleEngineVersion);
|
this.writeCodeAdd(ruleEngineVersion);
|
||||||
log.info("编码保存成功",build);
|
log.info("编码保存成功");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//生产源文件
|
|
||||||
public void writeCodeAdd(RuleEngineVersion ruleEngineVersion) {
|
|
||||||
try{
|
|
||||||
//文件路径
|
|
||||||
String fileName =ruleEngineVersion.getVersionCode()+".java";
|
|
||||||
String filePath = url+fileName;
|
|
||||||
|
|
||||||
//编写java文件
|
|
||||||
ProcessBuilder pbCompiler = new ProcessBuilder("javac", fileName);
|
|
||||||
pbCompiler.directory(Paths.get(url).toFile());
|
|
||||||
pbCompiler.redirectErrorStream(true);
|
|
||||||
|
|
||||||
//将字符串写入文件中
|
|
||||||
Path path = Paths.get(filePath);
|
|
||||||
Files.write(path,ruleEngineVersion.getCodeIng().getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
// 编译
|
|
||||||
Process process = pbCompiler.start();
|
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
||||||
// 等待编译结果
|
|
||||||
int exitCode = process.waitFor();
|
|
||||||
|
|
||||||
if (exitCode == 0) {
|
|
||||||
System.out.println("编译成功");
|
|
||||||
} else {
|
|
||||||
System.out.println("编译失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
//编译成class文件
|
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder("java", ruleEngineVersion.getWriteCode());
|
|
||||||
processBuilder.directory(Paths.get(url).toFile());
|
|
||||||
processBuilder.redirectErrorStream(true);
|
|
||||||
Process Runprocess = processBuilder.start();
|
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(Runprocess.getInputStream()));
|
|
||||||
String str ;
|
|
||||||
while ((str = bufferedReader.readLine()) != null) {
|
|
||||||
System.out.println(str);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Runprocess.waitFor();
|
|
||||||
int i = Runprocess.exitValue();
|
|
||||||
if (i==0){
|
|
||||||
System.out.println("运行成功");
|
|
||||||
}else {
|
|
||||||
System.out.println("运行失败");
|
|
||||||
}
|
|
||||||
}catch (Exception e){
|
|
||||||
throw new RuntimeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// private String url ="D:\\work\\zglkh\\cloud-server\\muyu-modules\\muyu-rule-engine\\muyu-rule-engine-common\\src\\main\\java\\com\\muyu\\engine\\java";
|
|
||||||
//
|
|
||||||
// //生产源文件
|
// //生产源文件
|
||||||
// public void writeCodeAdd(RuleEngineVersion ruleEngineVersion) {
|
// public void writeCodeAdd(RuleEngineVersion ruleEngineVersion) {
|
||||||
// try{
|
// try{
|
||||||
|
// //文件路径
|
||||||
|
// String fileName =ruleEngineVersion.getVersionCode()+".java";
|
||||||
|
// String filePath = url+fileName;
|
||||||
//
|
//
|
||||||
// String className = ruleEngineVersion.getVersionCode();
|
// //编写java文件
|
||||||
// String content = ruleEngineVersion.getCodeIng();
|
// ProcessBuilder pbCompiler = new ProcessBuilder("javac", fileName);
|
||||||
// // 指定输出目录
|
// pbCompiler.directory(Paths.get(url).toFile());
|
||||||
// JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
// pbCompiler.redirectErrorStream(true);
|
||||||
|
// System.out.println("Writing to file: " + filePath);
|
||||||
|
// //将字符串写入文件中
|
||||||
|
// Path path = Paths.get(filePath); Files.write(path,ruleEngineVersion.getCodeIng().getBytes(StandardCharsets.UTF_8));
|
||||||
//
|
//
|
||||||
// try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null)) {
|
|
||||||
// // 创建一个内存中的源文件
|
|
||||||
// JavaFileObject sourceFileObject = new JavaSourceFromString(className, content);
|
|
||||||
//
|
//
|
||||||
// // 编译选项
|
// // 编译
|
||||||
// Iterable<String> options = Arrays.asList("-d", url);
|
// Process process = pbCompiler.start();
|
||||||
// // 编译源代码
|
|
||||||
// JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, options, null, Arrays.asList(sourceFileObject));
|
|
||||||
// boolean success = task.call();
|
|
||||||
//
|
//
|
||||||
// if (success) {
|
// BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
// // 等待编译结果
|
||||||
|
// int exitCode = process.waitFor();
|
||||||
|
//
|
||||||
|
// if (exitCode == 0) {
|
||||||
// System.out.println("编译成功");
|
// System.out.println("编译成功");
|
||||||
// } else {
|
// } else {
|
||||||
// System.out.println("编译失败");
|
// System.out.println("编译失败");
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
//
|
// //编译成class文件
|
||||||
// } catch (Exception e) {
|
// ProcessBuilder processBuilder = new ProcessBuilder("java", ruleEngineVersion.getWriteCode());
|
||||||
// e.printStackTrace();
|
// processBuilder.directory(Paths.get(url).toFile());
|
||||||
|
// processBuilder.redirectErrorStream(true);
|
||||||
|
// Process Runprocess = processBuilder.start();
|
||||||
|
// BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(Runprocess.getInputStream()));
|
||||||
|
// String str ;
|
||||||
|
// while ((str = bufferedReader.readLine()) != null) {
|
||||||
|
// System.out.println(str);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// Runprocess.waitFor();
|
||||||
|
// int i = Runprocess.exitValue();
|
||||||
|
// if (i==0){
|
||||||
|
// System.out.println("运行成功");
|
||||||
|
// }else {
|
||||||
|
// System.out.println("运行失败");
|
||||||
// }
|
// }
|
||||||
// }catch (Exception e){
|
// }catch (Exception e){
|
||||||
// e.printStackTrace();
|
// throw new RuntimeException();
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
// static class JavaSourceFromString extends SimpleJavaFileObject {
|
|
||||||
// final String code;
|
private String url ="D:\\work\\zglkh\\cloud-server\\muyu-modules\\muyu-rule-engine\\muyu-rule-engine-common\\src\\main\\java\\com\\muyu\\engine\\java";
|
||||||
//
|
|
||||||
//
|
//生产源文件
|
||||||
// JavaSourceFromString(String name, String code) {
|
public void writeCodeAdd(RuleEngineVersion ruleEngineVersion) {
|
||||||
// super(URI.create("string:///" + name.replace('.', '/') + Kind.SOURCE.extension), Kind.SOURCE);
|
try {
|
||||||
// this.code = code;
|
//编译
|
||||||
// }
|
String className = ruleEngineVersion.getVersionCode();
|
||||||
// @Override
|
//编译内容
|
||||||
// public CharSequence getCharContent(boolean ignoreEncodingErrors) {
|
String content = ruleEngineVersion.getCodeIng();
|
||||||
// return code;
|
// 指定输出目录
|
||||||
// }
|
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||||
// }
|
// 获取编译器
|
||||||
|
try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null)) {
|
||||||
|
// 创建一个内存中的源文件
|
||||||
|
JavaFileObject sourceFileObject = new JavaSourceFromString(className, content);
|
||||||
|
|
||||||
|
// 编译选项
|
||||||
|
Iterable<String> options = Arrays.asList("-d", url);
|
||||||
|
// 编译源代码
|
||||||
|
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, options, null, Arrays.asList(sourceFileObject));
|
||||||
|
boolean success = task.call();
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
System.out.println("编译成功");
|
||||||
|
} else {
|
||||||
|
System.out.println("编译失败");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//内存中的源文件
|
||||||
|
static class JavaSourceFromString extends SimpleJavaFileObject {
|
||||||
|
final String code;
|
||||||
|
// 构造方法
|
||||||
|
JavaSourceFromString(String name, String code) {
|
||||||
|
// URI
|
||||||
|
super(URI.create("string:///" + name.replace('.', '/') + Kind.SOURCE.extension), Kind.SOURCE);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
// 返回源代码
|
||||||
|
@Override
|
||||||
|
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,14 @@
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.postgresql</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>muyu-rule-engine-clinet</artifactId>
|
||||||
<version>42.2.18</version>
|
<version>3.6.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>muyu-kvt-client</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- SpringCloud Alibaba Nacos -->
|
<!-- SpringCloud Alibaba Nacos -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
Loading…
Reference in New Issue