feat: 测试线程变量
parent
b71163984e
commit
10a34edcd4
|
@ -3,7 +3,7 @@ package com.muyu.data.source.client.pool;
|
||||||
/**
|
/**
|
||||||
* 基础定值
|
* 基础定值
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @Date 2024/4/29 029 14:30
|
* @Date 2024/4/29 029 14:30
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.muyu.data.source.client.pool;
|
||||||
/**
|
/**
|
||||||
* 提供了一个连接池的准则
|
* 提供了一个连接池的准则
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @Date 2024/4/29 029 14:41
|
* @Date 2024/4/29 029 14:41
|
||||||
*/
|
*/
|
||||||
public interface BasePool<T> {
|
public interface BasePool<T> {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.muyu.data.source.client.pool;
|
||||||
/**
|
/**
|
||||||
* Mysql超时异常
|
* Mysql超时异常
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @Date 2024/4/29 029 15:17
|
* @Date 2024/4/29 029 15:17
|
||||||
*/
|
*/
|
||||||
public class MysqlConnException extends RuntimeException{
|
public class MysqlConnException extends RuntimeException{
|
||||||
|
|
|
@ -16,7 +16,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
/**
|
/**
|
||||||
* Mysql的连接池信息
|
* Mysql的连接池信息
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @Date 2024/4/29 029 14:36
|
* @Date 2024/4/29 029 14:36
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
|
|
|
@ -14,7 +14,7 @@ import lombok.Data;
|
||||||
/**
|
/**
|
||||||
* mysql连接池配置
|
* mysql连接池配置
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @Date 2024/4/29 029 14:24
|
* @Date 2024/4/29 029 14:24
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.muyu.data.source.domain.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A
|
||||||
|
*
|
||||||
|
* @author DeKangLiu
|
||||||
|
* Date 2024/5/13 16:40
|
||||||
|
*/
|
||||||
|
public class A implements Base{
|
||||||
|
@Override
|
||||||
|
public void execution() {
|
||||||
|
DataModel dataModel = ThreadConstant.get();
|
||||||
|
System.out.println(dataModel.getValue());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.muyu.data.source.domain.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* B
|
||||||
|
*
|
||||||
|
* @author DeKangLiu
|
||||||
|
* Date 2024/5/13 16:46
|
||||||
|
*/
|
||||||
|
public class B implements Base{
|
||||||
|
@Override
|
||||||
|
public void execution() {
|
||||||
|
DataModel dataModel = ThreadConstant.get();
|
||||||
|
dataModel.setValue("李四");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.muyu.data.source.domain.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base
|
||||||
|
*
|
||||||
|
* @author DeKangLiu
|
||||||
|
* Date 2024/5/13 16:57
|
||||||
|
*/
|
||||||
|
public interface Base {
|
||||||
|
public void execution();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.muyu.data.source.domain.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* C
|
||||||
|
*
|
||||||
|
* @author DeKangLiu
|
||||||
|
* Date 2024/5/13 16:47
|
||||||
|
*/
|
||||||
|
public class C implements Base{
|
||||||
|
@Override
|
||||||
|
public void execution() {
|
||||||
|
DataModel dataModel = ThreadConstant.get();
|
||||||
|
if ("张三".equals(dataModel.getValue())){
|
||||||
|
System.out.println("是张三");
|
||||||
|
}else {
|
||||||
|
System.out.printf("不是张三,而是%s%n", dataModel.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.muyu.data.source.domain.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DataModel
|
||||||
|
*
|
||||||
|
* @author DeKangLiu
|
||||||
|
* Date 2024/5/13 16:37
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DataModel {
|
||||||
|
/**
|
||||||
|
* 数据键
|
||||||
|
*/
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据值
|
||||||
|
*/
|
||||||
|
private Object value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 源标准 -枚举
|
||||||
|
*/
|
||||||
|
private String sourceType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理标准-枚举
|
||||||
|
*/
|
||||||
|
private String processType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理类型
|
||||||
|
*/
|
||||||
|
private Class<?> processClass;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.muyu.data.source.domain.model;
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试 Main
|
||||||
|
*
|
||||||
|
* @author DeKangLiu
|
||||||
|
* Date 2024/5/13 16:51
|
||||||
|
*/
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
private static final ConcurrentHashMap<String, Base> ruleEngineMap = new ConcurrentHashMap<>();
|
||||||
|
static {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
public static void init(){
|
||||||
|
ruleEngineMap.put("a",new A());
|
||||||
|
ruleEngineMap.put("b",new B());
|
||||||
|
ruleEngineMap.put("c",new C());
|
||||||
|
}
|
||||||
|
public static void main(String[] args) {
|
||||||
|
DataModel dataModel = new DataModel();
|
||||||
|
dataModel.setValue("王五");
|
||||||
|
dataModel.setKey("name");
|
||||||
|
dataModel.setProcessClass(String.class);
|
||||||
|
dataModel.setSourceType("varchar");
|
||||||
|
dataModel.setProcessType("String");
|
||||||
|
ThreadConstant.set(dataModel);
|
||||||
|
Base a = ruleEngineMap.get("a");
|
||||||
|
Base b = ruleEngineMap.get("b");
|
||||||
|
Base c = ruleEngineMap.get("c");
|
||||||
|
a.execution();
|
||||||
|
b.execution();
|
||||||
|
c.execution();
|
||||||
|
ThreadConstant.remove();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.muyu.data.source.domain.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ThreadContsant
|
||||||
|
*
|
||||||
|
* @author DeKangLiu
|
||||||
|
* Date 2024/5/13 16:40
|
||||||
|
*/
|
||||||
|
public class ThreadConstant {
|
||||||
|
|
||||||
|
private static ThreadLocal<DataModel> threadLocal = new ThreadLocal<>();
|
||||||
|
|
||||||
|
public static DataModel get() {
|
||||||
|
return threadLocal.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(DataModel dataModel) {
|
||||||
|
threadLocal.set(dataModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void remove() {
|
||||||
|
threadLocal.remove();
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ import lombok.NoArgsConstructor;
|
||||||
/**
|
/**
|
||||||
* RuleContentModel
|
* RuleContentModel
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @Date 2024/5/2 002 14:27
|
* @Date 2024/5/2 002 14:27
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* 规则引擎对象 ruleengine
|
* 规则引擎对象 ruleengine
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @date 2024-04-24
|
* @date 2024-04-24
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
|
|
@ -5,7 +5,7 @@ import lombok.Data;
|
||||||
/**
|
/**
|
||||||
* RuleContentReq
|
* RuleContentReq
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @Date 2024/5/2 002 14:30
|
* @Date 2024/5/2 002 14:30
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
|
|
@ -12,7 +12,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
/**
|
/**
|
||||||
* 规则引擎对象 ruleengine
|
* 规则引擎对象 ruleengine
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @date 2024-04-24
|
* @date 2024-04-24
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
|
|
@ -12,7 +12,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
/**
|
/**
|
||||||
* 规则引擎对象 ruleengine
|
* 规则引擎对象 ruleengine
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @date 2024-04-24
|
* @date 2024-04-24
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
|
|
@ -12,7 +12,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
/**
|
/**
|
||||||
* 规则引擎对象 ruleengine
|
* 规则引擎对象 ruleengine
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @date 2024-04-24
|
* @date 2024-04-24
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
/**
|
/**
|
||||||
* MuYuRuleEngineApplication
|
* MuYuRuleEngineApplication
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @Date 2024/4/24 024 10:07
|
* @Date 2024/4/24 024 10:07
|
||||||
*/
|
*/
|
||||||
@EnableCustomConfig
|
@EnableCustomConfig
|
||||||
|
|
|
@ -22,7 +22,7 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
/**
|
/**
|
||||||
* 规则引擎Controller
|
* 规则引擎Controller
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @date 2024-04-24
|
* @date 2024-04-24
|
||||||
*/
|
*/
|
||||||
@Api(tags = "规则引擎")
|
@Api(tags = "规则引擎")
|
||||||
|
@ -153,4 +153,9 @@ public class RuleengineController extends BaseController {
|
||||||
public Result updateEngineCodeIng(@RequestBody Engineversion engineversion) {
|
public Result updateEngineCodeIng(@RequestBody Engineversion engineversion) {
|
||||||
return ruleengineService.updateEngineCodeIng(engineversion);
|
return ruleengineService.updateEngineCodeIng(engineversion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/engineGeneration")
|
||||||
|
public Result engineGeneration(@RequestParam String codeIng) {
|
||||||
|
return ruleengineService.engineGeneration(codeIng);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* 规则引擎Mapper接口
|
* 规则引擎Mapper接口
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @date 2024-04-24
|
* @date 2024-04-24
|
||||||
*/
|
*/
|
||||||
public interface RuleengineMapper extends BaseMapper<Ruleengine> {
|
public interface RuleengineMapper extends BaseMapper<Ruleengine> {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import com.muyu.ruleengine.domain.req.RuleContentReq;
|
||||||
/**
|
/**
|
||||||
* 规则引擎Service接口
|
* 规则引擎Service接口
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @date 2024-04-24
|
* @date 2024-04-24
|
||||||
*/
|
*/
|
||||||
public interface RuleengineService extends IService<Ruleengine> {
|
public interface RuleengineService extends IService<Ruleengine> {
|
||||||
|
@ -39,4 +39,6 @@ public interface RuleengineService extends IService<Ruleengine> {
|
||||||
Result updateRuleStatus(Ruleengine ruleengine);
|
Result updateRuleStatus(Ruleengine ruleengine);
|
||||||
|
|
||||||
Result updateEngineCodeIng(Engineversion engineversion);
|
Result updateEngineCodeIng(Engineversion engineversion);
|
||||||
|
|
||||||
|
Result engineGeneration(String codeIng);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ import javax.tools.*;
|
||||||
/**
|
/**
|
||||||
* 规则引擎Service业务层处理
|
* 规则引擎Service业务层处理
|
||||||
*
|
*
|
||||||
* @author WangLei
|
* @author DeKangLiu
|
||||||
* @date 2024-04-24
|
* @date 2024-04-24
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -195,6 +195,41 @@ public class RuleengineServiceImpl extends ServiceImpl<RuleengineMapper, Ruleeng
|
||||||
return Result.success("编码保存成功");
|
return Result.success("编码保存成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result engineGeneration(String codeIng) {
|
||||||
|
//指定目录
|
||||||
|
String targetDirectory ="D:\\";
|
||||||
|
JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
|
||||||
|
StandardJavaFileManager standardFileManager = systemJavaCompiler.getStandardFileManager(null, null, null);
|
||||||
|
log.info(codeIng);
|
||||||
|
// JavaSourceFromString javaSourceFromString = new JavaSourceFromString(codeIng);
|
||||||
|
|
||||||
|
// JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||||
|
// try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null)) {
|
||||||
|
// // 创建一个内存中的源文件
|
||||||
|
// JavaFileObject sourceFileObject = new JavaSourceFromString("Test"+ruleId, content);
|
||||||
|
//
|
||||||
|
// // 编译选项
|
||||||
|
// Iterable<String> options = Arrays.asList("-d", targetDirectory);
|
||||||
|
//
|
||||||
|
// // 编译源代码
|
||||||
|
// JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, options, null, Arrays.asList(sourceFileObject));
|
||||||
|
// boolean success = task.call();
|
||||||
|
//
|
||||||
|
// if (success) {
|
||||||
|
// ruleengineMapper.addRulecontent(ruleContentReq);
|
||||||
|
// System.out.println("编译成功");
|
||||||
|
// } else {
|
||||||
|
// System.out.println("编译失败");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// return Result.success("编译成功");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class MyClassLoader extends ClassLoader {
|
public static class MyClassLoader extends ClassLoader {
|
||||||
public Class<?> defineClassFromBytes(String name, byte[] data) {
|
public Class<?> defineClassFromBytes(String name, byte[] data) {
|
||||||
|
|
Loading…
Reference in New Issue