feat():引擎版本单增删改查

master
Saisai Liu 2024-05-07 13:56:31 +08:00
parent 1abb6e89b9
commit e7336a4f59
15 changed files with 638 additions and 669 deletions

View File

@ -41,9 +41,13 @@ public class RuleEngine extends BaseEntity
@Excel(name = "规则作用域")
private String level;
/** 规则编码 */
@Excel(name = "规则编码")
private String code;
/** 引擎编码 */
@Excel(name = "引擎编码")
private String code;
private String engineCode;
/** 描述 */
@Excel(name = "描述")

View File

@ -0,0 +1,66 @@
package com.muyu.engine.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
/**
* rule_engine_version
*
* @author Saisai
* @date 2024-05-06
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class RuleEngineVersion extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
private Long id;
/** 引擎id */
@Excel(name = "引擎id")
private Long ruleEngineId;
/** 版本类 */
@Excel(name = "版本类")
private String versionCode;
/** 版本名称 */
@Excel(name = "版本名称")
private String name;
/** 版本code */
@Excel(name = "版本code")
private String code;
/** 引擎编码 */
@Excel(name = "引擎编码")
private String codeIng;
/** 是否激活 */
@Excel(name = "是否激活")
private String isActivate;
/** 测试状态 */
@Excel(name = "是否激活")
private String isTest;
/** 版本状态 */
@Excel(name = "版本状态")
private String status;
/** 描述 */
@Excel(name = "描述")
private String description;
}

View File

@ -1,67 +0,0 @@
package com.muyu.engine.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.function.Supplier;
/**
* scope
*
* @author Saisai
* @date 2024-05-03
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class Scope extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(value = "id",type = IdType.AUTO)
private Long id;
/** 引擎id */
@Excel(name = "引擎id")
private Long ruleEngineId;
/** 类型 */
@Excel(name = "类型")
private String type;
/** 类型值 */
@Excel(name = "类型值")
private String value;
/** 编码 */
@Excel(name = "编码")
private String code;
public static List<Scope> list(Long id, Supplier<String> username) {
Scope scopetaskContext = new Scope() {{setType("任务");setValue("taskContext");setRuleEngineId(id);setCreateBy(username.get());setCreateTime(new Date());}};
Scope scoperecordContext = new Scope() {{setType("资产集");setValue("recordContext");setRuleEngineId(id);setCreateBy(username.get());setCreateTime(new Date());}};
Scope scopedataSetContext = new Scope() {{setType("资产记录");setValue("dataSetContext");setRuleEngineId(id);setCreateBy(username.get());setCreateTime(new Date());}};
Scope scopedataModelContext = new Scope() {{setType("资产模型");setValue("dataModelContext");setRuleEngineId(id);setCreateBy(username.get());setCreateTime(new Date());}};
List<Scope> scopes = new ArrayList<>() {{
add(scopetaskContext);
add(scoperecordContext);
add(scopedataSetContext);
add(scopedataModelContext);
}};
return scopes;
}
}

View File

