1.删除无效代码

2.修改匹配规则和输出结果使用节点Id对应数据
This commit is contained in:
chenweilong 2022-12-13 10:30:17 +08:00
parent 3eb89a9433
commit 6ebf3b8c30
17 changed files with 91 additions and 661 deletions

View File

@ -7,10 +7,11 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.entity.BaseDataEntity; import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.entity.DynamicScriptEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum; import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter; import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.service.BaseDataService; import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.service.BaseRoleService; import com.example.liteflow.mysql.service.DynamicScriptService;
import com.example.liteflow.mysql.util.ConditionParser; import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.core.NodeIfComponent; import com.yomahub.liteflow.core.NodeIfComponent;
@ -40,7 +41,7 @@ public class CostCenterCmp extends NodeIfComponent {
@Resource @Resource
private BaseDataService baseDataService; private BaseDataService baseDataService;
@Resource @Resource
private BaseRoleService baseRoleService; private DynamicScriptService dynamicScriptService;
/** /**
* 匹配规则 * 匹配规则
@ -52,9 +53,9 @@ public class CostCenterCmp extends NodeIfComponent {
String nodeId = this.getNodeId(); String nodeId = this.getNodeId();
String nodeName = this.getName(); String nodeName = this.getName();
log.info("nodeId = {}, nodeName = {}", nodeId, nodeName); log.info("nodeId = {}, nodeName = {}", nodeId, nodeName);
// 根据节点名称获取对应规则 DynamicScriptEntity dynamicScriptEntity = dynamicScriptService.getByScriptId(nodeId);
String droolStr = baseRoleService.getByName(nodeName); if (ObjectUtil.isNotNull(dynamicScriptEntity) && StrUtil.isNotBlank(dynamicScriptEntity.getScriptRole())) {
if (StrUtil.isNotBlank(droolStr)) { String droolStr = dynamicScriptEntity.getScriptRole();
// 替换规则中的关键字 // 替换规则中的关键字
Field[] fields = ReflectUtil.getFields(BaseCenter.class); Field[] fields = ReflectUtil.getFields(BaseCenter.class);
for (Field field : fields) { for (Field field : fields) {

View File

@ -1,11 +1,18 @@
package com.example.liteflow.mysql.cmp.costCenter; package com.example.liteflow.mysql.cmp.costCenter;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.entity.BaseDataEntity; import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.entity.DynamicScriptEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum; import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter; import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.model.SoutFrom;
import com.example.liteflow.mysql.service.BaseDataService; import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.service.DynamicScriptService;
import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -19,11 +26,8 @@ import javax.annotation.Resource;
@Slf4j @Slf4j
public class CostCenterSoutCmp extends NodeComponent { public class CostCenterSoutCmp extends NodeComponent {
// private static final String costCenter02Code = "P350401026";
// private static final String costCenter02Name = "商品车物流部利润中心";
@Resource @Resource
private BaseDataService baseDataService; private DynamicScriptService dynamicScriptService;
@Override @Override
public void process() { public void process() {
@ -31,10 +35,12 @@ public class CostCenterSoutCmp extends NodeComponent {
String nodeId = this.getNodeId(); String nodeId = this.getNodeId();
String nodeName = this.getName(); String nodeName = this.getName();
log.info("nodeId = {}, nodeName = {}", nodeId, nodeName); log.info("nodeId = {}, nodeName = {}", nodeId, nodeName);
BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("costCenterCode", BaseDataAttributionEnum.costCenter.getAttribution(), nodeName); DynamicScriptEntity dynamicScriptEntity = dynamicScriptService.getByScriptId(nodeId);
BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("costCenterName", BaseDataAttributionEnum.costCenter.getAttribution(), nodeName); String scriptContent = dynamicScriptEntity.getScriptContent();
String costCenterCode = codeBaseData.getContent(); JSONObject jsonObject = JSONUtil.parseObj(scriptContent);
String costCenterName = nameBaseData.getContent(); SoutFrom soutFrom = BeanUtil.toBean(jsonObject, SoutFrom.class);
String costCenterCode = soutFrom.getCode();
String costCenterName = soutFrom.getName();
baseCenter.setCostCenterCode(costCenterCode); baseCenter.setCostCenterCode(costCenterCode);
baseCenter.setCostCenterName(costCenterName); baseCenter.setCostCenterName(costCenterName);
baseCenter.setCostCenterGenerateCode(costCenterCode + costCenterName); baseCenter.setCostCenterGenerateCode(costCenterCode + costCenterName);

View File

@ -1,6 +1,5 @@
package com.example.liteflow.mysql.cmp.profitCenter; package com.example.liteflow.mysql.cmp.profitCenter;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.ReflectUtil;
@ -8,13 +7,13 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.entity.BaseDataEntity; import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.entity.DynamicScriptEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum; import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter; import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.service.BaseDataService; import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.service.BaseRoleService; import com.example.liteflow.mysql.service.DynamicScriptService;
import com.example.liteflow.mysql.util.ConditionParser; import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent; import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -35,7 +34,7 @@ public class ProfitCenterCmp extends NodeIfComponent {
@Resource @Resource
private BaseDataService baseDataService; private BaseDataService baseDataService;
@Resource @Resource
private BaseRoleService baseRoleService; private DynamicScriptService dynamicScriptService;
/** /**
* 匹配规则 * 匹配规则
@ -47,9 +46,9 @@ public class ProfitCenterCmp extends NodeIfComponent {
String nodeId = this.getNodeId(); String nodeId = this.getNodeId();
String nodeName = this.getName(); String nodeName = this.getName();
log.info("nodeId = {}, nodeName = {}", nodeId, nodeName); log.info("nodeId = {}, nodeName = {}", nodeId, nodeName);
// 根据节点名称获取对应规则 DynamicScriptEntity dynamicScriptEntity = dynamicScriptService.getByScriptId(nodeId);
String droolStr = baseRoleService.getByName(nodeName); if (ObjectUtil.isNotNull(dynamicScriptEntity) && StrUtil.isNotBlank(dynamicScriptEntity.getScriptRole())) {
if (StrUtil.isNotBlank(droolStr)) { String droolStr = dynamicScriptEntity.getScriptRole();
// 替换规则中的关键字 // 替换规则中的关键字
Field[] fields = ReflectUtil.getFields(BaseCenter.class); Field[] fields = ReflectUtil.getFields(BaseCenter.class);
for (Field field : fields) { for (Field field : fields) {

View File

@ -1,9 +1,15 @@
package com.example.liteflow.mysql.cmp.profitCenter; package com.example.liteflow.mysql.cmp.profitCenter;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.entity.BaseDataEntity; import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.entity.DynamicScriptEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum; import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
import com.example.liteflow.mysql.model.BaseCenter; import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.model.SoutFrom;
import com.example.liteflow.mysql.service.BaseDataService; import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.service.DynamicScriptService;
import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -22,7 +28,7 @@ public class ProfitCenterSoutCmp extends NodeComponent {
// private static final String profitCenter02Name = "商品车物流部利润中心"; // private static final String profitCenter02Name = "商品车物流部利润中心";
@Resource @Resource
private BaseDataService baseDataService; private DynamicScriptService dynamicScriptService;
@Override @Override
public void process() { public void process() {
@ -30,10 +36,12 @@ public class ProfitCenterSoutCmp extends NodeComponent {
String nodeId = this.getNodeId(); String nodeId = this.getNodeId();
String nodeName = this.getName(); String nodeName = this.getName();
log.info("nodeId = {}, nodeName = {}", nodeId, nodeName); log.info("nodeId = {}, nodeName = {}", nodeId, nodeName);
BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("profitCenterCode", BaseDataAttributionEnum.profitCenter.getAttribution(), nodeName); DynamicScriptEntity dynamicScriptEntity = dynamicScriptService.getByScriptId(nodeId);
BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("profitCenterName", BaseDataAttributionEnum.profitCenter.getAttribution(), nodeName); String scriptContent = dynamicScriptEntity.getScriptContent();
String profitCenterCode = codeBaseData.getContent(); JSONObject jsonObject = JSONUtil.parseObj(scriptContent);
String profitCenterName = nameBaseData.getContent(); SoutFrom soutFrom = BeanUtil.toBean(jsonObject, SoutFrom.class);
String profitCenterCode = soutFrom.getCode();
String profitCenterName = soutFrom.getName();
baseCenter.setProfitCenterCode(profitCenterCode); baseCenter.setProfitCenterCode(profitCenterCode);
baseCenter.setProfitCenterName(profitCenterName); baseCenter.setProfitCenterName(profitCenterName);
baseCenter.setProfitCenterGenerateCode(profitCenterCode + profitCenterName); baseCenter.setProfitCenterGenerateCode(profitCenterCode + profitCenterName);

View File

@ -1,39 +0,0 @@
package com.example.liteflow.mysql.controller;
import com.example.liteflow.mysql.model.role.RoleForm;
import com.example.liteflow.mysql.service.BaseRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* @author: 陈韦龙
* @date: 2022年12月07日 10:36
*/
@Slf4j
@RestController
@RequestMapping("/baseRole")
public class BaseRoleController {
@Resource
private BaseRoleService baseRoleService;
/**
* 创建规则
*
* @param roleForm
*/
@PostMapping("/createRole")
public void createRole(@RequestBody RoleForm roleForm) {
baseRoleService.createRole(roleForm);
}
/**
* 创建测试用规则
*/
@GetMapping("/testCreateRole")
public void testCreateRole() {
baseRoleService.testCreateRole();
}
}

View File

@ -1,14 +1,13 @@
package com.example.liteflow.mysql.controller; package com.example.liteflow.mysql.controller;
import cn.hutool.json.JSONObject;
import com.example.liteflow.mysql.model.dynamicScript.CreateDynamicScriptFrom; import com.example.liteflow.mysql.model.dynamicScript.CreateDynamicScriptFrom;
import com.example.liteflow.mysql.service.DynamicScriptService; import com.example.liteflow.mysql.service.DynamicScriptService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
/** /**
* @author: 陈韦龙 * @author: 陈韦龙
@ -41,4 +40,9 @@ public class DynamicScriptController {
public void createProfitCenterIfNode(@RequestBody CreateDynamicScriptFrom createDynamicScriptFrom) { public void createProfitCenterIfNode(@RequestBody CreateDynamicScriptFrom createDynamicScriptFrom) {
dynamicScriptService.createProfitCenterIfNode(createDynamicScriptFrom); dynamicScriptService.createProfitCenterIfNode(createDynamicScriptFrom);
} }
@GetMapping("/getNode")
public List<JSONObject> getNode() {
return dynamicScriptService.getNode();
}
} }

View File

@ -1,89 +0,0 @@
package com.example.liteflow.mysql.controller;
import com.example.liteflow.mysql.model.node.CreateNodeFrom;
import com.example.liteflow.mysql.service.NodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月12日 09:29
*/
@Slf4j
@RestController
@RequestMapping("/node")
public class NodeController {
@Resource
private NodeService nodeService;
/**
* 创建成本中心判断节点
* @param createNodeFrom
*/
@PostMapping("/createCostCenterIfNode")
public void createCostCenterIfNode(@RequestBody CreateNodeFrom createNodeFrom) {
nodeService.createCostCenterIfNode(createNodeFrom);
}
/**
* 批量创建成本中心判断节点
* @param createNodeFroms
*/
@PostMapping("/batchCreateCostCenterIfNode")
public void batchCreateCostCenterIfNode(@RequestBody List<CreateNodeFrom> createNodeFroms) {
nodeService.batchCreateCostCenterIfNode(createNodeFroms);
}
/**
* 创建成本中心普通节点
* @param createNodeFrom
*/
@PostMapping("/createCostCenterNode")
public void createCostCenterNode(@RequestBody CreateNodeFrom createNodeFrom) {
nodeService.createCostCenterNode(createNodeFrom);
}
/**
* 批量创建成本中心普通节点
* @param createNodeFroms
*/
@PostMapping("/batchCreateCostCenterNode")
public void batchCreateCostCenterNode(@RequestBody List<CreateNodeFrom> createNodeFroms) {
nodeService.batchCreateCostCenterNode(createNodeFroms);
}
/**
* 创建利润中心判断节点
* @param createNodeFrom
*/
@PostMapping("/createProfitCenterIfNode")
public void createProfitCenterIfNode(@RequestBody CreateNodeFrom createNodeFrom) {
nodeService.createProfitCenterIfNode(createNodeFrom);
}
/**
* 批量创建利润中心判断节点
* @param createNodeFroms
*/
@PostMapping("/batchCreateProfitCenterIfNode")
public void batchCreateProfitCenterIfNode(@RequestBody List<CreateNodeFrom> createNodeFroms) {
nodeService.batchCreateProfitCenterIfNode(createNodeFroms);
}
/**
* 创建利润中心普通节点
* @param createNodeFrom
*/
@PostMapping("/createProfitCenterNode")
public void createProfitCenterNode(@RequestBody CreateNodeFrom createNodeFrom) {
nodeService.createProfitCenterNode(createNodeFrom);
}
/**
* 批量创建利润中心普通节点
* @param createNodeFroms
*/
@PostMapping("/batchCreateProfitCostCenterNode")
public void batchCreateProfitCostCenterNode(@RequestBody List<CreateNodeFrom> createNodeFroms) {
nodeService.batchCreateProfitCostCenterNode(createNodeFroms);
}
}

View File

@ -1,22 +0,0 @@
package com.example.liteflow.mysql.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
* @author: 陈韦龙
* @date: 2022年12月06日 09:59
*/
@TableName("base_role")
@Data
public class BaseRoleEntity {
@TableId(value = "ID", type = IdType.ASSIGN_UUID)
private String id;
@TableField("role_str")
private String roleStr;
@TableField("role_name")
private String roleName;
}

View File

@ -1,13 +0,0 @@
package com.example.liteflow.mysql.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.liteflow.mysql.entity.BaseRoleEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* @author: 陈韦龙
* @date: 2022年12月06日 10:08
*/
@Mapper
public interface BaseRoleMapper extends BaseMapper<BaseRoleEntity> {
}

View File

@ -1,13 +0,0 @@
package com.example.liteflow.mysql.model.node;
import lombok.Data;
/**
* @author: 陈韦龙
* @date: 2022年12月12日 09:38
*/
@Data
public class CreateNodeFrom {
private String id;
private String name;
}

View File

@ -1,15 +0,0 @@
package com.example.liteflow.mysql.service;
import com.example.liteflow.mysql.model.role.RoleForm;
/**
* @author: 陈韦龙
* @date: 2022年12月08日 16:09
*/
public interface BaseRoleService {
void createRole(RoleForm roleForm);
void testCreateRole();
String getByName(String roleName);
}

View File

@ -1,9 +1,12 @@
package com.example.liteflow.mysql.service; package com.example.liteflow.mysql.service;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.example.liteflow.mysql.entity.DynamicScriptEntity; import com.example.liteflow.mysql.entity.DynamicScriptEntity;
import com.example.liteflow.mysql.model.dynamicScript.CreateDynamicScriptFrom; import com.example.liteflow.mysql.model.dynamicScript.CreateDynamicScriptFrom;
import java.util.List;
/** /**
* @author 75349 * @author 75349
* @description 针对表dynamic_script的数据库操作Service * @description 针对表dynamic_script的数据库操作Service
@ -18,4 +21,12 @@ public interface DynamicScriptService extends IService<DynamicScriptEntity> {
void createProfitCenterNode(CreateDynamicScriptFrom createDynamicScriptFrom); void createProfitCenterNode(CreateDynamicScriptFrom createDynamicScriptFrom);
void createProfitCenterIfNode(CreateDynamicScriptFrom createDynamicScriptFrom); void createProfitCenterIfNode(CreateDynamicScriptFrom createDynamicScriptFrom);
/**
* 获取所有节点
*
* @return Map<String, Node>
*/
List<JSONObject> getNode();
DynamicScriptEntity getByScriptId(String scriptId);
} }

View File

@ -1,27 +0,0 @@
package com.example.liteflow.mysql.service;
import com.example.liteflow.mysql.model.node.CreateNodeFrom;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月12日 09:30
*/
public interface NodeService {
void createCostCenterIfNode(CreateNodeFrom createNodeFrom);
void batchCreateCostCenterIfNode(List<CreateNodeFrom> createNodeFroms);
void createCostCenterNode(CreateNodeFrom createNodeFrom);
void batchCreateCostCenterNode(List<CreateNodeFrom> createNodeFroms);
void createProfitCenterIfNode(CreateNodeFrom createNodeFrom);
void batchCreateProfitCenterIfNode(List<CreateNodeFrom> createNodeFroms);
void createProfitCenterNode(CreateNodeFrom createNodeFrom);
void batchCreateProfitCostCenterNode(List<CreateNodeFrom> createNodeFroms);
}

View File

@ -1,309 +0,0 @@
package com.example.liteflow.mysql.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.liteflow.mysql.entity.BaseRoleEntity;
import com.example.liteflow.mysql.enums.MathOperatorEnum;
import com.example.liteflow.mysql.mapper.BaseRoleMapper;
import com.example.liteflow.mysql.model.role.Match;
import com.example.liteflow.mysql.model.role.Role;
import com.example.liteflow.mysql.model.role.RoleForm;
import com.example.liteflow.mysql.service.BaseRoleService;
import com.example.liteflow.mysql.util.RoleUtil;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author: 陈韦龙
* @date: 2022年12月08日 16:09
*/
@Slf4j
@Service
public class BaseRoleServiceImpl extends ServiceImpl<BaseRoleMapper, BaseRoleEntity> implements BaseRoleService {
@Override
public void createRole(RoleForm roleForm) {
List<Role> roles = roleForm.getRoles();
String roleName = roleForm.getRoleName();
LambdaQueryWrapper<BaseRoleEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(BaseRoleEntity::getRoleName, roleName);
BaseRoleEntity baseRoleEntity = this.getOne(queryWrapper);
if(ObjectUtil.isNull(baseRoleEntity)) {
baseRoleEntity = new BaseRoleEntity();
baseRoleEntity.setRoleStr(JSONUtil.toJsonStr(roles));
baseRoleEntity.setRoleName(JSONUtil.toJsonStr(roleName));
this.save(baseRoleEntity);
} else {
baseRoleEntity.setRoleStr(JSONUtil.toJsonStr(roles));
this.updateById(baseRoleEntity);
}
}
@Override
public void testCreateRole() {
List<RoleForm> roleForms =
Lists.newArrayList(
this.costCenter01Cmp(),
this.costCenter02Cmp(),
this.profitCenter01Cmp(),
this.profitCenter02Cmp()
);
roleForms.forEach(roleForm -> {
List<Role> roles = roleForm.getRoles();
String roleName = roleForm.getRoleName();
LambdaQueryWrapper<BaseRoleEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(BaseRoleEntity::getRoleName, roleName);
BaseRoleEntity baseRoleEntity = this.getOne(queryWrapper);
if(ObjectUtil.isNull(baseRoleEntity)) {
baseRoleEntity = new BaseRoleEntity();
baseRoleEntity.setRoleStr(JSONUtil.toJsonStr(roles));
baseRoleEntity.setRoleName(JSONUtil.toJsonStr(roleName));
this.save(baseRoleEntity);
} else {
baseRoleEntity.setRoleStr(JSONUtil.toJsonStr(roles));
this.updateById(baseRoleEntity);
}
});
}
@Override
public String getByName(String roleName) {
LambdaQueryWrapper<BaseRoleEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(BaseRoleEntity::getRoleName, roleName);
BaseRoleEntity baseRoleEntity = this.getOne(queryWrapper);
if (ObjectUtil.isNotNull(baseRoleEntity)) {
String roleStr = baseRoleEntity.getRoleStr();
log.info("roleStr = {}", roleStr);
// JSONObject jsonObject = JSONUtil.parseObj(roleStr);
List<Role> roles = JSONUtil.toList(JSONUtil.parseArray(roleStr), Role.class);
List<Map<String, Object>> collect = roles.stream().map(RoleUtil::parseRole).collect(Collectors.toList());
return JSONUtil.toJsonStr(collect);
} else {
return "";
}
}
public RoleForm costCenter01Cmp() {
Role role = new Role();
role.setLogicOperators(MathOperatorEnum.or.getOperator());
Role child = new Role();
child.setLogicOperators(MathOperatorEnum.and.getOperator());
List<Match> matches = new ArrayList<>();
Match match = new Match();
match.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match.setMatchingValue("sectionClassification");
match.setMatchingContent("sectionClassificationList");
matches.add(match);
match = new Match();
match.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match.setMatchingValue("businessType");
match.setMatchingContent("businessTypeList");
matches.add(match);
match = new Match();
match.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match.setMatchingValue("salesman");
match.setMatchingContent("salesmanList");
matches.add(match);
match = new Match();
match.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match.setMatchingValue("businessCategory");
match.setMatchingContent("businessCategoryList");
matches.add(match);
child.setMatches(matches);
List<Role> children = Lists.newArrayList(child);
role.setChildren(children);
List<Role> roles = Lists.newArrayList(role);
RoleForm roleForm = new RoleForm();
roleForm.setRoles(roles);
roleForm.setRoleName("costCenter01Cmp");
return roleForm;
// System.out.println(JSONUtil.toJsonStr(roles));
// List<? extends Map<String, ?>> collect = roles.stream().map(this::parseRole).collect(Collectors.toList());
// System.out.println(JSONUtil.toJsonStr(collect));
}
public RoleForm costCenter02Cmp() {
Role role = new Role();
role.setLogicOperators(MathOperatorEnum.or.getOperator());
Role child = new Role();
child.setLogicOperators(MathOperatorEnum.or.getOperator());
Role sun = new Role();
sun.setLogicOperators(MathOperatorEnum.and.getOperator());
List<Match> matches = new ArrayList<>();
Match match = new Match();
match.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match.setMatchingValue("sectionClassification");
match.setMatchingContent("sectionClassificationList");
matches.add(match);
match = new Match();
match.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match.setMatchingValue("salesman");
match.setMatchingContent("salesmanList");
matches.add(match);
sun.setMatches(matches);
List<Role> sunList = Lists.newArrayList(sun);
child.setChildren(sunList);
List<Role> children = Lists.newArrayList(child);
role.setChildren(children);
List<Match> matches2 = new ArrayList<>();
Match match2 = new Match();
match2.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match2.setMatchingValue("businessType");
match2.setMatchingContent("businessTypeList");
matches2.add(match2);
Role role2 = new Role();
role2.setLogicOperators(MathOperatorEnum.or.getOperator());
role2.setMatches(matches2);
List<Role> roles = Lists.newArrayList(role, role2);
RoleForm roleForm = new RoleForm();
roleForm.setRoles(roles);
roleForm.setRoleName("costCenter02Cmp");
return roleForm;
// baseRoleService.createRole(roleForm);
// System.out.println(JSONUtil.toJsonStr(roles));
// List<? extends Map<String, ?>> collect = roles.stream().map(this::parseRole).collect(Collectors.toList());
// System.out.println(JSONUtil.toJsonStr(collect));
}
public RoleForm profitCenter01Cmp() {
Role role = new Role();
role.setLogicOperators(MathOperatorEnum.or.getOperator());
Role child = new Role();
child.setLogicOperators(MathOperatorEnum.and.getOperator());
List<Match> matches = new ArrayList<>();
Match match = new Match();
match.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match.setMatchingValue("businessType");
match.setMatchingContent("businessTypeList");
matches.add(match);
match = new Match();
match.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match.setMatchingValue("salesman");
match.setMatchingContent("salesmanList");
matches.add(match);
match = new Match();
match.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match.setMatchingValue("businessCategory");
match.setMatchingContent("businessCategoryList");
matches.add(match);
child.setMatches(matches);
List<Role> children = Lists.newArrayList(child);
role.setChildren(children);
Role role2 = new Role();
role2.setLogicOperators(MathOperatorEnum.or.getOperator());
Role child2 = new Role();
child2.setLogicOperators(MathOperatorEnum.and.getOperator());
List<Match> matches2 = new ArrayList<>();
Match match2 = new Match();
match2.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match2.setMatchingValue("sectionClassification");
match2.setMatchingContent("sectionClassificationList");
matches2.add(match2);
match2 = new Match();
match2.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match2.setMatchingValue("businessType");
match2.setMatchingContent("businessTypeList");
matches2.add(match2);
child2.setMatches(matches2);
List<Role> children2 = Lists.newArrayList(child2);
role2.setChildren(children2);
List<Role> roles = Lists.newArrayList(role, role2);
RoleForm roleForm = new RoleForm();
roleForm.setRoles(roles);
roleForm.setRoleName("profitCenter01Cmp");
return roleForm;
// baseRoleService.createRole(roleForm);
// System.out.println(JSONUtil.toJsonStr(roles));
// List<? extends Map<String, ?>> collect = roles.stream().map(this::parseRole).collect(Collectors.toList());
// System.out.println(JSONUtil.toJsonStr(collect));
}
public RoleForm profitCenter02Cmp() {
Role role = new Role();
role.setLogicOperators(MathOperatorEnum.or.getOperator());
Role child = new Role();
child.setLogicOperators(MathOperatorEnum.and.getOperator());
List<Match> matches = new ArrayList<>();
Match match = new Match();
match.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match.setMatchingValue("businessType");
match.setMatchingContent("businessTypeList");
matches.add(match);
match = new Match();
match.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match.setMatchingValue("salesman");
match.setMatchingContent("salesmanList");
matches.add(match);
child.setMatches(matches);
List<Role> children = Lists.newArrayList(child);
role.setChildren(children);
Role role2 = new Role();
role2.setLogicOperators(MathOperatorEnum.or.getOperator());
Role child2 = new Role();
child2.setLogicOperators(MathOperatorEnum.and.getOperator());
List<Match> matches2 = new ArrayList<>();
Match match2 = new Match();
match2.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match2.setMatchingValue("sectionClassification");
match2.setMatchingContent("sectionClassificationList");
matches2.add(match2);
match2 = new Match();
match2.setConditionalOperators(MathOperatorEnum.contains.getOperator());
match2.setMatchingValue("businessType");
match2.setMatchingContent("businessTypeList");
matches2.add(match2);
child2.setMatches(matches2);
List<Role> children2 = Lists.newArrayList(child2);
role2.setChildren(children2);
List<Role> roles = Lists.newArrayList(role, role2);
RoleForm roleForm = new RoleForm();
roleForm.setRoles(roles);
roleForm.setRoleName("profitCenter02Cmp");
return roleForm;
// baseRoleService.createRole(roleForm);
// System.out.println(JSONUtil.toJsonStr(roles));
// List<? extends Map<String, ?>> collect = roles.stream().map(this::parseRole).collect(Collectors.toList());
// System.out.println(JSONUtil.toJsonStr(collect));
}
}

