11111
parent
221d5e36cd
commit
9022d4995d
|
@ -7,7 +7,7 @@ import com.muyu.rule.common.basic.abstracts.DataEngineValueActuator;
|
||||||
* @Author:张承志
|
* @Author:张承志
|
||||||
* @Package:com.muyu.rule.server.basic.engine
|
* @Package:com.muyu.rule.server.basic.engine
|
||||||
* @Project:cloud-etl-rule
|
* @Project:cloud-etl-rule
|
||||||
* @name:ENGINE_phone_zzzzz_V9
|
* @name:非空
|
||||||
* @Date:2024/8/29 15:51
|
* @Date:2024/8/29 15:51
|
||||||
*/
|
*/
|
||||||
public class ENGINE_phone_zzzzz_V9 extends DataEngineValueActuator {
|
public class ENGINE_phone_zzzzz_V9 extends DataEngineValueActuator {
|
||||||
|
@ -16,6 +16,8 @@ public class ENGINE_phone_zzzzz_V9 extends DataEngineValueActuator {
|
||||||
DataValue dataValue = get();
|
DataValue dataValue = get();
|
||||||
if (dataValue.getValue() == null){
|
if (dataValue.getValue() == null){
|
||||||
System.out.println("数据为空");
|
System.out.println("数据为空");
|
||||||
|
}else {
|
||||||
|
System.out.println("数据非空:"+dataValue.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
|
||||||
import javax.tools.JavaCompiler;
|
import javax.tools.JavaCompiler;
|
||||||
import javax.tools.ToolProvider;
|
import javax.tools.ToolProvider;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
@ -96,12 +97,13 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||||
public static final String engineWorkSourcePath = "home/source/";
|
public static final String engineWorkSourcePath = "home/source/";
|
||||||
public static final String engineWorkClassPath = "home/class/";
|
public static final String engineWorkClassPath = "home/class/";
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
public static final String className_prefix = "com.muyu.rule.server.basic.engine.value.";
|
public static final String className_prefix = "com.muyu.rule.common.basic.engine.value.";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//todo
|
//todo
|
||||||
|
@ -148,7 +150,7 @@ log.info("规则引擎的编译参数{}[]",Arrays.toString(strings));
|
||||||
}
|
}
|
||||||
// 假设这是你的外部类文件路径
|
// 假设这是你的外部类文件路径
|
||||||
String externalClassFilePath =
|
String externalClassFilePath =
|
||||||
engineWorkSourcePath +className+Suffix_CLASS;
|
"home/lib/"+"com//" +className+Suffix_CLASS;
|
||||||
Path classFilePath = Paths.get(externalClassFilePath);
|
Path classFilePath = Paths.get(externalClassFilePath);
|
||||||
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
||||||
URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
||||||
|
@ -158,42 +160,60 @@ log.info("规则引擎的编译参数{}[]",Arrays.toString(strings));
|
||||||
|
|
||||||
//加载类
|
//加载类
|
||||||
//注意类名必须是完全限定名(包括包名)
|
//注意类名必须是完全限定名(包括包名)
|
||||||
// Class<?> clazz = externalClassLoader.loadClassFromPath(classFilePath,className_prefix+className+Suffix_CLASS);
|
Class<?> clazz = externalClassLoader.loadClassFromPath(classFilePath,className_prefix+className);
|
||||||
|
|
||||||
//创建类的实例
|
//创建类的实例
|
||||||
//Object instance = clazz.getDeclaredConstructor().newInstance();
|
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
engineMap.put(className, (BasicEngine<DataValue>) instance);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(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("name")
|
||||||
|
.value("张三")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
BasicEngine<DataValue> engine = engineMap.get(className);
|
||||||
|
engine.set(dataValue);
|
||||||
|
engine.execution();
|
||||||
|
|
||||||
|
|
||||||
//对class文件进行自定义类加载规则引擎
|
//对class文件进行自定义类加载规则引擎
|
||||||
// Map<String, Class<?>> stringClassMap = JavaBinaryClassLoader.loadClassesByLocation(engineConfig.getServerPack(), engineConfig.getClassPath());
|
// Map<String, Class<?>> stringClassMap = JavaBinaryClassLoader.loadClassesByLocation(engineConfig.getServerPack(), engineConfig.getClassPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
// static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||||
|
//
|
||||||
static {
|
// static {
|
||||||
try {
|
// try {
|
||||||
Class<?> aClass = Class.forName("com.muyu.rule.common.basic.engine.value.ENGINE_VALUE_VFD1000_V1");
|
// Class<?> aClass = Class.forName("com.muyu.rule.common.basic.engine.value.ENGINE_VALUE_VFD1000_V1");
|
||||||
Class<?> aClass2 = Class.forName("com.muyu.rule.common.basic.engine.value.ENGINE_VALUE_VFD1000_V2");
|
// Class<?> aClass2 = Class.forName("com.muyu.rule.common.basic.engine.value.ENGINE_VALUE_VFD1000_V2");
|
||||||
try {
|
// try {
|
||||||
engineMap.put("ENGINE_VALUE_VFD1000_V1", (BasicEngine<DataValue>) aClass.newInstance());
|
// engineMap.put("ENGINE_VALUE_VFD1000_V1", (BasicEngine<DataValue>) aClass.newInstance());
|
||||||
engineMap.put("ENGINE_VALUE_VFD1000_V2", (BasicEngine<DataValue>) aClass2.newInstance());
|
// engineMap.put("ENGINE_VALUE_VFD1000_V2", (BasicEngine<DataValue>) aClass2.newInstance());
|
||||||
} catch (InstantiationException e) {
|
// } catch (InstantiationException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
} catch (IllegalAccessException e) {
|
// } catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
} catch (ClassNotFoundException e) {
|
// } catch (ClassNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void testValue(String versionClazz, DataValue dataValue) {
|
public void testValue(String versionClazz, DataValue dataValue) {
|
||||||
|
|
Loading…
Reference in New Issue