@ -0,0 +1,103 @@
package com.muyu.engine.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.engine.domain.RuleEngineVersion;
import com.muyu.engine.service.RuleEngineVersionService;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.page.TableDataInfo;
/**
* Controller
*
* @author Saisai
* @date 2024-05-06
*/
@RestController
@RequestMapping("/version")
public class RuleEngineVersionController extends BaseController
{
@Autowired
private RuleEngineVersionService ruleEngineVersionService;
/**
*
*/
@RequiresPermissions("engine:version:list")
@GetMapping("/list/{ruleEngineId}")
public Result<TableDataInfo<RuleEngineVersion>> list(@PathVariable Long ruleEngineId)
{
List<RuleEngineVersion> list = ruleEngineVersionService.selectRuleEngineVersionList(ruleEngineId);
return getDataTable(list);
}
/**
*
*/
@RequiresPermissions("engine:version:export")
@Log(title = "规则版本", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, Long ruleEngineId)
{
List<RuleEngineVersion> list = ruleEngineVersionService.selectRuleEngineVersionList(ruleEngineId);
ExcelUtil<RuleEngineVersion> util = new ExcelUtil<RuleEngineVersion>(RuleEngineVersion.class);
util.exportExcel(response, list, "规则版本数据");
}
/**
*
*/
@RequiresPermissions("engine:version:query")
@GetMapping(value = "/{id}")
public Result getInfo(@PathVariable("id") Long id)
{
return success(ruleEngineVersionService.selectRuleEngineVersionById(id));
}
/**
*
*/
@RequiresPermissions("engine:version:add")
@Log(title = "规则版本", businessType = BusinessType.INSERT)
@PostMapping
public Result add(@RequestBody RuleEngineVersion ruleEngineVersion)
{
return toAjax(ruleEngineVersionService.insertRuleEngineVersion(ruleEngineVersion));
}
/**
*
*/
@RequiresPermissions("engine:version:edit")
@Log(title = "规则版本", businessType = BusinessType.UPDATE)
@PutMapping
public Result edit(@RequestBody RuleEngineVersion ruleEngineVersion)
{
return toAjax(ruleEngineVersionService.updateRuleEngineVersion(ruleEngineVersion));
}
/**
*
*/
@RequiresPermissions("engine:version:remove")
@Log(title = "规则版本", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public Result remove(@PathVariable Long[] ids)
{
return toAjax(ruleEngineVersionService.deleteRuleEngineVersionByIds(ids));
}
}

View File

@ -1,122 +0,0 @@
package com.muyu.engine.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.engine.domain.Scope;
import com.muyu.engine.service.ScopeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* Controller
*
* @author Saisai
* @date 2024-05-03
*/
@RestController
@RequestMapping("/scope")
public class ScopeController extends BaseController
{
@Autowired
private ScopeService scopeService;
/**
*
*/
@RequiresPermissions("engine:scope:list")
@GetMapping("/list")
public Result<TableDataInfo<Scope>> list(Scope scope)
{
startPage();
List<Scope> list = scopeService.selectScopeList(scope);
return getDataTable(list);
}
/**
*
*/
@RequiresPermissions("engine:scope:export")
@Log(title = "规则引擎代码", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, Scope scope)
{
List<Scope> list = scopeService.selectScopeList(scope);
ExcelUtil<Scope> util = new ExcelUtil<Scope>(Scope.class);
util.exportExcel(response, list, "规则引擎代码数据");
}
/**
*
*/
@RequiresPermissions("engine:scope:query")
@GetMapping(value = "/{id}")
public Result getInfo(@PathVariable("id") Long id)
{
return success(scopeService.selectScopeById(id));
}
/**
*
*/
@RequiresPermissions("engine:scope:add")
@Log(title = "规则引擎代码", businessType = BusinessType.INSERT)
@PostMapping
public Result add(@RequestBody Scope scope)
{
return toAjax(scopeService.insertScope(scope));
}
/**
*
*/
@RequiresPermissions("engine:scope:edit")
@Log(title = "规则引擎代码", businessType = BusinessType.UPDATE)
@PutMapping
public Result edit(@RequestBody Scope scope)
{
return toAjax(scopeService.updateScope(scope));
}
/**
*
*/
@RequiresPermissions("engine:scope:remove")
@Log(title = "规则引擎代码", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public Result remove(@PathVariable Long[] ids)
{
return toAjax(scopeService.deleteScopeByIds(ids));
}
/**
*
*/
@RequiresPermissions("engine:scope:init")
@Log(title = "规则引擎", businessType = BusinessType.DELETE)
@GetMapping("init/{id}")
public Result init(@PathVariable Long id) throws ServletException {
return toAjax(scopeService.init(id));
}
/**
*
*/
@RequiresPermissions("engine:scope:testEngine")
@Log(title = "规则引擎", businessType = BusinessType.DELETE)
@GetMapping("testEngine/{id}")
public Result test(@PathVariable Long id) throws Exception {
return toAjax(scopeService.testEngine(id));
}
}

View File

@ -0,0 +1,63 @@
package com.muyu.engine.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.engine.domain.RuleEngineVersion;
/**
* Mapper
*
* @author Saisai
* @date 2024-05-06
*/
public interface RuleEngineVersionMapper extends BaseMapper<RuleEngineVersion>
{
/**
*
*
* @param id
* @return
*/
public RuleEngineVersion selectRuleEngineVersionById(Long id);
/**
*
*
* @param ruleEngineVersion
* @return
*/
public List<RuleEngineVersion> selectRuleEngineVersionList(RuleEngineVersion ruleEngineVersion);
/**
*
*
* @param ruleEngineVersion
* @return
*/
public int insertRuleEngineVersion(RuleEngineVersion ruleEngineVersion);
/**
*
*
* @param ruleEngineVersion
* @return
*/
public int updateRuleEngineVersion(RuleEngineVersion ruleEngineVersion);
/**
*
*
* @param id
* @return
*/
public int deleteRuleEngineVersionById(Long id);
/**
*
*
* @param ids
* @return
*/
public int deleteRuleEngineVersionByIds(Long[] ids);
}

View File

@ -1,63 +0,0 @@
package com.muyu.engine.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.engine.domain.Scope;
/**
* Mapper
*
* @author Saisai
* @date 2024-05-03
*/
public interface ScopeMapper extends BaseMapper<Scope>
{
/**
*
*
* @param id
* @return
*/
public Scope selectScopeById(Long id);
/**
*
*
* @param scope
* @return
*/
public List<Scope> selectScopeList(Scope scope);
/**
*
*
* @param scope
* @return
*/
public int insertScope(Scope scope);
/**
*
*
* @param scope
* @return
*/
public int updateScope(Scope scope);
/**
*
*
* @param id
* @return
*/
public int deleteScopeById(Long id);
/**
*
*
* @param ids
* @return
*/
public int deleteScopeByIds(Long[] ids);
}

View File

@ -0,0 +1,63 @@
package com.muyu.engine.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.engine.domain.RuleEngineVersion;
/**
* Service
*
* @author Saisai
* @date 2024-05-06
*/
public interface RuleEngineVersionService extends IService<RuleEngineVersion>
{
/**
*
*
* @param id
* @return
*/
public RuleEngineVersion selectRuleEngineVersionById(Long id);
/**
*
*
* @param ruleEngineVersion
* @return
*/
public List<RuleEngineVersion> selectRuleEngineVersionList(Long ruleEngineVersion);
/**
*
*
* @param ruleEngineVersion
* @return
*/
public int insertRuleEngineVersion(RuleEngineVersion ruleEngineVersion);
/**
*
*
* @param ruleEngineVersion
* @return
*/
public int updateRuleEngineVersion(RuleEngineVersion ruleEngineVersion);
/**
*
*
* @param ids
* @return
*/
public int deleteRuleEngineVersionByIds(Long[] ids);
/**
*
*
* @param id
* @return
*/
public int deleteRuleEngineVersionById(Long id);
}

View File

@ -1,78 +0,0 @@
package com.muyu.engine.service;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.engine.domain.Scope;
import javax.servlet.ServletException;
/**
* Service
*
* @author Saisai
* @date 2024-05-03
*/
public interface ScopeService extends IService<Scope>
{
/**
*
*
* @param id
* @return
*/
public Scope selectScopeById(Long id);
/**
*
*
* @param scope
* @return
*/
public List<Scope> selectScopeList(Scope scope);
/**
*
*
* @param scope
* @return
*/
public int insertScope(Scope scope);
/**
*
*
* @param scope
* @return
*/
public int updateScope(Scope scope);
/**
*
*
* @param ids
* @return
*/
public int deleteScopeByIds(Long[] ids);
/**
*
*
* @param id
* @return
*/
public int deleteScopeById(Long id);
/**
*
* @param id
* @return
*/
boolean init(Long id) throws ServletException;
void deleteScopeByRuleIds(Long[] ids);
boolean testEngine(Long id) throws Exception;
}

View File

@ -2,12 +2,9 @@ package com.muyu.engine.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.engine.domain.RuleEngine;
import com.muyu.engine.domain.Scope;
import com.muyu.engine.mapper.RuleEngineMapper;
import com.muyu.engine.service.RuleEngineService;
import com.muyu.engine.service.ScopeService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -22,12 +19,10 @@ import java.util.List;
*/
@Service
@Log4j2
public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper,RuleEngine> implements RuleEngineService
{
public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper, RuleEngine> implements RuleEngineService {
@Autowired
private RuleEngineMapper ruleEngineMapper;
@Autowired
private ScopeService scopeService;
/**
*
*
@ -35,8 +30,7 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper,RuleEngi
* @return
*/
@Override
public RuleEngine selectRuleEngineById(Long id)
{
public RuleEngine selectRuleEngineById(Long id) {
return ruleEngineMapper.selectRuleEngineById(id);
}
@ -47,8 +41,7 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper,RuleEngi
* @return
*/
@Override
public List<RuleEngine> selectRuleEngineList(RuleEngine ruleEngine)
{
public List<RuleEngine> selectRuleEngineList(RuleEngine ruleEngine) {
return ruleEngineMapper.selectRuleEngineList(ruleEngine);
}
@ -59,14 +52,14 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper,RuleEngi
* @return
*/
@Override
public int insertRuleEngine(RuleEngine ruleEngine)
{
public int insertRuleEngine(RuleEngine ruleEngine) {
ruleEngine.setCreateTime(DateUtils.getNowDate());
ruleEngine.setEngineCode("engine_custom_" + ruleEngine.getCode());
boolean save = this.save(ruleEngine);
if (save){
scopeService.saveBatch(Scope.list(ruleEngine.getId(), SecurityUtils::getUsername));
if (save) {
return 1;
}
return 1;
return 0;
}
/**
@ -76,8 +69,7 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper,RuleEngi
* @return
*/
@Override
public int updateRuleEngine(RuleEngine ruleEngine)
{
public int updateRuleEngine(RuleEngine ruleEngine) {
ruleEngine.setUpdateTime(DateUtils.getNowDate());
return ruleEngineMapper.updateRuleEngine(ruleEngine);
}
@ -89,9 +81,7 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper,RuleEngi
* @return
*/
@Override
public int deleteRuleEngineByIds(Long[] ids)
{
scopeService.deleteScopeByRuleIds(ids);
public int deleteRuleEngineByIds(Long[] ids) {
return ruleEngineMapper.deleteRuleEngineByIds(ids);
}
@ -102,11 +92,9 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper,RuleEngi
* @return
*/
@Override
public int deleteRuleEngineById(Long id)
{
public int deleteRuleEngineById(Long id) {
return ruleEngineMapper.deleteRuleEngineById(id);
}
}

View File

@ -0,0 +1,204 @@
package com.muyu.engine.service.impl;
import java.io.*;
import java.util.List;
import com.alibaba.nacos.shaded.com.google.common.base.Supplier;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.engine.domain.RuleEngine;
import com.muyu.engine.service.RuleEngineService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.muyu.engine.mapper.RuleEngineVersionMapper;
import com.muyu.engine.domain.RuleEngineVersion;
import com.muyu.engine.service.RuleEngineVersionService;
import javax.servlet.ServletException;
/**
* Service
*
* @author Saisai
* @date 2024-05-06
*/
@Service
@Log4j2
public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionMapper,RuleEngineVersion> implements RuleEngineVersionService
{
@Autowired
private RuleEngineVersionMapper ruleEngineVersionMapper;
@Autowired
private RuleEngineService ruleEngineService;
/**
*
*
* @param id
* @return
*/
@Override
public RuleEngineVersion selectRuleEngineVersionById(Long id)
{
return ruleEngineVersionMapper.selectRuleEngineVersionById(id);
}
/**
*
*
* @param ruleEngineId
* @return
*/
@Override
public List<RuleEngineVersion> selectRuleEngineVersionList(Long ruleEngineId)
{
return list(new LambdaQueryWrapper<RuleEngineVersion>(){{
eq(RuleEngineVersion::getRuleEngineId,ruleEngineId);
}});
}
/**
*
*
* @param ruleEngineVersion
* @return
*/
@Override
public int insertRuleEngineVersion(RuleEngineVersion ruleEngineVersion)
{
ruleEngineVersion.setCreateTime(DateUtils.getNowDate());
return ruleEngineVersionMapper.insertRuleEngineVersion(ruleEngineVersion);
}
/**
*
*
* @param ruleEngineVersion
* @return
*/
@Override
public int updateRuleEngineVersion(RuleEngineVersion ruleEngineVersion)
{
ruleEngineVersion.setUpdateTime(DateUtils.getNowDate());
return ruleEngineVersionMapper.updateRuleEngineVersion(ruleEngineVersion);
}
/**
*
*
* @param ids
* @return
*/
@Override
public int deleteRuleEngineVersionByIds(Long[] ids)
{
return ruleEngineVersionMapper.deleteRuleEngineVersionByIds(ids);
}
/**
*
*
* @param id
* @return
*/
@Override
public int deleteRuleEngineVersionById(Long id)
{
return ruleEngineVersionMapper.deleteRuleEngineVersionById(id);
}
// @Override
public boolean testEngine(Long id) throws Exception {
// RuleEngine ruleEngine = ruleEngineService.getById(id);
// if (ruleEngine.getIsActivate().contains("no")) throw new ServletException("未激活");
// if (ruleEngine.getStatus().contains("1")) throw new ServletException("已停用");
// 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();
// String name = path+"."+fileName;
// String javaPackageName = name.replace(".", File.separator)+".java";
// String javaAbsolutePath = "D:/ruoyi/FinallyTest/muyu-modules/muyu-ruleEngine/muyu-ruleEngine-service/src/main/java/" +javaPackageName;
// String jarAbsolutePath = "D:/ruoyi/FinallyTest/muyu-modules/muyu-ruleEngine/muyu-ruleEngine-service/target/classes/com/muyu/engine/controller";
// Process process = Runtime.getRuntime().exec("javac -classpath "+ jarAbsolutePath+ " " + javaAbsolutePath);
// try {
// int exitVal = process.waitFor();
// System.out.println("Process exitValue: " + exitVal);
// ClassLoader classLoader = ReflectionUtils.class.getClassLoader();
// Class aClass = classLoader.loadClass(name);
// Object o = aClass.newInstance();
// Method[] methods = aClass.getMethods();
// for (Method method : methods) {
// method.invoke(o,null);
// }
// } catch (Exception e) {
// log.error(e.getMessage());
// }
return true;
}
/**
*
*
* @param id
* @return
*/
// @Override
public boolean init(Long id) throws ServletException {
RuleEngine ruleEngine = ruleEngineService.getById(id);
if (ruleEngine.getIsActivate().contains("no")) throw new ServletException("未激活");
if (ruleEngine.getStatus().contains("1")) throw new ServletException("已停用");
Supplier<Boolean> booleanSupplier = () -> {
try {
return testEngine(ruleEngine);
} catch (Exception e) {
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();
return true;
}
}

View File

@ -1,220 +0,0 @@
package com.muyu.engine.service.impl;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import com.alibaba.nacos.shaded.com.google.common.base.Supplier;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.text.Convert;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.engine.domain.RuleEngine;
import com.muyu.engine.service.RuleEngineService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.muyu.engine.mapper.ScopeMapper;
import com.muyu.engine.domain.Scope;
import com.muyu.engine.service.ScopeService;
import org.springframework.util.ReflectionUtils;
import javax.servlet.ServletException;
/**
* Service
*
* @author Saisai
* @date 2024-05-03
*/
@Service
@Log4j2
public class ScopeServiceImpl extends ServiceImpl<ScopeMapper, Scope> implements ScopeService {
@Autowired
private ScopeMapper scopeMapper;
@Autowired
private RuleEngineService ruleEngineService;
/**
*
*
* @param id
* @return
*/
@Override
public Scope selectScopeById(Long id) {
return scopeMapper.selectScopeById(id);
}
/**
*
*
* @param scope
* @return
*/
@Override
public List<Scope> selectScopeList(Scope scope) {
return scopeMapper.selectScopeList(scope);
}
/**
*
*
* @param scope
* @return
*/
@Override
public int insertScope(Scope scope) {
scope.setCreateTime(DateUtils.getNowDate());
return scopeMapper.insertScope(scope);
}
/**
*
*
* @param scope
* @return
*/
@Override
public int updateScope(Scope scope) {
scope.setUpdateTime(DateUtils.getNowDate());
Scope one = this.getOne(new LambdaQueryWrapper<>() {{
eq(Scope::getValue, scope.getValue());
eq(Scope::getRuleEngineId, scope.getRuleEngineId());
}});
one.setCode(scope.getCode());
return scopeMapper.updateScope(one);
}
/**
*
*
* @param ids
* @return
*/
@Override
public int deleteScopeByIds(Long[] ids) {
return scopeMapper.deleteScopeByIds(ids);
}
/**
*
*
* @param id
* @return
*/
@Override
public int deleteScopeById(Long id) {
return scopeMapper.deleteScopeById(id);
}
@Override
public void deleteScopeByRuleIds(Long[] ids) {
List<Long> longs = new ArrayList<>();
for (Long id : ids) {
List<Long> list = this.list(new LambdaQueryWrapper<Scope>() {{
eq(Scope::getRuleEngineId, id);
}}).stream().map(Scope::getId).toList();
longs.addAll(list);
}
if (!longs.isEmpty()) {
this.deleteScopeByIds(longs.toArray(Long[]::new));
}
}
@Override
public boolean testEngine(Long id) throws Exception {
RuleEngine ruleEngine = ruleEngineService.getById(id);
if (ruleEngine.getIsActivate().contains("no")) throw new ServletException("未激活");
if (ruleEngine.getStatus().contains("1")) throw new ServletException("已停用");
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();
String name = path+"."+fileName;
String javaPackageName = name.replace(".",File.separator)+".java";
String javaAbsolutePath = "D:/ruoyi/FinallyTest/muyu-modules/muyu-ruleEngine/muyu-ruleEngine-service/src/main/java/" +javaPackageName;
String jarAbsolutePath = "D:/ruoyi/FinallyTest/muyu-modules/muyu-ruleEngine/muyu-ruleEngine-service/target/classes/com/muyu/engine/controller";
Process process = Runtime.getRuntime().exec("javac -classpath "+ jarAbsolutePath+ " " + javaAbsolutePath);
ClassLoader classLoader = ReflectionUtils.class.getClassLoader();
// Class aClass = Class.forName(fileName);
Class aClass = classLoader.loadClass(name);
Object o = aClass.newInstance();
Method test = aClass.getMethod("test",null);
test.invoke(o,null);
try {
InputStream errorStream = process.getErrorStream();
InputStreamReader inputStreamReader = new InputStreamReader(errorStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line = null;
while ((line=bufferedReader.readLine()) != null){
System.out.println(line);
}
int exitVal = process.waitFor();
System.out.println("Process exitValue: " + exitVal);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
*
*
* @param id
* @return
*/
@Override
public boolean init(Long id) throws ServletException {
RuleEngine ruleEngine = ruleEngineService.getById(id);
if (ruleEngine.getIsActivate().contains("no")) throw new ServletException("未激活");
if (ruleEngine.getStatus().contains("1")) throw new ServletException("已停用");
Supplier<Boolean> booleanSupplier = () -> {
try {
return testEngine(ruleEngine);
} catch (Exception e) {
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();
}
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;
}
}

View File

@ -10,6 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="type" column="type" />
<result property="level" column="level" />
<result property="code" column="code" />
<result property="engineCode" column="engine_code" />
<result property="description" column="description" />
<result property="isActivate" column="is_activate" />
<result property="status" column="status" />
@ -21,7 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectRuleEngineVo">
select id, name, type, level, code,description, is_activate, status, remark, create_by, create_time, update_by, update_time from rule_engine
select id, name, type, level, code,engine_code,description, is_activate, status, remark, create_by, create_time, update_by, update_time from rule_engine
</sql>
<select id="selectRuleEngineList" parameterType="com.muyu.engine.domain.RuleEngine" resultMap="RuleEngineResult">
@ -31,6 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="type != null and type != ''"> and type = #{type}</if>
<if test="level != null and level != ''"> and level = #{level}</if>
<if test="code != null and code != ''"> and code = #{code}</if>
<if test="engineCode != null and engineCode != ''"> and engine_code = #{engineCode}</if>
<if test="description != null and description != ''"> and description = #{description}</if>
<if test="isActivate != null and isActivate != ''"> and is_activate = #{isActivate}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
@ -50,6 +52,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="type != null">type,</if>
<if test="level != null">level,</if>
<if test="code != null">code,</if>
<if test="engineCode != null">engine_code,</if>
<if test="description != null">description,</if>
<if test="isActivate != null">is_activate,</if>
<if test="status != null">status,</if>
@ -65,6 +68,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="type != null">#{type},</if>
<if test="level != null">#{level},</if>
<if test="code != null">#{code},</if>
<if test="engine_code != null">#{engineCode},</if>
<if test="description != null">#{description},</if>
<if test="isActivate != null">#{isActivate},</if>
<if test="status != null">#{status},</if>
@ -83,6 +87,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="type != null">type = #{type},</if>
<if test="level != null">level = #{level},</if>
<if test="code != null">code = #{code},</if>
<if test="engineCode != null">engine_code = #{engineCode},</if>
<if test="description != null">description = #{description},</if>
<if test="isActivate != null">is_activate = #{isActivate},</if>
<if test="status != null">status = #{status},</if>

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.engine.mapper.RuleEngineVersionMapper">
<resultMap type="com.muyu.engine.domain.RuleEngineVersion" id="RuleEngineVersionResult">
<result property="id" column="id" />
<result property="ruleEngineId" column="rule_engine_id" />
<result property="versionCode" column="version_code" />
<result property="name" column="name" />
<result property="code" column="code" />
<result property="codeIng" column="codeIng" />
<result property="isActivate" column="is_activate" />
<result property="isTest" column="is_test" />
<result property="status" column="status" />
<result property="description" column="description" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectRuleEngineVersionVo">
select id, rule_engine_id, version_code, name, code, code_ing, is_activate,is_test, status, description, remark, create_by, create_time, update_by, update_time from rule_engine_version
</sql>
<select id="selectRuleEngineVersionList" parameterType="com.muyu.engine.domain.RuleEngineVersion" resultMap="RuleEngineVersionResult">
<include refid="selectRuleEngineVersionVo"/>
<where>
<if test="ruleEngineId != null "> and rule_engine_id = #{ruleEngineId}</if>
<if test="versionCode != null and versionCode != ''"> and version_code = #{versionCode}</if>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="code != null and code != ''"> and code = #{code}</if>
<if test="codeIng != null and codeIng != ''"> and code_ing = #{codeIng}</if>
<if test="isActivate != null and isActivate != ''"> and is_activate = #{isActivate}</if>
<if test="isTest != null and isTest != ''"> and is_test = #{isTest}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="description != null and description != ''"> and description = #{description}</if>
</where>
</select>
<select id="selectRuleEngineVersionById" parameterType="Long" resultMap="RuleEngineVersionResult">
<include refid="selectRuleEngineVersionVo"/>
where id = #{id}
</select>
<insert id="insertRuleEngineVersion" parameterType="com.muyu.engine.domain.RuleEngineVersion" useGeneratedKeys="true" keyProperty="id">
insert into rule_engine_version
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="ruleEngineId != null">rule_engine_id,</if>
<if test="versionCode != null">version_code,</if>
<if test="name != null">name,</if>
<if test="code != null">code,</if>
<if test="codeIng != null">code_ing,</if>
<if test="isActivate != null">is_activate,</if>
<if test="isTest != null">is_test,</if>
<if test="status != null">status,</if>
<if test="description != null">description,</if>
<if test="remark != null">remark,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="ruleEngineId != null">#{ruleEngineId},</if>
<if test="versionCode != null">#{versionCode},</if>
<if test="name != null">#{name},</if>
<if test="code != null">#{code},</if>
<if test="codeIng != null">#{codeIng},</if>
<if test="isActivate != null">#{isActivate},</if>
<if test="isTest != null">#{isTest},</if>
<if test="status != null">#{status},</if>
<if test="description != null">#{description},</if>
<if test="remark != null">#{remark},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateRuleEngineVersion" parameterType="com.muyu.engine.domain.RuleEngineVersion">
update rule_engine_version
<trim prefix="SET" suffixOverrides=",">
<if test="ruleEngineId != null">rule_engine_id = #{ruleEngineId},</if>
<if test="versionCode != null">version_code = #{versionCode},</if>
<if test="name != null">name = #{name},</if>
<if test="code != null">code = #{code},</if>
<if test="codeIng != null">code_ing = #{codeIng},</if>
<if test="isActivate != null">is_activate = #{isActivate},</if>
<if test="isTest != null">is_test = #{isTest},</if>
<if test="status != null">status = #{status},</if>
<if test="description != null">description = #{description},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteRuleEngineVersionById" parameterType="Long">
delete from rule_engine_version where id = #{id}
</delete>
<delete id="deleteRuleEngineVersionByIds" parameterType="String">
delete from rule_engine_version where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -1,93 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.engine.mapper.ScopeMapper">
<resultMap type="com.muyu.engine.domain.Scope" id="ScopeResult">
<result property="id" column="id" />
<result property="ruleEngineId" column="rule_engine_id" />
<result property="type" column="type" />
<result property="value" column="value" />
<result property="code" column="code" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectScopeVo">
select id, rule_engine_id, type, value, code, remark, create_by, create_time, update_by, update_time from scope
</sql>
<select id="selectScopeList" parameterType="com.muyu.engine.domain.Scope" resultMap="ScopeResult">
<include refid="selectScopeVo"/>
<where>
<if test="ruleEngineId != null "> and rule_engine_id = #{ruleEngineId}</if>
<if test="type != null and type != ''"> and type = #{type}</if>
<if test="value != null and value != ''"> and value = #{value}</if>
<if test="code != null and code != ''"> and code = #{code}</if>
</where>
</select>
<select id="selectScopeById" parameterType="Long" resultMap="ScopeResult">
<include refid="selectScopeVo"/>
where id = #{id}
</select>
<insert id="insertScope" parameterType="com.muyu.engine.domain.Scope">
insert into scope
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="ruleEngineId != null">rule_engine_id,</if>
<if test="type != null">type,</if>
<if test="value != null">value,</if>
<if test="code != null">code,</if>
<if test="remark != null">remark,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="ruleEngineId != null">#{ruleEngineId},</if>
<if test="type != null">#{type},</if>
<if test="value != null">#{value},</if>
<if test="code != null">#{code},</if>
<if test="remark != null">#{remark},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateScope" parameterType="com.muyu.engine.domain.Scope">
update scope
<trim prefix="SET" suffixOverrides=",">
<if test="ruleEngineId != null">rule_engine_id = #{ruleEngineId},</if>
<if test="type != null">type = #{type},</if>
<if test="value != null">value = #{value},</if>
<if test="code != null">code = #{code},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteScopeById" parameterType="Long">
delete from scope where id = #{id}
</delete>
<delete id="deleteScopeByIds" parameterType="String">
delete from scope where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>