master
chentaisen 2024-08-31 20:41:38 +08:00
parent 210a3024a7
commit b6661cdd78
27 changed files with 1178 additions and 85 deletions

View File

@ -0,0 +1,66 @@
package rule.data.engine;
import org.springframework.stereotype.Component;
import rule.domain.Rule;
import rule.domain.RuleEdition;
import java.text.SimpleDateFormat;
import java.util.Date;
@Component
public class GenerateConstant {
public static final String DATA_FIELD = "DataEngineValueActuator";
public static final String DATA_RECORD = "DataEngineRecordActuator";
public static final String DATA_SET = "DataEngineSetActuator";
public static final String ACTION_IMPORT = "import com.muyu.rule.engine.action.ActionDiscard;\n";
public static final String SCOPE_IMPORT = "import com.muyu.rule.engine.scope.DataModelEngine";
public static final String PACKAGE_PATH = "package com.muyu.generate;";
public static String getClassName(String versionCode){
String[] splits = versionCode.split("_");
String className="";
for (String split : splits) {
className += split.substring(0,1).toUpperCase()+split.substring(1);
}
return className;
}
public static String generateConstant(Rule rule, RuleEdition ruleEdition){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String format = simpleDateFormat.format(new Date());
String level = selectType(rule.getRuleType());
return PACKAGE_PATH + "\n" +
ACTION_IMPORT + "\n" +
SCOPE_IMPORT+level+";\n" +
"\n" +
"/**\n" +
" * @date: "+format+"\n" +
" * @Description: "+ruleEdition.getName()+"_"+ruleEdition.getRuleKind()+"\n" +
" * @Version: 1.0\n" +
" */\n" +
"public class "+getClassName(ruleEdition.getName()) + " extends "+level+" {\n" +
" @Override\n" +
" public void run () {\n" +
" }\n" +
"}";
}
public static String selectType(String level){
String type = "";
switch (level) {
case "F":
type = DATA_FIELD;
break;
case "R":
type = DATA_RECORD;
break;
case "C":
type = DATA_SET;
break;
}
return type;
}
}

View File

@ -0,0 +1,47 @@
//package rule.data.engine;
//
//
//import rule.data.engine.basic.BasicEngine;
//import rule.domain.DataValue;
//
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//
///**
// * @ClassName Main
// * @Description 测试类
// * @Author Chen
// * @Date 2024/8/29 14:27
// */
//public class Main {
// static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
//
// static {
// try {
// Class<?> aClass = Class.forName("com.muyu.rule.data.engine.service.ENGINE_VALUE_JDIE3456711_V1");
// try {
// engineMap.put("ENGINE_VALUE_JDIE3456711_V1", (BasicEngine<DataValue>) aClass.newInstance());
//
// } catch (InstantiationException e) {
// throw new RuntimeException(e);
// } catch (IllegalAccessException e) {
// throw new RuntimeException(e);
// }
//
// } catch (ClassNotFoundException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static void main(String[] args) {
// DataValue dataValue = DataValue.builder()
// .type("String")
// .label("姓名")
// .key("name")
// .value(null)
// .build();
// BasicEngine<DataValue> engine = engineMap.get("ENGINE_VALUE_JDIE3456711_V1");
// engine.set(dataValue);
// engine.execution();
// }
//}

View File

@ -0,0 +1,17 @@
//package rule.data.engine.basic;
//
///**
// * @ClassName BasicEngin
// * @Description 规则引擎基准
// * @Author Chen
// * @Date 2024/8/29 14:28
// */
//public interface BasicEngine<V> {
// public void set(V dataValue);
//
// public V get();
//
// public void remove();
//
// public void execution();
//}

View File

@ -0,0 +1,22 @@
//package rule.data.engine.basic.abstracts;
//
//
//import rule.data.engine.basic.BasicEngine;
//import rule.data.engine.basic.handler.DataEngineHandler;
//import rule.domain.DataValue;
//
///**
// * @ClassName DataEngineValueActuator
// * @Description 数据值处理对象
// * @Author Chen
// * @Date 2024/8/29 16:10
// */
//public abstract class DataEngineRowActuator implements BasicEngine<DataValue[]> {
// public void set(DataValue[] dataValue) {
// DataEngineHandler.set(dataValue);
// }
//
// public DataValue[] get() {
// return DataEngineHandler.get();
// }
//}

View File

@ -0,0 +1,33 @@
//package rule.data.engine.basic.abstracts;
//
//
//import rule.data.engine.basic.BasicEngine;
//import rule.data.engine.basic.handler.DataEngineValueHandler;
//import rule.domain.DataValue;
//
///**
// * @ClassName DataEngineValueActuator
// * @Description 数据值处理对象
// * @Author Chen
// * @Date 2024/8/29 16:10
// */
//public abstract class DataEngineValueActuator implements BasicEngine<DataValue> {
// @Override
// public void set(DataValue dataValue) {
// DataEngineValueHandler.set(dataValue);
// }
//
// @Override
// public DataValue get() {
// return DataEngineValueHandler.get();
// }
//
// @Override
// public void execution() {
// this.run();
// this.remove();
// }
//
//
// public abstract void run();
//}

View File

@ -0,0 +1,23 @@
//package rule.data.engine.basic.handler;
//
///**
// * @ClassName DataEngineHandler
// * @Description 规则引擎作用域
// * @Author Chen
// * @Date 2024/8/29 14:35
// */
//public class DataEngineHandler {
// private static final ThreadLocal<Object> dataEngineHandler = new ThreadLocal<>();
//
// public static void set(final Object handler) {
// dataEngineHandler.set(handler);
// }
//
// public static <T> T get() {
// return (T) dataEngineHandler.get();
// }
//
// public static void remove() {
// dataEngineHandler.remove();
// }
//}

View File

@ -0,0 +1,20 @@
//package rule.data.engine.basic.handler;
//
//import rule.domain.DataValue;
//
///**
// * @ClassName DataEngineValueHandler
// * @Description 数据值作用域 数据记录
// * @Author Chen
// * @Date 2024/8/29 14:41
// */
//public class DataEngineRowHandler {
// public static void set(DataValue[] dataValue) {
// DataEngineHandler.set(dataValue);
// }
//
// public DataValue[] get() {
// return DataEngineHandler.get();
// }
//
//}

View File

@ -0,0 +1,33 @@
//package rule.data.engine.basic.handler;
//
//import com.muyu.common.core.text.Convert;
//import rule.domain.DataValue;
//
///**
// * @ClassName DataEngineValueHandler
// * @Description 数据值作用域
// * @Author Chen
// * @Date 2024/8/29 14:41
// */
//public class DataEngineValueHandler {
// public static void set(DataValue dataValue) {
// DataEngineHandler.set(dataValue);
// }
//
// public static DataValue get() {
// return DataEngineHandler.get();
// }
//
// public static void remove() {
// DataEngineHandler.remove();
// }
// public static Object getValue() {
// return get().getValue();
// }
//
// public static Integer getIntegerValue() {
// return Convert.toInt(getValue(), null);
// }
//
//
//}

View File

@ -0,0 +1,27 @@
//package rule.data.engine.service;
//
//import rule.data.engine.basic.abstracts.DataEngineValueActuator;
//import rule.domain.DataValue;
//
///**
// * @ClassName ENGINE_VALUE_JDIE3456711
// * @Description 判空
// * @Author Chen
// * @Date 2024/8/29 16:26
// */
//public class ENGINE_VALUE_JDIE3456711_V1 extends DataEngineValueActuator {
//
//
// @Override
// public void run() {
// DataValue dataValue = get();
// if (dataValue.getValue()==null){
// System.out.println("数据为空,需要丢弃");
// }
// }
//
// @Override
// public void remove() {
//
// }
//}

View File

@ -0,0 +1,27 @@
//package rule.domain;
//
//import lombok.AllArgsConstructor;
//import lombok.Builder;
//import lombok.Data;
//import lombok.NoArgsConstructor;
//
//import java.net.SocketOption;
//
///**
// * @ClassName DataValue
// * @Description 描述
// * @Author Chen
// * @Date 2024/8/29 15:05
// */
//@Data
//@Builder
//@AllArgsConstructor
//@NoArgsConstructor
//public class DataValue {
// private Object value;
// private String type;
// private String key;
// private String label;
//
//
//}

View File

