enhancement #ICR1PL AND关键字的逻辑和语意明确点

This commit is contained in:
everywhere.z
2025-08-21 00:00:27 +08:00
parent fba92dace1
commit 3333f25182
6 changed files with 40 additions and 6 deletions

View File

@@ -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());
}

View File

@@ -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

View File

@@ -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) {