feat():个人理解创建4个模块代码的引擎库

master
Saisai Liu 2024-05-03 19:49:45 +08:00
parent 8a33e76f51
commit d4ac304b07
9 changed files with 496 additions and 0 deletions

View File

@ -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();
}
}

View File

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

View File

@ -12,6 +12,7 @@ import com.muyu.engine.service.RuleEngineService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
@ -95,4 +96,17 @@ public class RuleEngineController extends BaseController
{ {
return toAjax(ruleEngineService.deleteRuleEngineByIds(ids)); 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));
}
} }

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.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

@ -3,6 +3,7 @@ package com.muyu.engine.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.engine.domain.RuleEngine; import com.muyu.engine.domain.RuleEngine;
import javax.servlet.ServletException;
import java.util.List; import java.util.List;
/** /**
@ -60,4 +61,11 @@ public interface RuleEngineService extends IService<RuleEngine>
* @return * @return
*/ */
public int deleteRuleEngineById(Long id); public int deleteRuleEngineById(Long id);
/**
*
* @param id
* @return
*/
boolean testRuleEngine(Long id) throws ServletException;
} }

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.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);
}

View File

@ -1,5 +1,6 @@
package com.muyu.engine.service.impl; 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.DateUtils; import com.muyu.common.core.utils.DateUtils;
import com.muyu.engine.domain.RuleEngine; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.ServletException;
import java.io.File;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable;
/** /**
* Service * Service
@ -97,4 +101,33 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper,RuleEngi
{ {
return ruleEngineMapper.deleteRuleEngineById(id); 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;
}
} }

View File

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

View File

@ -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>