@ -0,0 +1,28 @@
//package rule.domain;
//
///**
// * @ClassName Main
// * @Description 描述
// * @Author Chen
// * @Date 2024/8/27 09:31
// */
//public class Main {
// public static void main(String[] args) {
// RuleDescribe ruleDescribe = new RuleDescribe();
// /**
// * {
// * "name":"zhangsan",
// *
// *
// * "age":11
// * }
// */
// ruleDescribe.setKey("name");
// ruleDescribe.setType("String");
// ruleDescribe.setLabel("name");
// ruleDescribe.setValue("zhangsan");
//
// System.out.println(ruleDescribe.getKey()+ruleDescribe.getType()+ruleDescribe.getLabel()+ruleDescribe.getValue());
//
// }
//}

View File

@ -0,0 +1,25 @@
//package rule.domain;
//
//import lombok.AllArgsConstructor;
//import lombok.Data;
//import lombok.NoArgsConstructor;
//
///**
// * @ClassName RuleAll
// * @Description 描述
// * @Author Chen
// * @Date 2024/8/27 09:04
// */
//@Data
//@AllArgsConstructor
//@NoArgsConstructor
//public class RuleDescribe {
// //字段名
// private String key;
// private Object value;
// //元类型 目标类型 逻辑类型
// private Object type;
// //描述
// private String label;
//}
//

View File

@ -66,4 +66,5 @@ public class RuleEdition {
* dia * dia
*/ */
private String ruleEngine; private String ruleEngine;
} }

View File

@ -0,0 +1,117 @@
//package com.muyu.rule.build;
//
//import com.muyu.rule.engine.annotation.EngineParam;
//import com.muyu.rule.exception.RuleEngineException;
//import com.muyu.rule.scan.EngineConfig;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.bind.annotation.RequestParam;
//
//import java.lang.annotation.Annotation;
//import java.lang.reflect.Method;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//
///**
// * @ClassName EngineContainer
// * @Description 描述
// * @Author Chen
// * @Date 2024/8/29 19:39
// */
//@Slf4j
//public class EngineContainer {
// private static Map<String, Object> instanceMap = new ConcurrentHashMap<>(16);
// private static Map<String, Object> classMap = new ConcurrentHashMap<>(16);
// private static Map<String, Method> methodMap = new ConcurrentHashMap<>(16);
//
// /**
// * 缓存规则引擎
// * @param engineKey
// * @param clazz
// */
// public static void loadEngineInstace(String engineKey, Class<?> clazz) {
// Method method = findMethodByClass(EngineConfig.executionMethodName, clazz);
// if (method == null) {
// log.info("初始化规则引擎->{} 失败缺少 {} 方法", engineKey, EngineConfig.executionMethodName);
// return;
// }
// try {
// instanceMap.put(engineKey, clazz.newInstance());
// } catch (InstantiationException e) {
// throw new RuntimeException(e);
// } catch (IllegalAccessException e) {
// throw new RuntimeException(e);
// }
// classMap.put(engineKey, clazz);
// methodMap.put(engineKey, method);
// Class<?>[] parameterTypes = method.getParameterTypes();
// Annotation[][] parameterAnnotations = method.getParameterAnnotations();
// //获取参数
// List<String> engineParams = new ArrayList<>();
// int parameterTypeLength = parameterTypes.length;
// for (int i = 0; i < parameterTypeLength; i++) {
// Annotation[] paramAnn = parameterAnnotations[i];
// if (paramAnn.length == 0) {
// throw new RuleEngineException("请给所有参数填写注解!");
// }
// if (paramAnn.length > 1) {
// throw new RuleEngineException("参数仅支持一个注解!!!");
// }
// EngineParam engineParam = null;
// if (paramAnn[0] instanceof EngineParam) {
// engineParam = (EngineParam) paramAnn[0];
// }
// if (engineParam == null) {
// throw new RuleEngineException("请使用EngineParam注解");
// } else if (engineParam.name() == null) {
// throw new RuleEngineException("EngineParam--name 不能为空!!");
// }
// engineParams.add(engineParam.name());
// log.info("初始化规则引擎完成 ->规则引擎名称:{} 执行方法:{} 参数名称:{}", engineKey, method.getName(), engineParams.toString());
// }
// }
//
// private static Method findMethodByClass(String methodName, Class<?> clazz) {
// Method[] methods = clazz.getDeclaredMethods();
// return Arrays.stream(methods)
// .filter(method -> method.getName().equals(methodName))
// .findFirst()
// .orElse(null);
// }
//
// public static List<String> getMethodEngineParamMap(String engineKey) {
// Method method = methodMap.get(engineKey);
// if (method == null) {
// return new ArrayList<>();
// }
// Class<?>[] parameterTypes = method.getParameterTypes();
// Annotation[][] parameterAnnotations = method.getParameterAnnotations();
// List<String> params = new ArrayList<>();
// for (int i = 0; i < parameterTypes.length; i++) {
// Annotation[] paramAnn = parameterAnnotations[i];
// if (paramAnn.length == 0) {
// continue;
// }
// EngineParam engineParam = (EngineParam) paramAnn[0];
// if (engineParam != null && !engineParam.name().isEmpty()) {
// params.add(engineParam.name());
// }
// }
// return params;
// }
//
// public static Object getInstanceMap(String engineKey) {
// return instanceMap.get(engineKey);
// }
//
// public static Method getMethodMap(String engineKey) {
// return methodMap.get(engineKey);
// }
//
// public static int getSumEngine() {
// return classMap.size();
// }
//
//}

