1.更新为从上往下动态增长

2.更新初始化方法从下往上
3.删除多余代码
This commit is contained in:
chenweilong 2022-12-14 18:23:59 +08:00
parent 5249b545c5
commit daefc826ff
40 changed files with 620 additions and 1209 deletions

View File

@ -1,74 +0,0 @@
package com.example.liteflow.mysql.bean;
import com.example.liteflow.mysql.entity.ChainEntity;
import com.example.liteflow.mysql.entity.DynamicScriptEntity;
import com.example.liteflow.mysql.enums.NodeEnum;
import com.example.liteflow.mysql.service.ChainService;
import com.example.liteflow.mysql.service.DynamicScriptService;
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.FlowBus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月12日 17:21
*/
@Component
@Slf4j
public class AviatorEvaluatorRunner implements CommandLineRunner {
@Resource
private DynamicScriptService dynamicScriptService;
@Resource
private ChainService chainService;
@Resource
private FlowExecutor flowExecutor;
@Override
public void run(String... args) throws Exception {
List<DynamicScriptEntity> dynamicScriptEntityList = dynamicScriptService.list();
log.info("AviatorEvaluatorRunner-dynamicScriptEntityList = {}", dynamicScriptEntityList.size());
dynamicScriptEntityList.forEach(dynamicScript -> {
String scriptId = dynamicScript.getScriptId();
boolean containNode = FlowBus.containNode(scriptId);
if (!containNode) {
String scriptName = dynamicScript.getScriptName();
String scriptClass = dynamicScript.getScriptClass();
String nodeType = dynamicScript.getNodeType();
if (NodeEnum.CommonNode.getName().equals(nodeType)) {
LiteFlowNodeBuilder.createCommonNode()
.setId(scriptId)
.setName(scriptName)
.setClazz(scriptClass)
.build();
} else if (NodeEnum.IfNode.getName().equals(nodeType)) {
LiteFlowNodeBuilder.createIfNode()
.setId(scriptId)
.setName(scriptName)
.setClazz(scriptClass)
.build();
}
}
});
List<ChainEntity> chainEntityList = chainService.list();
log.info("AviatorEvaluatorRunner-chainEntityList = {}", chainEntityList.size());
chainEntityList.forEach(chainEntity -> {
String chainName = chainEntity.getChainName();
boolean containChain = FlowBus.containChain(chainName);
if (!containChain) {
LiteFlowChainELBuilder.createChain()
.setChainId(chainName)
.setEL(chainEntity.getElData())
.build();
flowExecutor.reloadRule();
}
});
}
}

View File

@ -1,4 +1,4 @@
package com.example.liteflow.mysql.cmp.profitCenter;
package com.example.liteflow.mysql.cmp;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
@ -7,12 +7,11 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
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.entity.BaseNodeEntity;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.model.role.Role;
import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.service.DynamicScriptService;
import com.example.liteflow.mysql.service.BaseNodeService;
import com.example.liteflow.mysql.util.ConditionParser;
import com.example.liteflow.mysql.util.RoleUtil;
import com.googlecode.aviator.AviatorEvaluator;
@ -28,17 +27,15 @@ import java.util.stream.Collectors;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
* @date: 2022年12月14日 10:18
*/
//@LiteflowComponent("profitCenterCmp")
@Component
@Slf4j
public class ProfitCenterCmp extends NodeIfComponent {
public class CenterCmp extends NodeIfComponent {
@Resource
private BaseDataService baseDataService;
@Resource
private DynamicScriptService dynamicScriptService;
private BaseNodeService baseNodeService;
/**
* 匹配规则
@ -50,19 +47,21 @@ public class ProfitCenterCmp extends NodeIfComponent {
String nodeId = this.getNodeId();
String nodeName = this.getName();
log.info("nodeId = {}, nodeName = {}", nodeId, nodeName);
DynamicScriptEntity dynamicScriptEntity = dynamicScriptService.getByScriptId(nodeId);
if (ObjectUtil.isNotNull(dynamicScriptEntity) && StrUtil.isNotBlank(dynamicScriptEntity.getScriptRole())) {
String scriptRole = dynamicScriptEntity.getScriptRole();
log.info("scriptRole = {}", scriptRole);
List<Role> roles = JSONUtil.toList(JSONUtil.parseArray(scriptRole), Role.class);
BaseNodeEntity baseNodeEntity = baseNodeService.getByNodeId(nodeId);
if (ObjectUtil.isNotNull(baseNodeEntity) && StrUtil.isNotBlank(baseNodeEntity.getNodeRole())) {
String nodeRole = baseNodeEntity.getNodeRole();
String templateId = baseNodeEntity.getTemplateId();
log.info("nodeRole = {}", nodeRole);
List<Role> roles = JSONUtil.toList(JSONUtil.parseArray(nodeRole), Role.class);
List<Map<String, Object>> collect = roles.stream().map(RoleUtil::parseRole).collect(Collectors.toList());
String droolStr = JSONUtil.toJsonStr(collect);
// 替换规则中的关键字
Field[] fields = ReflectUtil.getFields(BaseCenter.class);
for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName();
BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.profitCenter.getAttribution());
BaseDataEntity baseDataEntity = baseDataService.getByTypeAndTemplateId(name, templateId);
if (ObjectUtil.isNotNull(baseDataEntity)) {
String content = baseDataEntity.getContent();
String contentName = baseDataEntity.getContentName();
@ -83,9 +82,9 @@ public class ProfitCenterCmp extends NodeIfComponent {
log.info("condition template = {}", conditionResult);
Object executeB = AviatorEvaluator.execute(conditionResult);
log.info("ProfitCenterCmp-{} = {}", conditionResult, executeB);
log.info("CenterCmp-{} = {}", conditionResult, executeB);
boolean aBoolean = BooleanUtil.toBoolean(executeB.toString());
log.info("ProfitCenterCmp-aBoolean = {}", aBoolean);
log.info("CenterCmp-aBoolean = {}", aBoolean);
return aBoolean;
} else {
return false;

View File

@ -0,0 +1,21 @@
package com.example.liteflow.mysql.cmp;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.model.BaseCenter;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("defaultOutput")
public class DefaultOutputCmp extends NodeComponent {
@Override
public void process() {
BaseCenter requestData = this.getRequestData();
JSONObject jsonObject = requestData.getJsonObject();
if (JSONUtil.isNull(jsonObject)) {
requestData.setGenerateCode("无匹配项");
}
}
}

View File

@ -0,0 +1,67 @@
package com.example.liteflow.mysql.cmp;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONNull;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.entity.BaseNodeEntity;
import com.example.liteflow.mysql.entity.BaseTemplateEntity;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.model.OutputFrom;
import com.example.liteflow.mysql.service.BaseNodeService;
import com.example.liteflow.mysql.service.BaseTemplateService;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.lang.reflect.Field;
@Component
@Slf4j
public class OutputCmp extends NodeComponent {
@Resource
private BaseNodeService baseNodeService;
@Resource
private BaseTemplateService baseTemplateService;
@Override
public void process() {
BaseCenter requestData = this.getRequestData();
String nodeId = this.getNodeId();
log.info("OutputCmp-nodeId = {}", nodeId);
BaseNodeEntity baseNodeEntity = baseNodeService.getByNodeId(nodeId);
String nodeContent = baseNodeEntity.getNodeContent();
if (StrUtil.isNotBlank(nodeContent)) {
JSONObject nodeJsonObject = JSONUtil.parseObj(nodeContent);
OutputFrom outputFrom = BeanUtil.toBean(nodeJsonObject, OutputFrom.class);
String templateId = baseNodeEntity.getTemplateId();
BaseTemplateEntity baseTemplateEntity = baseTemplateService.getById(templateId);
String templateName = baseTemplateEntity.getTemplateName();
Field[] fields = ReflectUtil.getFields(OutputFrom.class);
for (Field field : fields) {
String fieldName = field.getName();
Object fieldValue = ReflectUtil.getFieldValue(outputFrom, field);
JSONObject jsonObject = requestData.getJsonObject();
if (ObjectUtil.isNull(jsonObject)) {
jsonObject = new JSONObject();
jsonObject.putOpt(templateName + fieldName, fieldValue);
requestData.setGenerateCode(null);
requestData.setJsonObject(jsonObject);
} else {
jsonObject.putOpt(templateName + fieldName, fieldValue);
requestData.setGenerateCode(null);
requestData.setJsonObject(jsonObject);
}
}
}
}
}

View File

@ -1,24 +0,0 @@
package com.example.liteflow.mysql.cmp;
import cn.hutool.core.util.StrUtil;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.model.CostCenter;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("sout")
public class SoutCmp extends NodeComponent {
@Override
public void process() {
BaseCenter requestData = this.getRequestData();
String costCenterGenerateCode = requestData.getCostCenterGenerateCode();
String profitCenterGenerateCode = requestData.getProfitCenterGenerateCode();
if (StrUtil.isBlank(costCenterGenerateCode) && StrUtil.isBlank(profitCenterGenerateCode)) {
requestData.setGenerateCode("无匹配项");
}
}
}

View File

@ -1,96 +0,0 @@
package com.example.liteflow.mysql.cmp.costCenter;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
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.model.BaseCenter;
import com.example.liteflow.mysql.model.role.Role;
import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.service.DynamicScriptService;
import com.example.liteflow.mysql.util.ConditionParser;
import com.example.liteflow.mysql.util.RoleUtil;
import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
*/
@Component
@Slf4j
public class CostCenterCmp extends NodeIfComponent {
@Resource
private BaseDataService baseDataService;
@Resource
private DynamicScriptService dynamicScriptService;
/**
* 匹配规则
* @return boolean
*/
@Override
public boolean processIf() {
BaseCenter requestData = this.getRequestData();
String nodeId = this.getNodeId();
String nodeName = this.getName();
log.info("nodeId = {}, nodeName = {}", nodeId, nodeName);
DynamicScriptEntity dynamicScriptEntity = dynamicScriptService.getByScriptId(nodeId);
if (ObjectUtil.isNotNull(dynamicScriptEntity) && StrUtil.isNotBlank(dynamicScriptEntity.getScriptRole())) {
String scriptRole = dynamicScriptEntity.getScriptRole();
log.info("scriptRole = {}", scriptRole);
List<Role> roles = JSONUtil.toList(JSONUtil.parseArray(scriptRole), Role.class);
List<Map<String, Object>> collect = roles.stream().map(RoleUtil::parseRole).collect(Collectors.toList());
String droolStr = JSONUtil.toJsonStr(collect);
// 替换规则中的关键字
Field[] fields = ReflectUtil.getFields(BaseCenter.class);
for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName();
BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.costCenter.getAttribution());
if (ObjectUtil.isNotNull(baseDataEntity)) {
String content = baseDataEntity.getContent();
String contentName = baseDataEntity.getContentName();
droolStr = StrUtil.replace(droolStr, contentName, content, false);
}
String filedValueStr = "";
if (ObjectUtil.isNotNull(fieldValue)) {
filedValueStr = fieldValue.toString();
}
droolStr = StrUtil.replace(droolStr, name, filedValueStr, false);
}
log.info("after - droolStr = {}", droolStr);
JSONArray jsonArray = JSONUtil.parseArray(droolStr);
log.info("jsonArray = {}", jsonArray);
// 解析成google能识别的结构
String conditionResult = ConditionParser.parseCondition(jsonArray);
log.info("condition template = {}", conditionResult);
Object executeB = AviatorEvaluator.execute(conditionResult);
log.info("CostCenterCmp-{} = {}", conditionResult, executeB);
boolean aBoolean = BooleanUtil.toBoolean(executeB.toString());
log.info("CostCenterCmp-aBoolean = {}", aBoolean);
return aBoolean;
} else {
return false;
}
}
}

