feat():引擎版本初始化加载

master
Saisai Liu 2024-05-08 17:21:06 +08:00
parent e7336a4f59
commit 86dd8a7060
19 changed files with 462 additions and 32 deletions

View File

@ -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();
}

View File

@ -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{
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -0,0 +1,12 @@
package com.muyu.engine.domain.model;
/**
*
* @Author: DongZeLiang
* @date: 2024/5/5
* @Description:
* @Version: 1.0
*/
public interface DataStandard {
}

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -163,42 +163,40 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}; };
System.out.println();
return booleanSupplier.get(); return booleanSupplier.get();
} }
private Boolean testEngine(RuleEngine ruleEngine) throws ServletException, IOException { private Boolean testEngine(RuleEngine ruleEngine) throws ServletException, IOException {
// System.out.println("初始化"); System.out.println("初始化");
// System.out.println(ruleEngine); System.out.println(ruleEngine);
// Scope scope = this.getOne(new LambdaQueryWrapper<Scope>() {{ RuleEngineVersion ruleEngineVersion = this.getOne(new LambdaQueryWrapper<RuleEngineVersion>() {{
// eq(Scope::getRuleEngineId, ruleEngine.getId()); eq(RuleEngineVersion::getRuleEngineId, ruleEngine.getId());
// eq(Scope::getValue, "taskContext"); }});
// }}); String code = ruleEngineVersion.getCodeIng();
// String code = scope.getCode(); String path = code.substring(code.indexOf("com"), code.indexOf(";")).replaceAll("\\.", "/").trim();
// String path = code.substring(code.indexOf("com"), code.indexOf(";")).replaceAll("\\.", "/").trim(); String fileName = code.substring(code.indexOf("class") + 6, code.indexOf("{")).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");
// File file = new File("D:/ruoyi/FinallyTest/muyu-modules/muyu-ruleEngine/muyu-ruleEngine-service/src/main/java/" + path + "/" + fileName + ".java"); if (!file.exists()) {
// if (!file.exists()) { //不存在创建
// //不存在创建 file.createNewFile();
// file.createNewFile(); }else {
// }else { //存在测重新创建
// //存在测重新创建 file.delete();
// file.delete(); file.createNewFile();
// file.createNewFile(); }
// } String[] split = code.split("/n");
// String[] split = code.split("/n"); //OutputStreamWriter对象将字符转换为字节流指定了文件输出流和编码方式。
// //OutputStreamWriter对象将字符转换为字节流指定了文件输出流和编码方式。 OutputStreamWriter outputStreamWriter =
// OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8");
// new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8"); //BufferedWriter对象用于缓冲写入数据提高写入效率。
// //BufferedWriter对象用于缓冲写入数据提高写入效率。 BufferedWriter bw = new BufferedWriter(outputStreamWriter);
// BufferedWriter bw = new BufferedWriter(outputStreamWriter); for (String str : split) {
// for (String str : split) { bw.write(str);
// bw.write(str); bw.newLine();
// bw.newLine(); }
// } bw.close();
// bw.close(); outputStreamWriter.close();
// outputStreamWriter.close();
return true; return true;
} }
} }