diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index 090d4080c..c0db15eb4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -383,7 +383,8 @@ public class FlowExecutor { String errorMsg = StrUtil.format("[{}]:couldn't find chain with the id[{}]", slot.getRequestId(), chainId); throw new ChainNotFoundException(errorMsg); } - + // 执行前置 + chain.executePre(slotIndex); // 执行chain chain.execute(slotIndex); } catch (ChainEndException e) { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Chain.java b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Chain.java index 88b4495b5..79835e172 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Chain.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Chain.java @@ -80,11 +80,7 @@ public class Chain implements Executable { throw new FlowSystemException("no conditionList in this chain[" + chainName + "]"); } for (Condition condition : conditionList) { - if (condition instanceof PreCondition){ - for (Executable executableItem : condition.getNodeList()) { - executableItem.execute(slotIndex); - } - } else if (condition instanceof ThenCondition) { + if (condition instanceof ThenCondition) { for (Executable executableItem : condition.getNodeList()) { executableItem.execute(slotIndex); } @@ -94,10 +90,20 @@ public class Chain implements Executable { } } + // 执行pre节点 + public void executePre(Integer slotIndex) throws Exception { + //先把pre的节点过滤出来 + List preConditionList =filterCondition(ConditionTypeEnum.TYPE_PRE); + for (Condition finallyCondition : preConditionList){ + for(Executable executableItem : finallyCondition.getNodeList()){ + executableItem.execute(slotIndex); + } + } + } + public void executeFinally(Integer slotIndex) throws Exception { //先把finally的节点过滤出来 - List finallyConditionList = conditionList.stream().filter(condition -> - condition.getConditionType().equals(ConditionTypeEnum.TYPE_FINALLY)).collect(Collectors.toList()); + List finallyConditionList =filterCondition(ConditionTypeEnum.TYPE_FINALLY); for (Condition finallyCondition : finallyConditionList){ for(Executable executableItem : finallyCondition.getNodeList()){ executableItem.execute(slotIndex); @@ -105,6 +111,13 @@ public class Chain implements Executable { } } + // 根据节点condition类型过去出节点列表 + private List filterCondition(ConditionTypeEnum conditionTypeEnum) { + assert conditionTypeEnum != null; + return conditionList.stream().filter(condition -> + condition.getConditionType().equals(conditionTypeEnum)).collect(Collectors.toList()); + } + @Override public ExecuteTypeEnum getExecuteType() { return ExecuteTypeEnum.CHAIN;