View File

@ -1,50 +0,0 @@
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.DynamicScriptEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
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.DynamicScriptService;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
*/
//@LiteflowComponent("CostCenter02SoutCmp")
@Component
@Slf4j
public class CostCenterSoutCmp extends NodeComponent {
@Resource
private DynamicScriptService dynamicScriptService;
@Override
public void process() {
BaseCenter baseCenter = this.getRequestData();
String nodeId = this.getNodeId();
String nodeName = this.getName();
log.info("nodeId = {}, nodeName = {}", nodeId, nodeName);
DynamicScriptEntity dynamicScriptEntity = dynamicScriptService.getByScriptId(nodeId);
String scriptContent = dynamicScriptEntity.getScriptContent();
JSONObject jsonObject = JSONUtil.parseObj(scriptContent);
SoutFrom soutFrom = BeanUtil.toBean(jsonObject, SoutFrom.class);
String costCenterCode = soutFrom.getCode();
String costCenterName = soutFrom.getName();
baseCenter.setCostCenterCode(costCenterCode);
baseCenter.setCostCenterName(costCenterName);
baseCenter.setCostCenterGenerateCode(costCenterCode + costCenterName);
baseCenter.setGenerateCode(null);
}
}

View File

@ -1,51 +0,0 @@
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.DynamicScriptEntity;
import com.example.liteflow.mysql.enums.BaseDataAttributionEnum;
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.DynamicScriptService;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
*/
@Component
@Slf4j
public class ProfitCenterSoutCmp extends NodeComponent {
// private static final String profitCenter02Code = "P350401026";
// private static final String profitCenter02Name = "商品车物流部利润中心";
@Resource
private DynamicScriptService dynamicScriptService;
@Override
public void process() {
BaseCenter baseCenter = this.getRequestData();
String nodeId = this.getNodeId();
String nodeName = this.getName();
log.info("nodeId = {}, nodeName = {}", nodeId, nodeName);
DynamicScriptEntity dynamicScriptEntity = dynamicScriptService.getByScriptId(nodeId);
String scriptContent = dynamicScriptEntity.getScriptContent();
JSONObject jsonObject = JSONUtil.parseObj(scriptContent);
SoutFrom soutFrom = BeanUtil.toBean(jsonObject, SoutFrom.class);
String profitCenterCode = soutFrom.getCode();
String profitCenterName = soutFrom.getName();
baseCenter.setProfitCenterCode(profitCenterCode);
baseCenter.setProfitCenterName(profitCenterName);
baseCenter.setProfitCenterGenerateCode(profitCenterCode + profitCenterName);
baseCenter.setGenerateCode(null);
}
}

View File

@ -0,0 +1,33 @@
package com.example.liteflow.mysql.controller;
import com.example.liteflow.mysql.model.node.CreateNodeFrom;
import com.example.liteflow.mysql.service.BaseChainService;
import com.example.liteflow.mysql.service.BaseNodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* @author: 陈韦龙
* @date: 2022年12月08日 18:31
*/
@Slf4j
@RestController
@RequestMapping("/baseChain")
public class BaseChainController {
@Resource
private BaseChainService baseChainService;
@PostMapping("/generateDynamicChain")
public void generateDynamicChain() {
baseChainService.generateDynamicChain();
}
@GetMapping("/executeChain/{chainName}")
public void executeChain(@PathVariable String chainName) {
baseChainService.executeChain(chainName);
}
}

View File

@ -0,0 +1,30 @@
package com.example.liteflow.mysql.controller;
import com.example.liteflow.mysql.model.node.CreateNodeFrom;
import com.example.liteflow.mysql.service.BaseNodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
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;
/**
* @author: 陈韦龙
* @date: 2022年12月08日 18:31
*/
@Slf4j
@RestController
@RequestMapping("/baseNode")
public class BaseNodeController {
@Resource
private BaseNodeService baseNodeService;
@PostMapping("/createNode")
public void createNode(@RequestBody CreateNodeFrom createNodeFrom) {
baseNodeService.createNode(createNodeFrom);
}
}

View File

@ -0,0 +1,33 @@
package com.example.liteflow.mysql.controller;
import com.example.liteflow.mysql.model.CommonResult;
import com.example.liteflow.mysql.model.baseTemplate.CreateTemplateFrom;
import com.example.liteflow.mysql.model.node.CreateNodeFrom;
import com.example.liteflow.mysql.service.BaseNodeService;
import com.example.liteflow.mysql.service.BaseTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
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;
/**
* @author: 陈韦龙
* @date: 2022年12月08日 18:31
*/
@Slf4j
@RestController
@RequestMapping("/baseTemplate")
public class BaseTemplateController {
@Resource
private BaseTemplateService baseTemplateService;
@PostMapping("/createTemplate")
public CommonResult createTemplate(@RequestBody CreateTemplateFrom createTemplateFrom) {
return baseTemplateService.createTemplate(createTemplateFrom);
}
}

View File

@ -1,89 +0,0 @@
package com.example.liteflow.mysql.controller;
import cn.hutool.json.JSONObject;
import com.example.liteflow.mysql.entity.ChainEntity;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.service.ChainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月08日 18:31
*/
@Slf4j
@RestController
@RequestMapping("/chain")
public class ChainController {
@Resource
private ChainService chainService;
/**
* 创建链路实体
*
* @param chainEntity
*/
@PostMapping("/createChain")
public void createChain(@RequestBody ChainEntity chainEntity) {
chainService.createChain(chainEntity);
}
/**
* 创建动态链路
*
* @param chainEntity
*/
@PostMapping("/dynamicGenerateChain")
public void dynamicGenerateChain(@RequestBody ChainEntity chainEntity) {
chainService.dynamicGenerateChain(chainEntity);
}
/**
* 根据链路名称执行链路
*
* @param chainName
*/
@GetMapping("/executeChain/{chainName}")
public List<BaseCenter> executeChain(@PathVariable("chainName") String chainName) {
return chainService.executeChain(chainName);
}
/**
* 获取链路
*
* @param chainName
*/
@GetMapping("/getChainByName/{chainName}")
public ChainEntity getChainByName(@PathVariable("chainName") String chainName) {
return chainService.getChainName(chainName);
}
/**
* 删除链路
*
* @param id
*/
@DeleteMapping("/deleteChain/{id}")
public String deleteChain(@PathVariable("id") String id) {
return chainService.deleteChain(id);
}
/**
* 跟新链路
*
* @param chainEntity
*/
@PostMapping("/updateChain")
public String updateChain(@RequestBody ChainEntity chainEntity) {
return chainService.updateChain(chainEntity);
}
@GetMapping("/getChain")
public List<JSONObject> getChain() {
return chainService.getChain();
}
}

View File

@ -1,48 +0,0 @@
package com.example.liteflow.mysql.controller;
import cn.hutool.json.JSONObject;
import com.example.liteflow.mysql.model.dynamicScript.CreateDynamicScriptFrom;
import com.example.liteflow.mysql.service.DynamicScriptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月12日 15:51
*/
@Slf4j
@RestController
@RequestMapping("/dynamicScript")
public class DynamicScriptController {
@Resource
private DynamicScriptService dynamicScriptService;
@PostMapping("/createCostCenterNode")
public void createCostCenterNode(@RequestBody CreateDynamicScriptFrom createDynamicScriptFrom) {
dynamicScriptService.createCostCenterNode(createDynamicScriptFrom);
}
@PostMapping("/createCostCenterIfNode")
public void createCostCenterIfNode(@RequestBody CreateDynamicScriptFrom createDynamicScriptFrom) {
dynamicScriptService.createCostCenterIfNode(createDynamicScriptFrom);
}
@PostMapping("/createProfitCenterNode")
public void createProfitCenterNode(@RequestBody CreateDynamicScriptFrom createDynamicScriptFrom) {
dynamicScriptService.createProfitCenterNode(createDynamicScriptFrom);
}
@PostMapping("/createProfitCenterIfNode")
public void createProfitCenterIfNode(@RequestBody CreateDynamicScriptFrom createDynamicScriptFrom) {
dynamicScriptService.createProfitCenterIfNode(createDynamicScriptFrom);
}
@GetMapping("/getNode")
public List<JSONObject> getNode() {
return dynamicScriptService.getNode();
}
}

View File

@ -17,8 +17,8 @@ public class BaseDataEntity {
private String id;
@TableField("type")
private String type;
@TableField("attribution")
private String attribution;
@TableField("template_id")
private String templateId;
@TableField("content")
private String content;
@TableField("content_type")

View File

@ -1,30 +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;
import java.time.LocalDateTime;
/**
* @author: 陈韦龙
* @date: 2022年12月06日 09:59
*/
@TableName("chain")
@Data
public class ChainEntity {
@TableId(value = "ID", type = IdType.AUTO)
private String id;
@TableField("application_name")
private String applicationName;
@TableField("chain_name")
private String chainName;
@TableField("chain_desc")
private String chainDesc;
@TableField("el_data")
private String elData;
@TableField("create_time")
private LocalDateTime createTime = LocalDateTime.now();
}

View File

@ -1,56 +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;
/**
*
* @TableName dynamic_script
*/
@TableName("dynamic_script")
@Data
public class DynamicScriptEntity {
/**
* 主键
*/
@TableId(value = "ID", type = IdType.ASSIGN_ID)
private String id;
/**
* 脚本Id
*/
@TableField("script_id")
private String scriptId;
/**
* 脚本名称
*/
@TableField("script_name")
private String scriptName;
/**
* 脚本对应类名
*/
@TableField("script_class")
private String scriptClass;
/**
* 脚本对应节点类型
*/
@TableField("node_type")
private String nodeType;
/**
* 脚本规则
*/
@TableField("script_role")
private String scriptRole;
/**
* 脚本内容
*/
@TableField("script_content")
private String scriptContent;
}

View File

@ -0,0 +1,50 @@
package com.example.liteflow.mysql.enums;
import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Objects;
/**
* @author: 陈韦龙
* @date: 2022年12月14日 11:28
*/
@Getter
@AllArgsConstructor
public enum EnableMarkEnum {
/**
* 启用状态
*/
Enable(1, "启用"),
Disable(0, "禁用"),
;
private final Integer value;
private final String name;
public static EnableMarkEnum fromValue(int value) {
for (EnableMarkEnum enableMarkEnum : EnableMarkEnum.values()) {
if (Objects.equals(value, enableMarkEnum.getValue())) {
return enableMarkEnum;
}
}
throw new IllegalArgumentException("Enum type does not exist!");
}
public static EnableMarkEnum fromName(String name) {
if (StrUtil.isBlank(name)) {
return null;
}
for (EnableMarkEnum enableMarkEnum : EnableMarkEnum.values()) {
if (Objects.equals(name, enableMarkEnum.getName())) {
return enableMarkEnum;
}
}
return null;
}
}

View File

@ -12,8 +12,18 @@ import lombok.ToString;
@AllArgsConstructor
@ToString
public enum NodeEnum {
CommonNode("CommonNode"),
IfNode("IfNode"),
CommonNode("CommonNode", "com.example.liteflow.mysql.cmp.OutputCmp"),
IfNode("IfNode", "com.example.liteflow.mysql.cmp.CenterCmp"),
;
private final String name;
private final String nodeClass;
public static NodeEnum getByName(String name) {
for (NodeEnum nodeEnum : NodeEnum.values()) {
if (nodeEnum.getName().equals(name)) {
return nodeEnum;
}
}
return null;
}
}

View File

@ -0,0 +1,29 @@
package com.example.liteflow.mysql.handler;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author: 陈韦龙
* @date: 2022年12月14日 09:39
*/
@Component
@Slf4j
public class MybatisHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
log.info("start insert .. ");
this.setFieldValByName("creatorTime", LocalDateTime.now(), metaObject);
// this.setFieldValByName("lastModifyTime", LocalDateTime.now(), metaObject);
}
@Override
public void updateFill(MetaObject metaObject) {
log.info("start update .. ");
this.setFieldValByName("lastModifyTime", LocalDateTime.now(), metaObject);
}
}

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.ChainEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* @author: 陈韦龙
* @date: 2022年12月06日 10:08
*/
@Mapper
public interface ChainMapper extends BaseMapper<ChainEntity> {
}

View File

@ -1,17 +0,0 @@
package com.example.liteflow.mysql.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.liteflow.mysql.entity.DynamicScriptEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* @author 75349
* @description 针对表dynamic_script的数据库操作Mapper
* @createDate 2022-12-12 15:46:00
* @Entity generator.domain.DynamicScript
*/
@Mapper
public interface DynamicScriptMapper extends BaseMapper<DynamicScriptEntity> {
}

View File

@ -1,5 +1,6 @@
package com.example.liteflow.mysql.model;
import cn.hutool.json.JSONObject;
import lombok.Data;
/**
@ -29,11 +30,5 @@ public class BaseCenter {
private String name;
private String generateCode;
private String costCenterCode;
private String costCenterName;
private String costCenterGenerateCode;
private String profitCenterCode;
private String profitCenterName;
private String profitCenterGenerateCode;
private JSONObject jsonObject;
}

View File

@ -0,0 +1,47 @@
package com.example.liteflow.mysql.model;
import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author: 陈韦龙
* @date: 2022年12月14日 10:50
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T> {
private Integer code;
private String message;
private T data;
public CommonResult(Integer code, String message) {
this(code, message, null);
}
public static CommonResult fail(String message) {
CommonResult commonResult = new CommonResult();
commonResult.setCode(999);
commonResult.setMessage(message);
return commonResult;
}
public static CommonResult success(String message) {
CommonResult commonResult = new CommonResult();
commonResult.setCode(200);
commonResult.setMessage(message);
return commonResult;
}
public static CommonResult success(String message, Object obj) {
CommonResult commonResult = new CommonResult();
commonResult.setCode(200);
commonResult.setMessage(message);
commonResult.setData(obj);
return commonResult;
}
}

View File

@ -7,7 +7,7 @@ import lombok.Data;
* @date: 2022年12月12日 18:30
*/
@Data
public class SoutFrom {
public class OutputFrom {
private String code;
private String name;
}

View File

@ -0,0 +1,12 @@
package com.example.liteflow.mysql.model.baseTemplate;
import lombok.Data;
/**
* @author: 陈韦龙
* @date: 2022年12月14日 09:57
*/
@Data
public class CreateTemplateFrom {
private String templateName;
}

View File

@ -0,0 +1,14 @@
package com.example.liteflow.mysql.model.baseTemplate;
import lombok.Data;
/**
* @author: 陈韦龙
* @date: 2022年12月14日 09:57
*/
@Data
public class UpdateTemplateFrom {
private String id;
private String templateName;
private Integer EnableMark;
}

View File

@ -1,33 +0,0 @@
package com.example.liteflow.mysql.model.dynamicScript;
import com.example.liteflow.mysql.model.SoutFrom;
import com.example.liteflow.mysql.model.role.Role;
import lombok.Data;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月12日 15:52
*/
@Data
public class CreateDynamicScriptFrom {
/**
* 脚本Id
*/
private String scriptId;
/**
* 脚本名称
*/
private String scriptName;
/**
* 规则
*/
private List<Role> roles;
/**
* 内容
*/
private SoutFrom content;
}

View File

@ -1,36 +0,0 @@
package com.example.liteflow.mysql.model.dynamicScript;
import com.example.liteflow.mysql.model.SoutFrom;
import com.example.liteflow.mysql.model.role.Role;
import lombok.Data;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月12日 15:52
*/
@Data
public class UpdateDynamicScriptFrom {
/**
* 主键
*/
private String id;
/**
* 脚本Id
*/
private String scriptId;
/**
* 脚本名称
*/
private String scriptName;
/**
* 规则
*/
private List<Role> roles;
/**
* 内容
*/
private SoutFrom content;
}

View File

@ -0,0 +1,47 @@
package com.example.liteflow.mysql.model.node;
import com.example.liteflow.mysql.model.OutputFrom;
import com.example.liteflow.mysql.model.role.Role;
import lombok.Data;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月14日 10:15
*/
@Data
public class CreateNodeFrom {
/**
* 节点在规则引擎中的Id
*/
private String nodeId;
/**
* 所属模板id
*/
private String templateId;
/**
* 节点名称
*/
private String nodeName;
/**
* 节点类型
*/
private String nodeType;
/**
* 规则
*/
private List<Role> roles;
/**
* 节点对应输出节点id
*/
private String nodeContentId;
/**
* 内容
*/
private OutputFrom content;
}

View File

@ -0,0 +1,32 @@
package com.example.liteflow.mysql.model.node;
import com.example.liteflow.mysql.model.OutputFrom;
import com.example.liteflow.mysql.model.role.Role;
import lombok.Data;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月14日 10:15
*/
@Data
public class UpdateNodeFrom {
private String id;
/**
* 节点对应输出节点id
*/
private String nodeContentId;
/**
* 规则
*/
private List<Role> roles;
/**
* 内容
*/
private OutputFrom content;
/**
* 有效状态1-有效0无效
*/
private Integer enableMark;
}

View File

@ -0,0 +1,26 @@
package com.example.liteflow.mysql.runner;
import com.example.liteflow.mysql.service.BaseChainService;
import com.yomahub.liteflow.core.FlowExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @author: 陈韦龙
* @date: 2022年12月12日 17:21
*/
@Component
@Slf4j
public class AviatorEvaluatorRunner implements CommandLineRunner {
@Resource
private BaseChainService baseChainService;
@Override
public void run(String... args) throws Exception {
baseChainService.initDynamicChain();
baseChainService.initMainChain();
}
}

View File

@ -8,7 +8,7 @@ import com.example.liteflow.mysql.entity.BaseDataEntity;
* @date: 2022年12月06日 09:58
*/
public interface BaseDataService extends IService<BaseDataEntity> {
BaseDataEntity getByType(String type, String attribution);
BaseDataEntity getByTypeAndTemplateId(String type, String attribution);
BaseDataEntity getByTypeAndName(String type, String attribution, String contentName);
}

View File

@ -1,28 +0,0 @@
package com.example.liteflow.mysql.service;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.liteflow.mysql.entity.ChainEntity;
import com.example.liteflow.mysql.model.BaseCenter;
import java.util.List;
/**
* @author: 陈韦龙
* @date: 2022年12月08日 18:23
*/
public interface ChainService extends IService<ChainEntity> {
void createChain(ChainEntity chainEntity);
void dynamicGenerateChain(ChainEntity chainEntity);
List<BaseCenter> executeChain(String chainName);
ChainEntity getChainName(String chainName);
String deleteChain(String id);
String updateChain(ChainEntity chainEntity);
List<JSONObject> getChain();
}

View File

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

View File

@ -16,11 +16,11 @@ import org.springframework.stereotype.Service;
@Service
public class BaseDataServiceImpl extends ServiceImpl<BaseDataMapper, BaseDataEntity> implements BaseDataService {
@Override
public BaseDataEntity getByType(String type, String attribution) {
log.info("type = {}, attribution = {}", type, attribution);
public BaseDataEntity getByTypeAndTemplateId(String type, String templateId) {
log.info("type = {}, templateId = {}", type, templateId);
LambdaQueryWrapper<BaseDataEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(BaseDataEntity::getType, type)
.eq(BaseDataEntity::getAttribution, attribution);
.eq(BaseDataEntity::getTemplateId, templateId);
return this.getOne(queryWrapper);
}
@ -29,7 +29,7 @@ public class BaseDataServiceImpl extends ServiceImpl<BaseDataMapper, BaseDataEnt
log.info("type = {}, attribution = {}", type, attribution);
LambdaQueryWrapper<BaseDataEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(BaseDataEntity::getType, type)
.eq(BaseDataEntity::getAttribution, attribution)
.eq(BaseDataEntity::getTemplateId, attribution)
.eq(BaseDataEntity::getContentName, contentName);
return this.getOne(queryWrapper);
}

View File

@ -1,149 +0,0 @@
package com.example.liteflow.mysql.service.impl;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.liteflow.mysql.entity.ChainEntity;
import com.example.liteflow.mysql.mapper.ChainMapper;
import com.example.liteflow.mysql.model.BaseCenter;
import com.example.liteflow.mysql.model.CostCenter;
import com.example.liteflow.mysql.model.ProfitCenter;
import com.example.liteflow.mysql.service.ChainService;
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.flow.element.Chain;
import com.yomahub.liteflow.flow.element.Node;
import com.yomahub.liteflow.flow.element.condition.Condition;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author: 陈韦龙
* @date: 2022年12月08日 18:23
*/
@Service
@Slf4j
public class ChainServiceImpl extends ServiceImpl<ChainMapper, ChainEntity> implements ChainService {
@Resource
private FlowExecutor flowExecutor;
@Override
public void createChain(ChainEntity chainEntity) {
this.save(chainEntity);
}
@Override
public void dynamicGenerateChain(ChainEntity chainEntity) {
LiteFlowChainELBuilder.createChain()
.setChainId(chainEntity.getChainName())
.setEL(chainEntity.getElData())
.build();
flowExecutor.reloadRule();
this.save(chainEntity);
}
@Override
public ChainEntity getChainName(String chainName) {
LambdaQueryWrapper<ChainEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(ChainEntity::getChainName, chainName);
return this.getOne(queryWrapper);
}
@Override
public List<BaseCenter> executeChain(String chainName) {
List<BaseCenter> list = this.generateCostCenterTestData();
log.info("before-list = {}", JSONUtil.toJsonStr(list));
list.forEach(item -> {
LiteflowResponse response = flowExecutor.execute2Resp(chainName, item);
if (response.isSuccess()) {
log.info("执行成功");
} else {
log.info("执行失败");
}
});
log.info("after-list = {}", JSONUtil.toJsonStr(list));
return list;
}
private List<BaseCenter> generateCostCenterTestData() {
List<BaseCenter> list = new ArrayList<>();
CostCenter costCenter = new CostCenter();
costCenter.setSectionClassification("成本科目");
costCenter.setBusinessType("货代");
costCenter.setSalesman("仓干配物流部(物流)");
costCenter.setBusinessCategory("全货船业务");
list.add(costCenter);
costCenter = new CostCenter();
costCenter.setBusinessType("货代");
costCenter.setSalesman("仓干配物流部(物流)");
list.add(costCenter);
costCenter = new CostCenter();
costCenter.setBusinessType("货代");
list.add(costCenter);
ProfitCenter profitCenter = new ProfitCenter();
profitCenter.setSectionClassification("银行科目");
profitCenter.setBusinessType("货代");
profitCenter.setSalesman("商品车物流部(物流)");
profitCenter.setBusinessCategory("运输业务");
list.add(profitCenter);
profitCenter = new ProfitCenter();
profitCenter.setBusinessType("货代");
profitCenter.setSalesman("商品车物流部(物流)");
list.add(profitCenter);
return list;
}
@Override
public String deleteChain(String id) {
LambdaQueryWrapper<ChainEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(ChainEntity::getId, id);
if (this.remove(queryWrapper)) {
flowExecutor.reloadRule();
return "删除成功";
} else {
return "删除失败";
}
}
@Override
public String updateChain(ChainEntity chainEntity) {
String id = chainEntity.getId();
String elData = chainEntity.getElData();
LambdaUpdateWrapper<ChainEntity> queryWrapper = new LambdaUpdateWrapper<>();
queryWrapper.set(ChainEntity::getElData, elData).eq(ChainEntity::getId, id);
if (this.update(queryWrapper)) {
flowExecutor.reloadRule();
return "更新成功";
} else {
return "更新失败";
}
}
@Override
public List<JSONObject> getChain() {
List<ChainEntity> list = this.list();
return list.stream().filter(item -> FlowBus.containChain(item.getChainName())).map(item -> {
String chainName = item.getChainName();
String elData = item.getElData();
JSONObject jsonObject = new JSONObject();
jsonObject.putOpt("chainName", chainName).putOpt("elData", elData);
return jsonObject;
}).collect(Collectors.toList());
}
}

View File

@ -1,240 +0,0 @@
package com.example.liteflow.mysql.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.liteflow.mysql.entity.DynamicScriptEntity;
import com.example.liteflow.mysql.enums.NodeEnum;
import com.example.liteflow.mysql.mapper.DynamicScriptMapper;
import com.example.liteflow.mysql.model.SoutFrom;
import com.example.liteflow.mysql.model.dynamicScript.CreateDynamicScriptFrom;
import com.example.liteflow.mysql.model.dynamicScript.UpdateDynamicScriptFrom;
import com.example.liteflow.mysql.model.role.Role;
import com.example.liteflow.mysql.service.DynamicScriptService;
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 java.util.List;
import java.util.stream.Collectors;
/**
* @author 75349
* @description 针对表dynamic_script的数据库操作Service实现
* @createDate 2022-12-12 15:46:00
*/
@Service
@Slf4j
public class DynamicScriptServiceImpl extends ServiceImpl<DynamicScriptMapper, DynamicScriptEntity>
implements DynamicScriptService {
private final static String costCenterCmp = "com.example.liteflow.mysql.cmp.costCenter.CostCenterCmp";
private final static String costCenterSoutCmp = "com.example.liteflow.mysql.cmp.costCenter.CostCenterSoutCmp";
private final static String profitCenterCmp = "com.example.liteflow.mysql.cmp.profitCenter.ProfitCenterCmp";
private final static String profitCenterSoutCmp = "com.example.liteflow.mysql.cmp.profitCenter.ProfitCenterSoutCmp";
@Override
public void createCostCenterNode(CreateDynamicScriptFrom createDynamicScriptFrom) {
String scriptId = createDynamicScriptFrom.getScriptId();
String scriptName = createDynamicScriptFrom.getScriptName();
SoutFrom content = createDynamicScriptFrom.getContent();
LambdaQueryWrapper<DynamicScriptEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DynamicScriptEntity::getScriptId, scriptId);
DynamicScriptEntity entity = this.getOne(queryWrapper);
if (ObjectUtil.isNotNull(entity)) {
UpdateDynamicScriptFrom updateDynamicScriptFrom = BeanUtil.toBean(createDynamicScriptFrom, UpdateDynamicScriptFrom.class);
updateDynamicScriptFrom.setId(entity.getId());
this.updateCostCenterNode(updateDynamicScriptFrom);
} else {
DynamicScriptEntity dynamicScriptEntity = new DynamicScriptEntity();
dynamicScriptEntity.setScriptId(scriptId);
dynamicScriptEntity.setScriptName(scriptName);
dynamicScriptEntity.setScriptContent(JSONUtil.toJsonStr(content));
dynamicScriptEntity.setNodeType(NodeEnum.CommonNode.getName());
dynamicScriptEntity.setScriptClass(costCenterSoutCmp);
this.save(dynamicScriptEntity);
LiteFlowNodeBuilder.createCommonNode().setId(scriptId)
.setName(scriptName)
.setClazz(costCenterSoutCmp)
.build();
}
}
@Override
public void createCostCenterIfNode(CreateDynamicScriptFrom createDynamicScriptFrom) {
String scriptId = createDynamicScriptFrom.getScriptId();
String scriptName = createDynamicScriptFrom.getScriptName();
List<Role> roles = createDynamicScriptFrom.getRoles();
LambdaQueryWrapper<DynamicScriptEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DynamicScriptEntity::getScriptId, scriptId);
DynamicScriptEntity entity = this.getOne(queryWrapper);
if (ObjectUtil.isNotNull(entity)) {
UpdateDynamicScriptFrom updateDynamicScriptFrom = BeanUtil.toBean(createDynamicScriptFrom, UpdateDynamicScriptFrom.class);
updateDynamicScriptFrom.setId(entity.getId());
this.updateCostCenterIfNode(updateDynamicScriptFrom);
} else {
DynamicScriptEntity dynamicScriptEntity = new DynamicScriptEntity();
dynamicScriptEntity.setScriptId(scriptId);
dynamicScriptEntity.setScriptName(scriptName);
dynamicScriptEntity.setScriptRole(JSONUtil.toJsonStr(roles));
dynamicScriptEntity.setNodeType(NodeEnum.IfNode.getName());
dynamicScriptEntity.setScriptClass(costCenterCmp);
this.save(dynamicScriptEntity);
LiteFlowNodeBuilder.createIfNode().setId(scriptId)
.setName(scriptName)
.setClazz(costCenterCmp)
.build();
}
}
public void updateCostCenterNode(UpdateDynamicScriptFrom updateDynamicScriptFrom) {
String id = updateDynamicScriptFrom.getId();
String scriptId = updateDynamicScriptFrom.getScriptId();
String scriptName = updateDynamicScriptFrom.getScriptName();
SoutFrom content = updateDynamicScriptFrom.getContent();
LambdaUpdateWrapper<DynamicScriptEntity> queryWrapper = new LambdaUpdateWrapper<>();
queryWrapper.eq(DynamicScriptEntity::getId, id)
.set(DynamicScriptEntity::getScriptId, scriptId)
.set(DynamicScriptEntity::getScriptName, scriptName)
.set(DynamicScriptEntity::getScriptContent, JSONUtil.toJsonStr(content));
this.update(queryWrapper);
LiteFlowNodeBuilder.createCommonNode().setId(scriptId)
.setName(scriptName)
.setClazz(costCenterSoutCmp)
.build();
}
public void updateCostCenterIfNode(UpdateDynamicScriptFrom updateDynamicScriptFrom) {
String id = updateDynamicScriptFrom.getId();
String scriptId = updateDynamicScriptFrom.getScriptId();
String scriptName = updateDynamicScriptFrom.getScriptName();
List<Role> roles = updateDynamicScriptFrom.getRoles();
LambdaUpdateWrapper<DynamicScriptEntity> queryWrapper = new LambdaUpdateWrapper<>();
queryWrapper.eq(DynamicScriptEntity::getId, id)
.set(DynamicScriptEntity::getScriptId, scriptId)
.set(DynamicScriptEntity::getScriptName, scriptName)
.set(DynamicScriptEntity::getScriptRole, JSONUtil.toJsonStr(roles));
this.update(queryWrapper);
LiteFlowNodeBuilder.createIfNode().setId(scriptId)
.setName(scriptName)
.setClazz(costCenterCmp)
.build();
}
@Override
public void createProfitCenterNode(CreateDynamicScriptFrom createDynamicScriptFrom) {
String scriptId = createDynamicScriptFrom.getScriptId();
String scriptName = createDynamicScriptFrom.getScriptName();
SoutFrom content = createDynamicScriptFrom.getContent();
LambdaQueryWrapper<DynamicScriptEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DynamicScriptEntity::getScriptId, scriptId);
DynamicScriptEntity entity = this.getOne(queryWrapper);
if (ObjectUtil.isNotNull(entity)) {
UpdateDynamicScriptFrom updateDynamicScriptFrom = BeanUtil.toBean(createDynamicScriptFrom, UpdateDynamicScriptFrom.class);
updateDynamicScriptFrom.setId(entity.getId());
this.updateProfitCenterNode(updateDynamicScriptFrom);
} else {
DynamicScriptEntity dynamicScriptEntity = new DynamicScriptEntity();
dynamicScriptEntity.setScriptId(scriptId);
dynamicScriptEntity.setScriptName(scriptName);
dynamicScriptEntity.setScriptContent(JSONUtil.toJsonStr(content));
dynamicScriptEntity.setNodeType(NodeEnum.CommonNode.getName());
dynamicScriptEntity.setScriptClass(profitCenterSoutCmp);
this.save(dynamicScriptEntity);
LiteFlowNodeBuilder.createCommonNode().setId(scriptId)
.setName(scriptName)
.setClazz(profitCenterSoutCmp)
.build();
}
}
@Override
public void createProfitCenterIfNode(CreateDynamicScriptFrom createDynamicScriptFrom) {
String scriptId = createDynamicScriptFrom.getScriptId();
String scriptName = createDynamicScriptFrom.getScriptName();
List<Role> roles = createDynamicScriptFrom.getRoles();
LambdaQueryWrapper<DynamicScriptEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DynamicScriptEntity::getScriptId, scriptId);
DynamicScriptEntity entity = this.getOne(queryWrapper);
if (ObjectUtil.isNotNull(entity)) {
UpdateDynamicScriptFrom updateDynamicScriptFrom = BeanUtil.toBean(createDynamicScriptFrom, UpdateDynamicScriptFrom.class);
updateDynamicScriptFrom.setId(entity.getId());
this.updateProfitCenterIfNode(updateDynamicScriptFrom);
} else {
DynamicScriptEntity dynamicScriptEntity = new DynamicScriptEntity();
dynamicScriptEntity.setScriptId(scriptId);
dynamicScriptEntity.setScriptName(scriptName);
dynamicScriptEntity.setScriptRole(JSONUtil.toJsonStr(roles));
dynamicScriptEntity.setNodeType(NodeEnum.IfNode.getName());
dynamicScriptEntity.setScriptClass(profitCenterCmp);
this.save(dynamicScriptEntity);
LiteFlowNodeBuilder.createIfNode().setId(scriptId)
.setName(scriptName)
.setClazz(profitCenterCmp)
.build();
}
}
public void updateProfitCenterNode(UpdateDynamicScriptFrom updateDynamicScriptFrom) {
String id = updateDynamicScriptFrom.getId();
String scriptId = updateDynamicScriptFrom.getScriptId();
String scriptName = updateDynamicScriptFrom.getScriptName();
SoutFrom content = updateDynamicScriptFrom.getContent();
LambdaUpdateWrapper<DynamicScriptEntity> queryWrapper = new LambdaUpdateWrapper<>();
queryWrapper.eq(DynamicScriptEntity::getId, id)
.set(DynamicScriptEntity::getScriptId, scriptId)
.set(DynamicScriptEntity::getScriptName, scriptName)
.set(DynamicScriptEntity::getScriptContent, JSONUtil.toJsonStr(content));
this.update(queryWrapper);
LiteFlowNodeBuilder.createCommonNode().setId(scriptId)
.setName(scriptName)
.setClazz(profitCenterSoutCmp)
.build();
}
public void updateProfitCenterIfNode(UpdateDynamicScriptFrom updateDynamicScriptFrom) {
String id = updateDynamicScriptFrom.getId();
String scriptId = updateDynamicScriptFrom.getScriptId();
String scriptName = updateDynamicScriptFrom.getScriptName();
List<Role> roles = updateDynamicScriptFrom.getRoles();
LambdaUpdateWrapper<DynamicScriptEntity> queryWrapper = new LambdaUpdateWrapper<>();
queryWrapper.eq(DynamicScriptEntity::getId, id)
.set(DynamicScriptEntity::getScriptId, scriptId)
.set(DynamicScriptEntity::getScriptName, scriptName)
.set(DynamicScriptEntity::getScriptRole, JSONUtil.toJsonStr(roles));
this.update(queryWrapper);
LiteFlowNodeBuilder.createIfNode().setId(scriptId)
.setName(scriptName)
.setClazz(profitCenterCmp)
.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,44 +1,62 @@
create table chain
(
id bigint auto_increment
primary key,
application_name varchar(32) null,
chain_name varchar(32) null,
chain_desc varchar(64) null,
el_data text null,
create_time datetime null
CREATE TABLE `base_template` (
`id` varchar(255) NOT NULL COMMENT '主键',
`template_name` varchar(255) NULL DEFAULT NULL COMMENT '模板名称',
`enable_mark` int(0) NULL DEFAULT NULL COMMENT '有效状态1-有效0无效',
`creator_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`last_modify_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间',
PRIMARY KEY (`id`) USING BTREE
);
INSERT INTO `base_template` VALUES ('1f0e7e01404eb4186b08d4d430fb4121', 'costCenter', 1, '2022-12-14 16:46:39', NULL);
INSERT INTO `base_template` VALUES ('d98ad12ba55c00a047f09bc2a2808004', 'profitCenter', 1, '2022-12-14 17:07:01', NULL);
CREATE TABLE `base_chain` (
`id` varchar(255) NOT NULL COMMENT '主键',
`template_id` varchar(255) NULL DEFAULT NULL COMMENT '所属模板id',
`chain_name` varchar(32) NULL DEFAULT NULL COMMENT '链路名称',
`el_data` text NULL COMMENT '链路语句',
`enable_mark` int(0) NULL DEFAULT NULL COMMENT '有效状态1-有效0无效',
`creator_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`last_modify_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间',
PRIMARY KEY (`id`) USING BTREE
);
CREATE TABLE `base_data` (
`id` varchar(255) NOT NULL,
`type` varchar(30) NULL,
`attribution` varchar(30) NULL,
`content` text NULL,
`content_type` varchar(30) NULL,
`content_name` varchar(30) NULL,
PRIMARY KEY (`id`)
`id` varchar(255) NOT NULL,
`template_id` varchar(255) NULL DEFAULT NULL COMMENT '所属模板id',
`type` varchar(30) NULL DEFAULT NULL,
`content` text NULL,
`content_type` varchar(30) NULL DEFAULT NULL,
`content_name` varchar(30) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
);
INSERT INTO `base_data`(`id`, `template_id`, `type`, `content`, `content_type`, `content_name`) VALUES ('3843512879501886', '1f0e7e01404eb4186b08d4d430fb4121', 'businessCategory', '[全货船业务, 进出岛仓干配]', 'List', 'businessCategoryList');
INSERT INTO `base_data`(`id`, `template_id`, `type`, `content`, `content_type`, `content_name`) VALUES ('9047450688035130', '1f0e7e01404eb4186b08d4d430fb4121', 'businessType', '[货代, 报关, 船代, 散杂货]', 'List', 'businessTypeList');
INSERT INTO `base_data`(`id`, `template_id`, `type`, `content`, `content_type`, `content_name`) VALUES ('5587514507650183', '1f0e7e01404eb4186b08d4d430fb4121', 'salesman', '[仓干配物流部(物流)]', 'List', 'salesmanList');
INSERT INTO `base_data`(`id`, `template_id`, `type`, `content`, `content_type`, `content_name`) VALUES ('7203685907622705', '1f0e7e01404eb4186b08d4d430fb4121', 'sectionClassification', '[汇差, 手续费, 成本科目]', 'List', 'sectionClassificationList');
INSERT INTO `base_data`(`id`, `template_id`, `type`, `content`, `content_type`, `content_name`) VALUES ('3927088550655742', 'd98ad12ba55c00a047f09bc2a2808004', 'businessCategory', '[运输业务, 全货船业务, 进出岛仓干配]', 'List', 'businessCategoryList');
INSERT INTO `base_data`(`id`, `template_id`, `type`, `content`, `content_type`, `content_name`) VALUES ('5363457043311084', 'd98ad12ba55c00a047f09bc2a2808004', 'businessType', '[货代, 船代, 散杂货]', 'List', 'businessTypeList');
INSERT INTO `base_data`(`id`, `template_id`, `type`, `content`, `content_type`, `content_name`) VALUES ('2790513253702116', 'd98ad12ba55c00a047f09bc2a2808004', 'salesman', '[仓干配物流部(物流)]', 'List', 'salesmanList');
INSERT INTO `base_data`(`id`, `template_id`, `type`, `content`, `content_type`, `content_name`) VALUES ('0927941726325838', 'd98ad12ba55c00a047f09bc2a2808004', 'sectionClassification', '[银行科目, 预付科目, 预收科目]', 'List', 'sectionClassificationList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('0927941726325838', 'sectionClassification', 'costCenter', '[银行科目, 预付科目, 预收科目]', 'List', 'sectionClassificationList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('3927088550655742', 'businessCategory', 'costCenter', '[运输业务, 全货船业务, 进出岛仓干配]', 'List', 'businessCategoryList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('5363457043311084', 'businessType', 'costCenter', '[货代, 船代, 散杂货]', 'List', 'businessTypeList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('5587514507650183', 'salesman', 'costCenter', '[仓干配物流部(物流)]', 'List', 'salesmanList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('7203685907622705', 'sectionClassification', 'costCenter', '[汇差, 手续费, 成本科目]', 'List','sectionClassificationList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('3843512879501886', 'businessCategory', 'costCenter', '[全货船业务, 进出岛仓干配]', 'List', 'businessCategoryList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('9047450688035130', 'businessType', 'costCenter', '[货代, 报关, 船代, 散杂货]', 'List', 'businessTypeList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('2790513253702116', 'salesman', 'costCenter', '[仓干配物流部(物流)]', 'List', 'salesmanList');
CREATE TABLE `dynamic_script` (
`id` varchar(255) NOT NULL COMMENT '主键',
`script_id` varchar(32) NULL DEFAULT NULL COMMENT '脚本Id',
`script_name` varchar(64) NULL DEFAULT NULL COMMENT '脚本名称',
`script_class` text NULL COMMENT '脚本对应类名',
`node_type` varchar(30) NULL COMMENT '脚本对应节点类型',
`script_role` text NULL COMMENT '脚本规则',
`script_content` text NULL COMMENT '脚本内容'
PRIMARY KEY (`id`)
CREATE TABLE `base_node` (
`id` varchar(255) NOT NULL COMMENT '主键',
`node_id` varchar(32) NULL DEFAULT NULL COMMENT '节点在规则引擎中的Id',
`template_id` varchar(255) NULL DEFAULT NULL COMMENT '所属模板id',
`node_name` varchar(64) NULL DEFAULT NULL COMMENT '节点名称',
`node_class` text NULL COMMENT '节点对应类名',
`node_type` varchar(30) NULL DEFAULT NULL COMMENT '节点类型',
`node_role` text NULL COMMENT '节点规则',
`node_content_id` varchar(255) NULL DEFAULT NULL COMMENT '节点对应输出节点id',
`node_content` text NULL COMMENT '节点内容',
`enable_mark` int(0) NULL DEFAULT NULL COMMENT '有效状态1-有效0无效',
`creator_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`last_modify_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间',
PRIMARY KEY (`id`) USING BTREE
);

View File

@ -1,7 +1,34 @@
/dynamicScript/createCostCenterIfNode
/baseNode/createNode
{
"scriptId": "a3",
"scriptName": "costCenter01Cmp",
"nodeId": "a7",
"templateId": "1f0e7e01404eb4186b08d4d430fb4121",
"nodeName": "costCenter01Sout",
"nodeType": "CommonNode",
"content": {
"code": "P350401028",
"name": "仓干配物流部利润中心"
}
}
/baseNode/createNode
{
"nodeId": "a8",
"templateId": "1f0e7e01404eb4186b08d4d430fb4121",
"nodeName": "costCenter02Sout",
"nodeType": "CommonNode",
"content": {
"code": "P350401026",
"name": "商品车物流部利润中心"
}
}
/baseNode/createNode
{
"nodeId": "a3",
"templateId": "1f0e7e01404eb4186b08d4d430fb4121",
"nodeName": "costCenter01Cmp",
"nodeType": "IfNode",
"nodeContentId": "2480deadc736b40435a2b6930851aaa5",
"roles": [
{
"logicOperators": "$or",
@ -36,10 +63,13 @@
]
}
/dynamicScript/createCostCenterIfNode
/baseNode/createNode
{
"scriptId": "a4",
"scriptName": "costCenter02Cmp",
"nodeId": "a4",
"templateId": "1f0e7e01404eb4186b08d4d430fb4121",
"nodeName": "costCenter02Cmp",
"nodeType": "IfNode",
"nodeContentId": "0264efebbfb4c7cb5e4cb81092e1bce4",
"roles": [
{
"logicOperators": "$or",
@ -79,10 +109,37 @@
]
}
/dynamicScript/createProfitCenterIfNode
/baseNode/createNode
{
"scriptId": "a1",
"scriptName": "profitCenter01Cmp",
"nodeId": "a5",
"templateId": "d98ad12ba55c00a047f09bc2a2808004",
"nodeName": "profitCenter01Sout",
"nodeType": "CommonNode",
"content": {
"code": "P350401029",
"name": "仓干配物流部成本中心"
}
}
/baseNode/createNode
{
"nodeId": "a6",
"templateId": "d98ad12ba55c00a047f09bc2a2808004",
"nodeName": "profitCenter02Sout",
"nodeType": "CommonNode",
"content": {
"code": "P350401027",
"name": "商品车物流部成本中心"
}
}
/baseNode/createNode
{
"nodeId": "a1",
"templateId": "d98ad12ba55c00a047f09bc2a2808004",
"nodeName": "profitCenter01Cmp",
"nodeType": "IfNode",
"nodeContentId": "1a1df8cbdc9983fa03b3060049293b87",
"roles": [
{
"logicOperators": "$or",
@ -132,10 +189,13 @@
]
}
/dynamicScript/createProfitCenterIfNode
/baseNode/createNode
{
"scriptId": "a2",
"scriptName": "profitCenter02Cmp",
"nodeId": "a2",
"templateId": "d98ad12ba55c00a047f09bc2a2808004",
"nodeName": "profitCenter02Cmp",
"nodeType": "IfNode",
"nodeContentId": "f050bd67f23cd0152f17d4f82d29b8a4",
"roles": [
{
"logicOperators": "$or",
@ -179,67 +239,3 @@
}
]
}
/dynamicScript/createProfitCenterNode
{
"scriptId": "a5",
"scriptName": "profitCenter01Sout",
"content": {
"code": "P350401029",
"name": "仓干配物流部成本中心"
}
}
/dynamicScript/createProfitCenterNode
{
"scriptId": "a6",
"scriptName": "profitCenter02Sout",
"content": {
"code": "P350401027",
"name": "商品车物流部成本中心"
}
}
/dynamicScript/createCostCenterNode
{
"scriptId": "a7",
"scriptName": "costCenter01Sout",
"content": {
"code": "P350401028",
"name": "仓干配物流部利润中心"
}
}
/dynamicScript/createCostCenterNode
{
"scriptId": "a8",
"scriptName": "costCenter02Sout",
"content": {
"code": "P350401026",
"name": "商品车物流部利润中心"
}
}
/chain/dynamicGenerateChain
{
"applicationName": "demo",
"chainName": "cost01AndCost02",
"chainDesc": "测试流程",
"elData": "IF(a3, a7, IF(a4, a8, sout));"
}
/chain/dynamicGenerateChain
{
"applicationName": "demo",
"chainName": "profit01AndProfit02",
"chainDesc": "测试流程",
"elData": "IF(a1, a5, IF(a2, a6, sout));"
}
/chain/dynamicGenerateChain
{
"applicationName": "demo",
"chainName": "costAndProfit",
"chainDesc": "测试流程",
"elData": "THEN(cost01AndCost02, profit01AndProfit02);"
}

View File

@ -2,9 +2,13 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.enums.MathOperatorEnum;
import com.example.liteflow.mysql.enums.NodeEnum;
import com.example.liteflow.mysql.model.node.CreateNodeFrom;
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.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.element.Node;
import org.assertj.core.util.Lists;
import org.junit.Test;
@ -485,4 +489,18 @@ public class MyTest {
public void generateId () {
System.out.println(RandomUtil.randomNumbers(16));
}
@Test
public void soutEnum() {
System.out.println(NodeEnum.CommonNode);
}
@Test
public void test11() {
CreateNodeFrom createNodeFrom = new CreateNodeFrom();
createNodeFrom.setNodeId("a3");
createNodeFrom.setNodeName("costCenter01Cmp");
createNodeFrom.setNodeType(NodeEnum.IfNode.getName());
System.out.println(JSONUtil.toJsonStr(createNodeFrom));
}
}