From 433bc31eb57c78ea57e96eb45b21c11e6e86b7d8 Mon Sep 17 00:00:00 2001 From: 75349 <753495441@qq.com> Date: Mon, 5 Dec 2022 18:03:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=9A=E7=A7=8D=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/mysql/LiteFlowCommand.java | 21 +++--- .../liteflow/mysql/cmp/CostCenter01Cmp.java | 70 +++++++++++++++++++ .../mysql/cmp/CostCenter01SoutCmp.java | 29 ++++++++ .../liteflow/mysql/cmp/CostCenter02Cmp.java | 69 ++++++++++++++++++ .../mysql/cmp/CostCenter02SoutCmp.java | 29 ++++++++ .../example/liteflow/mysql/cmp/SoutCmp.java | 16 ++--- src/main/resources/liteflow/flow1.el.xml | 2 +- 7 files changed, 217 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/example/liteflow/mysql/cmp/CostCenter01Cmp.java create mode 100644 src/main/java/com/example/liteflow/mysql/cmp/CostCenter01SoutCmp.java create mode 100644 src/main/java/com/example/liteflow/mysql/cmp/CostCenter02Cmp.java create mode 100644 src/main/java/com/example/liteflow/mysql/cmp/CostCenter02SoutCmp.java diff --git a/src/main/java/com/example/liteflow/mysql/LiteFlowCommand.java b/src/main/java/com/example/liteflow/mysql/LiteFlowCommand.java index 51fcd04..76b1f8e 100644 --- a/src/main/java/com/example/liteflow/mysql/LiteFlowCommand.java +++ b/src/main/java/com/example/liteflow/mysql/LiteFlowCommand.java @@ -1,5 +1,6 @@ package com.example.liteflow.mysql; +import cn.hutool.json.JSON; import cn.hutool.json.JSONUtil; import com.example.liteflow.mysql.model.CostCenter; import com.example.liteflow.mysql.model.CostCenterContext; @@ -33,17 +34,17 @@ public class LiteFlowCommand implements CommandLineRunner { // LiteflowResponse response = flowExecutor.execute2Resp("costCenter", costCenter, CostCenterContext.class); // xml匹配 // LiteflowResponse response = flowExecutor.execute2Resp("mainChain", costCenter, CostCenterContext.class); - LiteflowResponse response = flowExecutor.execute2Resp("mainChain2", costCenter, CostCenterContext.class); + LiteflowResponse response = flowExecutor.execute2Resp("mainChain2", costCenter); + log.info("costCenter = {}", JSONUtil.toJsonStr(costCenter)); - - CostCenterContext costCenterContext = response.getFirstContextBean(); - String code = costCenterContext.getCode(); - String name = costCenterContext.getName(); - String generateCode = costCenterContext.getGenerateCode(); - costCenter.setCode(code); - costCenter.setName(name); - costCenter.setGenerateCode(generateCode); - log.info(JSONUtil.toJsonStr(costCenter)); +// CostCenterContext costCenterContext = response.getFirstContextBean(); +// String code = costCenterContext.getCode(); +// String name = costCenterContext.getName(); +// String generateCode = costCenterContext.getGenerateCode(); +// costCenter.setCode(code); +// costCenter.setName(name); +// costCenter.setGenerateCode(generateCode); +// log.info(JSONUtil.toJsonStr(costCenter)); if (response.isSuccess()) { log.info("执行成功"); } else { diff --git a/src/main/java/com/example/liteflow/mysql/cmp/CostCenter01Cmp.java b/src/main/java/com/example/liteflow/mysql/cmp/CostCenter01Cmp.java new file mode 100644 index 0000000..dd38707 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/cmp/CostCenter01Cmp.java @@ -0,0 +1,70 @@ +package com.example.liteflow.mysql.cmp; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.BooleanUtil; +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.model.CostCenter; +import com.example.liteflow.mysql.util.ConditionParser; +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 java.lang.reflect.Field; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * @author: 陈韦龙 + * @date: 2022年12月05日 10:15 + */ +@LiteflowComponent("costCenter01Cmp") +@Slf4j +public class CostCenter01Cmp extends NodeIfComponent { + + private static final String drool = "[{\"$or\": [{\"$and\": [{\"contains\": [sectionClassification, sectionClassificationList]}, {\"contains\": [businessType, businessTypeList]}, {\"contains\": [salesman, salesmanList]}, {\"contains\": [businessCategory, businessCategoryList]}]}]}]"; + + private final LinkedHashMap> map = new LinkedHashMap>(){{ + put("sectionClassificationList", Lists.newArrayList("汇差", "手续费", "成本科目")); + put("businessTypeList", Lists.newArrayList("货代", "报关", "船代", "散杂货")); + put("salesmanList", Lists.newArrayList("仓干配物流部(物流)")); + put("businessCategoryList", Lists.newArrayList("全货船业务", "进出岛仓干配")); + }}; + @Override + public boolean processIf() throws Exception { + CostCenter requestData = this.getRequestData(); + String droolStr = drool; + for (Map.Entry> entry : map.entrySet()) { + String key = entry.getKey(); + List list = entry.getValue(); + droolStr = StrUtil.replace(droolStr, key, list.toString(), false); + } + log.info("before - droolStr = {}", droolStr); + Field[] fields = ReflectUtil.getFields(CostCenter.class); + for (Field field : fields) { + Object fieldValue = ReflectUtil.getFieldValue(requestData, field); + String name = field.getName(); + droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", false); + } + + log.info("after - replace4 = {}", droolStr); + JSONArray jsonArray = JSONUtil.parseArray(droolStr); + log.info("jsonArray = {}", jsonArray); + + String conditionResult = ConditionParser.parseCondition(jsonArray); + + log.info("condition template = {}", conditionResult); + AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class); + AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class); + Object executeB = AviatorEvaluator.execute(conditionResult); + log.info("CostCenter01Cmp-{} = {}", conditionResult, executeB); + boolean aBoolean = BooleanUtil.toBoolean(executeB.toString()); + log.info("CostCenter01Cmp-aBoolean = {}", aBoolean); + return aBoolean; + } +} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/CostCenter01SoutCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/CostCenter01SoutCmp.java new file mode 100644 index 0000000..3e1656a --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/cmp/CostCenter01SoutCmp.java @@ -0,0 +1,29 @@ +package com.example.liteflow.mysql.cmp; + +import com.example.liteflow.mysql.model.CostCenter; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; +import lombok.extern.slf4j.Slf4j; + +/** + * @author: 陈韦龙 + * @date: 2022年12月05日 10:15 + */ +@LiteflowComponent("CostCenter01SoutCmp") +@Slf4j +public class CostCenter01SoutCmp extends NodeComponent { + + private static final String costCenter01Code = "P350401028"; + private static final String costCenter01Name = "仓干配物流部利润中心"; + + + + @Override + public void process() { + CostCenter costCenter = this.getRequestData(); + costCenter.setCode(costCenter01Code); + costCenter.setName(costCenter01Name); + costCenter.setGenerateCode(costCenter01Code + costCenter01Name); + + } +} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/CostCenter02Cmp.java b/src/main/java/com/example/liteflow/mysql/cmp/CostCenter02Cmp.java new file mode 100644 index 0000000..92079fb --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/cmp/CostCenter02Cmp.java @@ -0,0 +1,69 @@ +package com.example.liteflow.mysql.cmp; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.BooleanUtil; +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.model.CostCenter; +import com.example.liteflow.mysql.util.ConditionParser; +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 java.lang.reflect.Field; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * @author: 陈韦龙 + * @date: 2022年12月05日 10:15 + */ +@LiteflowComponent("costCenter02Cmp") +@Slf4j +public class CostCenter02Cmp extends NodeIfComponent { + + private static final String drool = "[{\"$or\": [{\"$or\": [{\"$and\": [{\"contains\": [sectionClassification, sectionClassificationList]}, {\"contains\": [salesman, salesmanList]}]}]}, {\"$or\": [{\"contains\": [businessType, businessTypeList]}]}]}]"; + + private final LinkedHashMap> map = new LinkedHashMap>(){{ + put("sectionClassificationList", Lists.newArrayList("汇差", "手续费", "成本科目")); + put("businessTypeList", Lists.newArrayList("货代", "报关", "船代", "散杂货")); + put("salesmanList", Lists.newArrayList("仓干配物流部(物流)")); + }}; + @Override + public boolean processIf() throws Exception { + CostCenter requestData = this.getRequestData(); + String droolStr = drool; + for (Map.Entry> entry : map.entrySet()) { + String key = entry.getKey(); + List list = entry.getValue(); + droolStr = StrUtil.replace(droolStr, key, list.toString(), false); + } + log.info("before - droolStr = {}", droolStr); + Field[] fields = ReflectUtil.getFields(CostCenter.class); + for (Field field : fields) { + Object fieldValue = ReflectUtil.getFieldValue(requestData, field); + String name = field.getName(); + droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", false); + } + + log.info("after - replace4 = {}", droolStr); + JSONArray jsonArray = JSONUtil.parseArray(droolStr); + log.info("jsonArray = {}", jsonArray); + + String conditionResult = ConditionParser.parseCondition(jsonArray); + + log.info("condition template = {}", conditionResult); + AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class); + AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class); + Object executeB = AviatorEvaluator.execute(conditionResult); + log.info("CostCenter02Cmp-{} = {}", conditionResult, executeB); + boolean aBoolean = BooleanUtil.toBoolean(executeB.toString()); + log.info("CostCenter01Cmp-aBoolean = {}", aBoolean); + return aBoolean; + } +} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/CostCenter02SoutCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/CostCenter02SoutCmp.java new file mode 100644 index 0000000..7663494 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/cmp/CostCenter02SoutCmp.java @@ -0,0 +1,29 @@ +package com.example.liteflow.mysql.cmp; + +import com.example.liteflow.mysql.model.CostCenter; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; +import lombok.extern.slf4j.Slf4j; + +/** + * @author: 陈韦龙 + * @date: 2022年12月05日 10:15 + */ +@LiteflowComponent("CostCenter02SoutCmp") +@Slf4j +public class CostCenter02SoutCmp extends NodeComponent { + + private static final String costCenter02Code = "P350401026"; + private static final String costCenter02Name = "商品车物流部利润中心"; + + + + @Override + public void process() { + CostCenter costCenter = this.getRequestData(); + costCenter.setCode(costCenter02Code); + costCenter.setName(costCenter02Name); + costCenter.setGenerateCode(costCenter02Code + costCenter02Name); + + } +} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/SoutCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/SoutCmp.java index e2508b3..8b36d98 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/SoutCmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/SoutCmp.java @@ -1,6 +1,5 @@ package com.example.liteflow.mysql.cmp; -import cn.hutool.core.util.StrUtil; import com.example.liteflow.mysql.model.CostCenter; import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; @@ -20,13 +19,14 @@ public class SoutCmp extends NodeComponent { // } // System.out.println(JsonUtil.toJsonString(map)); - String code = costCenter.getCode(); - String name = costCenter.getName(); - String generateCode = costCenter.getGenerateCode(); - - if (StrUtil.isBlank(code) && StrUtil.isBlank(name) && StrUtil.isBlank(generateCode)) { - costCenter.setGenerateCode("无匹配项"); - } +// String code = costCenter.getCode(); +// String name = costCenter.getName(); +// String generateCode = costCenter.getGenerateCode(); +// +// if (StrUtil.isBlank(code) && StrUtil.isBlank(name) && StrUtil.isBlank(generateCode)) { +// costCenter.setGenerateCode("无匹配项"); +// } + costCenter.setGenerateCode("无匹配项"); } } diff --git a/src/main/resources/liteflow/flow1.el.xml b/src/main/resources/liteflow/flow1.el.xml index 5fb705e..237193b 100644 --- a/src/main/resources/liteflow/flow1.el.xml +++ b/src/main/resources/liteflow/flow1.el.xml @@ -29,7 +29,7 @@ - THEN(costCenterCmp); + IF(costCenter01Cmp, CostCenter01SoutCmp, IF(costCenter02Cmp, CostCenter02SoutCmp, sout));