View File

@ -1,85 +1,85 @@
package com.muyu.rule.compile; //package com.muyu.rule.compile;
//
import com.muyu.rule.scan.JavaCodeScan; //import com.muyu.rule.scan.JavaCodeScan;
import io.jsonwebtoken.io.IOException; //import io.jsonwebtoken.io.IOException;
//
import javax.tools.JavaCompiler; //import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject; //import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager; //import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider; //import javax.tools.ToolProvider;
import java.io.File; //import java.io.File;
import java.io.FileNotFoundException; //import java.io.FileNotFoundException;
import java.nio.file.Files; //import java.nio.file.Files;
//
/** ///**
* java // * java源码编译工具
*/ // */
public class SourceCodeCompiler { //public class SourceCodeCompiler {
//
//
/** // /**
* 1.java // * 1.获取系统java编译器
*/ // */
private static JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); // private static JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
/** // /**
* JAVA // * 获取JAVA文件管理器
*/ // */
private static StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); // private static StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
//
/** // /**
* // * 输入编译的文件夹路径
* // *
* @param path // * @param path 文件夹路径
*/ // */
public static void javaCompilerPath(String path) { // public static void javaCompilerPath(String path) {
File[] files = JavaCodeScan.javaSourceScanByPath(path); // File[] files = JavaCodeScan.javaSourceScanByPath(path);
//进行编译 // //进行编译
javaCompiler(files); // javaCompiler(files);
} // }
//
/** // /**
* // * 输入编译的文件夹路径
* // *
* @param filePath // * @param filePath
*/ // */
public static void javaCompilerFile(String... filePath) { // public static void javaCompilerFile(String... filePath) {
int filesPathLength = filePath.length; // int filesPathLength = filePath.length;
File[] files = new File[filesPathLength]; // File[] files = new File[filesPathLength];
//定义要编译的源文件 // //定义要编译的源文件
for (int i = 0; i < filesPathLength; i++) { // for (int i = 0; i < filesPathLength; i++) {
files[i] = new File(filePath[i]); // files[i] = new File(filePath[i]);
} // }
} // }
/** // /**
*java // *可同时编译多个java源文件
* @param file // * @param file
*/ // */
public static void javaCompiler(File... file) { // public static void javaCompiler(File... file) {
//通过源文件获取到要编译的java类源码迭代器包括所有内部类,其中每个类都是一个 javaFileObject,也被称为一个汇编单元 // //通过源文件获取到要编译的java类源码迭代器包括所有内部类,其中每个类都是一个 javaFileObject,也被称为一个汇编单元
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(file); // Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(file);
//生成编译任务 // //生成编译任务
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, null, null, compilationUnits); // JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, null, null, compilationUnits);
//执行编译任务 // //执行编译任务
task.call(); // task.call();
} // }
//
//
} //}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

View File

