feat():引擎版本初始化加载
parent
e7336a4f59
commit
86dd8a7060
|
@ -0,0 +1,14 @@
|
|||
package com.muyu.engine.domain.engine;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/6
|
||||
* @Description: 引擎
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface Engine<V> {
|
||||
|
||||
public void execution();
|
||||
|
||||
public V get();
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.muyu.engine.domain.engine.action;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/6
|
||||
* @Description: 丢弃
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class ActionDiscard extends RuntimeException{
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.engine.domain.engine.custom;
|
||||
|
||||
|
||||
import com.muyu.engine.domain.engine.action.ActionDiscard;
|
||||
import com.muyu.engine.domain.engine.scope.DataModelEngine;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/6
|
||||
* @Description: 自定义不为空引擎
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class IsNotNullEngineCustom extends DataModelEngine {
|
||||
@Override
|
||||
public void execution () {
|
||||
Object value = getValue();
|
||||
|
||||
if (value == null || "".equals(value) || "null".equals(value)) {
|
||||
throw new ActionDiscard();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.muyu.engine.domain.engine.scope;
|
||||
|
||||
|
||||
import com.muyu.engine.domain.engine.Engine;
|
||||
import com.muyu.engine.domain.model.DataModel;
|
||||
import com.muyu.engine.domain.scope.DataModelContext;
|
||||
import com.muyu.engine.domain.scope.model.DataProcessModel;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/6
|
||||
* @Description: 数据模型引擎接口
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public abstract class DataModelEngine implements Engine<DataProcessModel> {
|
||||
|
||||
private DataModelContext dataModelContext;
|
||||
|
||||
@Override
|
||||
public DataProcessModel get (){
|
||||
return dataModelContext.get();
|
||||
}
|
||||
|
||||
public DataModel getModel(){
|
||||
return get().getDataModel();
|
||||
}
|
||||
|
||||
|
||||
public String getKey () {
|
||||
return getModel().getKey();
|
||||
}
|
||||
|
||||
public Object getValue () {
|
||||
return getModel().getValue();
|
||||
}
|
||||
|
||||
public String getSourceType () {
|
||||
return getModel().getSourceType();
|
||||
}
|
||||
|
||||
public String getProcessType () {
|
||||
return getModel().getProcessType();
|
||||
}
|
||||
|
||||
public Class<?> getProcessClass () {
|
||||
return getModel().getProcessClass();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.engine.domain.engine.scope;
|
||||
|
||||
import com.muyu.engine.domain.engine.Engine;
|
||||
import com.muyu.engine.domain.model.DataSetModel;
|
||||
import com.muyu.engine.domain.scope.DataSetContext;
|
||||
import com.muyu.engine.domain.scope.model.DataSetProcessModel;
|
||||
|
||||
/**
|
||||
* 数据模型引擎接口
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/6
|
||||
* @Description: 数据模型引擎接口
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public abstract class DataSetEngine implements Engine<DataSetProcessModel> {
|
||||
//上下文对象
|
||||
private DataSetContext dataSetContext;
|
||||
|
||||
@Override
|
||||
public DataSetProcessModel get() {
|
||||
return dataSetContext.get();
|
||||
}
|
||||
|
||||
public DataSetModel getModel(){
|
||||
return get().getDataSetModel();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.engine.domain.engine.scope;
|
||||
|
||||
|
||||
import com.muyu.engine.domain.engine.Engine;
|
||||
import com.muyu.engine.domain.model.RecordModel;
|
||||
import com.muyu.engine.domain.scope.RecordContext;
|
||||
import com.muyu.engine.domain.scope.model.RecordProcessModel;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/6
|
||||
* @Description: 数据模型引擎接口
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public abstract class RecordEngine implements Engine<RecordProcessModel> {
|
||||
|
||||
private RecordContext recordContext;
|
||||
|
||||
@Override
|
||||
public RecordProcessModel get() {
|
||||
return recordContext.get();
|
||||
}
|
||||
|
||||
//获取记录模型
|
||||
public RecordModel getModel(){
|
||||
return get().getRecordModel();
|
||||
}
|
||||
|
||||
//获取键唯一值
|
||||
public String[] getKeys(){
|
||||
return get().getKeys();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.muyu.engine.domain.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 数据模型
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/5
|
||||
* @Description: 数据模型
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
public class DataModel {
|
||||
|
||||
/**
|
||||
* 数据键
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 数据值
|
||||
*/
|
||||
private Object value;
|
||||
|
||||
/**
|
||||
* 源标准-枚举
|
||||
*/
|
||||
private String sourceType;
|
||||
|
||||
/**
|
||||
* 处理标准-枚举
|
||||
*/
|
||||
private String processType;
|
||||
|
||||
/**
|
||||
* 处理类型
|
||||
*/
|
||||
private Class<?> processClass;
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.muyu.engine.domain.model;
|
||||
|
||||
/**
|
||||
* 一页
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/5
|
||||
* @Description: 一页
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class DataSetModel {
|
||||
|
||||
// [[DataModel,DataModel,DataModel],[DataModel,DataModel,DataModel]]
|
||||
|
||||
private RecordModel[] recordModelArr = null;
|
||||
|
||||
private DataSetModel(int recordModelLength){
|
||||
recordModelArr = new RecordModel[recordModelLength];
|
||||
}
|
||||
private DataSetModel(RecordModel[] recordModelArr){
|
||||
recordModelArr = recordModelArr;
|
||||
}
|
||||
|
||||
public static DataSetModel build(int recordModelLength){
|
||||
return new DataSetModel(recordModelLength);
|
||||
}
|
||||
|
||||
public static DataSetModel build(RecordModel[] recordModelArr){
|
||||
return new DataSetModel(recordModelArr);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.muyu.engine.domain.model;
|
||||
|
||||
/**
|
||||
* 数据标准
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/5
|
||||
* @Description: 数据标准
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface DataStandard {
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.engine.domain.model;
|
||||
|
||||
/**
|
||||
* 记录模型
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/5
|
||||
* @Description: 记录模型
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class RecordModel {
|
||||
// [DataModel,DataModel,DataModel]
|
||||
|
||||
private RecordModel(int dataModelLength){
|
||||
dataModelArr = new DataModel[dataModelLength];
|
||||
}
|
||||
private RecordModel(DataModel[] dataModelArr){
|
||||
dataModelArr = dataModelArr;
|
||||
}
|
||||
|
||||
private DataModel[] dataModelArr = null;
|
||||
|
||||
public static RecordModel build(int dataModelLength){
|
||||
return new RecordModel(dataModelLength);
|
||||
}
|
||||
|
||||
public static RecordModel build(DataModel[] dataModelArr){
|
||||
return new RecordModel(dataModelArr);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.engine.domain.scope;
|
||||
|
||||
|
||||
import com.muyu.engine.domain.scope.model.DataProcessModel;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/4/29
|
||||
* @Description: 数据模型
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class DataModelContext implements ScopeContext <DataProcessModel>{
|
||||
|
||||
private static final ThreadLocal<DataProcessModel> THREAD_LOCAL = new ThreadLocal<>();
|
||||
|
||||
private final DataSetContext dataSetContext;
|
||||
|
||||
public DataModelContext (DataSetContext dataSetContext) {
|
||||
this.dataSetContext = dataSetContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataProcessModel get () {
|
||||
return THREAD_LOCAL.get();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.engine.domain.scope;
|
||||
|
||||
|
||||
import com.muyu.engine.domain.scope.model.DataSetProcessModel;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/4/29
|
||||
* @Description: 数据集
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class DataSetContext implements ScopeContext<DataSetProcessModel>{
|
||||
|
||||
private static final ThreadLocal<DataSetProcessModel> THREAD_LOCAL = new ThreadLocal<>();
|
||||
|
||||
private final RecordContext recordContext;
|
||||
|
||||
public DataSetContext (RecordContext recordContext) {
|
||||
this.recordContext = recordContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSetProcessModel get() {
|
||||
return THREAD_LOCAL.get();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.engine.domain.scope;
|
||||
|
||||
|
||||
import com.muyu.engine.domain.scope.model.RecordProcessModel;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/4/29
|
||||
* @Description: 记录/资产模型
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class RecordContext implements ScopeContext<RecordProcessModel> {
|
||||
|
||||
private static final ThreadLocal<RecordProcessModel> THREAD_LOCAL = new ThreadLocal<>();
|
||||
|
||||
private final TaskContext taskContext;
|
||||
|
||||
public RecordContext(TaskContext taskContext) {
|
||||
this.taskContext = taskContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecordProcessModel get(){
|
||||
return THREAD_LOCAL.get();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.muyu.engine.domain.scope;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/6
|
||||
* @Description: 数据域规范
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface ScopeContext<V> {
|
||||
|
||||
V get();
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.muyu.engine.domain.scope;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/4/29
|
||||
* @Description: 任务上下文
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class TaskContext {
|
||||
|
||||
public static TaskContext build(){
|
||||
return new TaskContext();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.engine.domain.scope.model;
|
||||
|
||||
|
||||
import com.muyu.engine.domain.model.DataModel;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 数据处理模型
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/5
|
||||
* @Description: 数据处理模型
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
public class DataProcessModel {
|
||||
|
||||
private DataModel dataModel;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.engine.domain.scope.model;
|
||||
|
||||
|
||||
import com.muyu.engine.domain.model.DataSetModel;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 数据集处理模型
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/5
|
||||
* @Description: 数据集处理模型
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
public class DataSetProcessModel {
|
||||
|
||||
private DataSetModel dataSetModel;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.muyu.engine.domain.scope.model;
|
||||
|
||||
|
||||
import com.muyu.engine.domain.model.RecordModel;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 行级别任务处理模型
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/5
|
||||
* @Description: 行级别任务处理模型
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
public class RecordProcessModel {
|
||||
|
||||
private String[] keys;
|
||||
|
||||
private RecordModel recordModel;
|
||||
}
|
|
@ -163,42 +163,40 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
System.out.println();
|
||||
return booleanSupplier.get();
|
||||
}
|
||||
|
||||
private Boolean testEngine(RuleEngine ruleEngine) throws ServletException, IOException {
|
||||
// System.out.println("初始化");
|
||||
// System.out.println(ruleEngine);
|
||||
// Scope scope = this.getOne(new LambdaQueryWrapper<Scope>() {{
|
||||
// eq(Scope::getRuleEngineId, ruleEngine.getId());
|
||||
// eq(Scope::getValue, "taskContext");
|
||||
// }});
|
||||
// String code = scope.getCode();
|
||||
// String path = code.substring(code.indexOf("com"), code.indexOf(";")).replaceAll("\\.", "/").trim();
|
||||
// String fileName = code.substring(code.indexOf("class") + 6, code.indexOf("{")).trim();
|
||||
// //代码编译
|
||||
// File file = new File("D:/ruoyi/FinallyTest/muyu-modules/muyu-ruleEngine/muyu-ruleEngine-service/src/main/java/" + path + "/" + fileName + ".java");
|
||||
// if (!file.exists()) {
|
||||
// //不存在创建
|
||||
// file.createNewFile();
|
||||
// }else {
|
||||
// //存在测重新创建
|
||||
// file.delete();
|
||||
// file.createNewFile();
|
||||
// }
|
||||
// String[] split = code.split("/n");
|
||||
// //OutputStreamWriter对象将字符转换为字节流,指定了文件输出流和编码方式。
|
||||
// OutputStreamWriter outputStreamWriter =
|
||||
// new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8");
|
||||
// //BufferedWriter对象,用于缓冲写入数据,提高写入效率。
|
||||
// BufferedWriter bw = new BufferedWriter(outputStreamWriter);
|
||||
// for (String str : split) {
|
||||
// bw.write(str);
|
||||
// bw.newLine();
|
||||
// }
|
||||
// bw.close();
|
||||
// outputStreamWriter.close();
|
||||
System.out.println("初始化");
|
||||
System.out.println(ruleEngine);
|
||||
RuleEngineVersion ruleEngineVersion = this.getOne(new LambdaQueryWrapper<RuleEngineVersion>() {{
|
||||
eq(RuleEngineVersion::getRuleEngineId, ruleEngine.getId());
|
||||
}});
|
||||
String code = ruleEngineVersion.getCodeIng();
|
||||
String path = code.substring(code.indexOf("com"), code.indexOf(";")).replaceAll("\\.", "/").trim();
|
||||
String fileName = code.substring(code.indexOf("class") + 6, code.indexOf("{")).trim();
|
||||
//代码编译
|
||||
File file = new File("D:/ruoyi/FinallyTest/muyu-modules/muyu-ruleEngine/muyu-ruleEngine-service/src/main/java/" + path + "/" + fileName + ".java");
|
||||
if (!file.exists()) {
|
||||
//不存在创建
|
||||
file.createNewFile();
|
||||
}else {
|
||||
//存在测重新创建
|
||||
file.delete();
|
||||
file.createNewFile();
|
||||
}
|
||||
String[] split = code.split("/n");
|
||||
//OutputStreamWriter对象将字符转换为字节流,指定了文件输出流和编码方式。
|
||||
OutputStreamWriter outputStreamWriter =
|
||||
new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8");
|
||||
//BufferedWriter对象,用于缓冲写入数据,提高写入效率。
|
||||
BufferedWriter bw = new BufferedWriter(outputStreamWriter);
|
||||
for (String str : split) {
|
||||
bw.write(str);
|
||||
bw.newLine();
|
||||
}
|
||||
bw.close();
|
||||
outputStreamWriter.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue