mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 04:02:09 +08:00
enhancement #ICR1PL AND关键字的逻辑和语意明确点
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -131,7 +131,7 @@ public class Slot {
|
||||
|
||||
private <T> 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 <T> void putMetaDataMap(String key, T t) {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -34,4 +34,7 @@
|
||||
IF(OR(x3,x4,x5), a, b);
|
||||
</chain>
|
||||
|
||||
<chain name="chain8">
|
||||
IF(AND(NOT(x3), NOT(x4), x5), a, b);
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user