feat: jdbc 封装(测试成功)
parent
db1da8613d
commit
59cc24f8c9
|
@ -22,6 +22,12 @@
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.30</version>
|
<version>1.18.30</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.26</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.muyu.mysql;
|
package com.muyu.mysql;
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mysql基本定值 MySqlConfig
|
* mysql基本定值 MySqlConfig
|
||||||
*
|
*
|
||||||
|
@ -7,6 +9,7 @@ package com.muyu.mysql;
|
||||||
* on 2024/5/10
|
* on 2024/5/10
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
public class MySqlConfig {
|
public class MySqlConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,7 +20,9 @@ public class MySqlConfig {
|
||||||
public static void dirver(String dirverName)
|
public static void dirver(String dirverName)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
//加载驱动
|
||||||
Class.forName(dirverName);
|
Class.forName(dirverName);
|
||||||
|
log.info("加载驱动成功");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,15 @@ public class MysqlApp {
|
||||||
|
|
||||||
Mysql mysql = new Mysql();
|
Mysql mysql = new Mysql();
|
||||||
mysql.setId("1");
|
mysql.setId("1");
|
||||||
|
mysql.setName("root");
|
||||||
|
mysql.setSystemName("2222");
|
||||||
mysql.setUsername("root");
|
mysql.setUsername("root");
|
||||||
mysql.setPassword("root");
|
mysql.setPassword("root");
|
||||||
mysql.setHost("localhost");
|
mysql.setHost("127.0.0.1");
|
||||||
mysql.setDatabaseName("data_basete");
|
mysql.setDatabaseName("damo01");
|
||||||
mysql.setPort("3306");
|
mysql.setPort("3306");
|
||||||
mysql.setType("mysql");
|
mysql.setType("Mysql");
|
||||||
|
mysql.setDriverName("com.mysql.cj.jdbc.Driver");
|
||||||
mysql.setConnectionParam("useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
|
mysql.setConnectionParam("useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
|
||||||
|
|
||||||
mySqlConfigs.add(mysql);
|
mySqlConfigs.add(mysql);
|
||||||
|
@ -47,7 +50,8 @@ public class MysqlApp {
|
||||||
.databaseName(mysql1.getDatabaseName())
|
.databaseName(mysql1.getDatabaseName())
|
||||||
.port(mysql1.getPort())
|
.port(mysql1.getPort())
|
||||||
.type(mysql1.getType())
|
.type(mysql1.getType())
|
||||||
.driverName(mysql1.getConnectionParam())
|
.driverName(mysql1.getDriverName())
|
||||||
|
.param(mysql1.getConnectionParam())
|
||||||
.ip(mysql1.getHost())
|
.ip(mysql1.getHost())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ public class MySqlConfilg {
|
||||||
*/
|
*/
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 密码
|
* 密码
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -42,4 +42,6 @@ public class Mysql {
|
||||||
/** 数据连接参数 */
|
/** 数据连接参数 */
|
||||||
private String connectionParam;
|
private String connectionParam;
|
||||||
|
|
||||||
|
private String driverName;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package com.muyu.kvt.client.pool;
|
package com.muyu.kvt.client.pool;
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基本定值 BaseConfig
|
* 基本定值 BaseConfig
|
||||||
*
|
*
|
||||||
* @author LeYang
|
* @author LeYang
|
||||||
* on 2024/5/9
|
* on 2024/5/9
|
||||||
*/
|
*/
|
||||||
|
@Log4j2
|
||||||
public class BaseConfig {
|
public class BaseConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +19,7 @@ public class BaseConfig {
|
||||||
public static void dirver(String dirverName){
|
public static void dirver(String dirverName){
|
||||||
try {
|
try {
|
||||||
Class.forName(dirverName);
|
Class.forName(dirverName);
|
||||||
|
log.info("加载驱动成功",dirverName,Class.forName(dirverName));
|
||||||
}catch (ClassNotFoundException e){
|
}catch (ClassNotFoundException e){
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,9 @@ package com.muyu.engine.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.engine.domain.RuleEngine;
|
import com.muyu.engine.domain.RuleEngine;
|
||||||
import com.muyu.engine.domain.req.RuleEngineQueryReq;
|
|
||||||
import com.muyu.engine.remote.factory.RuleEngineManangerServiceFactory;
|
import com.muyu.engine.remote.factory.RuleEngineManangerServiceFactory;
|
||||||
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 org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -18,10 +15,18 @@ import java.util.List;
|
||||||
* @author LeYang
|
* @author LeYang
|
||||||
* on 2024/5/9
|
* on 2024/5/9
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* 使用Feign创建的客户端注解,用于定义与服务提供者之间的通信配置。
|
||||||
|
* 主要用于微服务架构中,通过声明式的方式定义远程服务调用。
|
||||||
|
*/
|
||||||
@FeignClient(
|
@FeignClient(
|
||||||
|
//定义上下文ID,用于区分不同的Feign客户端实例。
|
||||||
contextId = "RuleEngineManangerService",
|
contextId = "RuleEngineManangerService",
|
||||||
|
//指定要调用的服务的名称
|
||||||
value = ServiceNameConstants.MUYU_RULE_ENGINE,
|
value = ServiceNameConstants.MUYU_RULE_ENGINE,
|
||||||
|
//指定服务调用失败时的回退工厂
|
||||||
fallbackFactory = RuleEngineManangerServiceFactory.class,
|
fallbackFactory = RuleEngineManangerServiceFactory.class,
|
||||||
|
// 指定服务访问的路径前缀。
|
||||||
path = "/engine"
|
path = "/engine"
|
||||||
)
|
)
|
||||||
public interface RuleEngineManangerService {
|
public interface RuleEngineManangerService {
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
package com.muyu.engine.remote.factory;
|
package com.muyu.engine.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.engine.domain.RuleEngine;
|
import com.muyu.engine.domain.RuleEngine;
|
||||||
import com.muyu.engine.domain.req.RuleEngineQueryReq;
|
|
||||||
import com.muyu.engine.remote.RuleEngineManangerService;
|
import com.muyu.engine.remote.RuleEngineManangerService;
|
||||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
|
@ -96,8 +96,10 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper, RuleEng
|
||||||
//找到文件并读取
|
//找到文件并读取
|
||||||
Path path = Paths.get(url + ruleEngine.getWriteCode() + ".java");
|
Path path = Paths.get(url + ruleEngine.getWriteCode() + ".java");
|
||||||
if (Files.exists(path)) {
|
if (Files.exists(path)) {
|
||||||
|
// 读取文件内容
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(path), StandardCharsets.UTF_8));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(path), StandardCharsets.UTF_8));
|
||||||
String line;
|
String line;
|
||||||
|
// 将每一行内容拼接起来
|
||||||
StringBuilder content = new StringBuilder();
|
StringBuilder content = new StringBuilder();
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
content.append(line).append("\n");
|
content.append(line).append("\n");
|
||||||
|
@ -204,6 +206,7 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper, RuleEng
|
||||||
System.out.println(compileResult == 0 ? "编译成功" : "编译失败");
|
System.out.println(compileResult == 0 ? "编译成功" : "编译失败");
|
||||||
|
|
||||||
ProcessBuilder pbRun = new ProcessBuilder("java",ruleEngine.getWriteCode());
|
ProcessBuilder pbRun = new ProcessBuilder("java",ruleEngine.getWriteCode());
|
||||||
|
// 设置工作目录
|
||||||
pbRun.directory(Paths.get(url).toFile());
|
pbRun.directory(Paths.get(url).toFile());
|
||||||
Process runProcess = pbRun.start();
|
Process runProcess = pbRun.start();
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(runProcess.getInputStream()));
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(runProcess.getInputStream()));
|
||||||
|
|
Loading…
Reference in New Issue