From 4d896f5674360c6e150bae985977a4fb6af052bc Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Mon, 28 Nov 2022 13:30:18 +0800 Subject: [PATCH] =?UTF-8?q?bug=20#I61UZ6=20switch=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E4=BD=BF=E7=94=A8=E6=A0=87=E7=AD=BE=E5=9C=A8?= =?UTF-8?q?=E5=90=8C=E4=B8=80=E7=BB=84=E4=BB=B6=E6=97=B6=E5=9B=BA=E5=AE=9A?= =?UTF-8?q?=E9=80=89=E5=88=B0=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../element/condition/SwitchCondition.java | 21 ++++++++++++------- .../switchcase/SwitchELSpringbootTest.java | 8 +++++++ .../src/test/resources/switchcase/flow.el.xml | 7 +++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java index d510da8d..784d167d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java @@ -15,7 +15,9 @@ import com.yomahub.liteflow.slot.DataBus; import com.yomahub.liteflow.slot.Slot; import com.yomahub.liteflow.util.LiteFlowProxyUtil; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Predicate; @@ -27,7 +29,8 @@ import java.util.function.Predicate; */ public class SwitchCondition extends Condition{ - private final Map targetMap = new HashMap<>(); + + private final List targetList = new ArrayList<>(); private final String TAG_PREFIX = "tag"; private final String TAG_FLAG = ":"; @@ -37,7 +40,7 @@ public class SwitchCondition extends Condition{ public void execute(Integer slotIndex) throws Exception { if (ListUtil.toList(NodeTypeEnum.SWITCH, NodeTypeEnum.SWITCH_SCRIPT).contains(this.getSwitchNode().getType())){ //先执行switch节点 - this.getSwitchNode().setCurrChainName(this.getCurrChainName()); + this.getSwitchNode().setCurrChainId(this.getCurrChainId()); this.getSwitchNode().execute(slotIndex); //根据switch节点执行出来的结果选择 @@ -53,7 +56,7 @@ public class SwitchCondition extends Condition{ String[] target = targetId.split(TAG_FLAG, 2); String _targetId = target[0]; String _targetTag = target[1]; - targetExecutor = targetMap.values().stream().filter(executable -> { + targetExecutor = targetList.stream().filter(executable -> { if (executable instanceof Node){ Node node = (Node) executable; return (StrUtil.startWith(_targetId, TAG_PREFIX) && _targetTag.equals(node.getTag())) || ((StrUtil.isEmpty(_targetId) || _targetId.equals(node.getId())) && (StrUtil.isEmpty(_targetTag) || _targetTag.equals(node.getTag()))); @@ -62,7 +65,9 @@ public class SwitchCondition extends Condition{ } }).findFirst().orElse(null); }else{ - targetExecutor = targetMap.get(targetId); + targetExecutor = targetList.stream().filter( + executable -> executable.getExecuteId().equals(targetId) + ).findFirst().orElse(null); } if (ObjectUtil.isNotNull(targetExecutor)) { @@ -71,7 +76,7 @@ public class SwitchCondition extends Condition{ String errorInfo = StrUtil.format("[{}]:switch component[{}] error, switch target node cannot be pre or finally", slot.getRequestId(), this.getSwitchNode().getInstance().getDisplayName()); throw new SwitchTargetCannotBePreOrFinallyException(errorInfo); } - targetExecutor.setCurrChainName(this.getCurrChainName()); + targetExecutor.setCurrChainId(this.getCurrChainId()); targetExecutor.execute(slotIndex); }else{ String errorInfo = StrUtil.format("[{}]:no target node find for the component[{}]", slot.getRequestId(), this.getSwitchNode().getInstance().getDisplayName()); @@ -89,15 +94,15 @@ public class SwitchCondition extends Condition{ } public void addTargetItem(Executable executable){ - this.targetMap.put(executable.getExecuteId(), executable); + this.targetList.add(executable); } public void setSwitchNode(Node switchNode) { this.getExecutableList().add(switchNode); } - public Map getTargetMap() { - return targetMap; + public List getTargetList(){ + return targetList; } public Node getSwitchNode(){ diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringbootTest.java index 7df2f08a..e5d2db28 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringbootTest.java @@ -67,4 +67,12 @@ public class SwitchELSpringbootTest extends BaseTest { Assert.assertTrue(response.isSuccess()); Assert.assertEquals("a==>h==>b",response.getExecuteStepStr()); } + + //相同组件的tag的跳转 + @Test + public void testSwitch6() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>h==>b",response.getExecuteStepStr()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/switchcase/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/switchcase/flow.el.xml index fc93c329..4a5148de 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/switchcase/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/switchcase/flow.el.xml @@ -35,4 +35,11 @@ SWITCH(h).to(b.tag("td"), d.tag("td")) ); + + + THEN( + a, + SWITCH(h).to(b.tag("td"), b.tag("xx")) + ); + \ No newline at end of file