View File

@ -2,6 +2,7 @@ package com.example.liteflow.mysql.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@ -15,9 +16,13 @@ import com.example.liteflow.mysql.model.dynamicScript.UpdateDynamicScriptFrom;
import com.example.liteflow.mysql.model.role.Role; import com.example.liteflow.mysql.model.role.Role;
import com.example.liteflow.mysql.service.DynamicScriptService; import com.example.liteflow.mysql.service.DynamicScriptService;
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder; import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.element.Node;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author 75349 * @author 75349
@ -25,6 +30,7 @@ import java.util.List;
* @createDate 2022-12-12 15:46:00 * @createDate 2022-12-12 15:46:00
*/ */
@Service @Service
@Slf4j
public class DynamicScriptServiceImpl extends ServiceImpl<DynamicScriptMapper, DynamicScriptEntity> public class DynamicScriptServiceImpl extends ServiceImpl<DynamicScriptMapper, DynamicScriptEntity>
implements DynamicScriptService { implements DynamicScriptService {
private final static String costCenterCmp = "com.example.liteflow.mysql.cmp.costCenter.CostCenterCmp"; private final static String costCenterCmp = "com.example.liteflow.mysql.cmp.costCenter.CostCenterCmp";
@ -70,7 +76,7 @@ public class DynamicScriptServiceImpl extends ServiceImpl<DynamicScriptMapper, D
if (ObjectUtil.isNotNull(entity)) { if (ObjectUtil.isNotNull(entity)) {
UpdateDynamicScriptFrom updateDynamicScriptFrom = BeanUtil.toBean(createDynamicScriptFrom, UpdateDynamicScriptFrom.class); UpdateDynamicScriptFrom updateDynamicScriptFrom = BeanUtil.toBean(createDynamicScriptFrom, UpdateDynamicScriptFrom.class);
updateDynamicScriptFrom.setId(entity.getId()); updateDynamicScriptFrom.setId(entity.getId());
this.updateCostCenterNode(updateDynamicScriptFrom); this.updateCostCenterIfNode(updateDynamicScriptFrom);
} else { } else {
DynamicScriptEntity dynamicScriptEntity = new DynamicScriptEntity(); DynamicScriptEntity dynamicScriptEntity = new DynamicScriptEntity();
dynamicScriptEntity.setScriptId(scriptId); dynamicScriptEntity.setScriptId(scriptId);
@ -207,4 +213,28 @@ public class DynamicScriptServiceImpl extends ServiceImpl<DynamicScriptMapper, D
.setClazz(profitCenterCmp) .setClazz(profitCenterCmp)
.build(); .build();
} }
/**
* 获取所有节点
*
* @return Map<String, Node>
*/
@Override
public List<JSONObject> getNode() {
List<DynamicScriptEntity> list = this.list();
return list.stream().filter(item -> FlowBus.containNode(item.getScriptId())).map(item -> {
String scriptId = item.getScriptId();
Node node = FlowBus.getNode(scriptId);
JSONObject jsonObject = new JSONObject();
jsonObject.putOpt("scriptId", scriptId).putOpt("name", node.getName());
return jsonObject;
}).collect(Collectors.toList());
}
@Override
public DynamicScriptEntity getByScriptId(String scriptId) {
LambdaQueryWrapper<DynamicScriptEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DynamicScriptEntity::getScriptId, scriptId);
return this.getOne(queryWrapper);
}
} }

