|
8 | 8 | import com.codingapi.flow.manager.NodeStrategyManager; |
9 | 9 | import com.codingapi.flow.manager.OperatorManager; |
10 | 10 | import com.codingapi.flow.node.IFlowNode; |
| 11 | +import com.codingapi.flow.node.nodes.ConditionBranchNode; |
| 12 | +import com.codingapi.flow.node.nodes.ConditionElseBranchNode; |
| 13 | +import com.codingapi.flow.node.nodes.InclusiveBranchNode; |
| 14 | +import com.codingapi.flow.node.nodes.InclusiveElseBranchNode; |
11 | 15 | import com.codingapi.flow.node.nodes.StartNode; |
12 | 16 | import com.codingapi.flow.operator.IFlowOperator; |
13 | 17 | import com.codingapi.flow.pojo.request.FlowProcessNodeRequest; |
@@ -187,10 +191,41 @@ private void fetchNextNode(FlowSession flowSession, List<IFlowNode> nexNodes) { |
187 | 191 | } |
188 | 192 | this.nodeList.add(processNode); |
189 | 193 | List<IFlowNode> nextNodes = workflow.nextNodes(flowNode); |
190 | | - this.fetchNextNode(flowSession.updateSession(flowNode), nextNodes); |
| 194 | + List<IFlowNode> selected = selectBranchNodes(nextNodes, flowSession.updateSession(flowNode)); |
| 195 | + this.fetchNextNode(flowSession.updateSession(flowNode), selected); |
191 | 196 | } |
192 | 197 | } |
193 | 198 |
|
| 199 | + private List<IFlowNode> selectBranchNodes(List<IFlowNode> nextNodes, FlowSession flowSession) { |
| 200 | + if (nextNodes == null || nextNodes.isEmpty()) { |
| 201 | + return nextNodes; |
| 202 | + } |
| 203 | + IFlowNode first = nextNodes.get(0); |
| 204 | + String type = first.getType(); |
| 205 | + boolean isBranchControl = |
| 206 | + ConditionBranchNode.NODE_TYPE.equals(type) |
| 207 | + || ConditionElseBranchNode.NODE_TYPE.equals(type) |
| 208 | + || InclusiveBranchNode.NODE_TYPE.equals(type) |
| 209 | + || InclusiveElseBranchNode.NODE_TYPE.equals(type); |
| 210 | + if (!isBranchControl) { |
| 211 | + return nextNodes; |
| 212 | + } |
| 213 | + try { |
| 214 | + // 优先按 if 条件脚本匹配;脚本天然 fallback else(else.handle() 恒为 true) |
| 215 | + List<IFlowNode> matched = first.filterBranches(nextNodes, flowSession); |
| 216 | + if (matched != null && !matched.isEmpty()) { |
| 217 | + return matched; |
| 218 | + } |
| 219 | + } catch (Exception ignored) { |
| 220 | + // 表单数据缺失导致条件脚本异常 —— 降级到 else |
| 221 | + } |
| 222 | + List<IFlowNode> elseOnly = nextNodes.stream() |
| 223 | + .filter(n -> ConditionElseBranchNode.NODE_TYPE.equals(n.getType()) |
| 224 | + || InclusiveElseBranchNode.NODE_TYPE.equals(n.getType())) |
| 225 | + .toList(); |
| 226 | + return elseOnly.isEmpty() ? nextNodes : elseOnly; |
| 227 | + } |
| 228 | + |
194 | 229 | public List<ProcessNode> loadNextNode(FlowSession flowSession) { |
195 | 230 | this.fetchNextNode(flowSession, List.of(this.currentNode)); |
196 | 231 |
|
|
0 commit comments