From daefc826ff491faa4895ccccdd9937833a406793 Mon Sep 17 00:00:00 2001 From: 75349 <753495441@qq.com> Date: Wed, 14 Dec 2022 18:23:59 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=9B=B4=E6=96=B0=E4=B8=BA=E4=BB=8E=E4=B8=8A?= =?UTF-8?q?=E5=BE=80=E4=B8=8B=E5=8A=A8=E6=80=81=E5=A2=9E=E9=95=BF=202.?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=88=9D=E5=A7=8B=E5=8C=96=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BB=8E=E4=B8=8B=E5=BE=80=E4=B8=8A=203.=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mysql/bean/AviatorEvaluatorRunner.java | 74 ------ .../ProfitCenterCmp.java => CenterCmp.java} | 33 ++- .../liteflow/mysql/cmp/DefaultOutputCmp.java | 21 ++ .../example/liteflow/mysql/cmp/OutputCmp.java | 67 +++++ .../example/liteflow/mysql/cmp/SoutCmp.java | 24 -- .../mysql/cmp/costCenter/CostCenterCmp.java | 96 ------- .../cmp/costCenter/CostCenterSoutCmp.java | 50 ---- .../cmp/profitCenter/ProfitCenterSoutCmp.java | 51 ---- .../mysql/controller/BaseChainController.java | 33 +++ .../mysql/controller/BaseNodeController.java | 30 +++ .../controller/BaseTemplateController.java | 33 +++ .../mysql/controller/ChainController.java | 89 ------- .../controller/DynamicScriptController.java | 48 ---- .../liteflow/mysql/entity/BaseDataEntity.java | 4 +- .../liteflow/mysql/entity/ChainEntity.java | 30 --- .../mysql/entity/DynamicScriptEntity.java | 56 ---- .../liteflow/mysql/enums/EnableMarkEnum.java | 50 ++++ .../liteflow/mysql/enums/NodeEnum.java | 14 +- .../mysql/handler/MybatisHandler.java | 29 +++ .../liteflow/mysql/mapper/ChainMapper.java | 13 - .../mysql/mapper/DynamicScriptMapper.java | 17 -- .../liteflow/mysql/model/BaseCenter.java | 9 +- .../liteflow/mysql/model/CommonResult.java | 47 ++++ .../model/{SoutFrom.java => OutputFrom.java} | 2 +- .../baseTemplate/CreateTemplateFrom.java | 12 + .../baseTemplate/UpdateTemplateFrom.java | 14 + .../CreateDynamicScriptFrom.java | 33 --- .../UpdateDynamicScriptFrom.java | 36 --- .../mysql/model/node/CreateNodeFrom.java | 47 ++++ .../mysql/model/node/UpdateNodeFrom.java | 32 +++ .../mysql/runner/AviatorEvaluatorRunner.java | 26 ++ .../mysql/service/BaseDataService.java | 2 +- .../liteflow/mysql/service/ChainService.java | 28 -- .../mysql/service/DynamicScriptService.java | 32 --- .../service/impl/BaseDataServiceImpl.java | 8 +- .../mysql/service/impl/ChainServiceImpl.java | 149 ----------- .../impl/DynamicScriptServiceImpl.java | 240 ------------------ src/main/resources/db.sql | 84 +++--- src/main/resources/测试参数.txt | 148 ++++++----- src/test/java/MyTest.java | 18 ++ 40 files changed, 620 insertions(+), 1209 deletions(-) delete mode 100644 src/main/java/com/example/liteflow/mysql/bean/AviatorEvaluatorRunner.java rename src/main/java/com/example/liteflow/mysql/cmp/{profitCenter/ProfitCenterCmp.java => CenterCmp.java} (75%) create mode 100644 src/main/java/com/example/liteflow/mysql/cmp/DefaultOutputCmp.java create mode 100644 src/main/java/com/example/liteflow/mysql/cmp/OutputCmp.java delete mode 100644 src/main/java/com/example/liteflow/mysql/cmp/SoutCmp.java delete mode 100644 src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterCmp.java delete mode 100644 src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterSoutCmp.java delete mode 100644 src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenterSoutCmp.java create mode 100644 src/main/java/com/example/liteflow/mysql/controller/BaseChainController.java create mode 100644 src/main/java/com/example/liteflow/mysql/controller/BaseNodeController.java create mode 100644 src/main/java/com/example/liteflow/mysql/controller/BaseTemplateController.java delete mode 100644 src/main/java/com/example/liteflow/mysql/controller/ChainController.java delete mode 100644 src/main/java/com/example/liteflow/mysql/controller/DynamicScriptController.java delete mode 100644 src/main/java/com/example/liteflow/mysql/entity/ChainEntity.java delete mode 100644 src/main/java/com/example/liteflow/mysql/entity/DynamicScriptEntity.java create mode 100644 src/main/java/com/example/liteflow/mysql/enums/EnableMarkEnum.java create mode 100644 src/main/java/com/example/liteflow/mysql/handler/MybatisHandler.java delete mode 100644 src/main/java/com/example/liteflow/mysql/mapper/ChainMapper.java delete mode 100644 src/main/java/com/example/liteflow/mysql/mapper/DynamicScriptMapper.java create mode 100644 src/main/java/com/example/liteflow/mysql/model/CommonResult.java rename src/main/java/com/example/liteflow/mysql/model/{SoutFrom.java => OutputFrom.java} (87%) create mode 100644 src/main/java/com/example/liteflow/mysql/model/baseTemplate/CreateTemplateFrom.java create mode 100644 src/main/java/com/example/liteflow/mysql/model/baseTemplate/UpdateTemplateFrom.java delete mode 100644 src/main/java/com/example/liteflow/mysql/model/dynamicScript/CreateDynamicScriptFrom.java delete mode 100644 src/main/java/com/example/liteflow/mysql/model/dynamicScript/UpdateDynamicScriptFrom.java create mode 100644 src/main/java/com/example/liteflow/mysql/model/node/CreateNodeFrom.java create mode 100644 src/main/java/com/example/liteflow/mysql/model/node/UpdateNodeFrom.java create mode 100644 src/main/java/com/example/liteflow/mysql/runner/AviatorEvaluatorRunner.java delete mode 100644 src/main/java/com/example/liteflow/mysql/service/ChainService.java delete mode 100644 src/main/java/com/example/liteflow/mysql/service/DynamicScriptService.java delete mode 100644 src/main/java/com/example/liteflow/mysql/service/impl/ChainServiceImpl.java delete mode 100644 src/main/java/com/example/liteflow/mysql/service/impl/DynamicScriptServiceImpl.java diff --git a/src/main/java/com/example/liteflow/mysql/bean/AviatorEvaluatorRunner.java b/src/main/java/com/example/liteflow/mysql/bean/AviatorEvaluatorRunner.java deleted file mode 100644 index f80c894..0000000 --- a/src/main/java/com/example/liteflow/mysql/bean/AviatorEvaluatorRunner.java +++ /dev/null @@ -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 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 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(); - } - }); - } -} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenterCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/CenterCmp.java similarity index 75% rename from src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenterCmp.java rename to src/main/java/com/example/liteflow/mysql/cmp/CenterCmp.java index c8ff2c5..e00db01 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenterCmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/CenterCmp.java @@ -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 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 roles = JSONUtil.toList(JSONUtil.parseArray(nodeRole), Role.class); List> 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; diff --git a/src/main/java/com/example/liteflow/mysql/cmp/DefaultOutputCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/DefaultOutputCmp.java new file mode 100644 index 0000000..bce38f1 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/cmp/DefaultOutputCmp.java @@ -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("无匹配项"); + } + } + +} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/OutputCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/OutputCmp.java new file mode 100644 index 0000000..bb72c75 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/cmp/OutputCmp.java @@ -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); + } + } + } + + + } + +} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/SoutCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/SoutCmp.java deleted file mode 100644 index c5ec0ea..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/SoutCmp.java +++ /dev/null @@ -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("无匹配项"); - } - } - -} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterCmp.java deleted file mode 100644 index 5382762..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterCmp.java +++ /dev/null @@ -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 roles = JSONUtil.toList(JSONUtil.parseArray(scriptRole), Role.class); - List> 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; - } - } -} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterSoutCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterSoutCmp.java deleted file mode 100644 index 020f06f..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterSoutCmp.java +++ /dev/null @@ -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); - - } -} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenterSoutCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenterSoutCmp.java deleted file mode 100644 index 153b903..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenterSoutCmp.java +++ /dev/null @@ -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); - - } -} diff --git a/src/main/java/com/example/liteflow/mysql/controller/BaseChainController.java b/src/main/java/com/example/liteflow/mysql/controller/BaseChainController.java new file mode 100644 index 0000000..074dc19 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/controller/BaseChainController.java @@ -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); + } + +} diff --git a/src/main/java/com/example/liteflow/mysql/controller/BaseNodeController.java b/src/main/java/com/example/liteflow/mysql/controller/BaseNodeController.java new file mode 100644 index 0000000..30f5e29 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/controller/BaseNodeController.java @@ -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); + } + +} diff --git a/src/main/java/com/example/liteflow/mysql/controller/BaseTemplateController.java b/src/main/java/com/example/liteflow/mysql/controller/BaseTemplateController.java new file mode 100644 index 0000000..a92f280 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/controller/BaseTemplateController.java @@ -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); + } + +} diff --git a/src/main/java/com/example/liteflow/mysql/controller/ChainController.java b/src/main/java/com/example/liteflow/mysql/controller/ChainController.java deleted file mode 100644 index f9e7e13..0000000 --- a/src/main/java/com/example/liteflow/mysql/controller/ChainController.java +++ /dev/null @@ -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 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 getChain() { - return chainService.getChain(); - } -} diff --git a/src/main/java/com/example/liteflow/mysql/controller/DynamicScriptController.java b/src/main/java/com/example/liteflow/mysql/controller/DynamicScriptController.java deleted file mode 100644 index f8bbc3f..0000000 --- a/src/main/java/com/example/liteflow/mysql/controller/DynamicScriptController.java +++ /dev/null @@ -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 getNode() { - return dynamicScriptService.getNode(); - } -} diff --git a/src/main/java/com/example/liteflow/mysql/entity/BaseDataEntity.java b/src/main/java/com/example/liteflow/mysql/entity/BaseDataEntity.java index 7d528ef..528e73a 100644 --- a/src/main/java/com/example/liteflow/mysql/entity/BaseDataEntity.java +++ b/src/main/java/com/example/liteflow/mysql/entity/BaseDataEntity.java @@ -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") diff --git a/src/main/java/com/example/liteflow/mysql/entity/ChainEntity.java b/src/main/java/com/example/liteflow/mysql/entity/ChainEntity.java deleted file mode 100644 index 699eefe..0000000 --- a/src/main/java/com/example/liteflow/mysql/entity/ChainEntity.java +++ /dev/null @@ -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(); -} diff --git a/src/main/java/com/example/liteflow/mysql/entity/DynamicScriptEntity.java b/src/main/java/com/example/liteflow/mysql/entity/DynamicScriptEntity.java deleted file mode 100644 index cc81a2d..0000000 --- a/src/main/java/com/example/liteflow/mysql/entity/DynamicScriptEntity.java +++ /dev/null @@ -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; - -} \ No newline at end of file diff --git a/src/main/java/com/example/liteflow/mysql/enums/EnableMarkEnum.java b/src/main/java/com/example/liteflow/mysql/enums/EnableMarkEnum.java new file mode 100644 index 0000000..6951821 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/enums/EnableMarkEnum.java @@ -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; + } + +} diff --git a/src/main/java/com/example/liteflow/mysql/enums/NodeEnum.java b/src/main/java/com/example/liteflow/mysql/enums/NodeEnum.java index cc315c5..a0882b2 100644 --- a/src/main/java/com/example/liteflow/mysql/enums/NodeEnum.java +++ b/src/main/java/com/example/liteflow/mysql/enums/NodeEnum.java @@ -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; + } } diff --git a/src/main/java/com/example/liteflow/mysql/handler/MybatisHandler.java b/src/main/java/com/example/liteflow/mysql/handler/MybatisHandler.java new file mode 100644 index 0000000..25092d7 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/handler/MybatisHandler.java @@ -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); + } +} diff --git a/src/main/java/com/example/liteflow/mysql/mapper/ChainMapper.java b/src/main/java/com/example/liteflow/mysql/mapper/ChainMapper.java deleted file mode 100644 index fdc55d6..0000000 --- a/src/main/java/com/example/liteflow/mysql/mapper/ChainMapper.java +++ /dev/null @@ -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 { -} diff --git a/src/main/java/com/example/liteflow/mysql/mapper/DynamicScriptMapper.java b/src/main/java/com/example/liteflow/mysql/mapper/DynamicScriptMapper.java deleted file mode 100644 index 63d279e..0000000 --- a/src/main/java/com/example/liteflow/mysql/mapper/DynamicScriptMapper.java +++ /dev/null @@ -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 { - - -} diff --git a/src/main/java/com/example/liteflow/mysql/model/BaseCenter.java b/src/main/java/com/example/liteflow/mysql/model/BaseCenter.java index 159c3cc..1a16155 100644 --- a/src/main/java/com/example/liteflow/mysql/model/BaseCenter.java +++ b/src/main/java/com/example/liteflow/mysql/model/BaseCenter.java @@ -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; } diff --git a/src/main/java/com/example/liteflow/mysql/model/CommonResult.java b/src/main/java/com/example/liteflow/mysql/model/CommonResult.java new file mode 100644 index 0000000..6b4e4a8 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/model/CommonResult.java @@ -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 { + 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; + } + +} diff --git a/src/main/java/com/example/liteflow/mysql/model/SoutFrom.java b/src/main/java/com/example/liteflow/mysql/model/OutputFrom.java similarity index 87% rename from src/main/java/com/example/liteflow/mysql/model/SoutFrom.java rename to src/main/java/com/example/liteflow/mysql/model/OutputFrom.java index 3d9744c..c25a9d1 100644 --- a/src/main/java/com/example/liteflow/mysql/model/SoutFrom.java +++ b/src/main/java/com/example/liteflow/mysql/model/OutputFrom.java @@ -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; } diff --git a/src/main/java/com/example/liteflow/mysql/model/baseTemplate/CreateTemplateFrom.java b/src/main/java/com/example/liteflow/mysql/model/baseTemplate/CreateTemplateFrom.java new file mode 100644 index 0000000..53ae245 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/model/baseTemplate/CreateTemplateFrom.java @@ -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; +} diff --git a/src/main/java/com/example/liteflow/mysql/model/baseTemplate/UpdateTemplateFrom.java b/src/main/java/com/example/liteflow/mysql/model/baseTemplate/UpdateTemplateFrom.java new file mode 100644 index 0000000..9455c62 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/model/baseTemplate/UpdateTemplateFrom.java @@ -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; +} diff --git a/src/main/java/com/example/liteflow/mysql/model/dynamicScript/CreateDynamicScriptFrom.java b/src/main/java/com/example/liteflow/mysql/model/dynamicScript/CreateDynamicScriptFrom.java deleted file mode 100644 index 81ffbaa..0000000 --- a/src/main/java/com/example/liteflow/mysql/model/dynamicScript/CreateDynamicScriptFrom.java +++ /dev/null @@ -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 roles; - /** - * 内容 - */ - private SoutFrom content; - -} diff --git a/src/main/java/com/example/liteflow/mysql/model/dynamicScript/UpdateDynamicScriptFrom.java b/src/main/java/com/example/liteflow/mysql/model/dynamicScript/UpdateDynamicScriptFrom.java deleted file mode 100644 index b0574bc..0000000 --- a/src/main/java/com/example/liteflow/mysql/model/dynamicScript/UpdateDynamicScriptFrom.java +++ /dev/null @@ -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 roles; - /** - * 内容 - */ - private SoutFrom content; -} diff --git a/src/main/java/com/example/liteflow/mysql/model/node/CreateNodeFrom.java b/src/main/java/com/example/liteflow/mysql/model/node/CreateNodeFrom.java new file mode 100644 index 0000000..1f90cbd --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/model/node/CreateNodeFrom.java @@ -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 roles; + /** + * 节点对应输出节点id + */ + private String nodeContentId; + /** + * 内容 + */ + private OutputFrom content; +} diff --git a/src/main/java/com/example/liteflow/mysql/model/node/UpdateNodeFrom.java b/src/main/java/com/example/liteflow/mysql/model/node/UpdateNodeFrom.java new file mode 100644 index 0000000..aff3825 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/model/node/UpdateNodeFrom.java @@ -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 roles; + /** + * 内容 + */ + private OutputFrom content; + /** + * 有效状态:1-有效;0无效 + */ + private Integer enableMark; +} diff --git a/src/main/java/com/example/liteflow/mysql/runner/AviatorEvaluatorRunner.java b/src/main/java/com/example/liteflow/mysql/runner/AviatorEvaluatorRunner.java new file mode 100644 index 0000000..7b23714 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/runner/AviatorEvaluatorRunner.java @@ -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(); + } +} diff --git a/src/main/java/com/example/liteflow/mysql/service/BaseDataService.java b/src/main/java/com/example/liteflow/mysql/service/BaseDataService.java index e994343..3138d90 100644 --- a/src/main/java/com/example/liteflow/mysql/service/BaseDataService.java +++ b/src/main/java/com/example/liteflow/mysql/service/BaseDataService.java @@ -8,7 +8,7 @@ import com.example.liteflow.mysql.entity.BaseDataEntity; * @date: 2022年12月06日 09:58 */ public interface BaseDataService extends IService { - BaseDataEntity getByType(String type, String attribution); + BaseDataEntity getByTypeAndTemplateId(String type, String attribution); BaseDataEntity getByTypeAndName(String type, String attribution, String contentName); } diff --git a/src/main/java/com/example/liteflow/mysql/service/ChainService.java b/src/main/java/com/example/liteflow/mysql/service/ChainService.java deleted file mode 100644 index 30773d7..0000000 --- a/src/main/java/com/example/liteflow/mysql/service/ChainService.java +++ /dev/null @@ -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 { - void createChain(ChainEntity chainEntity); - - void dynamicGenerateChain(ChainEntity chainEntity); - - List executeChain(String chainName); - - ChainEntity getChainName(String chainName); - - String deleteChain(String id); - - String updateChain(ChainEntity chainEntity); - - List getChain(); -} diff --git a/src/main/java/com/example/liteflow/mysql/service/DynamicScriptService.java b/src/main/java/com/example/liteflow/mysql/service/DynamicScriptService.java deleted file mode 100644 index 196a2aa..0000000 --- a/src/main/java/com/example/liteflow/mysql/service/DynamicScriptService.java +++ /dev/null @@ -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 { - - void createCostCenterNode(CreateDynamicScriptFrom createDynamicScriptFrom); - - void createCostCenterIfNode(CreateDynamicScriptFrom createDynamicScriptFrom); - - void createProfitCenterNode(CreateDynamicScriptFrom createDynamicScriptFrom); - - void createProfitCenterIfNode(CreateDynamicScriptFrom createDynamicScriptFrom); - /** - * 获取所有节点 - * - * @return Map - */ - List getNode(); - - DynamicScriptEntity getByScriptId(String scriptId); -} diff --git a/src/main/java/com/example/liteflow/mysql/service/impl/BaseDataServiceImpl.java b/src/main/java/com/example/liteflow/mysql/service/impl/BaseDataServiceImpl.java index 1938407..c2adf32 100644 --- a/src/main/java/com/example/liteflow/mysql/service/impl/BaseDataServiceImpl.java +++ b/src/main/java/com/example/liteflow/mysql/service/impl/BaseDataServiceImpl.java @@ -16,11 +16,11 @@ import org.springframework.stereotype.Service; @Service public class BaseDataServiceImpl extends ServiceImpl 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 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 queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(BaseDataEntity::getType, type) - .eq(BaseDataEntity::getAttribution, attribution) + .eq(BaseDataEntity::getTemplateId, attribution) .eq(BaseDataEntity::getContentName, contentName); return this.getOne(queryWrapper); } diff --git a/src/main/java/com/example/liteflow/mysql/service/impl/ChainServiceImpl.java b/src/main/java/com/example/liteflow/mysql/service/impl/ChainServiceImpl.java deleted file mode 100644 index 7612689..0000000 --- a/src/main/java/com/example/liteflow/mysql/service/impl/ChainServiceImpl.java +++ /dev/null @@ -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 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 queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(ChainEntity::getChainName, chainName); - return this.getOne(queryWrapper); - } - - @Override - public List executeChain(String chainName) { - List 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 generateCostCenterTestData() { - List 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 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 queryWrapper = new LambdaUpdateWrapper<>(); - queryWrapper.set(ChainEntity::getElData, elData).eq(ChainEntity::getId, id); - if (this.update(queryWrapper)) { - flowExecutor.reloadRule(); - return "更新成功"; - } else { - return "更新失败"; - } - } - - @Override - public List getChain() { - List 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()); - } -} diff --git a/src/main/java/com/example/liteflow/mysql/service/impl/DynamicScriptServiceImpl.java b/src/main/java/com/example/liteflow/mysql/service/impl/DynamicScriptServiceImpl.java deleted file mode 100644 index 54d8aaa..0000000 --- a/src/main/java/com/example/liteflow/mysql/service/impl/DynamicScriptServiceImpl.java +++ /dev/null @@ -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 - 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 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 roles = createDynamicScriptFrom.getRoles(); - LambdaQueryWrapper 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 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 roles = updateDynamicScriptFrom.getRoles(); - LambdaUpdateWrapper 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 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 roles = createDynamicScriptFrom.getRoles(); - LambdaQueryWrapper 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 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 roles = updateDynamicScriptFrom.getRoles(); - LambdaUpdateWrapper 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 - */ - @Override - public List getNode() { - List 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 queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(DynamicScriptEntity::getScriptId, scriptId); - return this.getOne(queryWrapper); - } -} diff --git a/src/main/resources/db.sql b/src/main/resources/db.sql index fc0fdd7..b085bf5 100644 --- a/src/main/resources/db.sql +++ b/src/main/resources/db.sql @@ -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 ); + diff --git a/src/main/resources/测试参数.txt b/src/main/resources/测试参数.txt index db8a9a8..6c70e57 100644 --- a/src/main/resources/测试参数.txt +++ b/src/main/resources/测试参数.txt @@ -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);" -} \ No newline at end of file diff --git a/src/test/java/MyTest.java b/src/test/java/MyTest.java index c89caa1..c4abbc9 100644 --- a/src/test/java/MyTest.java +++ b/src/test/java/MyTest.java @@ -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)); + } }