支持规则块配置方式
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.fibo.ddp.common.dao.strategyx.guiderule;
|
||||
|
||||
import com.fibo.ddp.common.model.strategyx.guiderule.RuleBlock;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 规则块配置表(RuleBlock)表数据库访问层
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-08-05 10:32:11
|
||||
*/
|
||||
@Mapper
|
||||
public interface RuleBlockMapper extends BaseMapper<RuleBlock>{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?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.fibo.ddp.common.dao.strategyx.guiderule.RuleBlockMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -12,23 +12,16 @@
|
||||
<result property="author" column="author" jdbcType="INTEGER"/>
|
||||
<result property="userId" column="user_id" jdbcType="INTEGER"/>
|
||||
<result property="organId" column="organ_id" jdbcType="INTEGER"/>
|
||||
<result property="engineId" column="engine_id" jdbcType="INTEGER"/>
|
||||
<result property="status" column="status" jdbcType="INTEGER"/>
|
||||
<result property="type" column="type" jdbcType="INTEGER"/>
|
||||
<result property="isNon" column="is_non" jdbcType="INTEGER"/>
|
||||
<result property="content" column="content" jdbcType="VARCHAR"/>
|
||||
<result property="created" column="created" jdbcType="TIMESTAMP"/>
|
||||
<result property="updated" column="updated" jdbcType="TIMESTAMP"/>
|
||||
<result property="ruleType" column="rule_type" jdbcType="INTEGER"/>
|
||||
<result property="ruleAudit" column="rule_audit" jdbcType="INTEGER"/>
|
||||
<result property="score" column="score" jdbcType="INTEGER"/>
|
||||
<result property="difficulty" column="difficulty" jdbcType="INTEGER"/>
|
||||
<result property="scriptType" column="script_type" jdbcType="VARCHAR"/>
|
||||
<result property="lastLogical" column="last_logical" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_column">
|
||||
id, name, code, description, priority, parent_id, author, user_id, organ_id, engine_id, status, type, is_non, content, created, updated, rule_type, rule_audit, score, last_logical,difficulty,script_type,result_field_en,score_field_en
|
||||
id, name, code, description, priority, parent_id, author, user_id, organ_id, status, type, created, updated,difficulty,script_type
|
||||
</sql>
|
||||
<!--查询单个-->
|
||||
<select id="queryById" resultMap="RuleMap">
|
||||
@@ -76,9 +69,6 @@
|
||||
<if test="organId != null">
|
||||
and organ_id = #{organId}
|
||||
</if>
|
||||
<if test="engineId != null">
|
||||
and engine_id = #{engineId}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
and status = #{status}
|
||||
</if>
|
||||
@@ -88,30 +78,12 @@
|
||||
<if test="type != null">
|
||||
and `type` = #{type}
|
||||
</if>
|
||||
<if test="isNon != null">
|
||||
and is_non = #{isNon}
|
||||
</if>
|
||||
<if test="content != null and content != ''">
|
||||
and content = #{content}
|
||||
</if>
|
||||
<if test="created != null">
|
||||
and created >= #{created}
|
||||
</if>
|
||||
<if test="updated != null">
|
||||
and updated >= #{updated}
|
||||
</if>
|
||||
<if test="ruleType != null">
|
||||
and rule_type = #{ruleType}
|
||||
</if>
|
||||
<if test="ruleAudit != null">
|
||||
and rule_audit = #{ruleAudit}
|
||||
</if>
|
||||
<if test="score != null">
|
||||
and score = #{score}
|
||||
</if>
|
||||
<if test="lastLogical != null and lastLogical != ''">
|
||||
and last_logical = #{lastLogical}
|
||||
</if>
|
||||
<if test="difficulty != null">
|
||||
and difficulty = #{difficulty}
|
||||
</if>
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.fibo.ddp.common.model.strategyx.guiderule;
|
||||
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 规则块配置表(RuleBlock)实体类
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-08-05 10:32:12
|
||||
*/
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("t_rule_block")
|
||||
public class RuleBlock implements Serializable {
|
||||
private static final long serialVersionUID = 153524790651348062L;
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
/**
|
||||
* 主键:规则块id
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 规则id
|
||||
*/
|
||||
private Long ruleId;
|
||||
/**
|
||||
* 规则版本的id
|
||||
*/
|
||||
private Long versionId;
|
||||
/**
|
||||
* 存放执行结果的变量
|
||||
*/
|
||||
private String resultFieldEn;
|
||||
/**
|
||||
* 规则分数
|
||||
*/
|
||||
private Integer score;
|
||||
/**
|
||||
* 存放得分的变量
|
||||
*/
|
||||
private String scoreFieldEn;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ public class RuleConditionInfo
|
||||
|
||||
private Long versionId;//规则版本的id
|
||||
|
||||
private Long blockId;//规则块的id
|
||||
|
||||
private Long parentId;//父节点的id
|
||||
|
||||
private Integer conditionType;//规则节点的类型:1-关系节点,2-表达式节点
|
||||
|
||||
@@ -43,35 +43,18 @@ public class RuleInfo implements Serializable {
|
||||
|
||||
private Long organId;//组织id
|
||||
|
||||
private Integer engineId;
|
||||
|
||||
private Integer status;//状态 0 :停用 ,1 : 启用,-1:删除
|
||||
|
||||
private Integer type;//规则类型 0 : 系统的规则 1:组织的规则 2: 引擎的规则
|
||||
|
||||
private Integer isNon;//逻辑关系“非”,0:否 ,1:是
|
||||
|
||||
private String content;//规则具体内容
|
||||
|
||||
private Date created;
|
||||
|
||||
private Date updated;
|
||||
|
||||
private Integer ruleType;//0硬性拒绝规则1加减分规则
|
||||
|
||||
private Integer ruleAudit;
|
||||
|
||||
private Integer score;//得分
|
||||
|
||||
private String lastLogical;//逻辑关系符
|
||||
|
||||
private Integer difficulty;//规则难度:1-简单规则,2复杂规则
|
||||
|
||||
private String scriptType;//脚本类型python,js,groovy
|
||||
|
||||
private String resultFieldEn;//存放是否命中的字段
|
||||
|
||||
private String scoreFieldEn;//存放得分的字段en
|
||||
@TableField(exist = false)
|
||||
private String authorName;//创建人名称,需要去其他表查询
|
||||
@TableField(exist = false)
|
||||
|
||||
@@ -37,18 +37,18 @@ public class RuleVersion implements Serializable {
|
||||
* 状态:-1 删除 0停用 1启用
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 规则结果en(命中情况)
|
||||
*/
|
||||
private String resultFieldEn;
|
||||
/**
|
||||
* 规则得分
|
||||
*/
|
||||
private Integer score;
|
||||
/**
|
||||
* 规则得分的en
|
||||
*/
|
||||
private String scoreFieldEn;
|
||||
// /**
|
||||
// * 规则结果en(命中情况)
|
||||
// */
|
||||
// private String resultFieldEn;
|
||||
// /**
|
||||
// * 规则得分
|
||||
// */
|
||||
// private Integer score;
|
||||
// /**
|
||||
// * 规则得分的en
|
||||
// */
|
||||
// private String scoreFieldEn;
|
||||
/**
|
||||
* 组织id
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.fibo.ddp.common.model.strategyx.guiderule.vo;
|
||||
|
||||
import com.fibo.ddp.common.model.strategyx.guiderule.RuleBlock;
|
||||
import com.fibo.ddp.common.model.strategyx.strategyout.StrategyOutput;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors
|
||||
public class RuleBlockVo extends RuleBlock {
|
||||
|
||||
private RuleConditionVo ruleConditionVo;//规则对应的结点树
|
||||
|
||||
private List<StrategyOutput> strategyOutputList;//输出字段
|
||||
|
||||
private List<StrategyOutput> failOutputList;//失败输出字段
|
||||
}
|
||||
@@ -12,9 +12,11 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class RuleVersionVo extends RuleVersion {
|
||||
private RuleConditionVo ruleConditionVo;//规则对应的结点树
|
||||
// private RuleConditionVo ruleConditionVo;//规则对应的结点树
|
||||
//
|
||||
// private List<StrategyOutput> strategyOutputList;//输出字段
|
||||
//
|
||||
// private List<StrategyOutput> failOutputList;//失败输出字段
|
||||
|
||||
private List<StrategyOutput> strategyOutputList;//输出字段
|
||||
|
||||
private List<StrategyOutput> failOutputList;//失败输出字段
|
||||
private List<RuleBlockVo> ruleBlockVoList;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.fibo.ddp.common.model.strategyx.guiderule.vo;
|
||||
|
||||
import com.fibo.ddp.common.model.strategyx.guiderule.RuleInfo;
|
||||
import com.fibo.ddp.common.model.strategyx.scriptrule.RuleScriptVersion;
|
||||
import com.fibo.ddp.common.model.strategyx.strategyout.StrategyOutput;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -16,9 +15,9 @@ import java.util.List;
|
||||
@Accessors
|
||||
public class RuleVo extends RuleInfo {
|
||||
|
||||
private RuleConditionVo ruleConditionVo;//规则对应的结点树
|
||||
|
||||
private List<StrategyOutput> strategyOutputList;//输出字段
|
||||
// private RuleConditionVo ruleConditionVo;//规则对应的结点树
|
||||
//
|
||||
// private List<StrategyOutput> strategyOutputList;//输出字段
|
||||
|
||||
private List<RuleVersionVo> ruleVersionList;//规则版本列表
|
||||
// private List<T> ruleVersionList;//规则版本列表
|
||||
|
||||
@@ -598,7 +598,6 @@ public class EngineNodeServiceImpl extends ServiceImpl<EngineNodeMapper, EngineN
|
||||
case 3:
|
||||
scriptRuleVersionIds.add(ruleVersionId);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
List<RuleSetNodeResultParam> ruleSetNodeResultParams = new ArrayList<>();
|
||||
@@ -610,9 +609,9 @@ public class EngineNodeServiceImpl extends ServiceImpl<EngineNodeMapper, EngineN
|
||||
for (RuleInfo rule : ruleList) {
|
||||
ruleMap.put(rule.getId(),rule);
|
||||
if (rule.getDifficulty()==null||rule.getDifficulty()==1){
|
||||
String resultEn = rule.getResultFieldEn();
|
||||
String scoreEn = rule.getScoreFieldEn();
|
||||
ruleSetNodeResultParams.add(new RuleSetNodeResultParam(rule.getId(),1,null,resultEn,scoreEn,rule.getCode(),rule.getName()));
|
||||
// String resultEn = rule.getResultFieldEn();
|
||||
// String scoreEn = rule.getScoreFieldEn();
|
||||
// ruleSetNodeResultParams.add(new RuleSetNodeResultParam(rule.getId(),1,null,resultEn,scoreEn,rule.getCode(),rule.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -622,10 +621,10 @@ public class EngineNodeServiceImpl extends ServiceImpl<EngineNodeMapper, EngineN
|
||||
List<RuleVersion> ruleVersionList = ruleVersionService.listByIds(complexRuleVersionIds);
|
||||
if (CollectionUtils.isNotEmpty(ruleVersionList)){
|
||||
for (RuleVersion ruleVersion : ruleVersionList) {
|
||||
String resultEn = ruleVersion.getResultFieldEn();
|
||||
String scoreEn = ruleVersion.getScoreFieldEn();
|
||||
RuleInfo rule = ruleMap.get(ruleVersion.getRuleId());
|
||||
ruleSetNodeResultParams.add(new RuleSetNodeResultParam(ruleVersion.getRuleId(),2,ruleVersion.getId(),resultEn,scoreEn,rule.getCode(),rule.getName()));
|
||||
// String resultEn = ruleVersion.getResultFieldEn();
|
||||
// String scoreEn = ruleVersion.getScoreFieldEn();
|
||||
// RuleInfo rule = ruleMap.get(ruleVersion.getRuleId());
|
||||
// ruleSetNodeResultParams.add(new RuleSetNodeResultParam(ruleVersion.getRuleId(),2,ruleVersion.getId(),resultEn,scoreEn,rule.getCode(),rule.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.fibo.ddp.common.service.strategyx.guiderule;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.strategyx.guiderule.RuleBlock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 规则块配置表(RuleBlock)表服务接口
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-08-05 10:32:22
|
||||
*/
|
||||
public interface RuleBlockService extends IService<RuleBlock> {
|
||||
|
||||
List<RuleBlock> listObjectsByVersionId(Long versionId);
|
||||
|
||||
boolean removeObjects(Long ruleId, Long versionId);
|
||||
}
|
||||
@@ -16,9 +16,9 @@ public interface RuleConditionService extends IService<RuleConditionInfo> {
|
||||
* @param ruleConditionVo 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
RuleConditionVo insertRuleCondition(RuleConditionVo ruleConditionVo, Long ruleId);
|
||||
RuleConditionVo insertRuleCondition(RuleConditionVo ruleConditionVo, Long ruleId, Long blockId);
|
||||
|
||||
RuleConditionVo updateRuleCondition(Long ruleId, RuleConditionVo ruleConditionVo);
|
||||
RuleConditionVo updateRuleCondition(Long ruleId, Long blockId, RuleConditionVo ruleConditionVo);
|
||||
|
||||
boolean deleteRuleCondition(Long ruleId, Long versionId);
|
||||
|
||||
@@ -28,7 +28,7 @@ public interface RuleConditionService extends IService<RuleConditionInfo> {
|
||||
List<RuleConditionInfo> disassemble(RuleConditionVo vo, Long ruleId, boolean needTempId);
|
||||
|
||||
// runner
|
||||
RuleConditionVo queryByVersionId(Long versionId);
|
||||
RuleConditionVo queryByBlockId(Long blockId);
|
||||
|
||||
List<String> queryFieldEnByVersionIds(List<Long> versionIds);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.fibo.ddp.common.service.strategyx.guiderule.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.strategyx.guiderule.RuleBlockMapper;
|
||||
import com.fibo.ddp.common.model.strategyx.guiderule.RuleBlock;
|
||||
import com.fibo.ddp.common.service.strategyx.guiderule.RuleBlockService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 规则块配置表(RuleBlock)表服务实现类
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-08-05 10:32:25
|
||||
*/
|
||||
@Service
|
||||
public class RuleBlockServiceImpl extends ServiceImpl<RuleBlockMapper, RuleBlock> implements RuleBlockService {
|
||||
|
||||
@Override
|
||||
public List<RuleBlock> listObjectsByVersionId(Long versionId) {
|
||||
LambdaQueryWrapper<RuleBlock> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(RuleBlock::getVersionId, versionId);
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeObjects(Long ruleId, Long versionId) {
|
||||
LambdaQueryWrapper<RuleBlock> queryWrapper = new LambdaQueryWrapper();
|
||||
queryWrapper.eq(RuleBlock::getRuleId, ruleId);
|
||||
queryWrapper.eq(RuleBlock::getVersionId, versionId);
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
}
|
||||
@@ -68,22 +68,15 @@ public class RuleConditionServiceImpl extends ServiceImpl<RuleConditionInfoMappe
|
||||
// }
|
||||
|
||||
@Override
|
||||
public RuleConditionVo queryByVersionId(Long versionId) {
|
||||
if (versionId == null) {
|
||||
public RuleConditionVo queryByBlockId(Long blockId) {
|
||||
if (blockId == null) {
|
||||
return null;
|
||||
}
|
||||
//构造查询条件,查询条件列表
|
||||
RuleConditionVo result = null;
|
||||
|
||||
List<RuleConditionInfo> ruleConditionInfoList = null;
|
||||
if(Constants.switchFlag.ON.equals(cacheSwitch)){
|
||||
String key = RedisUtils.getForeignKey(TableEnum.T_RULE_CONDITION, versionId);
|
||||
ruleConditionInfoList = redisManager.getByForeignKey(key, RuleConditionInfo.class);
|
||||
} else {
|
||||
LambdaQueryWrapper<RuleConditionInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(RuleConditionInfo::getVersionId, versionId);
|
||||
ruleConditionInfoList = ruleConditionInfoMapper.selectList(queryWrapper);
|
||||
}
|
||||
LambdaQueryWrapper<RuleConditionInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(RuleConditionInfo::getBlockId, blockId);
|
||||
List<RuleConditionInfo> ruleConditionInfoList = this.list(queryWrapper);
|
||||
|
||||
//组装为需要的树形结构
|
||||
if (ruleConditionInfoList != null) {
|
||||
@@ -100,7 +93,7 @@ public class RuleConditionServiceImpl extends ServiceImpl<RuleConditionInfoMappe
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public RuleConditionVo insertRuleCondition(RuleConditionVo ruleConditionVo, Long ruleId) {
|
||||
public RuleConditionVo insertRuleCondition(RuleConditionVo ruleConditionVo, Long ruleId, Long blockId) {
|
||||
if (ruleConditionVo == null || ruleId == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -113,6 +106,7 @@ public class RuleConditionServiceImpl extends ServiceImpl<RuleConditionInfoMappe
|
||||
List<RuleConditionInfo> list = this.disassemble(ruleConditionVo, ruleId, true);
|
||||
for (RuleConditionInfo info : list) {
|
||||
info.setVersionId(versionId);
|
||||
info.setBlockId(blockId);
|
||||
}
|
||||
//找出唯一根节点
|
||||
RuleConditionInfo root = null;
|
||||
@@ -138,19 +132,13 @@ public class RuleConditionServiceImpl extends ServiceImpl<RuleConditionInfoMappe
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public RuleConditionVo updateRuleCondition(Long ruleId, RuleConditionVo ruleConditionVo) {
|
||||
public RuleConditionVo updateRuleCondition(Long ruleId, Long blockId, RuleConditionVo ruleConditionVo) {
|
||||
if (ruleId == null) {
|
||||
return null;
|
||||
}
|
||||
//删除一个规则下的所有条件
|
||||
boolean delete = this.deleteRuleCondition(ruleId,ruleConditionVo.getVersionId());
|
||||
RuleConditionVo ruleCondition = null;
|
||||
if (!delete) {
|
||||
ruleCondition = this.queryByVersionId(ruleConditionVo.getVersionId());
|
||||
}
|
||||
//插入条件树
|
||||
if ((delete || ruleCondition == null) && ruleConditionVo != null) {
|
||||
RuleConditionVo insertResult = this.insertRuleCondition(ruleConditionVo, ruleId);
|
||||
if (ruleConditionVo != null) {
|
||||
RuleConditionVo insertResult = this.insertRuleCondition(ruleConditionVo, ruleId, blockId);
|
||||
return insertResult;
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -119,7 +119,6 @@ public class RuleServiceImpl extends ServiceImpl<RuleInfoMapper, RuleInfo> imple
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public RuleVo insertRuleInfo(RuleVo vo) {
|
||||
@@ -268,21 +267,6 @@ public class RuleServiceImpl extends ServiceImpl<RuleInfoMapper, RuleInfo> imple
|
||||
//加入状态信息
|
||||
vo.setType(RuleConst.TYPE_ORGAN);
|
||||
vo.setStatus(RuleConst.STATUS_ENABLED);
|
||||
//加入规则类型
|
||||
if (vo == null || vo.getRuleAudit() == null) {
|
||||
throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(), ErrorCodeEnum.PARAMS_EXCEPTION.getMessage());
|
||||
}
|
||||
switch (vo.getRuleAudit()) {
|
||||
case RuleConst.RULE_AUDIT_TERMINATION:
|
||||
vo.setRuleType(RuleConst.RULE_TYPE_TERMINATION);
|
||||
break;
|
||||
case RuleConst.RULE_AUDIT_SCORING:
|
||||
vo.setRuleType(RuleConst.RULE_TYPE_SCORING);
|
||||
break;
|
||||
default:
|
||||
vo.setRuleType(RuleConst.RULE_TYPE_TERMINATION);
|
||||
}
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,14 +9,17 @@ import com.fibo.ddp.common.dao.datax.datamanage.FieldMapper;
|
||||
import com.fibo.ddp.common.dao.strategyx.guiderule.RuleVersionMapper;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.model.common.requestParam.StatusParam;
|
||||
import com.fibo.ddp.common.model.strategyx.guiderule.RuleBlock;
|
||||
import com.fibo.ddp.common.model.strategyx.guiderule.RuleConditionInfo;
|
||||
import com.fibo.ddp.common.model.strategyx.guiderule.RuleVersion;
|
||||
import com.fibo.ddp.common.model.strategyx.guiderule.vo.RuleBlockVo;
|
||||
import com.fibo.ddp.common.model.strategyx.guiderule.vo.RuleConditionVo;
|
||||
import com.fibo.ddp.common.model.strategyx.guiderule.vo.RuleVersionVo;
|
||||
import com.fibo.ddp.common.model.strategyx.strategyout.StrategyOutput;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.service.redis.RedisManager;
|
||||
import com.fibo.ddp.common.service.redis.RedisUtils;
|
||||
import com.fibo.ddp.common.service.strategyx.guiderule.RuleBlockService;
|
||||
import com.fibo.ddp.common.service.strategyx.guiderule.RuleConditionService;
|
||||
import com.fibo.ddp.common.service.strategyx.guiderule.RuleVersionService;
|
||||
import com.fibo.ddp.common.service.strategyx.strategyout.StrategyOutputService;
|
||||
@@ -43,6 +46,8 @@ public class RuleVersionServiceImpl extends ServiceImpl<RuleVersionMapper, RuleV
|
||||
@Autowired
|
||||
private RuleVersionMapper versionMapper;
|
||||
@Autowired
|
||||
private RuleBlockService ruleBlockService;
|
||||
@Autowired
|
||||
private RuleConditionService conditionService;
|
||||
@Autowired
|
||||
private StrategyOutputService outputService;
|
||||
@@ -88,13 +93,23 @@ public class RuleVersionServiceImpl extends ServiceImpl<RuleVersionMapper, RuleV
|
||||
return result;
|
||||
}
|
||||
BeanUtils.copyProperties(ruleVersion, result);
|
||||
//查询ruleCondition组装成树形结构
|
||||
RuleConditionVo ruleConditionVo = conditionService.queryByVersionId(id);
|
||||
List<StrategyOutput> strategyOutputList = outputService.queryByTactics(new StrategyOutput(id, StrategyType.COMPLEX_RULE, StrategyType.OutType.SUCCESS_OUT));
|
||||
List<StrategyOutput> failOutputList = outputService.queryByTactics(new StrategyOutput(id, StrategyType.COMPLEX_RULE, StrategyType.OutType.FAIL_OUT));
|
||||
result.setRuleConditionVo(ruleConditionVo);
|
||||
result.setStrategyOutputList(strategyOutputList);
|
||||
result.setFailOutputList(failOutputList);
|
||||
|
||||
List<RuleBlock> ruleBlockList = ruleBlockService.listObjectsByVersionId(id);
|
||||
List<RuleBlockVo> ruleBlockVoList = new ArrayList<>();
|
||||
for(RuleBlock ruleBlock : ruleBlockList){
|
||||
RuleBlockVo ruleBlockVo = new RuleBlockVo();
|
||||
BeanUtils.copyProperties(ruleBlock, ruleBlockVo);
|
||||
//查询ruleCondition组装成树形结构
|
||||
RuleConditionVo ruleConditionVo = conditionService.queryByBlockId(ruleBlock.getId());
|
||||
List<StrategyOutput> strategyOutputList = outputService.queryByTactics(new StrategyOutput(ruleBlock.getId(), StrategyType.COMPLEX_RULE, StrategyType.OutType.SUCCESS_OUT));
|
||||
List<StrategyOutput> failOutputList = outputService.queryByTactics(new StrategyOutput(ruleBlock.getId(), StrategyType.COMPLEX_RULE, StrategyType.OutType.FAIL_OUT));
|
||||
ruleBlockVo.setRuleConditionVo(ruleConditionVo);
|
||||
ruleBlockVo.setStrategyOutputList(strategyOutputList);
|
||||
ruleBlockVo.setFailOutputList(failOutputList);
|
||||
ruleBlockVoList.add(ruleBlockVo);
|
||||
}
|
||||
result.setRuleBlockVoList(ruleBlockVoList);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -132,31 +147,33 @@ public class RuleVersionServiceImpl extends ServiceImpl<RuleVersionMapper, RuleV
|
||||
|
||||
@Override
|
||||
public List<String> queryFieldEnByVersionId(Long versionId) {
|
||||
Set<String> fieldEns= new HashSet<>();
|
||||
Set<Long> fieldIds= new HashSet<>();
|
||||
RuleConditionVo ruleConditionVo = conditionService.queryByVersionId(versionId);
|
||||
List<RuleConditionInfo> ruleConditionInfoList = conditionService.disassemble(ruleConditionVo, versionId, false);
|
||||
for (RuleConditionInfo info : ruleConditionInfoList) {
|
||||
if (info.getFieldEn()!=null&&info.getFieldType()!=1&&!info.getFieldEn().startsWith("%")){
|
||||
if (info.getFieldEn().contains(".")){
|
||||
fieldEns.add(info.getFieldEn().split("\\.")[0]);
|
||||
Set<String> fieldEns = new HashSet<>();
|
||||
Set<Long> fieldIds = new HashSet<>();
|
||||
List<RuleBlock> ruleBlockList = ruleBlockService.listObjectsByVersionId(versionId);
|
||||
for (RuleBlock ruleBlock : ruleBlockList) {
|
||||
RuleConditionVo ruleConditionVo = conditionService.queryByBlockId(ruleBlock.getId());
|
||||
List<RuleConditionInfo> ruleConditionInfoList = conditionService.disassemble(ruleConditionVo, ruleBlock.getRuleId(), false);
|
||||
for (RuleConditionInfo info : ruleConditionInfoList) {
|
||||
if (info.getFieldEn() != null && info.getFieldType() != 1 && !info.getFieldEn().startsWith("%")) {
|
||||
if (info.getFieldEn().contains(".")) {
|
||||
fieldEns.add(info.getFieldEn().split("\\.")[0]);
|
||||
} else {
|
||||
fieldEns.add(info.getFieldEn());
|
||||
}
|
||||
} else if (info.getFieldId() != null) {
|
||||
fieldIds.add(info.getFieldId());
|
||||
}
|
||||
else {
|
||||
fieldEns.add(info.getFieldEn());
|
||||
}
|
||||
}else if(info.getFieldId()!=null){
|
||||
fieldIds.add(info.getFieldId());
|
||||
}
|
||||
if (info.getVariableType()!=null){
|
||||
if (info.getVariableType()==2&&info.getFieldValue()!=null&&!info.getFieldValue().contains("%")){
|
||||
fieldEns.add(info.getFieldValue());
|
||||
}else if (info.getVariableType()==3){
|
||||
fieldEns.addAll(CustomValueUtils.getFieldEnSet(info.getFieldValue()));
|
||||
if (info.getVariableType() != null) {
|
||||
if (info.getVariableType() == 2 && info.getFieldValue() != null && !info.getFieldValue().contains("%")) {
|
||||
fieldEns.add(info.getFieldValue());
|
||||
} else if (info.getVariableType() == 3) {
|
||||
fieldEns.addAll(CustomValueUtils.getFieldEnSet(info.getFieldValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Long fieldId : fieldIds) {
|
||||
String fieldName= fieldMapper.findFieldNameById(fieldId);
|
||||
String fieldName = fieldMapper.findFieldNameById(fieldId);
|
||||
fieldEns.add(fieldName);
|
||||
}
|
||||
return new ArrayList<>(fieldEns);
|
||||
@@ -201,21 +218,33 @@ public class RuleVersionServiceImpl extends ServiceImpl<RuleVersionMapper, RuleV
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean addVersionDetail(RuleVersionVo version){
|
||||
RuleConditionVo ruleConditionVo = version.getRuleConditionVo();
|
||||
ruleConditionVo.setVersionId(version.getId());
|
||||
//添加条件信息
|
||||
conditionService.insertRuleCondition(ruleConditionVo,version.getRuleId());
|
||||
//添加输出字段
|
||||
List<StrategyOutput> strategyOutputList = version.getStrategyOutputList();
|
||||
if (strategyOutputList !=null&& strategyOutputList.size()>0){
|
||||
outputService.insertTacticsOutput(version.getId(), strategyOutputList);
|
||||
}
|
||||
List<StrategyOutput> failOutputList = version.getFailOutputList();
|
||||
if (failOutputList!=null&&failOutputList.size()>0){
|
||||
outputService.insertTacticsOutput(version.getId(),failOutputList );
|
||||
List<RuleBlockVo> ruleBlockVoList = version.getRuleBlockVoList();
|
||||
for (RuleBlockVo ruleBlockVo : ruleBlockVoList){
|
||||
RuleBlock ruleBlock = new RuleBlock();
|
||||
BeanUtils.copyProperties(ruleBlockVo, ruleBlock);
|
||||
ruleBlock.setRuleId(version.getRuleId());
|
||||
ruleBlock.setVersionId(version.getId());
|
||||
ruleBlockService.save(ruleBlock);
|
||||
|
||||
RuleConditionVo ruleConditionVo = ruleBlockVo.getRuleConditionVo();
|
||||
ruleConditionVo.setVersionId(version.getId());
|
||||
ruleConditionVo.setBlockId(ruleBlock.getId());
|
||||
//添加条件信息
|
||||
conditionService.insertRuleCondition(ruleConditionVo,version.getRuleId(), ruleBlock.getId());
|
||||
//添加输出字段
|
||||
List<StrategyOutput> strategyOutputList = ruleBlockVo.getStrategyOutputList();
|
||||
if (strategyOutputList !=null&& strategyOutputList.size()>0){
|
||||
outputService.insertTacticsOutput(ruleBlock.getId(), strategyOutputList);
|
||||
}
|
||||
List<StrategyOutput> failOutputList = ruleBlockVo.getFailOutputList();
|
||||
if (failOutputList!=null&&failOutputList.size()>0){
|
||||
outputService.insertTacticsOutput(ruleBlock.getId(),failOutputList );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -232,23 +261,46 @@ public class RuleVersionServiceImpl extends ServiceImpl<RuleVersionMapper, RuleV
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateVersion(RuleVersionVo version) {
|
||||
Long ruleId = version.getRuleId();
|
||||
Long versionId = version.getId();
|
||||
if (versionId==null){
|
||||
return false;
|
||||
}
|
||||
SysUser loginSysUser = SessionManager.getLoginAccount();
|
||||
version.setUpdateUserId(loginSysUser.getUserId());
|
||||
//修改版本主表
|
||||
// 1. 修改版本主表
|
||||
versionMapper.updateById(version);
|
||||
//修改条件表
|
||||
conditionService.updateRuleCondition(version.getRuleId(),version.getRuleConditionVo());
|
||||
//修改策略输出
|
||||
outputService.updateTacticsOutput(versionId,version.getStrategyOutputList(),version.getFailOutputList(), StrategyType.COMPLEX_RULE);
|
||||
|
||||
// 2. 删除原版本下所有子表数据
|
||||
// 删除所有规则块
|
||||
ruleBlockService.removeObjects(ruleId, versionId);
|
||||
// 删除所有条件
|
||||
conditionService.deleteRuleCondition(ruleId, versionId);
|
||||
// 删除所有策略输出(需找出原来的所有块,然后逐一删除)
|
||||
List<RuleBlock> oldRuleBlockList = ruleBlockService.listObjectsByVersionId(versionId);
|
||||
for(RuleBlock ruleBlock : oldRuleBlockList){
|
||||
StrategyOutput strategyOutput = new StrategyOutput(ruleBlock.getId(), StrategyType.COMPLEX_RULE);
|
||||
outputService.deleteByTactics(strategyOutput);
|
||||
}
|
||||
|
||||
// 3. 插入新版本下子表数据
|
||||
List<RuleBlockVo> ruleBlockVoList = version.getRuleBlockVoList();
|
||||
for(RuleBlockVo ruleBlockVo : ruleBlockVoList){
|
||||
// 修改规则块配置表
|
||||
ruleBlockVo.setRuleId(ruleId);
|
||||
ruleBlockVo.setVersionId(versionId);
|
||||
ruleBlockService.save(ruleBlockVo);
|
||||
Long blockId = ruleBlockVo.getId();
|
||||
//修改条件表
|
||||
conditionService.updateRuleCondition(ruleId, blockId, ruleBlockVo.getRuleConditionVo());
|
||||
//修改策略输出
|
||||
outputService.updateTacticsOutput(blockId,ruleBlockVo.getStrategyOutputList(),ruleBlockVo.getFailOutputList(), StrategyType.COMPLEX_RULE);
|
||||
}
|
||||
|
||||
this.saveSnapshot(versionId);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateStatus(StatusParam statusParam) {
|
||||
|
||||
@@ -107,11 +107,6 @@ public class StrategyOutputServiceImpl extends ServiceImpl<StrategyOutputMapper,
|
||||
@Transactional
|
||||
@Override
|
||||
public boolean updateTacticsOutput(Long tacticsId, List<StrategyOutput> successList, List<StrategyOutput> failList, String tacticsType) {
|
||||
StrategyOutput strategyOutput = new StrategyOutput(tacticsId, tacticsType);
|
||||
boolean delete = this.deleteByTactics(strategyOutput);
|
||||
if (!delete && this.queryByTactics(strategyOutput).size() != 0) {
|
||||
return false;
|
||||
}
|
||||
if (successList != null && !successList.isEmpty()) {
|
||||
this.insertTacticsOutput(tacticsId, successList, StrategyType.OutType.SUCCESS_OUT);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user