View File

@ -1,94 +0,0 @@
package com.example.liteflow.mysql.service.impl;
import com.example.liteflow.mysql.model.node.CreateNodeFrom;
import com.example.liteflow.mysql.service.NodeService;
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
import com.yomahub.liteflow.core.FlowExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月12日 09:30
*/
@Service
@Slf4j
public class NodeServiceImpl implements NodeService {
@Resource
private FlowExecutor flowExecutor;
@Override
public void createCostCenterIfNode(CreateNodeFrom createNodeFrom) {
LiteFlowNodeBuilder.createIfNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.costCenter.CostCenterCmp")
.build();
// flowExecutor.reloadRule();
}
@Override
public void batchCreateCostCenterIfNode(List<CreateNodeFrom> createNodeFroms) {
createNodeFroms.forEach(createNodeFrom -> {
LiteFlowNodeBuilder.createIfNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.costCenter.CostCenterCmp")
.build();
});
}
@Override
public void createCostCenterNode(CreateNodeFrom createNodeFrom) {
LiteFlowNodeBuilder.createCommonNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.costCenter.CostCenterSoutCmp")
.build();
// flowExecutor.reloadRule();
}
@Override
public void batchCreateCostCenterNode(List<CreateNodeFrom> createNodeFroms) {
createNodeFroms.forEach(createNodeFrom -> {
LiteFlowNodeBuilder.createCommonNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.costCenter.CostCenterSoutCmp")
.build();
});
}
@Override
public void createProfitCenterIfNode(CreateNodeFrom createNodeFrom) {
LiteFlowNodeBuilder.createIfNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.profitCenter.ProfitCenterCmp")
.build();
// flowExecutor.reloadRule();
}
@Override
public void batchCreateProfitCenterIfNode(List<CreateNodeFrom> createNodeFroms) {
createNodeFroms.forEach(createNodeFrom -> {
LiteFlowNodeBuilder.createIfNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.profitCenter.ProfitCenterCmp")
.build();
});
}
@Override
public void createProfitCenterNode(CreateNodeFrom createNodeFrom) {
LiteFlowNodeBuilder.createCommonNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.profitCenter.ProfitCenterSoutCmp")
.build();
// flowExecutor.reloadRule();
}
@Override
public void batchCreateProfitCostCenterNode(List<CreateNodeFrom> createNodeFroms) {
createNodeFroms.forEach(createNodeFrom -> {
LiteFlowNodeBuilder.createCommonNode().setId(createNodeFrom.getId())
.setName(createNodeFrom.getName())
.setClazz("com.example.liteflow.mysql.cmp.profitCenter.ProfitCenterSoutCmp")
.build();
});
}
}

View File

@ -1,18 +1,12 @@
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.LiteflowMysqlApplication;
import com.example.liteflow.mysql.enums.MathOperatorEnum; import com.example.liteflow.mysql.enums.MathOperatorEnum;
import com.example.liteflow.mysql.model.role.Match; import com.example.liteflow.mysql.model.role.Match;
import com.example.liteflow.mysql.model.role.Role; import com.example.liteflow.mysql.model.role.Role;
import com.example.liteflow.mysql.model.role.RoleForm; import com.example.liteflow.mysql.model.role.RoleForm;
import com.example.liteflow.mysql.service.BaseRoleService;
import org.assertj.core.util.Lists; import org.assertj.core.util.Lists;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
@ -29,8 +23,6 @@ import java.util.stream.Collectors;
//@SpringBootTest(classes = LiteflowMysqlApplication.class) //@SpringBootTest(classes = LiteflowMysqlApplication.class)
public class MyTest { public class MyTest {
@Resource
private BaseRoleService baseRoleService;
@Test @Test
public void test01() { public void test01() {
List<Role> roles = new ArrayList<>(); List<Role> roles = new ArrayList<>();
@ -258,7 +250,7 @@ public class MyTest {
RoleForm roleForm = new RoleForm(); RoleForm roleForm = new RoleForm();
roleForm.setRoles(roles); roleForm.setRoles(roles);
roleForm.setRoleName("costCenter01Cmp"); roleForm.setRoleName("costCenter01Cmp");
baseRoleService.createRole(roleForm); // baseRoleService.createRole(roleForm);
// System.out.println(JSONUtil.toJsonStr(roles)); // System.out.println(JSONUtil.toJsonStr(roles));
// List<? extends Map<String, ?>> collect = roles.stream().map(this::parseRole).collect(Collectors.toList()); // List<? extends Map<String, ?>> collect = roles.stream().map(this::parseRole).collect(Collectors.toList());
// System.out.println(JSONUtil.toJsonStr(collect)); // System.out.println(JSONUtil.toJsonStr(collect));
@ -308,7 +300,7 @@ public class MyTest {
RoleForm roleForm = new RoleForm(); RoleForm roleForm = new RoleForm();
roleForm.setRoles(roles); roleForm.setRoles(roles);
roleForm.setRoleName("costCenter02Cmp"); roleForm.setRoleName("costCenter02Cmp");
baseRoleService.createRole(roleForm); // baseRoleService.createRole(roleForm);
System.out.println(JSONUtil.toJsonStr(roles)); System.out.println(JSONUtil.toJsonStr(roles));
List<? extends Map<String, ?>> collect = roles.stream().map(this::parseRole).collect(Collectors.toList()); List<? extends Map<String, ?>> collect = roles.stream().map(this::parseRole).collect(Collectors.toList());
System.out.println(JSONUtil.toJsonStr(collect)); System.out.println(JSONUtil.toJsonStr(collect));