@ -0,0 +1,57 @@
// package com.muyu.rule.engine;
//
//
// import com.muyu.rule.build.EngineContainer;
// import com.muyu.rule.engine.annotation.EngineParam;
// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;
//
// import java.time.LocalDate;
// import java.time.Period;
//
// public class Engine_2024_8_25_2342 {
//
//
// private static final Logger log = LoggerFactory.getLogger(Engine_2024_8_25_2342.class);
//
// public String execute( @EngineParam(name = "idcard") String idcard) {
//
// String msg = "";
// System.out.println();
// try {
// // 提取年份
// String yearStr = idcard.substring(6, 10);
// Integer year = Integer.parseInt(yearStr);
//
// // 获取当前年份
// LocalDate currentDate = LocalDate.now();
// // Integer currentYear = currentDate.getYear();
//
// // 计算年龄
// Period age = Period.between(LocalDate.of(year, 1, 1), currentDate);
// msg = "这个身份证的年龄是: " + age.getYears();
//
// // 判断性别
// String genderStr = idcard.substring(16, 17);
// Integer gender = Integer.parseInt(genderStr);
// if (gender % 2 == 0) {
// msg += ", 这个身份证是女生";
// } else {
// msg += ", 这个身份证是男生";
// }
//
// // 获取规则引擎数量
// Integer sumEngine = EngineContainer.getSumEngine();
// log.info("项目中规则引擎数量为: {}", sumEngine);
//
// // 可选:获取 User 对象并打印信息
// // User user = Springutils.getBean(User.class);
// // log.info("{} --- {}", user.getName(), user.getAge());
//
// return msg;
// } catch (Exception e) {
// log.error("处理身份证号码时发生错误: {}", e.getMessage(), e);
// return "处理身份证号码时发生错误: " + e.getMessage();
// }
// }
//}

View File

@ -0,0 +1,17 @@
//package com.muyu.rule.engine.annotation;
//
//import java.lang.annotation.ElementType;
//import java.lang.annotation.Retention;
//import java.lang.annotation.RetentionPolicy;
//import java.lang.annotation.Target;
//
//@Retention(RetentionPolicy.RUNTIME)
//@Target(ElementType.PARAMETER)
//public @interface EngineParam {
// /**
// * 输入字段名称
// *
// * @return
// */
// public String name();
//}

View File

@ -0,0 +1,44 @@
//package com.muyu.rule.exception;
//
//import com.muyu.rule.build.EngineContainer;
//import lombok.extern.log4j.Log4j2;
//
//import java.lang.reflect.InvocationTargetException;
//import java.lang.reflect.Method;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * @ClassName EngineExecution
// * @Description 描述
// * @Author Chen
// * @Date 2024/8/30 08:34
// */
//@Log4j2
//public class EngineExecution extends RuntimeException {
//
// public static Object engineExe(String engineKey, Map<String, Object> params) {
// Object instance = EngineContainer.getInstanceMap(engineKey);
// List<String> methodEngineParams = EngineContainer.getMethodEngineParamMap(engineKey);
// Method method = EngineContainer.getMethodMap(engineKey);
// try {
// int engineParamsLength = methodEngineParams.size();
// Object[] objects = new Object[engineParamsLength];
// for (int i = 0; i < engineParamsLength; i++) {
// params.get(methodEngineParams.get(i));
// methodEngineParams.get(i);
// }
// log.info("规则引擎[{}]调用参数:[{}]", engineKey, Arrays.toString(objects));
// Object invoke = method.invoke(instance, objects);
// log.info("规则引擎[{}]调用参数:[{}]", engineKey, invoke);
// return invoke;
// } catch (IllegalAccessException e) {
// throw new RuntimeException(e);
// } catch (InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
//}

View File

@ -0,0 +1,13 @@
//package com.muyu.rule.exception;
//
///**
// * @ClassName RuleEnginException
// * @Description 描述
// * @Author Chen
// * @Date 2024/8/30 09:53
// */
//public class RuleEngineException extends RuntimeException {
// public RuleEngineException(String message) {
// super(message);
// }
//}

View File

