数据接入
parent
3c6f1078cc
commit
d4f1fc26da
|
@ -14,6 +14,7 @@ import com.muyu.req.EngineVersionListResp;
|
|||
import com.muyu.service.EngIneService;
|
||||
import com.muyu.service.EngineVersionService;
|
||||
import com.muyu.test.JavaClass;
|
||||
import com.muyu.test.RuleTest;
|
||||
import com.muyu.test.TestService;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
@ -243,7 +244,7 @@ public class EngIneController extends BaseController {
|
|||
JavaClass.compile(String.valueOf(ruleEdition.getId()));
|
||||
log.error("错误原因:{}" + ruleEdition);
|
||||
//测试
|
||||
TestService.test(ruleEdition);
|
||||
RuleTest.test(ruleEdition);
|
||||
return Result.success(engIneService.measurementList(ruleEdition));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package com.muyu.test;
|
||||
|
||||
import com.muyu.basic.BasicEngine;
|
||||
import com.muyu.core.domain.DataValue;
|
||||
import com.muyu.domain.EngineVersion;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @ClassName RuleTest
|
||||
* @Description 描述
|
||||
* @Author Chen
|
||||
* @Date 2024/9/5 20:52
|
||||
*/
|
||||
public class RuleTest {
|
||||
static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||
|
||||
//外部类文件路径
|
||||
public static final String engineWorkSourcePath = "/home/lib";
|
||||
public static final String className = "com.muyu.abstracts.generate.";
|
||||
|
||||
public static void test(EngineVersion engineVersion) {
|
||||
try {
|
||||
//外部类文件路径
|
||||
String externalClassFilePath =
|
||||
engineWorkSourcePath + "/com/muyu/abstracts" + engineVersion.getName() + ".class";
|
||||
Path classFilePath = Paths.get(externalClassFilePath);
|
||||
//获取外部类所在的目录
|
||||
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
||||
URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
||||
ExternalClassLoader externalClassLoader = new ExternalClassLoader(urls);
|
||||
//加载类 全限定名
|
||||
Class<?> clazz = externalClassLoader.loadClassFromPath(classFilePath, className + engineVersion.getName());
|
||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
engineMap.put(engineVersion.getName(), (BasicEngine<DataValue>) instance);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InstantiationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
DataValue dataValue = DataValue.builder()
|
||||
.type("String")
|
||||
.label("手机号")
|
||||
.key("phone")
|
||||
.value("张三")
|
||||
.build();
|
||||
|
||||
BasicEngine<DataValue> engine = engineMap.get(engineVersion.getName());
|
||||
engine.set(dataValue);
|
||||
engine.execution();
|
||||
}
|
||||
|
||||
}
|
|
@ -27,9 +27,9 @@ public class TestService {
|
|||
|
||||
static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static final String engineWorkSourcePath = "D:\\work\\teaching\\2112A\\engine";
|
||||
public static final String engineWorkSourcePath = "/home/lib";
|
||||
public static final String engineWorkClassPath = engineWorkSourcePath;
|
||||
public static final String className = "com.muyu.data.engine.service.ENGINE_VALUE_JDIES979972_V2";
|
||||
public static final String className = "com.muyu.abstracts.generate.";
|
||||
|
||||
|
||||
// package com.muyu.data.engine.service;
|
||||
|
@ -83,6 +83,8 @@ public class TestService {
|
|||
} else {
|
||||
System.out.println("错误");
|
||||
}
|
||||
|
||||
|
||||
// 假设这是你的外部类文件路径
|
||||
String externalClassFilePath =
|
||||
engineWorkSourcePath + "\\com\\muyu\\abstracts\\"+engineVersion.getName()+".class";
|
||||
|
@ -98,11 +100,10 @@ public class TestService {
|
|||
// 加载类
|
||||
// 注意类名必须是完全限定名(包括包名)
|
||||
Class<?> clazz = externalClassLoader.loadClassFromPath(classFilePath, className);
|
||||
// Class<?> clazz = customClassLoader.defineClassFromBytes(externalClassBytes);
|
||||
// 创建类的实例
|
||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
engineMap.put("ENGINE_VALUE_JDIES979972_V2", (BasicEngine<DataValue>) instance);
|
||||
engineMap.put(engineVersion.getName(), (BasicEngine<DataValue>) instance);
|
||||
|
||||
} catch (IllegalAccessException | IOException | InstantiationException |
|
||||
NoSuchMethodException | InvocationTargetException e) {
|
||||
|
@ -115,7 +116,7 @@ public class TestService {
|
|||
.value("张三")
|
||||
.build();
|
||||
|
||||
BasicEngine<DataValue> engine = engineMap.get("ENGINE_VALUE_JDIES979972_V2");
|
||||
BasicEngine<DataValue> engine = engineMap.get(engineVersion.getName());
|
||||
engine.set(dataValue);
|
||||
engine.execution();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue