feat():个人理解创建4个模块代码的引擎库
parent
8a33e76f51
commit
d4ac304b07
|
@ -0,0 +1,98 @@
|
|||
package com.muyu.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;
|
||||
|
||||
/**
|
||||
* 规则引擎代码对象 scope
|
||||
*
|
||||
* @author Saisai
|
||||
* @date 2024-05-03
|
||||
*/
|
||||
public class Scope extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键 */
|
||||
private Long id;
|
||||
|
||||
/** 引擎id */
|
||||
@Excel(name = "引擎id")
|
||||
private Long ruleEnginId;
|
||||
|
||||
/** 类型 */
|
||||
@Excel(name = "类型")
|
||||
private String type;
|
||||
|
||||
/** 类型值 */
|
||||
@Excel(name = "类型值")
|
||||
private String value;
|
||||
|
||||
/** 编码 */
|
||||
@Excel(name = "编码")
|
||||
private String code;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
public void setRuleEnginId(Long ruleEnginId)
|
||||
{
|
||||
this.ruleEnginId = ruleEnginId;
|
||||
}
|
||||
|
||||
public Long getRuleEnginId()
|
||||
{
|
||||
return ruleEnginId;
|
||||
}
|
||||
public void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
public void setValue(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
public void setCode(String code)
|
||||
{
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("ruleEnginId", getRuleEnginId())
|
||||
.append("type", getType())
|
||||
.append("value", getValue())
|
||||
.append("code", getCode())
|
||||
.append("remark", getRemark())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu;
|
||||
|
||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* @ClassName RuleEngineApplication
|
||||
* @Description 描述
|
||||
* @Author SaiSai.Liu
|
||||
* @Date 2024/5/3 11:43
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class RuleEngineApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RuleEngineApplication.class);
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@ import com.muyu.engine.service.RuleEngineService;
|
|||
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;
|
||||
|
||||
|
@ -95,4 +96,17 @@ public class RuleEngineController extends BaseController
|
|||
{
|
||||
return toAjax(ruleEngineService.deleteRuleEngineByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试引擎流程
|
||||
*/
|
||||
@RequiresPermissions("engine:engine:testRuleEngine")
|
||||
@Log(title = "规则引擎", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("testRuleEngine/{id}")
|
||||
public Result testRuleEngine(@PathVariable Long id) throws ServletException {
|
||||
return toAjax(ruleEngineService.testRuleEngine(id));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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.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);
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.muyu.engine.service;
|
|||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.engine.domain.RuleEngine;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -60,4 +61,11 @@ public interface RuleEngineService extends IService<RuleEngine>
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteRuleEngineById(Long id);
|
||||
|
||||
/**
|
||||
* 测试引擎流程
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
boolean testRuleEngine(Long id) throws ServletException;
|
||||
}
|
||||
|
|
|
@ -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.Scope;
|
||||
|
||||
/**
|
||||
* 规则引擎代码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);
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.engine.service.impl;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.common.base.Supplier;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
import com.muyu.engine.domain.RuleEngine;
|
||||
|
@ -9,7 +10,10 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* 规则引擎Service业务层处理
|
||||
|
@ -97,4 +101,33 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper,RuleEngi
|
|||
{
|
||||
return ruleEngineMapper.deleteRuleEngineById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 引擎流程并执行测试
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean testRuleEngine(Long id) throws ServletException {
|
||||
RuleEngine ruleEngine = this.getById(id);
|
||||
if (ruleEngine.getIsActivate().contains("no"))throw new ServletException("未激活");
|
||||
if (ruleEngine.getStatus().contains("0"))throw new ServletException("已停用");
|
||||
Supplier<Boolean> booleanSupplier = () -> {
|
||||
try {
|
||||
return testEngine(ruleEngine).booleanValue();
|
||||
} catch (ServletException e) {
|
||||
log.error(e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
System.out.println();
|
||||
return booleanSupplier.get();
|
||||
}
|
||||
|
||||
private Boolean testEngine(RuleEngine ruleEngine) throws ServletException {
|
||||
|
||||
// new File(ruleEngine);
|
||||
// if (false)throw new ServletException("不存在");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
package com.muyu.engine.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 规则引擎代码Service业务层处理
|
||||
*
|
||||
* @author Saisai
|
||||
* @date 2024-05-03
|
||||
*/
|
||||
@Service
|
||||
@Log4j2
|
||||
public class ScopeServiceImpl extends ServiceImpl<ScopeMapper,Scope> implements ScopeService
|
||||
{
|
||||
@Autowired
|
||||
private ScopeMapper scopeMapper;
|
||||
|
||||
/**
|
||||
* 查询规则引擎代码
|
||||
*
|
||||
* @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());
|
||||
return scopeMapper.updateScope(scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除规则引擎代码
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
<?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="ruleEnginId" column="ruleEnginId" />
|
||||
<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, ruleEnginId, 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="ruleEnginId != null "> and ruleEnginId = #{ruleEnginId}</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="ruleEnginId != null">ruleEnginId,</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="ruleEnginId != null">#{ruleEnginId},</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="ruleEnginId != null">ruleEnginId = #{ruleEnginId},</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>
|
Loading…
Reference in New Issue