@ -0,0 +1,74 @@
//package com.muyu.rule.load;
//
//import com.muyu.rule.scan.JavaCodeScan;
//import io.jsonwebtoken.io.IOException;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.io.File;
//import java.io.FileNotFoundException;
//import java.nio.file.Files;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @ClassName Java java字节码加载器
// * @Description 加载
// * @Author Chen
// * @Date 2024/8/23 09:55
// */
//public class JavaBinaryClassLoader extends ClassLoader {
// private static JavaBinaryClassLoader loader = new JavaBinaryClassLoader();
//
// private static final Logger log = LoggerFactory.getLogger(JavaBinaryClassLoader.class);
//
//
// /**
// * @param name class 类的文件名
// * @param pack 类所在的包名
// * @param location 类文件的路径
// * @return
// */
// private static Class<?> loadClassByNameAndLocation(String name, String pack, File location) {
// byte[] datas = null;
// try {
// datas = loader.loadClassData(name, location);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// pack = loader.convert(pack);
// Class<?> aClass = loader.defineClass(pack + name, datas, 0, datas.length);
// log.info("成功加载规则引擎->{}", aClass.getName());
// return aClass;
// }
//
// /**
// * @param pack 类所在的包名 后面需要 "."
// * @param location 包所在的路径
// * @return
// */
// public static Map<String, Class<?>> loadClassesByLocation(String pack, String location) {
// File[] childFiles = JavaCodeScan.javaBinaryByPath(location);
// HashMap<String, Class<?>> map = new HashMap<>();
// for (File f : childFiles) {
// String name = f.getName().substring(0, f.getName().indexOf(".class"));
// Class<?> c = loadClassByNameAndLocation(name, pack, new File(location));
// map.put(name, c);
// }
// return map;
// }
//
//
// public byte[] loadClassData(String name, File location) throws Exception {
// File classFile = new File(location, name + ".class");
// if (!classFile.exists()) {
// throw new FileNotFoundException("找不到类文件: " + classFile.getAbsolutePath());
// }
// return Files.readAllBytes(classFile.toPath());
// }
//
// public String convert(String pack) {
// return pack;
// }
//
//}

View File

@ -0,0 +1,39 @@
//package com.muyu.rule.scan;
//
///**
// * @ClassName EngineConfig
// * @Description
// * @Author Chen
// * @Date 2024/8/29 20:22
// */
//public class EngineConfig {
// public static String executionMethodName;
// //包名称
// private String pack = "com.muyu.rule.engine.";
// //本地目录名称
// private String location = "D:\\String Boot\\zhuangao06\\group\\muyu-rule\\muyu-rule-server\\src\\main\\java\\com\\muyu\\rule\\engine\\";
//
// public String getPack() {
// return pack;
// }
//
// public void setPack(String pack) {
// this.pack = pack;
// }
//
// public String getLocation() {
// return location;
// }
//
// public void setLocation(String location) {
// this.location = location;
// }
//
// public static String getExecutionMethodName() {
// return executionMethodName;
// }
//
// public static void setExecutionMethodName(String executionMethodName) {
// EngineConfig.executionMethodName = executionMethodName;
// }
//}

View File

@ -0,0 +1,67 @@
//package com.muyu.rule.scan;
//
//import com.muyu.rule.build.EngineContainer;
//import com.muyu.rule.compile.SourceCodeCompiler;
//import com.muyu.rule.exception.EngineExecution;
//import com.muyu.rule.load.JavaBinaryClassLoader;
//import org.apache.http.impl.auth.NTLMEngineException;
//
//
//import java.lang.reflect.InvocationTargetException;
//import java.lang.reflect.Method;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @ClassName EngineTest
// * @Description EngineTest
// * @Author Chen
// * @Date 2024/8/29 19:33
// */
//public class EngineTest {
// public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
// EngineConfig engineConfig = new EngineConfig();
// //扫描源码进行编译
// SourceCodeCompiler.javaCompilerPath(engineConfig.getLocation());
// Map<String, Class<?>> stringClassMap = JavaBinaryClassLoader.loadClassesByLocation(engineConfig.getPack(), engineConfig.getLocation());
// stringClassMap.forEach((key, value) -> {
// //加载规则引擎实例化
// EngineContainer.loadEngineInstace(key, value);
// });
// HashMap<String, Object> params = new HashMap<>();
// params.put("idCard", "411098766567809834");
// Object Engine_2024_8_25_2342 = EngineExecution.engineExe("Engine_2024_8_25_2342", params);
// System.out.println(Engine_2024_8_25_2342);
//
//
// // 设置编码(仅在需要时启用)
// try {
// System.setOut(new java.io.PrintStream(System.out, true, "UTF-8"));
// } catch (java.io.UnsupportedEncodingException e) {
// System.err.println("无法设置UTF-8编码" + e.getMessage());
// }
// }
//}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

View File

