feat:规则引擎
parent
73c79effac
commit
d232708d45
|
@ -0,0 +1,53 @@
|
||||||
|
package com.muyu.rule.engine.ClassLoading;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
public class CustomClassLoader extends ClassLoader {
|
||||||
|
// public CustomClassLoader(ClassLoader parent, String classPath) throws MalformedURLException {
|
||||||
|
// super(new URL[]{new URL("file:" + classPath)},parent);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// protected Class<?> findClass(String name) throws ClassNotFoundException {
|
||||||
|
// try {
|
||||||
|
// byte[] classBytes = loadClassData(name);
|
||||||
|
// return defineClass(name, classBytes, 0, classBytes.length);
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// throw new ClassNotFoundException(name, e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private byte[] loadClassData(String className) throws IOException {
|
||||||
|
// String fileName = className.replace('.', File.separatorChar) + ".class";
|
||||||
|
// File classFile = new File(getPathForResource(fileName));
|
||||||
|
// if (!classFile.exists()) {
|
||||||
|
// throw new FileNotFoundException("Class file not found: " + classFile.getAbsolutePath());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try (InputStream in = new FileInputStream(classFile)) {
|
||||||
|
// ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
// byte[] buffer = new byte[4096];
|
||||||
|
// int n;
|
||||||
|
// while ((n = in.read(buffer)) != -1) {
|
||||||
|
// out.write(buffer, 0, n);
|
||||||
|
// }
|
||||||
|
// return out.toByteArray();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private String getPathForResource(String resource) {
|
||||||
|
// URL url = super.getResource(resource);
|
||||||
|
// if (url == null) {
|
||||||
|
// throw new IllegalArgumentException("Resource not found: " + resource);
|
||||||
|
// }
|
||||||
|
// return url.getPath();
|
||||||
|
// }
|
||||||
|
|
||||||
|
public Class<?> defineClassFromBytes(String name, byte[] data) {
|
||||||
|
return defineClass(name, data, 0, data.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,111 @@
|
||||||
|
package com.muyu.rule.engine.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import com.muyu.common.log.annotation.Log;
|
||||||
|
import com.muyu.common.log.enums.BusinessType;
|
||||||
|
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||||
|
import com.muyu.rule.engine.domain.EngineMaintenance;
|
||||||
|
import com.muyu.rule.engine.service.IEngineMaintenanceService;
|
||||||
|
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 ruoyi
|
||||||
|
* @date 2024-05-02
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/maintenance")
|
||||||
|
public class EngineMaintenanceController extends BaseController
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private IEngineMaintenanceService engineMaintenanceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询【请填写功能名称】列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
public Result<TableDataInfo<EngineMaintenance>> list(EngineMaintenance engineMaintenance)
|
||||||
|
{
|
||||||
|
startPage();
|
||||||
|
List<EngineMaintenance> list = engineMaintenanceService.selectEngineMaintenanceList(engineMaintenance);
|
||||||
|
return getDataTable(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出【请填写功能名称】列表
|
||||||
|
*/
|
||||||
|
@Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(HttpServletResponse response, EngineMaintenance engineMaintenance)
|
||||||
|
{
|
||||||
|
List<EngineMaintenance> list = engineMaintenanceService.selectEngineMaintenanceList(engineMaintenance);
|
||||||
|
ExcelUtil<EngineMaintenance> util = new ExcelUtil<EngineMaintenance>(EngineMaintenance.class);
|
||||||
|
util.exportExcel(response, list, "【请填写功能名称】数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取【请填写功能名称】详细信息
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/{id}")
|
||||||
|
public Result getInfo(@PathVariable("id") Long id)
|
||||||
|
{
|
||||||
|
return success(engineMaintenanceService.selectEngineMaintenanceById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试方法
|
||||||
|
* @param code
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/TestMethod")
|
||||||
|
public Result testMethod(@RequestParam("code") String code)
|
||||||
|
{
|
||||||
|
return engineMaintenanceService.testMethod(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增【请填写功能名称】
|
||||||
|
*/
|
||||||
|
@Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public Result add(@RequestBody EngineMaintenance engineMaintenance)
|
||||||
|
{
|
||||||
|
return toAjax(engineMaintenanceService.insertEngineMaintenance(engineMaintenance));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化规则引擎类
|
||||||
|
*/
|
||||||
|
@PostMapping("/InitializeRuleEngine")
|
||||||
|
public Result initializeRuleEngine(@RequestBody EngineMaintenance engineMaintenance)
|
||||||
|
{
|
||||||
|
return engineMaintenanceService.initializeRuleEngine(engineMaintenance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改【请填写功能名称】
|
||||||
|
*/
|
||||||
|
@Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public Result edit(@RequestBody EngineMaintenance engineMaintenance)
|
||||||
|
{
|
||||||
|
return toAjax(engineMaintenanceService.updateEngineMaintenance(engineMaintenance));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除【请填写功能名称】
|
||||||
|
*/
|
||||||
|
@Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{ids}")
|
||||||
|
public Result remove(@PathVariable Long[] ids)
|
||||||
|
{
|
||||||
|
return toAjax(engineMaintenanceService.deleteEngineMaintenanceByIds(ids));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,152 @@
|
||||||
|
package com.muyu.rule.engine.domain;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【请填写功能名称】对象 engine_maintenance
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-05-02
|
||||||
|
*/
|
||||||
|
public class EngineMaintenance extends BaseEntity {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** $column.columnComment */
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 规则引擎名称 */
|
||||||
|
@Excel(name = "规则引擎名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** 规则引擎类型 */
|
||||||
|
@Excel(name = "规则引擎类型")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/** 规则引擎激活状态 */
|
||||||
|
@Excel(name = "规则引擎激活状态")
|
||||||
|
private String isActivate;
|
||||||
|
|
||||||
|
/** 规则引擎状态 */
|
||||||
|
@Excel(name = "规则引擎状态")
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/** 规则引擎描述 */
|
||||||
|
@Excel(name = "规则引擎描述")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/** 规则引擎编码 */
|
||||||
|
@Excel(name = "规则引擎编码")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/** 规则引擎级别 */
|
||||||
|
@Excel(name = "规则引擎级别")
|
||||||
|
private String level;
|
||||||
|
|
||||||
|
/** 编辑代码文本 */
|
||||||
|
@Excel(name = "编辑代码文本")
|
||||||
|
private String codeText;
|
||||||
|
|
||||||
|
public String getCodeText() {
|
||||||
|
return codeText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCodeText(String codeText) {
|
||||||
|
this.codeText = codeText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setName(String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setType(String type)
|
||||||
|
{
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType()
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
public void setIsActivate(String isActivate)
|
||||||
|
{
|
||||||
|
this.isActivate = isActivate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIsActivate()
|
||||||
|
{
|
||||||
|
return isActivate;
|
||||||
|
}
|
||||||
|
public void setStatus(String status)
|
||||||
|
{
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus()
|
||||||
|
{
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
public void setDescription(String description)
|
||||||
|
{
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription()
|
||||||
|
{
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
public void setCode(String code)
|
||||||
|
{
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode()
|
||||||
|
{
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
public void setLevel(String level)
|
||||||
|
{
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLevel()
|
||||||
|
{
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
.append("id", getId())
|
||||||
|
.append("name", getName())
|
||||||
|
.append("type", getType())
|
||||||
|
.append("isActivate", getIsActivate())
|
||||||
|
.append("status", getStatus())
|
||||||
|
.append("description", getDescription())
|
||||||
|
.append("code", getCode())
|
||||||
|
.append("level", getLevel())
|
||||||
|
.append("codeText", getCodeText())
|
||||||
|
.append("remark", getRemark())
|
||||||
|
.append("createBy", getCreateBy())
|
||||||
|
.append("createTime", getCreateTime())
|
||||||
|
.append("updateBy", getUpdateBy())
|
||||||
|
.append("updateTime", getUpdateTime())
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.muyu.rule.engine.domain;
|
||||||
|
|
||||||
|
public class gg {
|
||||||
|
public void test() {
|
||||||
|
System.out.println("444444");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.muyu.rule.engine.mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.muyu.rule.engine.domain.EngineMaintenance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【请填写功能名称】Mapper接口
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-05-02
|
||||||
|
*/
|
||||||
|
public interface EngineMaintenanceMapper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 查询【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param id 【请填写功能名称】主键
|
||||||
|
* @return 【请填写功能名称】
|
||||||
|
*/
|
||||||
|
public EngineMaintenance selectEngineMaintenanceById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询【请填写功能名称】列表
|
||||||
|
*
|
||||||
|
* @param engineMaintenance 【请填写功能名称】
|
||||||
|
* @return 【请填写功能名称】集合
|
||||||
|
*/
|
||||||
|
public List<EngineMaintenance> selectEngineMaintenanceList(EngineMaintenance engineMaintenance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param engineMaintenance 【请填写功能名称】
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insertEngineMaintenance(EngineMaintenance engineMaintenance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param engineMaintenance 【请填写功能名称】
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateEngineMaintenance(EngineMaintenance engineMaintenance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param id 【请填写功能名称】主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteEngineMaintenanceById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的数据主键集合
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteEngineMaintenanceByIds(Long[] ids);
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package com.muyu.rule.engine.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.rule.engine.domain.EngineMaintenance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【请填写功能名称】Service接口
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-05-02
|
||||||
|
*/
|
||||||
|
public interface IEngineMaintenanceService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 查询【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param id 【请填写功能名称】主键
|
||||||
|
* @return 【请填写功能名称】
|
||||||
|
*/
|
||||||
|
public EngineMaintenance selectEngineMaintenanceById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询【请填写功能名称】列表
|
||||||
|
*
|
||||||
|
* @param engineMaintenance 【请填写功能名称】
|
||||||
|
* @return 【请填写功能名称】集合
|
||||||
|
*/
|
||||||
|
public List<EngineMaintenance> selectEngineMaintenanceList(EngineMaintenance engineMaintenance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param engineMaintenance 【请填写功能名称】
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insertEngineMaintenance(EngineMaintenance engineMaintenance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param engineMaintenance 【请填写功能名称】
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateEngineMaintenance(EngineMaintenance engineMaintenance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的【请填写功能名称】主键集合
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteEngineMaintenanceByIds(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除【请填写功能名称】信息
|
||||||
|
*
|
||||||
|
* @param id 【请填写功能名称】主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteEngineMaintenanceById(Long id);
|
||||||
|
|
||||||
|
Result initializeRuleEngine(EngineMaintenance engineMaintenance);
|
||||||
|
|
||||||
|
Result testMethod(String code);
|
||||||
|
}
|
|
@ -0,0 +1,217 @@
|
||||||
|
package com.muyu.rule.engine.service.impl;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.common.core.utils.DateUtils;
|
||||||
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
|
import com.muyu.rule.engine.ClassLoading.CustomClassLoader;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import com.muyu.rule.engine.mapper.EngineMaintenanceMapper;
|
||||||
|
import com.muyu.rule.engine.domain.EngineMaintenance;
|
||||||
|
import com.muyu.rule.engine.service.IEngineMaintenanceService;
|
||||||
|
|
||||||
|
import javax.tools.JavaCompiler;
|
||||||
|
import javax.tools.StandardJavaFileManager;
|
||||||
|
import javax.tools.ToolProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【请填写功能名称】Service业务层处理
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-05-02
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Log4j2
|
||||||
|
public class EngineMaintenanceServiceImpl implements IEngineMaintenanceService
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private EngineMaintenanceMapper engineMaintenanceMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param id 【请填写功能名称】主键
|
||||||
|
* @return 【请填写功能名称】
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public EngineMaintenance selectEngineMaintenanceById(Long id)
|
||||||
|
{
|
||||||
|
return engineMaintenanceMapper.selectEngineMaintenanceById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询【请填写功能名称】列表
|
||||||
|
*
|
||||||
|
* @param engineMaintenance 【请填写功能名称】
|
||||||
|
* @return 【请填写功能名称】
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<EngineMaintenance> selectEngineMaintenanceList(EngineMaintenance engineMaintenance)
|
||||||
|
{
|
||||||
|
return engineMaintenanceMapper.selectEngineMaintenanceList(engineMaintenance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param engineMaintenance 【请填写功能名称】
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int insertEngineMaintenance(EngineMaintenance engineMaintenance)
|
||||||
|
{
|
||||||
|
String className = "Rule"+Character.toUpperCase(engineMaintenance.getCode().charAt(0)) + engineMaintenance.getCode().substring(1)+"Class";
|
||||||
|
engineMaintenance.setCreateTime(DateUtils.getNowDate());
|
||||||
|
engineMaintenance.setCreateBy(SecurityUtils.getUsername());
|
||||||
|
engineMaintenance.setCodeText("package com.muyu.rule.engine.domain;\n\n\n"+
|
||||||
|
"public class " + className + " {\n" +
|
||||||
|
"}");
|
||||||
|
return engineMaintenanceMapper.insertEngineMaintenance(engineMaintenance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param engineMaintenance 【请填写功能名称】
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int updateEngineMaintenance(EngineMaintenance engineMaintenance)
|
||||||
|
{
|
||||||
|
engineMaintenance.setUpdateTime(DateUtils.getNowDate());
|
||||||
|
engineMaintenance.setUpdateBy(SecurityUtils.getUsername());
|
||||||
|
return engineMaintenanceMapper.updateEngineMaintenance(engineMaintenance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的【请填写功能名称】主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int deleteEngineMaintenanceByIds(Long[] ids)
|
||||||
|
{
|
||||||
|
return engineMaintenanceMapper.deleteEngineMaintenanceByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除【请填写功能名称】信息
|
||||||
|
*
|
||||||
|
* @param id 【请填写功能名称】主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int deleteEngineMaintenanceById(Long id)
|
||||||
|
{
|
||||||
|
return engineMaintenanceMapper.deleteEngineMaintenanceById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result initializeRuleEngine(EngineMaintenance engineMaintenance) {
|
||||||
|
try {
|
||||||
|
//创建源文件
|
||||||
|
String className = "Rule"+Character.toUpperCase(engineMaintenance.getCode().charAt(0)) + engineMaintenance.getCode().substring(1)+"Class";
|
||||||
|
// 源文件路径和名称
|
||||||
|
String javaPath = "D:\\work\\2108A\\sxh\\muyu-modules\\muyu-rule-engine\\src\\main\\java\\com\\muyu\\rule\\engine\\domain\\";
|
||||||
|
|
||||||
|
String classPath = "D:\\work\\2108A\\sxh\\muyu-modules\\muyu-rule-engine\\target\\classes\\";
|
||||||
|
String filename = javaPath+className+".java";
|
||||||
|
File file = new File(filename);
|
||||||
|
// 确保源文件所在的目录存在
|
||||||
|
File fileParent = file.getParentFile();
|
||||||
|
|
||||||
|
if (!fileParent.exists()) {
|
||||||
|
fileParent.mkdir();
|
||||||
|
}
|
||||||
|
// 确保源文件存在,如果已存在则先删除再创建
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete(); // 删除存在的文件
|
||||||
|
}
|
||||||
|
file.createNewFile();
|
||||||
|
// 将源代码写入文件
|
||||||
|
FileWriter fw = new FileWriter(file);
|
||||||
|
fw.write(engineMaintenance.getCodeText());
|
||||||
|
fw.flush();
|
||||||
|
fw.close();
|
||||||
|
// 使用JavaCompiler 编译java文件
|
||||||
|
// 获取系统Java编译器
|
||||||
|
JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
|
||||||
|
// 获取标准文件管理器
|
||||||
|
StandardJavaFileManager fileManager = jc.getStandardFileManager(null, null, null);
|
||||||
|
// 获取要编译的文件对象
|
||||||
|
Iterable fileObjects = fileManager.getJavaFileObjects(filename);
|
||||||
|
// 设置编译选项,指定输出目录
|
||||||
|
List<String> options = Arrays.asList("-d", classPath);
|
||||||
|
// 创建编译任务
|
||||||
|
JavaCompiler.CompilationTask cTask = jc.getTask(null, fileManager, null, options, null, fileObjects);
|
||||||
|
// 执行编译任务
|
||||||
|
Boolean call = cTask.call();
|
||||||
|
// 关闭文件管理器
|
||||||
|
fileManager.close();
|
||||||
|
if (call){
|
||||||
|
return Result.success("初始化成功");
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.getMessage());
|
||||||
|
Result.error("初始化失败");
|
||||||
|
}
|
||||||
|
return Result.error("初始化失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result testMethod(String code) {
|
||||||
|
String className = "com.muyu.rule.engine.domain.Rule"+Character.toUpperCase(code.charAt(0)) + code.substring(1)+"Class";
|
||||||
|
String classPath = "D:\\work\\2108A\\sxh\\muyu-modules\\muyu-rule-engine\\target\\classes\\"+className.replace(".", "\\")+".class";
|
||||||
|
try {
|
||||||
|
// 读取类文件
|
||||||
|
byte[] classData = Files.readAllBytes(Paths.get(classPath));
|
||||||
|
CustomClassLoader customClassLoader = new CustomClassLoader();
|
||||||
|
Class<?> aClass = customClassLoader.defineClassFromBytes(className,classData);
|
||||||
|
// 实例化类
|
||||||
|
Object obj = aClass.newInstance();
|
||||||
|
//获取类中所有方法
|
||||||
|
Method[] methods = aClass.getDeclaredMethods();
|
||||||
|
for (Method method : methods) {
|
||||||
|
method.invoke(obj);
|
||||||
|
}
|
||||||
|
customClassLoader = null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
Result.error("测试失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.success("测试成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTypeCodeText(EngineMaintenance engineMaintenance) {
|
||||||
|
String className =Character.toUpperCase(engineMaintenance.getCode().charAt(0)) + engineMaintenance.getCode().substring(1);
|
||||||
|
switch (engineMaintenance.getType()) {
|
||||||
|
case "data-set":
|
||||||
|
className = className+"DataSetContext";
|
||||||
|
return "package com.muyu.rule.engine.domain;\n" +
|
||||||
|
"\n" +
|
||||||
|
"public class "+className+" {\n" +
|
||||||
|
"\n" +
|
||||||
|
" private final RecordContext recordContext;\n" +
|
||||||
|
"\n" +
|
||||||
|
" public DataSetContext (RecordContext recordContext) {\n" +
|
||||||
|
" this.recordContext = recordContext;\n" +
|
||||||
|
" }\n" +
|
||||||
|
"}\n";
|
||||||
|
case "data-record":
|
||||||
|
return "记录";
|
||||||
|
default:
|
||||||
|
return "数据字段";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
Spring Boot Version: ${spring-boot.version}
|
||||||
|
Spring Application Name: ${spring.application.name}
|
|
@ -0,0 +1,29 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 9211
|
||||||
|
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: muyu-ruleEngine
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 101.34.248.9:8848
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 101.34.248.9:8848
|
||||||
|
namespace: b9d88e07-8713-4ccd-8e98-d7c19f40fe74
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
com.muyu.rule.engine.mapper: DEBUG
|
|
@ -0,0 +1,74 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||||
|
<!-- 日志存放路径 -->
|
||||||
|
<property name="log.path" value="logs/muyu-system"/>
|
||||||
|
<!-- 日志输出格式 -->
|
||||||
|
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||||
|
|
||||||
|
<!-- 控制台输出 -->
|
||||||
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统日志输出 -->
|
||||||
|
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/info.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>INFO</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/error.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>ERROR</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统模块日志级别控制 -->
|
||||||
|
<logger name="com.muyu" level="info"/>
|
||||||
|
<!-- Spring日志级别控制 -->
|
||||||
|
<logger name="org.springframework" level="warn"/>
|
||||||
|
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="console"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
<!--系统操作日志-->
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="file_info"/>
|
||||||
|
<appender-ref ref="file_error"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
|
@ -0,0 +1,111 @@
|
||||||
|
<?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.rule.engine.mapper.EngineMaintenanceMapper">
|
||||||
|
|
||||||
|
<resultMap type="com.muyu.rule.engine.domain.EngineMaintenance" id="EngineMaintenanceResult">
|
||||||
|
<result property="id" column="id" />
|
||||||
|
<result property="name" column="name" />
|
||||||
|
<result property="type" column="type" />
|
||||||
|
<result property="isActivate" column="is_activate" />
|
||||||
|
<result property="status" column="status" />
|
||||||
|
<result property="description" column="description" />
|
||||||
|
<result property="code" column="code" />
|
||||||
|
<result property="level" column="level" />
|
||||||
|
<result property="codeText" column="code_text" />
|
||||||
|
<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="selectEngineMaintenanceVo">
|
||||||
|
select id, name, type, is_activate, status, description, code, level,code_text, remark, create_by, create_time, update_by, update_time from engine_maintenance
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectEngineMaintenanceList" parameterType="com.muyu.rule.engine.domain.EngineMaintenance" resultMap="EngineMaintenanceResult">
|
||||||
|
<include refid="selectEngineMaintenanceVo"/>
|
||||||
|
<where>
|
||||||
|
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
|
||||||
|
<if test="type != null and type != ''"> and type = #{type}</if>
|
||||||
|
<if test="isActivate != null and isActivate != ''"> and is_activate = #{isActivate}</if>
|
||||||
|
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||||
|
<if test="description != null and description != ''"> and description = #{description}</if>
|
||||||
|
<if test="code != null and code != ''"> and code = #{code}</if>
|
||||||
|
<if test="level != null and level != ''"> and level = #{level}</if>
|
||||||
|
<if test="codeText != null and codeText != ''"> and code_text = #{codeText}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectEngineMaintenanceById" parameterType="Long" resultMap="EngineMaintenanceResult">
|
||||||
|
<include refid="selectEngineMaintenanceVo"/>
|
||||||
|
where id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insertEngineMaintenance" parameterType="com.muyu.rule.engine.domain.EngineMaintenance" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into engine_maintenance
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="name != null">name,</if>
|
||||||
|
<if test="type != null">type,</if>
|
||||||
|
<if test="isActivate != null">is_activate,</if>
|
||||||
|
<if test="status != null">status,</if>
|
||||||
|
<if test="description != null">description,</if>
|
||||||
|
<if test="code != null">code,</if>
|
||||||
|
<if test="level != null">level,</if>
|
||||||
|
<if test="codeText != null">code_text,</if>
|
||||||
|
<if test="remark != null">remark,</if>
|
||||||
|
<if test="createBy != null and createBy != ''">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="name != null">#{name},</if>
|
||||||
|
<if test="type != null">#{type},</if>
|
||||||
|
<if test="isActivate != null">#{isActivate},</if>
|
||||||
|
<if test="status != null">#{status},</if>
|
||||||
|
<if test="description != null">#{description},</if>
|
||||||
|
<if test="code != null">#{code},</if>
|
||||||
|
<if test="level != null">#{level},</if>
|
||||||
|
<if test="codeText != null">#{codeText},</if>
|
||||||
|
<if test="remark != null">#{remark},</if>
|
||||||
|
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||||
|
<if test="createTime != null">#{createTime},</if>
|
||||||
|
<if test="updateBy != null">#{updateBy},</if>
|
||||||
|
<if test="updateTime != null">#{updateTime},</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateEngineMaintenance" parameterType="com.muyu.rule.engine.domain.EngineMaintenance">
|
||||||
|
update engine_maintenance
|
||||||
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
|
<if test="name != null">name = #{name},</if>
|
||||||
|
<if test="type != null">type = #{type},</if>
|
||||||
|
<if test="isActivate != null">is_activate = #{isActivate},</if>
|
||||||
|
<if test="status != null">status = #{status},</if>
|
||||||
|
<if test="description != null">description = #{description},</if>
|
||||||
|
<if test="code != null">code = #{code},</if>
|
||||||
|
<if test="level != null">level = #{level},</if>
|
||||||
|
<if test="codeText != null">code_text = #{codeText},</if>
|
||||||
|
<if test="remark != null">remark = #{remark},</if>
|
||||||
|
<if test="createBy != null and createBy != ''">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="deleteEngineMaintenanceById" parameterType="Long">
|
||||||
|
delete from engine_maintenance where id = #{id}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteEngineMaintenanceByIds" parameterType="String">
|
||||||
|
delete from engine_maintenance where id in
|
||||||
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue