11111
parent
eb2870bb36
commit
24fc9c8eb2
|
@ -27,8 +27,8 @@ import java.util.function.Supplier;
|
|||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "etl_rule",autoResultMap = true)
|
||||
public class EtlRule extends BaseEntity {
|
||||
@TableName(value = "rule_engine",autoResultMap = true)
|
||||
public class RuleEngine extends BaseEntity {
|
||||
|
||||
/**
|
||||
*主键
|
||||
|
@ -41,24 +41,24 @@ public class EtlRule extends BaseEntity {
|
|||
/** 规则类型 */
|
||||
|
||||
private String type ;
|
||||
/** 全限定类名 */
|
||||
|
||||
private String fullClassName ;
|
||||
|
||||
/** 规则作用域 */
|
||||
private String regionName;
|
||||
|
||||
/** 是否公开 0已激活 1未激活 */
|
||||
private String open ;
|
||||
private String open;
|
||||
|
||||
|
||||
/** 状态 0正常 1停用 */
|
||||
private String status ;
|
||||
|
||||
|
||||
public static EtlRule updBuild(EtlRuleUpdReq etlRule, Supplier<Long> longSupplier){
|
||||
public static RuleEngine updBuild(EtlRuleUpdReq etlRule, Supplier<Long> longSupplier){
|
||||
|
||||
return EtlRule.builder().id(longSupplier.get())
|
||||
return RuleEngine.builder().id(longSupplier.get())
|
||||
.open(etlRule.getOpen())
|
||||
.name(etlRule.getName())
|
||||
.regionName(etlRule.getRegionName())
|
||||
.status(etlRule.getStatus())
|
||||
.type(etlRule.getType())
|
||||
.remark(etlRule.getRemark())
|
||||
|
@ -66,11 +66,12 @@ public class EtlRule extends BaseEntity {
|
|||
|
||||
}
|
||||
|
||||
public static EtlRule addBuild(EtlRuleAddReq etlRule){
|
||||
public static RuleEngine addBuild(EtlRuleAddReq etlRule){
|
||||
|
||||
return EtlRule.builder()
|
||||
return RuleEngine.builder()
|
||||
.open(etlRule.getOpen())
|
||||
.name(etlRule.getName())
|
||||
.regionName(etlRule.getRegionName())
|
||||
.status(etlRule.getStatus())
|
||||
.type(etlRule.getType())
|
||||
.remark(etlRule.getRemark())
|
|
@ -25,9 +25,6 @@ public class EtlRuleAddReq {
|
|||
/** 规则类型 */
|
||||
|
||||
private String type ;
|
||||
/** 全限定类名 */
|
||||
|
||||
private String fullClassName ;
|
||||
|
||||
/** 规则说明 */
|
||||
private String explain ;
|
||||
|
@ -35,6 +32,8 @@ public class EtlRuleAddReq {
|
|||
/** 是否公开 0已激活 1未激活 */
|
||||
private String open ;
|
||||
|
||||
/** 规则作用域 */
|
||||
private String regionName;
|
||||
|
||||
/** 状态 0正常 1停用 */
|
||||
private String status ;
|
||||
|
|
|
@ -30,6 +30,7 @@ public class EtlRuleListReq {
|
|||
private String open ;
|
||||
|
||||
|
||||
|
||||
/** 状态 0正常 1停用 */
|
||||
private String status ;
|
||||
|
||||
|
|
|
@ -26,13 +26,12 @@ public class EtlRuleUpdReq {
|
|||
/** 规则类型 */
|
||||
|
||||
private String type ;
|
||||
/** 全限定类名 */
|
||||
|
||||
private String fullClassName ;
|
||||
|
||||
/** 是否公开 0已激活 1未激活 */
|
||||
private String open ;
|
||||
|
||||
/** 规则作用域 */
|
||||
private String regionName;
|
||||
|
||||
/** 状态 0正常 1停用 */
|
||||
private String status ;
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.muyu.rule.common.domain.resp;
|
|||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.muyu.rule.common.domain.EtlRule;
|
||||
import com.muyu.rule.common.domain.RuleEngine;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -41,9 +41,10 @@ public class EtlRuleResp {
|
|||
/** 规则类型 */
|
||||
|
||||
private String type ;
|
||||
/** 全限定类名 */
|
||||
|
||||
private String fullClassName ;
|
||||
|
||||
/** 规则作用域 */
|
||||
private String regionName;
|
||||
|
||||
|
||||
@Schema(description = "创建人", defaultValue = "muyu", type = "String")
|
||||
|
@ -57,12 +58,13 @@ public class EtlRuleResp {
|
|||
@Schema(description = "创建时间", defaultValue = "2024-8-1 0:22:36", type = "Date")
|
||||
private Date createTime;
|
||||
|
||||
public static EtlRuleResp etlRuleRespBuilder(EtlRule etlRule){
|
||||
public static EtlRuleResp etlRuleRespBuilder(RuleEngine etlRule){
|
||||
|
||||
return EtlRuleResp.builder()
|
||||
.id(etlRule.getId())
|
||||
.type(etlRule.getType())
|
||||
.name(etlRule.getName())
|
||||
.regionName(etlRule.getRegionName())
|
||||
.createBy(etlRule.getCreateBy())
|
||||
.createTime(etlRule.getCreateTime()).build();
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.rule.common.domain.resp;
|
||||
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.common.domain.resp
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:RuleRegion
|
||||
* @Date:2024/8/23 9:03
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Tag(name = "规则作用域")
|
||||
public class RuleRegion extends BaseEntity {
|
||||
|
||||
private Long regionId;
|
||||
|
||||
private String regionName;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.rule.server.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server.annotation
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:EngineParam
|
||||
* @Date:2024/8/22 23:18
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.PARAMETER)
|
||||
public @interface EngineParam {
|
||||
|
||||
/**
|
||||
*
|
||||
* 输入字段结果
|
||||
*/
|
||||
|
||||
public String name();
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package com.muyu.rule.server.complie;
|
||||
|
||||
import com.muyu.rule.server.scan.JavaCodeScan;
|
||||
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
import javax.tools.ToolProvider;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server.complie
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:SourceCode
|
||||
* @Date:2024/8/22 19:10
|
||||
*/
|
||||
public class SourceCodeComplier extends ClassLoader {
|
||||
|
||||
|
||||
private static JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
|
||||
private static StandardJavaFileManager fileManager = compiler.getStandardFileManager(null,null,null);
|
||||
|
||||
/**
|
||||
* 输入编译的文件夹路径
|
||||
* @param path 文件夹路径
|
||||
*/
|
||||
|
||||
public static void javaCompilerPath(String path){
|
||||
File[] files = JavaCodeScan.javaSourceScanByPath(path);
|
||||
|
||||
javaCampiler(files);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输入编译的文件路径
|
||||
* @param filePath
|
||||
*/
|
||||
|
||||
public static void javaCompilerFile(String... filePath){
|
||||
int filePathLength = filePath.length;
|
||||
File[] files = new File[filePathLength];
|
||||
|
||||
for (int i = 0; i < filePathLength; i++) {
|
||||
files[i] = new File(filePath[i]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 可同时编译多个java源文件
|
||||
* @param file
|
||||
*/
|
||||
|
||||
|
||||
public static void javaCampiler(File... file){
|
||||
|
||||
Iterable<? extends JavaFileObject> comilationUnits = fileManager.getJavaFileObjects(file);
|
||||
|
||||
JavaCompiler.CompilationTask task= compiler.getTask(null,fileManager,null,null,null,comilationUnits);
|
||||
|
||||
task.call();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -2,12 +2,13 @@ package com.muyu.rule.server.controller;
|
|||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
|
||||
import com.muyu.rule.common.domain.EtlRule;
|
||||
import com.muyu.rule.common.domain.RuleEngine;
|
||||
import com.muyu.rule.common.domain.req.EtlRuleAddReq;
|
||||
import com.muyu.rule.common.domain.req.EtlRuleListReq;
|
||||
import com.muyu.rule.common.domain.req.EtlRuleUpdReq;
|
||||
import com.muyu.rule.common.domain.resp.EtlRuleResp;
|
||||
import com.muyu.rule.server.service.EtlRuleService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
@ -26,7 +27,7 @@ import java.util.List;
|
|||
*/
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/etlRule")
|
||||
@RequestMapping("/rule")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "etl规则控制层", description = "进行etl规则管理,查看等相关操作")
|
||||
public class EtlRuleController {
|
||||
|
@ -41,13 +42,15 @@ public class EtlRuleController {
|
|||
* @return 实例对象
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<EtlRule> queryById(@PathVariable("id") int id){
|
||||
EtlRule etlRule = etlRuleService.queryById(id);
|
||||
@Operation(summary = "规则引擎的查看", description = "通过Id对规则引擎的查看,并对规则引擎的逻辑模块进行设置")
|
||||
public Result<RuleEngine> queryById(@PathVariable("id") int id){
|
||||
RuleEngine etlRule = etlRuleService.queryById(id);
|
||||
return Result.success(etlRule);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "查看规则引擎", description = "根据规则引擎的名称,类型,是否激活,状态等可以进行对规则的筛选")
|
||||
public Result<List<EtlRuleResp>> selectList(@Validated @RequestBody EtlRuleListReq req){
|
||||
|
||||
List<EtlRuleResp> list = etlRuleService.selectList(req);
|
||||
|
@ -64,8 +67,9 @@ public class EtlRuleController {
|
|||
*/
|
||||
|
||||
@PostMapping
|
||||
public Result<EtlRule> add(@RequestBody EtlRuleAddReq etlRule){
|
||||
etlRuleService.save(EtlRule.addBuild(etlRule));
|
||||
@Operation(summary = "规则引擎的添加", description = "添加规则引擎的,添加成功后可以对规则引擎进行维护")
|
||||
public Result<RuleEngine> add(@RequestBody EtlRuleAddReq etlRule){
|
||||
etlRuleService.save(RuleEngine.addBuild(etlRule));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
@ -77,8 +81,9 @@ public class EtlRuleController {
|
|||
*/
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public Result<EtlRule> edit(@PathVariable("id") Long id, @RequestBody @Validated EtlRuleUpdReq etlRule){
|
||||
etlRuleService.updateById(EtlRule.updBuild(etlRule,()->id));
|
||||
@Operation(summary = "规则引擎的修改", description = "通过Id修改规则引擎的信息")
|
||||
public Result<RuleEngine> edit(@PathVariable("id") Long id, @RequestBody @Validated EtlRuleUpdReq etlRule){
|
||||
etlRuleService.updateById(RuleEngine.updBuild(etlRule,()->id));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
@ -89,6 +94,7 @@ public class EtlRuleController {
|
|||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping
|
||||
@Operation(summary = "规则引擎的删除", description = "通过Id删除规则信息")
|
||||
public Result<Boolean> deleteById(int id){
|
||||
etlRuleService.deleteById(id);
|
||||
return Result.success();
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
package com.muyu.rule.server.load;
|
||||
|
||||
import com.muyu.rule.server.scan.JavaCodeScan;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server.load
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:JavaBinaryClassLoader
|
||||
* @Date:2024/8/22 20:54
|
||||
*/
|
||||
|
||||
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 类所在的包名eg:com.ecoogy.etl.engine.
|
||||
* @param location 类文件的路径,设定目录: 设定目录时,需要在最后带上"/"
|
||||
* 自定义路径获取Class对象
|
||||
*/
|
||||
|
||||
|
||||
|
||||
private static Class<?> loadClassByNameAndLocation(String name,String pack,File location){
|
||||
Class<?> aClass = null;
|
||||
try {
|
||||
//将class文件的数据读入到byte数组中 转成二进制文件
|
||||
byte[] datas = loader.loadClassData(name,location);
|
||||
pack= loader.convert(pack);
|
||||
|
||||
//通过byte数组加载Class对象
|
||||
aClass = loader.defineClass(pack + name, datas, 0, datas.length);
|
||||
log.info("成功加载规则引擎-> {} ",aClass.getName());
|
||||
return aClass;
|
||||
} catch (IOException e) {
|
||||
log.error("从文件中加载类失败 {}", name, location, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param pack 类所在的包名 eg:com.szelink.test. 后面需要带个"."
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文件的格式
|
||||
* @param pack
|
||||
* @return
|
||||
*/
|
||||
private String convert(String pack) {
|
||||
return pack.replace('.', '/') + "/";
|
||||
}
|
||||
|
||||
public byte[] loadClassData(String name, File location)throws IOException {
|
||||
File classFile = new File(location, name + ".class");
|
||||
if (!classFile.exists()) {
|
||||
throw new FileNotFoundException("找不到类文件: " + classFile.getAbsolutePath());
|
||||
}
|
||||
return Files.readAllBytes(classFile.toPath());
|
||||
}
|
||||
}
|
|
@ -1,13 +1,8 @@
|
|||
package com.muyu.rule.server.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.muyu.rule.common.domain.EtlRule;
|
||||
import com.muyu.rule.common.domain.RuleEngine;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
|
@ -17,7 +12,7 @@ import org.apache.ibatis.annotations.Select;
|
|||
* @Date:2024/8/21 14:22
|
||||
*/
|
||||
@Mapper
|
||||
public interface EtlRuleMapper extends BaseMapper<EtlRule> {
|
||||
public interface EtlRuleMapper extends BaseMapper<RuleEngine> {
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package com.muyu.rule.server.pool;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server.pool
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:RuleEngineException
|
||||
* @Date:2024/8/22 23:13
|
||||
*/
|
||||
public class RuleEngineException extends RuntimeException{
|
||||
public RuleEngineException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public RuleEngineException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public RuleEngineException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public RuleEngineException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
protected RuleEngineException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.muyu.rule.server.pool.container;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:EngineContainer
|
||||
* @Date:2024/8/22 22:32
|
||||
*/
|
||||
public class EngineContainer {
|
||||
public static void loadEngineInstance(String key, Class<?> value) {
|
||||
|
||||
|
||||
}
|
||||
//
|
||||
// private static final Logger log = LoggerFactory.getLogger(JavaBinaryClassLoader.class);
|
||||
//
|
||||
// private static Map<String ,Object> instanceMap = new ConcurrentHashMap<>(16);
|
||||
//
|
||||
//
|
||||
//
|
||||
//public static void loadEngineInstance(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();
|
||||
// //获取参数
|
||||
// ArrayList<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 不可为null");
|
||||
// }
|
||||
// engineParams.add(engineParam.name());
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.muyu.rule.server.scan;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:EngineConfig
|
||||
* @Date:2024/8/22 18:59
|
||||
*/
|
||||
public class EngineConfig {
|
||||
|
||||
/**
|
||||
* 包名称
|
||||
*/
|
||||
private String pack ="com.ecology.etl.engine.";
|
||||
|
||||
/**
|
||||
* 本地目录名称
|
||||
*/
|
||||
|
||||
private String location ="F:\\临时\\2021年5月28日\\";
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package com.muyu.rule.server.scan;
|
||||
|
||||
import com.muyu.rule.server.load.JavaBinaryClassLoader;
|
||||
import com.muyu.rule.server.pool.container.EngineContainer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:EngineExecution
|
||||
* @Date:2024/8/22 23:31
|
||||
*/
|
||||
public class EngineExecution {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(JavaBinaryClassLoader.class);
|
||||
|
||||
//
|
||||
//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 methodEngineParamsLength = methodEngineParams.size();
|
||||
// Object[] objects = new Object[methodEngineParamsLength];
|
||||
// for (int i = 0; i < methodEngineParamsLength; i++) {
|
||||
// objects[i] = params.get(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);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.muyu.rule.server.scan;
|
||||
|
||||
|
||||
import com.muyu.rule.server.complie.SourceCodeComplier;
|
||||
import com.muyu.rule.server.load.JavaBinaryClassLoader;
|
||||
import com.muyu.rule.server.pool.container.EngineContainer;
|
||||
import com.muyu.rule.server.scan.EngineConfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:EngineTest
|
||||
* @Date:2024/8/22 18:55
|
||||
*/
|
||||
public class EngineTest {
|
||||
|
||||
public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException {
|
||||
|
||||
EngineConfig engineConfig = new EngineConfig();
|
||||
|
||||
//扫描原码进行编译
|
||||
SourceCodeComplier.javaCompilerPath(engineConfig.getLocation());
|
||||
|
||||
Map<String ,Class<?>> stringClassMap = JavaBinaryClassLoader.loadClassesByLocation(engineConfig.getPack(),engineConfig.getLocation());
|
||||
|
||||
stringClassMap.forEach((key,value)->{
|
||||
EngineContainer.loadEngineInstance(key,value);
|
||||
});
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("idCard","");
|
||||
|
||||
//EngineExecution.engineExe(,params);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package com.muyu.rule.server.scan;
|
||||
|
||||
import com.muyu.rule.server.load.JavaBinaryClassLoader;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server.scan
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:JavaCodeScan
|
||||
* @Date:2024/8/22 21:11
|
||||
*/
|
||||
@Log4j2
|
||||
public class JavaCodeScan {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(JavaBinaryClassLoader.class);
|
||||
|
||||
|
||||
private static final String JAVA_SOURCE_SUF = ".java";
|
||||
private static final String JAVA_BINARY_SUF = ".class";
|
||||
|
||||
/**
|
||||
* 扫描本路径下java所有源文件 并创建为file文件
|
||||
* @param filePath 文件路径
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static File[] javaSourceScanByPath(String filePath){
|
||||
|
||||
return filterFileBySuf(filePath,JAVA_SOURCE_SUF);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描本路径下java所有源文件 并创建为file文件
|
||||
* @param filePath 文件路径
|
||||
* @return
|
||||
*/
|
||||
public static File[] javaBinaryByPath(String filePath){
|
||||
|
||||
return filterFileBySuf(filePath,JAVA_BINARY_SUF);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验是否为java文件 是 返回File 否 抛出异常
|
||||
* @param filePath
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package com.muyu.rule.server.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.rule.common.domain.EtlRule;
|
||||
import com.muyu.rule.common.domain.RuleEngine;
|
||||
import com.muyu.rule.common.domain.req.EtlRuleListReq;
|
||||
import com.muyu.rule.common.domain.resp.EtlRuleResp;
|
||||
|
||||
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||
* @name:EtlRuleService
|
||||
* @Date:2024/8/21 14:21
|
||||
*/
|
||||
public interface EtlRuleService extends IService<EtlRule> {
|
||||
public interface EtlRuleService extends IService<RuleEngine> {
|
||||
|
||||
/**
|
||||
* 通过ID查询单条数据
|
||||
|
@ -22,7 +22,7 @@ public interface EtlRuleService extends IService<EtlRule> {
|
|||
* @param id 主键
|
||||
* @return 实例对象
|
||||
*/
|
||||
EtlRule queryById(int id);
|
||||
RuleEngine queryById(int id);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.muyu.rule.server.service.impl;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.rule.common.domain.EtlRule;
|
||||
import com.muyu.rule.common.domain.RuleEngine;
|
||||
import com.muyu.rule.common.domain.req.EtlRuleListReq;
|
||||
import com.muyu.rule.common.domain.resp.EtlRuleResp;
|
||||
import com.muyu.rule.server.mapper.EtlRuleMapper;
|
||||
|
@ -21,7 +21,7 @@ import java.util.List;
|
|||
* @Date:2024/8/21 14:22
|
||||
*/
|
||||
@Service
|
||||
public class EtlRuleServiceImpl extends ServiceImpl<EtlRuleMapper, EtlRule> implements EtlRuleService {
|
||||
public class EtlRuleServiceImpl extends ServiceImpl<EtlRuleMapper, RuleEngine> implements EtlRuleService {
|
||||
|
||||
@Autowired
|
||||
private EtlRuleMapper etlRuleMapper;
|
||||
|
@ -33,7 +33,7 @@ public class EtlRuleServiceImpl extends ServiceImpl<EtlRuleMapper, EtlRule> imp
|
|||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public EtlRule queryById(int id){
|
||||
public RuleEngine queryById(int id){
|
||||
return etlRuleMapper.selectById(id);
|
||||
}
|
||||
|
||||
|
@ -54,22 +54,22 @@ public class EtlRuleServiceImpl extends ServiceImpl<EtlRuleMapper, EtlRule> imp
|
|||
@Override
|
||||
public List<EtlRuleResp> selectList(EtlRuleListReq req) {
|
||||
|
||||
LambdaQueryWrapper<EtlRule> queryWrapper = new LambdaQueryWrapper<>();
|
||||
LambdaQueryWrapper<RuleEngine> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
queryWrapper.like(StringUtils.isNotEmpty(req.getName()),EtlRule::getName,req.getName());
|
||||
queryWrapper.like(StringUtils.isNotEmpty(req.getName()), RuleEngine::getName,req.getName());
|
||||
|
||||
queryWrapper.eq(
|
||||
StringUtils.isNotEmpty(req.getStatus()),EtlRule::getStatus,req.getStatus()
|
||||
StringUtils.isNotEmpty(req.getStatus()), RuleEngine::getStatus,req.getStatus()
|
||||
);
|
||||
queryWrapper.eq(
|
||||
StringUtils.isNotEmpty(req.getOpen()),EtlRule::getOpen,req.getOpen()
|
||||
StringUtils.isNotEmpty(req.getOpen()), RuleEngine::getOpen,req.getOpen()
|
||||
);
|
||||
|
||||
queryWrapper.eq(
|
||||
StringUtils.isNotEmpty(req.getType()),EtlRule::getType,req.getType()
|
||||
StringUtils.isNotEmpty(req.getType()), RuleEngine::getType,req.getType()
|
||||
);
|
||||
|
||||
List<EtlRule> etlRuleList = this.list(queryWrapper);
|
||||
List<RuleEngine> etlRuleList = this.list(queryWrapper);
|
||||
|
||||
List<EtlRuleResp> respList = etlRuleList.stream()
|
||||
.map(etlRule -> EtlRuleResp.etlRuleRespBuilder(etlRule)).toList();
|
||||
|
|
Loading…
Reference in New Issue