@ -0,0 +1,65 @@
//package com.muyu.rule.scan;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.io.File;
//import java.io.FilenameFilter;
//
//
///**
// * @ClassName JavaCodeScan
// * @Description 扫描文件器
// * @Author Chen
// * @Date 2024/8/23 09:56
// */
//public class JavaCodeScan {
// private static final Logger log = LoggerFactory.getLogger(JavaCodeScan.class);
// private static final String JAVA_SOURCE_SUF = ".java";
// private static final String JAVA_BINARY_SUF = ".class";
//
// /**
// * 扫描本路径下java所有源文件 并创建为file文件
// */
// public static File[] javaSourceScanByPath(String filePath) {
// return filterFileBySuf(filePath, JAVA_SOURCE_SUF);
// }
//
// /**
// * 扫描本路径下java所有源文件 并创建为file文件
// */
// public static File[] javaBinaryByPath(String filePath) {
// return filterFileBySuf(filePath, JAVA_BINARY_SUF);
// }
//
// public static File isJavaSourceScanByPath(String filePath) {
// File file = new File(filePath);
// if (file.isFile()) {
// return file;
// }
// return null;
// }
//
// /**
// * @param filePath 文件路径
// * @param suf 扫描后缀
// * @return
// */
// public static File[] filterFileBySuf(String filePath, String suf) {
// //创建需要扫描的文件夹
// File file = new File(filePath);
// //列出所有的筛选suf结尾的文件集
// File[] childFiles = file.listFiles(new FilenameFilter() {
// @Override
// public boolean accept(File dir, String name) {
// if (name.indexOf(suf) <= -1) {
// return false;
// } else {
// log.info("扫描到{}文件->{}", suf, name);
// return true;
// }
// }
// });
// return childFiles;
// }
//}

View File

@ -15,4 +15,7 @@ public interface RuleEditionService extends IService<RuleEdition> {
* @param id * @param id
*/ */
void enable(Long id); void enable(Long id);
RuleEdition generate(RuleEdition ruleEdition);
} }

View File

@ -0,0 +1,61 @@
//package com.muyu.rule.test;
//
//import com.aliyun.oss.ClientException;
//import com.aliyun.oss.OSS;
//import com.aliyun.oss.common.auth.*;
//import com.aliyun.oss.OSSClientBuilder;
//import com.aliyun.oss.OSSException;
//import com.aliyun.oss.model.PutObjectRequest;
//import com.aliyun.oss.model.PutObjectResult;
//import java.io.FileInputStream;
//import java.io.InputStream;
//
//public class Demo {
//
// public static void main(String[] args) throws Exception {
// // Endpoint以华东1杭州为例其它Region请按实际情况填写。
// String endpoint = "https://oss-tai.oss-cn-shanghai.aliyuncs.com/";
// // 从环境变量中获取访问凭证。运行本代码示例之前请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
// EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// // 填写Bucket名称例如examplebucket。
// String bucketName = "oss-tai";
// // 填写Object完整路径完整路径中不能包含Bucket名称例如exampledir/exampleobject.txt。
// String objectName = "D:\\123.txt";
// // 填写本地文件的完整路径例如D:\\localpath\\examplefile.txt。
// // 如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
// String filePath= "D:\\123.txt";
//
// // 创建OSSClient实例。
// OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);
//
////
//// private static String endPoint = "oss-cn-shanghai.aliyuncs.com";
//// private static String accessKeyId = "LTAI5t6ytyyHWWB693bMEo53";
//// private static String accessKeySecret = "CSubcq72LLVttBlo2XO1JEMEmw894z";
//// private static String accessPre = "https://oss-tai.oss-cn-shanghai.aliyuncs.com/";
//
// try {
// InputStream inputStream = new FileInputStream(filePath);
// // 创建PutObjectRequest对象。
// PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);
// // 创建PutObject请求。
// PutObjectResult result = ossClient.putObject(putObjectRequest);
// } catch (OSSException oe) {
// System.out.println("Caught an OSSException, which means your request made it to OSS, "
// + "but was rejected with an error response for some reason.");
// System.out.println("Error Message:" + oe.getErrorMessage());
// System.out.println("Error Code:" + oe.getErrorCode());
// System.out.println("Request ID:" + oe.getRequestId());
// System.out.println("Host ID:" + oe.getHostId());
// } catch (ClientException ce) {
// System.out.println("Caught an ClientException, which means the client encountered "
// + "a serious internal problem while trying to communicate with OSS, "
// + "such as not being able to access the network.");
// System.out.println("Error Message:" + ce.getMessage());
// } finally {
// if (ossClient != null) {
// ossClient.shutdown();
// }
// }
// }
//}

View File

@ -0,0 +1,154 @@
package com.muyu.rule.test;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyun.oss.model.PutObjectRequest;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.time.LocalDateTime;
import java.util.UUID;
/**
* Oss
*/
@Log4j2
public class OssUtil {
/**# LTAI5t6ytyyHWWB693bMEo53
# CSubcq72LLVttBlo2XO1JEMEmw894z
* Endpoint AccessKeyaccessKeySecretAPI访 访
*/
private static String endPoint = "oss-cn-shanghai.aliyuncs.com";
private static String accessKeyId = "LTAI5t6ytyyHWWB693bMEo53";
private static String accessKeySecret = "CSubcq72LLVttBlo2XO1JEMEmw894z";
private static String accessPre = "https://oss-tai.oss-cn-shanghai.aliyuncs.com/";
/**
* bucket
* @return
*/
private static String bucketName = "oss-tai";
private static OSS ossClient ;
static {
ossClient = new OSSClientBuilder().build(
endPoint,
accessKeyId,
accessKeySecret);
log.info("oss服务连接成功");
}
/**
*
* @param filePath
*/
public static String uploadFile(String filePath){
return uploadFileForBucket(bucketName,getOssFilePath(filePath) ,filePath);
}
/**
* multipartFile
* @param multipartFile
*/
public static String uploadMultipartFile(MultipartFile multipartFile) {
return uploadMultipartFile(bucketName,getOssFilePath(multipartFile.getOriginalFilename()),multipartFile);
}
/**
* multipartFile
* @param bucketName
* @param ossPath
* @param multipartFile
*/
public static String uploadMultipartFile(String bucketName , String ossPath , MultipartFile multipartFile){
InputStream inputStream = null;
try {
inputStream = multipartFile.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
return accessPre+ossPath;
}
/**
* 使FilePutObject ** 使
* @param bucketName
* @param ossPath oss
* @param filePath
*/
public static String uploadFileForBucket(String bucketName , String ossPath , String filePath) {
// 创建PutObjectRequest对象。
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, ossPath, new File(filePath));
// 上传
ossClient.putObject(putObjectRequest);
return accessPre+ossPath;
}
/**
* 使bucket
* @param bucketName
* @param ossPath oss
* @param filePath
*/
public static String uploadFileInputStreamForBucket(String bucketName , String ossPath , String filePath){
// 填写本地文件的完整路径。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
InputStream inputStream = null;
try {
inputStream = new FileInputStream(filePath);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
return accessPre+ossPath;
}
public static void uploadFileInputStreamForBucket(String bucketName , String ossPath , InputStream inputStream ){
ossClient.putObject(bucketName, ossPath, inputStream);
}
/**
*
* @param ossFilePath
* @param filePath
*/
public static void downloadFile(String ossFilePath , String filePath ){
downloadFileForBucket(bucketName , ossFilePath , filePath);
}
/**
*
* @param bucketName
* @param ossFilePath oss
* @param filePath
*/
public static void downloadFileForBucket(String bucketName , String ossFilePath , String filePath ){
ossClient.getObject(new GetObjectRequest(bucketName, ossFilePath), new File(filePath));
}
/**
*
* @return
*/
public static String getOssDefaultPath(){
LocalDateTime now = LocalDateTime.now();
String url =
now.getYear()+"/"+
now.getMonth()+"/"+
now.getDayOfMonth()+"/"+
now.getHour()+"/"+
now.getMinute()+"/";
return url;
}
public static String getOssFilePath(String filePath){
String fileSuf = filePath.substring(filePath.indexOf(".") + 1);
return getOssDefaultPath() + UUID.randomUUID().toString() + "." + fileSuf;
}
}

View File

@ -0,0 +1,13 @@
//package com.muyu.rule.test;
//
///**
// * @ClassName Test
// * @Description 描述
// * @Author Chen
// * @Date 2024/8/31 00:57
// */
//public class Test {
// public static void main(String[] args) {
// OssUtil.uploadFileForBucket("oss-tai","11","D:\\123.txt");
// }
//}