fix:修复引擎维护新增和修改时缺少描述语句的问题
parent
4e9ba19c33
commit
5af8c4155a
|
@ -0,0 +1,22 @@
|
|||
package com.ruoyi.ruleEngine.constant;
|
||||
|
||||
/**
|
||||
* 配置编码常量
|
||||
* @ClassName ConfigCodeConstants
|
||||
* @Author 森静若林
|
||||
* @Date 2024/5/4 15:28
|
||||
*/
|
||||
public class ConfigCodeConstants {
|
||||
/**
|
||||
* 文件基础路径
|
||||
*/
|
||||
public final static String BASE_FILE_PATH="D:/workspace/gtl-ruoyi-server/ruoyi-modules/ruoyi-rule_engine/ruoyi-rule_engine-server/src/main/java/com/ruoyi/ruleEngine/scope/";
|
||||
/**
|
||||
* 配置文件名数组
|
||||
*/
|
||||
public final static String[] CONFIG_FILE_NAME_ARRAY=new String[]{"TestClass.txt","TaskContextHolder.java","DataSetContextHolder.java","RecordContextHolder.java","DataModelContextHolder.java"};
|
||||
/**
|
||||
* 配置文件类型数组
|
||||
*/
|
||||
public final static String[] CONFIG_FILE_TYPE_ARRAY=new String[]{"测试模版","任务","数据集","资产记录","资产模型"};
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.ruoyi.ruleEngine.constant;
|
||||
|
||||
/**
|
||||
* 规则运行常量
|
||||
* @ClassName RuleOperationConstants
|
||||
* @Author 森静若林
|
||||
* @Date 2024/5/4 16:12
|
||||
*/
|
||||
public class RuleOperationConstants {
|
||||
/**
|
||||
* 运行类型
|
||||
*/
|
||||
public final static String CLASS_NAME="TestClass";
|
||||
/**
|
||||
* 文件后缀
|
||||
*/
|
||||
public final static String FILE_SUFFIX=".java";
|
||||
/**
|
||||
* 运行方法
|
||||
*/
|
||||
public final static String METHOD_NAME="ruleTest";
|
||||
}
|
|
@ -69,6 +69,10 @@ public class EngineMaintenance extends BaseEntity {
|
|||
@ApiModelProperty(name = "状态", value = "状态")
|
||||
private String status;
|
||||
|
||||
/** 描述 */
|
||||
@Excel(name = "描述")
|
||||
@ApiModelProperty(name = "描述", value = "描述")
|
||||
private String description;
|
||||
/**
|
||||
* 查询构造器
|
||||
*/
|
||||
|
@ -94,6 +98,8 @@ public class EngineMaintenance extends BaseEntity {
|
|||
.engineCode(engineMaintenanceSaveReq.getEngineCode())
|
||||
.isActivate(engineMaintenanceSaveReq.getIsActivate())
|
||||
.status(engineMaintenanceSaveReq.getStatus())
|
||||
.description(engineMaintenanceSaveReq.getDescription())
|
||||
.remark(engineMaintenanceSaveReq.getRemark())
|
||||
.createBy(createBy.get())
|
||||
.createTime(new Date())
|
||||
.build();
|
||||
|
@ -111,6 +117,8 @@ public class EngineMaintenance extends BaseEntity {
|
|||
.engineCode(engineMaintenanceEditReq.getEngineCode())
|
||||
.isActivate(engineMaintenanceEditReq.getIsActivate())
|
||||
.status(engineMaintenanceEditReq.getStatus())
|
||||
.remark(engineMaintenanceEditReq.getRemark())
|
||||
.description(engineMaintenanceEditReq.getDescription())
|
||||
.updateBy(updateBy.get())
|
||||
.updateTime(new Date())
|
||||
.build();
|
||||
|
|
|
@ -46,4 +46,7 @@ public class EngineMaintenanceEditReq extends BaseEntity {
|
|||
@ApiModelProperty(name = "状态", value = "状态")
|
||||
private String status;
|
||||
|
||||
/** 描述 */
|
||||
@ApiModelProperty(name = "描述", value = "描述")
|
||||
private String description;
|
||||
}
|
||||
|
|
|
@ -57,4 +57,9 @@ public class EngineMaintenanceSaveReq extends BaseEntity {
|
|||
@ApiModelProperty(name = "状态", value = "状态")
|
||||
private String status;
|
||||
|
||||
/** 描述 */
|
||||
|
||||
@ApiModelProperty(name = "描述", value = "描述")
|
||||
private String description;
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.List;
|
|||
* @Author 森静若林
|
||||
*/
|
||||
public class TestClass {
|
||||
public String ruleTest(List<String> list) {
|
||||
public static String ruleTest(List<String> list) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.ObjUtils;
|
||||
import com.ruoyi.ruleEngine.constant.ConfigCodeConstants;
|
||||
import com.ruoyi.ruleEngine.constant.RuleOperationConstants;
|
||||
import com.ruoyi.ruleEngine.domain.EngineConfig;
|
||||
import com.ruoyi.ruleEngine.domain.model.TestData;
|
||||
import com.ruoyi.ruleEngine.domain.resp.EngineConfigScopeResp;
|
||||
|
@ -13,7 +15,6 @@ import com.ruoyi.ruleEngine.service.EngineConfigService;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
@ -39,21 +40,16 @@ public class EngineConfigServiceImpl extends ServiceImpl<EngineConfigMapper, Eng
|
|||
@Override
|
||||
public List<EngineConfigScopeResp> getScopeList() {
|
||||
List<EngineConfigScopeResp> list=new ArrayList<>();
|
||||
List<String> scopeName=List.of("TaskContextHolder","DataSetContextHolder","RecordContextHolder","DataModelContextHolder");
|
||||
try {
|
||||
for (String scope : scopeName) {
|
||||
String path="D:/workspace/gtl-ruoyi-server/ruoyi-modules/ruoyi-rule_engine/ruoyi-rule_engine-server/src/main/java/com/ruoyi/ruleEngine/scope/"+scope+".java";
|
||||
String code = Files.readString(Paths.get(path));
|
||||
String type=null;
|
||||
if(scope.contains("Task")){
|
||||
type="任务";
|
||||
}else if(scope.contains("DataSet")){
|
||||
type="数据集";
|
||||
}else if(scope.contains("Record")){
|
||||
type="资产记录";
|
||||
}else{
|
||||
type="资产模型";
|
||||
int index=0;
|
||||
for (String scope : ConfigCodeConstants.CONFIG_FILE_NAME_ARRAY) {
|
||||
if(index==0){
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
String path=ConfigCodeConstants.BASE_FILE_PATH+scope;
|
||||
String code = Files.readString(Paths.get(path));
|
||||
String type=ConfigCodeConstants.CONFIG_FILE_TYPE_ARRAY[index++];
|
||||
list.add(EngineConfigScopeResp.builder().type(type).name(scope).code(code).build());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -99,25 +95,9 @@ public class EngineConfigServiceImpl extends ServiceImpl<EngineConfigMapper, Eng
|
|||
*/
|
||||
@Override
|
||||
public EngineConfigScopeResp getScopeInfoById(Integer id) {
|
||||
String scope=null;
|
||||
String type=null;
|
||||
if(id==0){
|
||||
type="测试模版";
|
||||
scope="TestClass.txt";
|
||||
}else if(id==1){
|
||||
type="任务";
|
||||
scope="TaskContextHolder.java";
|
||||
}else if(id==2){
|
||||
type="数据集";
|
||||
scope="DataSetContextHolder.java";
|
||||
}else if(id==3){
|
||||
type="资产记录";
|
||||
scope="RecordContextHolder.java";
|
||||
}else{
|
||||
type="资产模型";
|
||||
scope="DataModelContextHolder.java";
|
||||
}
|
||||
String path="D:/workspace/gtl-ruoyi-server/ruoyi-modules/ruoyi-rule_engine/ruoyi-rule_engine-server/src/main/java/com/ruoyi/ruleEngine/scope/"+scope;
|
||||
String scope=ConfigCodeConstants.CONFIG_FILE_NAME_ARRAY[id];
|
||||
String type=ConfigCodeConstants.CONFIG_FILE_TYPE_ARRAY[id];
|
||||
String path=ConfigCodeConstants.BASE_FILE_PATH+scope;
|
||||
String code = null;
|
||||
try {
|
||||
code = Files.readString(Paths.get(path));
|
||||
|
@ -135,23 +115,21 @@ public class EngineConfigServiceImpl extends ServiceImpl<EngineConfigMapper, Eng
|
|||
public Object ruleTest(TestData testData) {
|
||||
Object invoke=null;
|
||||
try {
|
||||
String className="TestClass";
|
||||
final String SUFFIX = ".java";// 类名后面要跟的后缀
|
||||
EngineConfig config = this.getById(testData.getId());
|
||||
String content = config.getRuleContent().replaceAll("\r\n", "");
|
||||
// 对source进行编译生成class文件存放在Map中,这里用bytecode接收
|
||||
Map<String, byte[]> bytecode = DynamicLoader.compile(className + SUFFIX,content );
|
||||
Map<String, byte[]> bytecode = DynamicLoader.compile(RuleOperationConstants.CLASS_NAME + RuleOperationConstants.FILE_SUFFIX,content );
|
||||
|
||||
// 加载class文件到虚拟机中,然后通过反射执行
|
||||
@SuppressWarnings("resource")
|
||||
DynamicLoader.MemoryClassLoader classLoader = new DynamicLoader.MemoryClassLoader(
|
||||
bytecode);
|
||||
Class<?> clazz = classLoader.loadClass(className);
|
||||
Class<?> clazz = classLoader.loadClass(RuleOperationConstants.CLASS_NAME);
|
||||
|
||||
// 调用ruleTest方法
|
||||
Method mainMethod = clazz.getDeclaredMethod("ruleTest", List.class);
|
||||
Method mainMethod = clazz.getDeclaredMethod(RuleOperationConstants.METHOD_NAME, List.class);
|
||||
invoke = mainMethod.invoke(null, testData.getList());
|
||||
} catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("测试失败");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue