feat:新增生成引擎版本类并返回规则模版接口
parent
6a2fb20342
commit
b36bfd17e8
|
@ -14,7 +14,7 @@ public class ConfigCodeConstants {
|
|||
/**
|
||||
* 配置文件名数组
|
||||
*/
|
||||
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_NAME_ARRAY=new String[]{"engine_custom.txt","TaskContextHolder.java","DataSetContextHolder.java","RecordContextHolder.java","DataModelContextHolder.java"};
|
||||
/**
|
||||
* 配置文件类型数组
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package com.ruoyi.ruleEngine.constant;
|
||||
|
||||
/**
|
||||
* 引擎版本常量
|
||||
* @ClassName EngineVersionConstants
|
||||
* @Author 森静若林
|
||||
* @Date 2024/5/7 15:38
|
||||
*/
|
||||
public class EngineVersionConstants {
|
||||
/**
|
||||
* 版本类前缀
|
||||
*/
|
||||
public final static String VERSION_CLASS_SUFFIX=EngineVersionConstants.DEFAULT_VERSION_CLASS+EngineVersionConstants.VERSION_SEPARATOR;
|
||||
|
||||
/**
|
||||
* 版本类前缀
|
||||
*/
|
||||
public final static String VERSION_SEPARATOR="_";
|
||||
|
||||
/**
|
||||
* 默认版本名
|
||||
*/
|
||||
public final static String DEFAULT_VERSION_CLASS="engine_custom";
|
||||
|
||||
/**
|
||||
* 默认版本号
|
||||
*/
|
||||
public final static String VERSION_CODE="version_code";
|
||||
|
||||
/**
|
||||
* 默认作用域引擎
|
||||
*/
|
||||
public final static String DEFAULT_SCOPE_ENGINE="scope_engine";
|
||||
|
||||
/**
|
||||
* 作用域引擎数组
|
||||
*/
|
||||
public final static String[] SCOPE_ENGINE=new String[]{"TaskEngine","DataSetEngine","RecordEngine","DataModelEngine"};
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author 森静若林
|
||||
*/
|
||||
public class TestClass {
|
||||
public static String ruleTest(List<String> list) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
import com.ruoyi.ruleEngine.engine.scope.scope_engine;
|
||||
|
||||
/**
|
||||
* 自定义引擎
|
||||
* @ClassName engine_custom
|
||||
* @Author: 森静若林
|
||||
* @Version: version_code
|
||||
*/
|
||||
public class engine_custom extends scope_engine{
|
||||
@Override
|
||||
public void execution () {
|
||||
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ import java.util.function.Supplier;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 引擎规则配置对象 engine_config
|
||||
* 引擎规则版本对象 engine_version
|
||||
*
|
||||
* @author gtl
|
||||
* @date 2024-05-02
|
||||
|
@ -27,10 +27,10 @@ import java.util.Date;
|
|||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("engine_config")
|
||||
@TableName("engine_version")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "EngineConfig", description = "引擎规则配置")
|
||||
public class EngineConfig extends BaseEntity {
|
||||
@ApiModel(value = "EngineVersion", description = "引擎规则版本")
|
||||
public class EngineVersion extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
@ -39,6 +39,16 @@ public class EngineConfig extends BaseEntity {
|
|||
@ApiModelProperty(name = "编号", value = "编号")
|
||||
private Long id;
|
||||
|
||||
/** 版本类名 */
|
||||
@Excel(name = "版本类名")
|
||||
@ApiModelProperty(name = "版本类名", value = "版本类名", required = true)
|
||||
private String versionClass;
|
||||
|
||||
/** 版本名 */
|
||||
@Excel(name = "版本名")
|
||||
@ApiModelProperty(name = "版本名", value = "版本名", required = true)
|
||||
private String name;
|
||||
|
||||
/** 版本编码 */
|
||||
@Excel(name = "版本编码")
|
||||
@ApiModelProperty(name = "版本编码", value = "版本编码", required = true)
|
||||
|
@ -49,6 +59,21 @@ public class EngineConfig extends BaseEntity {
|
|||
@ApiModelProperty(name = "规则内容", value = "规则内容", required = true)
|
||||
private String ruleContent;
|
||||
|
||||
/** 是否激活 */
|
||||
@Excel(name = "是否激活")
|
||||
@ApiModelProperty(name = "是否激活", value = "是否激活", required = true)
|
||||
private String isActivate;
|
||||
|
||||
/** 测试状态 */
|
||||
@Excel(name = "测试状态")
|
||||
@ApiModelProperty(name = "测试状态", value = "测试状态", required = true)
|
||||
private String testStatus;
|
||||
|
||||
/** 状态 */
|
||||
@Excel(name = "状态")
|
||||
@ApiModelProperty(name = "状态", value = "状态", required = true)
|
||||
private String status;
|
||||
|
||||
/** 引擎维护编号 */
|
||||
@Excel(name = "引擎维护编号")
|
||||
@ApiModelProperty(name = "引擎维护编号", value = "引擎维护编号", required = true)
|
||||
|
@ -57,10 +82,14 @@ public class EngineConfig extends BaseEntity {
|
|||
/**
|
||||
* 查询构造器
|
||||
*/
|
||||
public static EngineConfig queryBuild( EngineConfigQueryReq engineConfigQueryReq){
|
||||
return EngineConfig.builder()
|
||||
public static EngineVersion queryBuild(EngineConfigQueryReq engineConfigQueryReq){
|
||||
return EngineVersion.builder()
|
||||
.versionClass(engineConfigQueryReq.getVersionClass())
|
||||
.name(engineConfigQueryReq.getName())
|
||||
.versionCode(engineConfigQueryReq.getVersionCode())
|
||||
.ruleContent(engineConfigQueryReq.getRuleContent())
|
||||
.testStatus(engineConfigQueryReq.getTestStatus())
|
||||
.status(engineConfigQueryReq.getStatus())
|
||||
.engineMaintenanceId(engineConfigQueryReq.getEngineMaintenanceId())
|
||||
.build();
|
||||
}
|
||||
|
@ -68,10 +97,14 @@ public class EngineConfig extends BaseEntity {
|
|||
/**
|
||||
* 添加构造器
|
||||
*/
|
||||
public static EngineConfig saveBuild(EngineConfigSaveReq engineConfigSaveReq,Supplier<String> createBy){
|
||||
return EngineConfig.builder()
|
||||
public static EngineVersion saveBuild(EngineConfigSaveReq engineConfigSaveReq, Supplier<String> createBy){
|
||||
return EngineVersion.builder()
|
||||
.versionClass(engineConfigSaveReq.getVersionClass())
|
||||
.name(engineConfigSaveReq.getName())
|
||||
.versionCode(engineConfigSaveReq.getVersionCode())
|
||||
.ruleContent(engineConfigSaveReq.getRuleContent())
|
||||
.testStatus(engineConfigSaveReq.getTestStatus())
|
||||
.status(engineConfigSaveReq.getStatus())
|
||||
.engineMaintenanceId(engineConfigSaveReq.getEngineMaintenanceId())
|
||||
.remark(engineConfigSaveReq.getRemark())
|
||||
.createBy(createBy.get())
|
||||
|
@ -82,11 +115,15 @@ public class EngineConfig extends BaseEntity {
|
|||
/**
|
||||
* 修改构造器
|
||||
*/
|
||||
public static EngineConfig editBuild(Long id, EngineConfigEditReq engineConfigEditReq, Supplier<String> updateBy){
|
||||
return EngineConfig.builder()
|
||||
public static EngineVersion editBuild(Long id, EngineConfigEditReq engineConfigEditReq, Supplier<String> updateBy){
|
||||
return EngineVersion.builder()
|
||||
.id(id)
|
||||
.versionClass(engineConfigEditReq.getVersionClass())
|
||||
.name(engineConfigEditReq.getName())
|
||||
.versionCode(engineConfigEditReq.getVersionCode())
|
||||
.ruleContent(engineConfigEditReq.getRuleContent())
|
||||
.testStatus(engineConfigEditReq.getTestStatus())
|
||||
.status(engineConfigEditReq.getStatus())
|
||||
.engineMaintenanceId(engineConfigEditReq.getEngineMaintenanceId())
|
||||
.remark(engineConfigEditReq.getRemark())
|
||||
.updateBy(updateBy.get())
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.ruleEngine.domain.req;
|
||||
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -23,6 +24,16 @@ public class EngineConfigEditReq extends BaseEntity {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 版本类名 */
|
||||
@Excel(name = "版本类名")
|
||||
@ApiModelProperty(name = "版本类名", value = "版本类名", required = true)
|
||||
private String versionClass;
|
||||
|
||||
/** 版本名 */
|
||||
@Excel(name = "版本名")
|
||||
@ApiModelProperty(name = "版本名", value = "版本名", required = true)
|
||||
private String name;
|
||||
|
||||
/** 版本编码 */
|
||||
@ApiModelProperty(name = "版本编码", value = "版本编码", required = true)
|
||||
private String versionCode;
|
||||
|
@ -31,6 +42,21 @@ public class EngineConfigEditReq extends BaseEntity {
|
|||
@ApiModelProperty(name = "规则内容", value = "规则内容", required = true)
|
||||
private String ruleContent;
|
||||
|
||||
/** 是否激活 */
|
||||
@Excel(name = "是否激活")
|
||||
@ApiModelProperty(name = "是否激活", value = "是否激活", required = true)
|
||||
private String isActivate;
|
||||
|
||||
/** 测试状态 */
|
||||
@Excel(name = "测试状态")
|
||||
@ApiModelProperty(name = "测试状态", value = "测试状态", required = true)
|
||||
private String testStatus;
|
||||
|
||||
/** 状态 */
|
||||
@Excel(name = "状态")
|
||||
@ApiModelProperty(name = "状态", value = "状态", required = true)
|
||||
private String status;
|
||||
|
||||
/** 引擎维护编号 */
|
||||
@ApiModelProperty(name = "引擎维护编号", value = "引擎维护编号", required = true)
|
||||
private Long engineMaintenanceId;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.ruleEngine.domain.req;
|
||||
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -23,6 +24,16 @@ public class EngineConfigQueryReq extends BaseEntity {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 版本类名 */
|
||||
@Excel(name = "版本类名")
|
||||
@ApiModelProperty(name = "版本类名", value = "版本类名", required = true)
|
||||
private String versionClass;
|
||||
|
||||
/** 版本名 */
|
||||
@Excel(name = "版本名")
|
||||
@ApiModelProperty(name = "版本名", value = "版本名", required = true)
|
||||
private String name;
|
||||
|
||||
/** 版本编码 */
|
||||
@ApiModelProperty(name = "版本编码", value = "版本编码")
|
||||
private String versionCode;
|
||||
|
@ -31,6 +42,21 @@ public class EngineConfigQueryReq extends BaseEntity {
|
|||
@ApiModelProperty(name = "规则内容", value = "规则内容")
|
||||
private String ruleContent;
|
||||
|
||||
/** 是否激活 */
|
||||
@Excel(name = "是否激活")
|
||||
@ApiModelProperty(name = "是否激活", value = "是否激活", required = true)
|
||||
private String isActivate;
|
||||
|
||||
/** 测试状态 */
|
||||
@Excel(name = "测试状态")
|
||||
@ApiModelProperty(name = "测试状态", value = "测试状态", required = true)
|
||||
private String testStatus;
|
||||
|
||||
/** 状态 */
|
||||
@Excel(name = "状态")
|
||||
@ApiModelProperty(name = "状态", value = "状态", required = true)
|
||||
private String status;
|
||||
|
||||
/** 引擎维护编号 */
|
||||
@ApiModelProperty(name = "引擎维护编号", value = "引擎维护编号")
|
||||
private Long engineMaintenanceId;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.ruleEngine.domain.req;
|
||||
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -28,6 +29,16 @@ public class EngineConfigSaveReq extends BaseEntity {
|
|||
@ApiModelProperty(name = "编号", value = "编号")
|
||||
private Long id;
|
||||
|
||||
/** 版本类名 */
|
||||
@Excel(name = "版本类名")
|
||||
@ApiModelProperty(name = "版本类名", value = "版本类名", required = true)
|
||||
private String versionClass;
|
||||
|
||||
/** 版本名 */
|
||||
@Excel(name = "版本名")
|
||||
@ApiModelProperty(name = "版本名", value = "版本名", required = true)
|
||||
private String name;
|
||||
|
||||
/** 版本编码 */
|
||||
|
||||
@ApiModelProperty(name = "版本编码", value = "版本编码", required = true)
|
||||
|
@ -38,6 +49,21 @@ public class EngineConfigSaveReq extends BaseEntity {
|
|||
@ApiModelProperty(name = "规则内容", value = "规则内容", required = true)
|
||||
private String ruleContent;
|
||||
|
||||
/** 是否激活 */
|
||||
@Excel(name = "是否激活")
|
||||
@ApiModelProperty(name = "是否激活", value = "是否激活", required = true)
|
||||
private String isActivate;
|
||||
|
||||
/** 测试状态 */
|
||||
@Excel(name = "测试状态")
|
||||
@ApiModelProperty(name = "测试状态", value = "测试状态", required = true)
|
||||
private String testStatus;
|
||||
|
||||
/** 状态 */
|
||||
@Excel(name = "状态")
|
||||
@ApiModelProperty(name = "状态", value = "状态", required = true)
|
||||
private String status;
|
||||
|
||||
/** 引擎维护编号 */
|
||||
|
||||
@ApiModelProperty(name = "引擎维护编号", value = "引擎维护编号", required = true)
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package com.ruoyi.ruleEngine.domain.req;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 版本类创建
|
||||
* @ClassName VersionClassCreateReq
|
||||
* @Author 森静若林
|
||||
* @Date 2024/5/7 15:56
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ApiModel(value = "VersionClassCreateReq", description = "版本类创建")
|
||||
public class VersionClassCreateReq implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 引擎编码 */
|
||||
@ApiModelProperty(name = "引擎编码", value = "引擎编码", required = true)
|
||||
private String engineCode;
|
||||
|
||||
/** 作用域编号 */
|
||||
@ApiModelProperty(name = "作用域编号", value = "作用域编号", required = true)
|
||||
private Integer scope;
|
||||
|
||||
/** 版本编码 */
|
||||
@ApiModelProperty(name = "版本编码", value = "版本编码", required = true)
|
||||
private String versionCode;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.ruoyi.ruleEngine.domain.resp;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 版本类创建
|
||||
* @ClassName VersionClassCreateResp
|
||||
* @Author 森静若林
|
||||
* @Date 2024/5/7 15:56
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VersionClassCreateResp implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 版本类名 */
|
||||
private String versionClass;
|
||||
|
||||
/** 规则内容 */
|
||||
private String ruleContent;
|
||||
}
|
|
@ -2,19 +2,10 @@ package com.ruoyi.ruleEngine.controller;
|
|||
|
||||
import com.ruoyi.common.core.domain.Result;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.ruleEngine.domain.EngineConfig;
|
||||
import com.ruoyi.ruleEngine.domain.model.TestData;
|
||||
import com.ruoyi.ruleEngine.domain.req.EngineConfigEditReq;
|
||||
import com.ruoyi.ruleEngine.domain.req.EngineConfigQueryReq;
|
||||
import com.ruoyi.ruleEngine.domain.req.EngineConfigSaveReq;
|
||||
import com.ruoyi.ruleEngine.domain.resp.EngineConfigScopeResp;
|
||||
import com.ruoyi.ruleEngine.service.EngineConfigService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -54,58 +45,4 @@ public class EngineConfigController extends BaseController {
|
|||
return Result.success(engineConfigService.getScopeInfoById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询引擎规则配置列表
|
||||
*/
|
||||
@ApiOperation("获取引擎规则配置列表")
|
||||
@RequiresPermissions("ruleEngine:config:list")
|
||||
@GetMapping("/list")
|
||||
public Result<List<EngineConfig>> list(EngineConfigQueryReq engineConfigQueryReq) {
|
||||
return Result.success(engineConfigService.list(EngineConfig.queryBuild(engineConfigQueryReq)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试引擎规则配置
|
||||
*/
|
||||
@ApiOperation("测试引擎规则配置")
|
||||
@RequiresPermissions("ruleEngine:config:add")
|
||||
@PostMapping(value = "/test")
|
||||
public Result<Object> ruleTest(@RequestBody TestData testData) {
|
||||
return Result.success(engineConfigService.ruleTest(testData));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增引擎规则配置
|
||||
*/
|
||||
@RequiresPermissions("ruleEngine:config:add")
|
||||
@Log(title = "引擎规则配置", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增引擎规则配置")
|
||||
public Result<String> add(@RequestBody EngineConfigSaveReq engineConfigSaveReq) {
|
||||
return toAjax(engineConfigService.save(EngineConfig.saveBuild(engineConfigSaveReq, SecurityUtils::getUsername)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改引擎规则配置
|
||||
*/
|
||||
@RequiresPermissions("ruleEngine:config:edit")
|
||||
@Log(title = "引擎规则配置", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/{id}")
|
||||
@ApiOperation("修改引擎规则配置")
|
||||
public Result<String> edit(@PathVariable Long id, @RequestBody EngineConfigEditReq engineConfigEditReq) {
|
||||
return toAjax(engineConfigService.updateById(EngineConfig.editBuild(id,engineConfigEditReq, SecurityUtils::getUsername)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除引擎规则配置
|
||||
*/
|
||||
@RequiresPermissions("ruleEngine:config:remove")
|
||||
@Log(title = "引擎规则配置", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除引擎规则配置")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
|
||||
public Result<String> remove(@PathVariable List<Long> ids) {
|
||||
return toAjax(engineConfigService.removeBatchByIds(ids));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ public class EngineMaintenanceController extends BaseController {
|
|||
@PostMapping
|
||||
@ApiOperation("新增引擎维护")
|
||||
public Result<String> add(@RequestBody EngineMaintenanceSaveReq engineMaintenanceSaveReq) {
|
||||
return toAjax(engineMaintenanceService.saveEngineMaintenance(EngineMaintenance.saveBuild(engineMaintenanceSaveReq, SecurityUtils::getUsername)));
|
||||
return toAjax(engineMaintenanceService.save(EngineMaintenance.saveBuild(engineMaintenanceSaveReq, SecurityUtils::getUsername)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,6 +98,30 @@ public class EngineMaintenanceController extends BaseController {
|
|||
return toAjax(engineMaintenanceService.updateById(EngineMaintenance.editBuild(id,engineMaintenanceEditReq, SecurityUtils::getUsername)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过引擎维护编号激活引擎
|
||||
*/
|
||||
@RequiresPermissions("rule_engine:maintenance:edit")
|
||||
@Log(title = "引擎维护", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/activate/{id}")
|
||||
@ApiOperation("通过引擎维护编号激活引擎")
|
||||
public Result<String> activate(@PathVariable Long id) {
|
||||
engineMaintenanceService.activate(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过引擎维护编号关闭引擎
|
||||
*/
|
||||
@RequiresPermissions("rule_engine:maintenance:edit")
|
||||
@Log(title = "引擎维护", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/close/{id}")
|
||||
@ApiOperation("通过引擎维护编号激活引擎")
|
||||
public Result<String> close(@PathVariable Long id) {
|
||||
engineMaintenanceService.close(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除引擎维护
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
package com.ruoyi.ruleEngine.controller;
|
||||
|
||||
import com.ruoyi.common.core.domain.Result;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.ruleEngine.domain.EngineVersion;
|
||||
import com.ruoyi.ruleEngine.domain.model.TestData;
|
||||
import com.ruoyi.ruleEngine.domain.req.EngineConfigEditReq;
|
||||
import com.ruoyi.ruleEngine.domain.req.EngineConfigQueryReq;
|
||||
import com.ruoyi.ruleEngine.domain.req.EngineConfigSaveReq;
|
||||
import com.ruoyi.ruleEngine.domain.req.VersionClassCreateReq;
|
||||
import com.ruoyi.ruleEngine.domain.resp.VersionClassCreateResp;
|
||||
import com.ruoyi.ruleEngine.service.EngineVersionService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 引擎版本Controller
|
||||
*
|
||||
* @author gtl
|
||||
* @date 2024-05-02
|
||||
*/
|
||||
@Api(tags = "引擎版本")
|
||||
@RestController
|
||||
@RequestMapping("/version")
|
||||
public class EngineVersionController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private EngineVersionService engineVersionService;
|
||||
|
||||
/**
|
||||
* 查询引擎规则版本列表
|
||||
*/
|
||||
@ApiOperation("查询引擎规则版本列表")
|
||||
@RequiresPermissions("ruleEngine:version:list")
|
||||
@GetMapping("/list")
|
||||
public Result<List<EngineVersion>> list(EngineConfigQueryReq engineConfigQueryReq) {
|
||||
return Result.success(engineVersionService.list(EngineVersion.queryBuild(engineConfigQueryReq)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成引擎版本类并返回规则模版
|
||||
*/
|
||||
@ApiOperation("生成引擎版本类并返回规则模版")
|
||||
@RequiresPermissions("ruleEngine:version:query")
|
||||
@PostMapping(value = "/createVersionClass")
|
||||
public Result<VersionClassCreateResp> createVersionClass(@RequestBody VersionClassCreateReq req) {
|
||||
return Result.success(engineVersionService.createVersionClass(req));
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试引擎规则版本
|
||||
*/
|
||||
@ApiOperation("测试引擎规则配置")
|
||||
@RequiresPermissions("ruleEngine:version:add")
|
||||
@PostMapping(value = "/test")
|
||||
public Result<Object> ruleTest(@RequestBody TestData testData) {
|
||||
return Result.success(engineVersionService.ruleTest(testData));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增引擎规则版本
|
||||
*/
|
||||
@RequiresPermissions("ruleEngine:version:add")
|
||||
@Log(title = "引擎规则配置", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增引擎规则配置")
|
||||
public Result<String> add(@RequestBody EngineConfigSaveReq engineConfigSaveReq) {
|
||||
return toAjax(engineVersionService.save(EngineVersion.saveBuild(engineConfigSaveReq, SecurityUtils::getUsername)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改引擎规则版本
|
||||
*/
|
||||
@RequiresPermissions("ruleEngine:version:edit")
|
||||
@Log(title = "引擎规则配置", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/{id}")
|
||||
@ApiOperation("修改引擎规则配置")
|
||||
public Result<String> edit(@PathVariable Long id, @RequestBody EngineConfigEditReq engineConfigEditReq) {
|
||||
return toAjax(engineVersionService.updateById(EngineVersion.editBuild(id,engineConfigEditReq, SecurityUtils::getUsername)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除引擎规则版本
|
||||
*/
|
||||
@RequiresPermissions("ruleEngine:version:remove")
|
||||
@Log(title = "引擎规则配置", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除引擎规则配置")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
|
||||
public Result<String> remove(@PathVariable List<Long> ids) {
|
||||
return toAjax(engineVersionService.removeBatchByIds(ids));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package com.ruoyi.ruleEngine.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.ruleEngine.domain.EngineConfig;
|
||||
|
||||
/**
|
||||
* 引擎规则配置Mapper接口
|
||||
*
|
||||
* @author gtl
|
||||
* @date 2024-05-02
|
||||
*/
|
||||
public interface EngineConfigMapper extends BaseMapper<EngineConfig> {
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.ruoyi.ruleEngine.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.ruleEngine.domain.EngineVersion;
|
||||
|
||||
/**
|
||||
* 引擎规则版本Mapper接口
|
||||
*
|
||||
* @author gtl
|
||||
* @date 2024-05-02
|
||||
*/
|
||||
public interface EngineVersionMapper extends BaseMapper<EngineVersion> {
|
||||
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
package com.ruoyi.ruleEngine.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.ruleEngine.domain.EngineConfig;
|
||||
import com.ruoyi.ruleEngine.domain.model.TestData;
|
||||
import com.ruoyi.ruleEngine.domain.resp.EngineConfigScopeResp;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -12,7 +9,7 @@ import java.util.List;
|
|||
* @author gtl
|
||||
* @date 2024-05-02
|
||||
*/
|
||||
public interface EngineConfigService extends IService<EngineConfig> {
|
||||
public interface EngineConfigService {
|
||||
/**
|
||||
* 查询引擎配置作用域列表
|
||||
*
|
||||
|
@ -20,14 +17,6 @@ public interface EngineConfigService extends IService<EngineConfig> {
|
|||
*/
|
||||
public List<EngineConfigScopeResp> getScopeList();
|
||||
|
||||
/**
|
||||
* 查询引擎规则配置列表
|
||||
*
|
||||
* @param engineConfig 引擎规则配置
|
||||
* @return 引擎规则配置集合
|
||||
*/
|
||||
public List<EngineConfig> list(EngineConfig engineConfig);
|
||||
|
||||
/**
|
||||
* 通过引擎作用域编号获取引擎配置作用域信息
|
||||
* @param id 引擎作用域编号
|
||||
|
@ -35,9 +24,4 @@ public interface EngineConfigService extends IService<EngineConfig> {
|
|||
*/
|
||||
EngineConfigScopeResp getScopeInfoById(Integer id);
|
||||
|
||||
/**
|
||||
* 规则测试
|
||||
* @param testData 规则配置版本编号
|
||||
*/
|
||||
Object ruleTest(TestData testData);
|
||||
}
|
||||
|
|
|
@ -19,17 +19,22 @@ public interface EngineMaintenanceService extends IService<EngineMaintenance> {
|
|||
*/
|
||||
public List<EngineMaintenance> list(EngineMaintenance engineMaintenance);
|
||||
|
||||
/**
|
||||
* 新增引擎维护
|
||||
* @param engineMaintenance 引擎维护对象
|
||||
* @return 是否
|
||||
*/
|
||||
boolean saveEngineMaintenance(EngineMaintenance engineMaintenance);
|
||||
|
||||
/**
|
||||
* 批量删除引擎维护
|
||||
* @param ids 引擎维护编号集合
|
||||
* @return 是否
|
||||
*/
|
||||
boolean removeBatchEngineMaintenanceByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 激活引擎
|
||||
* @param id 引擎维护编号
|
||||
*/
|
||||
void activate(Long id);
|
||||
|
||||
/**
|
||||
* 关闭引擎
|
||||
* @param id 引擎维护编号
|
||||
*/
|
||||
void close(Long id);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.ruoyi.ruleEngine.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.ruleEngine.domain.EngineVersion;
|
||||
import com.ruoyi.ruleEngine.domain.model.TestData;
|
||||
import com.ruoyi.ruleEngine.domain.req.VersionClassCreateReq;
|
||||
import com.ruoyi.ruleEngine.domain.resp.VersionClassCreateResp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 引擎版本Service接口
|
||||
*
|
||||
* @author gtl
|
||||
* @date 2024-05-02
|
||||
*/
|
||||
public interface EngineVersionService extends IService<EngineVersion> {
|
||||
|
||||
/**
|
||||
* 查询引擎规则配置列表
|
||||
*
|
||||
* @param engineConfig 引擎规则配置
|
||||
* @return 引擎规则配置集合
|
||||
*/
|
||||
public List<EngineVersion> list(EngineVersion engineConfig);
|
||||
|
||||
/**
|
||||
* 规则测试
|
||||
* @param testData 规则配置版本编号
|
||||
*/
|
||||
Object ruleTest(TestData testData);
|
||||
|
||||
/**
|
||||
* 生成引擎版本类并返回规则模版
|
||||
* @param req 版本创建请求参数类
|
||||
* @return 版本创建响应类
|
||||
*/
|
||||
VersionClassCreateResp createVersionClass(VersionClassCreateReq req);
|
||||
}
|
|
@ -1,26 +1,15 @@
|
|||
package com.ruoyi.ruleEngine.service.impl;
|
||||
|
||||
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;
|
||||
import com.ruoyi.ruleEngine.dynamicLoad.DynamicLoader;
|
||||
import com.ruoyi.ruleEngine.mapper.EngineConfigMapper;
|
||||
import com.ruoyi.ruleEngine.service.EngineConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 引擎配置Service业务层处理
|
||||
|
@ -30,7 +19,7 @@ import java.util.Map;
|
|||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EngineConfigServiceImpl extends ServiceImpl<EngineConfigMapper, EngineConfig> implements EngineConfigService {
|
||||
public class EngineConfigServiceImpl implements EngineConfigService {
|
||||
|
||||
/**
|
||||
* 查询引擎配置作用域列表
|
||||
|
@ -58,36 +47,6 @@ public class EngineConfigServiceImpl extends ServiceImpl<EngineConfigMapper, Eng
|
|||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询引擎规则配置列表
|
||||
*
|
||||
* @param engineConfig 引擎规则配置
|
||||
* @return 引擎规则配置
|
||||
*/
|
||||
@Override
|
||||
public List<EngineConfig> list(EngineConfig engineConfig) {
|
||||
LambdaQueryWrapper<EngineConfig> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
|
||||
if (ObjUtils.notNull(engineConfig.getVersionCode())){
|
||||
queryWrapper.eq(EngineConfig::getVersionCode, engineConfig.getVersionCode());
|
||||
}
|
||||
|
||||
if (ObjUtils.notNull(engineConfig.getRuleContent())){
|
||||
queryWrapper.eq(EngineConfig::getRuleContent, engineConfig.getRuleContent());
|
||||
}
|
||||
|
||||
if (ObjUtils.notNull(engineConfig.getEngineMaintenanceId())){
|
||||
queryWrapper.eq(EngineConfig::getEngineMaintenanceId, engineConfig.getEngineMaintenanceId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过引擎作用域编号获取引擎配置作用域信息
|
||||
* @param id 引擎作用域编号
|
||||
|
@ -107,33 +66,4 @@ public class EngineConfigServiceImpl extends ServiceImpl<EngineConfigMapper, Eng
|
|||
return EngineConfigScopeResp.builder().type(type).name(scope).code(code).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则测试
|
||||
* @param testData 规则配置版本编号
|
||||
*/
|
||||
@Override
|
||||
public Object ruleTest(TestData testData) {
|
||||
Object invoke=null;
|
||||
try {
|
||||
EngineConfig config = this.getById(testData.getId());
|
||||
String content = config.getRuleContent().replaceAll("\r\n", "");
|
||||
// 对source进行编译生成class文件存放在Map中,这里用bytecode接收
|
||||
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(RuleOperationConstants.CLASS_NAME);
|
||||
|
||||
// 调用ruleTest方法
|
||||
Method mainMethod = clazz.getDeclaredMethod(RuleOperationConstants.METHOD_NAME, List.class);
|
||||
invoke = mainMethod.invoke(null, testData.getList());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("测试失败");
|
||||
}
|
||||
return invoke;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.ruoyi.ruleEngine.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.ruoyi.common.core.utils.ObjUtils;
|
||||
import com.ruoyi.ruleEngine.domain.EngineConfig;
|
||||
import com.ruoyi.ruleEngine.domain.resp.EngineConfigScopeResp;
|
||||
import com.ruoyi.ruleEngine.service.EngineConfigService;
|
||||
import com.ruoyi.ruleEngine.domain.EngineVersion;
|
||||
import com.ruoyi.ruleEngine.service.EngineVersionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -26,7 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
public class EngineMaintenanceServiceImpl extends ServiceImpl<EngineMaintenanceMapper, EngineMaintenance> implements EngineMaintenanceService {
|
||||
|
||||
@Autowired
|
||||
private EngineConfigService engineConfigService;
|
||||
private EngineVersionService engineVersionService;
|
||||
|
||||
/**
|
||||
* 查询引擎维护列表
|
||||
|
@ -70,20 +70,6 @@ public class EngineMaintenanceServiceImpl extends ServiceImpl<EngineMaintenanceM
|
|||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增引擎维护
|
||||
* @param engineMaintenance 引擎维护对象
|
||||
* @return 是否
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean saveEngineMaintenance(EngineMaintenance engineMaintenance) {
|
||||
boolean save = this.save(engineMaintenance);
|
||||
EngineConfigScopeResp scopeInfo = engineConfigService.getScopeInfoById(0);
|
||||
engineConfigService.save(EngineConfig.builder().versionCode("1.0").ruleContent(scopeInfo.getCode()).engineMaintenanceId(engineMaintenance.getId()).build());
|
||||
return save;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除引擎维护
|
||||
* @param ids 引擎维护编号集合
|
||||
|
@ -93,13 +79,35 @@ public class EngineMaintenanceServiceImpl extends ServiceImpl<EngineMaintenanceM
|
|||
@Transactional
|
||||
public boolean removeBatchEngineMaintenanceByIds(List<Long> ids) {
|
||||
boolean removed = this.removeBatchByIds(ids);
|
||||
List<EngineConfig> engineConfigs = engineConfigService.list(new LambdaQueryWrapper<EngineConfig>()
|
||||
.in(EngineConfig::getEngineMaintenanceId, ids));
|
||||
List<EngineVersion> engineConfigs = engineVersionService.list(new LambdaQueryWrapper<EngineVersion>()
|
||||
.in(EngineVersion::getEngineMaintenanceId, ids));
|
||||
if(!engineConfigs.isEmpty()){
|
||||
engineConfigService.removeBatchByIds(engineConfigs.stream().map(EngineConfig::getId).toList());
|
||||
engineVersionService.removeBatchByIds(engineConfigs.stream().map(EngineVersion::getId).toList());
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活引擎
|
||||
* @param id 引擎维护编号
|
||||
*/
|
||||
@Override
|
||||
public void activate(Long id) {
|
||||
this.update(new LambdaUpdateWrapper<EngineMaintenance>()
|
||||
.eq(EngineMaintenance::getId,id)
|
||||
.set(EngineMaintenance::getIsActivate,"Y"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭引擎
|
||||
* @param id 引擎维护编号
|
||||
*/
|
||||
@Override
|
||||
public void close(Long id) {
|
||||
this.update(new LambdaUpdateWrapper<EngineMaintenance>()
|
||||
.eq(EngineMaintenance::getId,id)
|
||||
.set(EngineMaintenance::getIsActivate,"N"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
package com.ruoyi.ruleEngine.service.impl;
|
||||
|
||||
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.EngineVersionConstants;
|
||||
import com.ruoyi.ruleEngine.constant.RuleOperationConstants;
|
||||
import com.ruoyi.ruleEngine.domain.EngineVersion;
|
||||
import com.ruoyi.ruleEngine.domain.model.TestData;
|
||||
import com.ruoyi.ruleEngine.domain.req.VersionClassCreateReq;
|
||||
import com.ruoyi.ruleEngine.domain.resp.EngineConfigScopeResp;
|
||||
import com.ruoyi.ruleEngine.domain.resp.VersionClassCreateResp;
|
||||
import com.ruoyi.ruleEngine.dynamicLoad.DynamicLoader;
|
||||
import com.ruoyi.ruleEngine.mapper.EngineVersionMapper;
|
||||
import com.ruoyi.ruleEngine.service.EngineConfigService;
|
||||
import com.ruoyi.ruleEngine.service.EngineVersionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 引擎配置Service业务层处理
|
||||
*
|
||||
* @author gtl
|
||||
* @date 2024-05-02
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EngineVersionServiceImpl extends ServiceImpl<EngineVersionMapper, EngineVersion> implements EngineVersionService {
|
||||
|
||||
@Autowired
|
||||
private EngineConfigService engineConfigService;
|
||||
|
||||
/**
|
||||
* 查询引擎规则配置列表
|
||||
*
|
||||
* @param engineConfig 引擎规则配置
|
||||
* @return 引擎规则配置
|
||||
*/
|
||||
@Override
|
||||
public List<EngineVersion> list(EngineVersion engineConfig) {
|
||||
LambdaQueryWrapper<EngineVersion> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
|
||||
if (ObjUtils.notNull(engineConfig.getVersionCode())){
|
||||
queryWrapper.eq(EngineVersion::getVersionCode, engineConfig.getVersionCode());
|
||||
}
|
||||
|
||||
if (ObjUtils.notNull(engineConfig.getRuleContent())){
|
||||
queryWrapper.eq(EngineVersion::getRuleContent, engineConfig.getRuleContent());
|
||||
}
|
||||
|
||||
if (ObjUtils.notNull(engineConfig.getEngineMaintenanceId())){
|
||||
queryWrapper.eq(EngineVersion::getEngineMaintenanceId, engineConfig.getEngineMaintenanceId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则测试
|
||||
* @param testData 规则配置版本编号
|
||||
*/
|
||||
@Override
|
||||
public Object ruleTest(TestData testData) {
|
||||
Object invoke=null;
|
||||
try {
|
||||
EngineVersion config = this.getById(testData.getId());
|
||||
String content = config.getRuleContent().replaceAll("\r\n", "");
|
||||
// 对source进行编译生成class文件存放在Map中,这里用bytecode接收
|
||||
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(RuleOperationConstants.CLASS_NAME);
|
||||
|
||||
// 调用ruleTest方法
|
||||
Method mainMethod = clazz.getDeclaredMethod(RuleOperationConstants.METHOD_NAME, List.class);
|
||||
invoke = mainMethod.invoke(null, testData.getList());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("测试失败");
|
||||
}
|
||||
return invoke;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成引擎版本类并返回规则模版
|
||||
* @param req 版本创建请求参数类
|
||||
* @return 版本创建响应类
|
||||
*/
|
||||
@Override
|
||||
public VersionClassCreateResp createVersionClass(VersionClassCreateReq req) {
|
||||
String versionClass = EngineVersionConstants.VERSION_CLASS_SUFFIX + req.getEngineCode() + EngineVersionConstants.VERSION_SEPARATOR + req.getVersionCode();
|
||||
EngineConfigScopeResp scopeResp = engineConfigService.getScopeInfoById(0);
|
||||
String ruleContent = scopeResp.getCode().replaceAll(EngineVersionConstants.DEFAULT_SCOPE_ENGINE, EngineVersionConstants.SCOPE_ENGINE[req.getScope() - 1])
|
||||
.replaceAll(EngineVersionConstants.VERSION_CODE, req.getVersionCode())
|
||||
.replaceAll(EngineVersionConstants.DEFAULT_VERSION_CLASS, versionClass);
|
||||
return VersionClassCreateResp.builder()
|
||||
.versionClass(versionClass)
|
||||
.ruleContent(ruleContent)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue