fix:修复引擎维护新增和修改时缺少描述语句的问题

dev
gtl 2024-05-04 17:49:54 +08:00
parent 4e9ba19c33
commit 5af8c4155a
7 changed files with 78 additions and 40 deletions

View File

@ -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[]{"测试模版","任务","数据集","资产记录","资产模型"};
}

View File

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

View File

@ -69,6 +69,10 @@ public class EngineMaintenance extends BaseEntity {
@ApiModelProperty(name = "状态", value = "状态") @ApiModelProperty(name = "状态", value = "状态")
private String status; private String status;
/** 描述 */
@Excel(name = "描述")
@ApiModelProperty(name = "描述", value = "描述")
private String description;
/** /**
* *
*/ */
@ -94,6 +98,8 @@ public class EngineMaintenance extends BaseEntity {
.engineCode(engineMaintenanceSaveReq.getEngineCode()) .engineCode(engineMaintenanceSaveReq.getEngineCode())
.isActivate(engineMaintenanceSaveReq.getIsActivate()) .isActivate(engineMaintenanceSaveReq.getIsActivate())
.status(engineMaintenanceSaveReq.getStatus()) .status(engineMaintenanceSaveReq.getStatus())
.description(engineMaintenanceSaveReq.getDescription())
.remark(engineMaintenanceSaveReq.getRemark())
.createBy(createBy.get()) .createBy(createBy.get())
.createTime(new Date()) .createTime(new Date())
.build(); .build();
@ -111,6 +117,8 @@ public class EngineMaintenance extends BaseEntity {
.engineCode(engineMaintenanceEditReq.getEngineCode()) .engineCode(engineMaintenanceEditReq.getEngineCode())
.isActivate(engineMaintenanceEditReq.getIsActivate()) .isActivate(engineMaintenanceEditReq.getIsActivate())
.status(engineMaintenanceEditReq.getStatus()) .status(engineMaintenanceEditReq.getStatus())
.remark(engineMaintenanceEditReq.getRemark())
.description(engineMaintenanceEditReq.getDescription())
.updateBy(updateBy.get()) .updateBy(updateBy.get())
.updateTime(new Date()) .updateTime(new Date())
.build(); .build();

View File

@ -46,4 +46,7 @@ public class EngineMaintenanceEditReq extends BaseEntity {
@ApiModelProperty(name = "状态", value = "状态") @ApiModelProperty(name = "状态", value = "状态")
private String status; private String status;
/** 描述 */
@ApiModelProperty(name = "描述", value = "描述")
private String description;
} }

View File

@ -57,4 +57,9 @@ public class EngineMaintenanceSaveReq extends BaseEntity {
@ApiModelProperty(name = "状态", value = "状态") @ApiModelProperty(name = "状态", value = "状态")
private String status; private String status;
/** 描述 */
@ApiModelProperty(name = "描述", value = "描述")
private String description;
} }

View File

@ -4,7 +4,7 @@ import java.util.List;
* @Author 森静若林 * @Author 森静若林
*/ */
public class TestClass { public class TestClass {
public String ruleTest(List<String> list) { public static String ruleTest(List<String> list) {
} }
} }

View File

@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.ObjUtils; 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.EngineConfig;
import com.ruoyi.ruleEngine.domain.model.TestData; import com.ruoyi.ruleEngine.domain.model.TestData;
import com.ruoyi.ruleEngine.domain.resp.EngineConfigScopeResp; import com.ruoyi.ruleEngine.domain.resp.EngineConfigScopeResp;
@ -13,7 +15,6 @@ import com.ruoyi.ruleEngine.service.EngineConfigService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -39,21 +40,16 @@ public class EngineConfigServiceImpl extends ServiceImpl<EngineConfigMapper, Eng
@Override @Override
public List<EngineConfigScopeResp> getScopeList() { public List<EngineConfigScopeResp> getScopeList() {
List<EngineConfigScopeResp> list=new ArrayList<>(); List<EngineConfigScopeResp> list=new ArrayList<>();
List<String> scopeName=List.of("TaskContextHolder","DataSetContextHolder","RecordContextHolder","DataModelContextHolder");
try { try {
for (String scope : scopeName) { int index=0;
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"; for (String scope : ConfigCodeConstants.CONFIG_FILE_NAME_ARRAY) {
String code = Files.readString(Paths.get(path)); if(index==0){
String type=null; index++;
if(scope.contains("Task")){ continue;
type="任务";
}else if(scope.contains("DataSet")){
type="数据集";
}else if(scope.contains("Record")){
type="资产记录";
}else{
type="资产模型";
} }
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()); list.add(EngineConfigScopeResp.builder().type(type).name(scope).code(code).build());
} }
} catch (IOException e) { } catch (IOException e) {
@ -99,25 +95,9 @@ public class EngineConfigServiceImpl extends ServiceImpl<EngineConfigMapper, Eng
*/ */
@Override @Override
public EngineConfigScopeResp getScopeInfoById(Integer id) { public EngineConfigScopeResp getScopeInfoById(Integer id) {
String scope=null; String scope=ConfigCodeConstants.CONFIG_FILE_NAME_ARRAY[id];
String type=null; String type=ConfigCodeConstants.CONFIG_FILE_TYPE_ARRAY[id];
if(id==0){ String path=ConfigCodeConstants.BASE_FILE_PATH+scope;
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 code = null; String code = null;
try { try {
code = Files.readString(Paths.get(path)); code = Files.readString(Paths.get(path));
@ -135,23 +115,21 @@ public class EngineConfigServiceImpl extends ServiceImpl<EngineConfigMapper, Eng
public Object ruleTest(TestData testData) { public Object ruleTest(TestData testData) {
Object invoke=null; Object invoke=null;
try { try {
String className="TestClass";
final String SUFFIX = ".java";// 类名后面要跟的后缀
EngineConfig config = this.getById(testData.getId()); EngineConfig config = this.getById(testData.getId());
String content = config.getRuleContent().replaceAll("\r\n", ""); String content = config.getRuleContent().replaceAll("\r\n", "");
// 对source进行编译生成class文件存放在Map中这里用bytecode接收 // 对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文件到虚拟机中然后通过反射执行 // 加载class文件到虚拟机中然后通过反射执行
@SuppressWarnings("resource") @SuppressWarnings("resource")
DynamicLoader.MemoryClassLoader classLoader = new DynamicLoader.MemoryClassLoader( DynamicLoader.MemoryClassLoader classLoader = new DynamicLoader.MemoryClassLoader(
bytecode); bytecode);
Class<?> clazz = classLoader.loadClass(className); Class<?> clazz = classLoader.loadClass(RuleOperationConstants.CLASS_NAME);
// 调用ruleTest方法 // 调用ruleTest方法
Method mainMethod = clazz.getDeclaredMethod("ruleTest", List.class); Method mainMethod = clazz.getDeclaredMethod(RuleOperationConstants.METHOD_NAME, List.class);
invoke = mainMethod.invoke(null, testData.getList()); invoke = mainMethod.invoke(null, testData.getList());
} catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new ServiceException("测试失败"); throw new ServiceException("测试失败");
} }