From 3333f2518274709db1610e2e7486db636446d2bc Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Thu, 21 Aug 2025 00:00:27 +0800 Subject: [PATCH] =?UTF-8?q?enhancement=20#ICR1PL=20AND=E5=85=B3=E9=94=AE?= =?UTF-8?q?=E5=AD=97=E7=9A=84=E9=80=BB=E8=BE=91=E5=92=8C=E8=AF=AD=E6=84=8F?= =?UTF-8?q?=E6=98=8E=E7=A1=AE=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../element/condition/AndOrCondition.java | 28 +++++++++++++++++-- .../flow/element/condition/NotCondition.java | 3 +- .../java/com/yomahub/liteflow/slot/Slot.java | 2 +- .../BooleanOptELSpringbootTest.java | 8 ++++++ .../liteflow/test/booleanOpt/cmp/X5.java | 2 +- .../src/test/resources/booleanOpt/flow.xml | 3 ++ 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/AndOrCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/AndOrCondition.java index b10b91118..226494dc8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/AndOrCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/AndOrCondition.java @@ -1,11 +1,13 @@ package com.yomahub.liteflow.flow.element.condition; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.enums.ConditionTypeEnum; import com.yomahub.liteflow.exception.AndOrConditionException; import com.yomahub.liteflow.flow.element.Condition; import com.yomahub.liteflow.flow.element.Executable; +import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; import com.yomahub.liteflow.slot.DataBus; @@ -35,10 +37,30 @@ public class AndOrCondition extends Condition { String resultKey = StrUtil.format("{}_{}",this.getClass().getName(),this.hashCode()); switch (booleanConditionType) { case AND: - slot.setAndOrResult(resultKey, itemList.stream().allMatch(new AndOrConditionPredicate(slotIndex))); + slot.setAndOrResult(resultKey, itemList.stream().filter(executable -> { + try{ + boolean flag = executable.isAccess(slotIndex); + if (executable instanceof Node){ + ((Node)executable).setAccessResult(flag); + } + return flag; + }catch (Exception e){ + return false; + } + }).allMatch(new AndOrConditionPredicate(slotIndex))); break; case OR: - slot.setAndOrResult(resultKey, itemList.stream().anyMatch(new AndOrConditionPredicate(slotIndex))); + slot.setAndOrResult(resultKey, itemList.stream().filter(executable -> { + try{ + boolean flag = executable.isAccess(slotIndex); + if (executable instanceof Node){ + ((Node)executable).setAccessResult(flag); + } + return flag; + }catch (Exception e){ + return false; + } + }).anyMatch(new AndOrConditionPredicate(slotIndex))); break; default: throw new AndOrConditionException("condition type must be 'AND' or 'OR'"); @@ -58,7 +80,7 @@ public class AndOrCondition extends Condition { try { executable.setCurrChainId(getCurrChainId()); executable.execute(slotIndex); - return executable.getItemResultMetaValue(slotIndex); + return BooleanUtil.isTrue(executable.getItemResultMetaValue(slotIndex)); } catch (Exception e) { throw new AndOrConditionException(e.getMessage()); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/NotCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/NotCondition.java index 3a8f3d9f9..d937b5050 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/NotCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/NotCondition.java @@ -1,5 +1,6 @@ package com.yomahub.liteflow.flow.element.condition; +import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.enums.ConditionTypeEnum; import com.yomahub.liteflow.flow.element.Condition; @@ -35,7 +36,7 @@ public class NotCondition extends Condition { public Boolean getItemResultMetaValue(Integer slotIndex) { Slot slot = DataBus.getSlot(slotIndex); String resultKey = StrUtil.format("{}_{}",this.getClass().getName(),this.hashCode()); - return slot.getNotResult(resultKey); + return BooleanUtil.isTrue(slot.getNotResult(resultKey)); } @Override diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java b/liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java index 463aa4e2f..0418a13dc 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java @@ -131,7 +131,7 @@ public class Slot { private T getThreadMetaData(String key) { String threadKey = StrUtil.format("{}_{}", key, Thread.currentThread().getName()); - return (T) metaDataMap.getOrDefault(threadKey, Boolean.FALSE); + return (T) metaDataMap.get(threadKey); } private void putMetaDataMap(String key, T t) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/BooleanOptELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/BooleanOptELSpringbootTest.java index 4fca0f59a..a2637868e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/BooleanOptELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/BooleanOptELSpringbootTest.java @@ -80,4 +80,12 @@ public class BooleanOptELSpringbootTest extends BaseTest { Assertions.assertTrue(response.isSuccess()); Assertions.assertEquals("x3==>x4==>b", response.getExecuteStepStr()); } + + // AND 有一个isAccess为false + @Test + public void testBooleanOpt8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("x3==>x4==>a", response.getExecuteStepStr()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X5.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X5.java index 4cf637add..d64ede83f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X5.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X5.java @@ -7,7 +7,7 @@ import org.springframework.stereotype.Component; public class X5 extends NodeBooleanComponent { @Override public boolean processBoolean() throws Exception { - return false; + return true; } @Override diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/booleanOpt/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/booleanOpt/flow.xml index b98002ea2..e07fa4a36 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/booleanOpt/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/booleanOpt/flow.xml @@ -34,4 +34,7 @@ IF(OR(x3,x4,x5), a, b); + + IF(AND(NOT(x3), NOT(x4), x5), a, b); + \ No newline at end of file