update - 解决实例执行流程中,网关节点出口节点选择异常的问题

This commit is contained in:
wangli 2024-05-06 13:37:26 +08:00
parent 55685a890b
commit 2eb5cf19c8
3 changed files with 25 additions and 10 deletions

View File

@ -29,7 +29,7 @@ public abstract class AbstractForecast<T extends FlowElement> implements Forecas
@Override
public final List<FlowElement> nextFlowElement(FlowElement sourceFlowElement, String processInstanceId) {
return forecastNextNodes(getOutgoing((T) sourceFlowElement), processInstanceId);
return forecastNextNodes(sourceFlowElement, getOutgoing((T) sourceFlowElement), processInstanceId);
}
protected abstract List<? extends FlowElement> getOutgoing(T flowElement);
@ -41,7 +41,8 @@ public abstract class AbstractForecast<T extends FlowElement> implements Forecas
* @param processInstanceId 流程实例
* @return
*/
private List<FlowElement> forecastNextNodes(List<? extends FlowElement> sourceFlowElements,
private List<FlowElement> forecastNextNodes(FlowElement sourceFlowElement,
List<? extends FlowElement> sourceFlowElements,
String processInstanceId) {
if (CollectionUtils.isEmpty(sourceFlowElements)) {
return Collections.emptyList();
@ -53,7 +54,7 @@ public abstract class AbstractForecast<T extends FlowElement> implements Forecas
elementGroup.forEach((k, v) -> {
AbstractForecast forecast = FORECAST_MAP.get(k);
if (Objects.nonNull(forecast)) {
result.addAll(forecast.calcRealOutgoingNodes(v, processInstanceId));
result.addAll(forecast.calcRealOutgoingNodes(v, sourceFlowElement, processInstanceId));
}
});
return result;
@ -66,10 +67,12 @@ public abstract class AbstractForecast<T extends FlowElement> implements Forecas
* @param processInstanceId
* @return
*/
public List<? extends FlowElement> calcRealOutgoingNodes(List<T> flowElements, String processInstanceId) {
public List<? extends FlowElement> calcRealOutgoingNodes(List<T> flowElements, FlowElement sourceFlowElement, String processInstanceId) {
if (!CollectionUtils.isEmpty(flowElements) && flowElements.size() == 1) {
return flowElements;
}
log.warn("流程实例未找到下一个节点,或者由于协议转换异常,出现多个下级节点, instanceId:{}, sourceNode: {}",
processInstanceId, sourceFlowElement.getId());
return Collections.emptyList();
}

View File

@ -28,10 +28,12 @@ public class EndEventForecasting extends AbstractForecast<EndEvent> {
}
@Override
public List<? extends FlowElement> calcRealOutgoingNodes(List<EndEvent> flowElements, String processInstanceId) {
public List<? extends FlowElement> calcRealOutgoingNodes(List<EndEvent> flowElements,
FlowElement sourceFlowElement,
String processInstanceId) {
if (CollectionUtils.isEmpty(flowElements)) {
return Collections.emptyList();
}
return super.calcRealOutgoingNodes(flowElements, processInstanceId);
return super.calcRealOutgoingNodes(flowElements, sourceFlowElement, processInstanceId);
}
}

View File

@ -3,11 +3,13 @@ package cn.axzo.workflow.core.service.support.forecast.impl;
import cn.axzo.workflow.core.service.support.forecast.AbstractForecast;
import com.google.common.collect.Lists;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.Gateway;
import org.flowable.bpmn.model.SequenceFlow;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@ -34,6 +36,7 @@ public class SequenceFlowForecasting extends AbstractForecast<SequenceFlow> {
@Override
public List<? extends FlowElement> calcRealOutgoingNodes(List<SequenceFlow> flowElements,
FlowElement sourceFlowElement,
String processInstanceId) {
if (CollectionUtils.isEmpty(flowElements)) {
return Collections.emptyList();
@ -47,12 +50,19 @@ public class SequenceFlowForecasting extends AbstractForecast<SequenceFlow> {
return Lists.newArrayList(executableFlows.get(0));
}
// 如果 conditionExpression 为空, 则认为是默认流
List<SequenceFlow> defaultFlows =
flowElements.stream().filter(i -> Objects.isNull(i.getConditionExpression())).collect(Collectors.toList());
List<SequenceFlow> defaultFlows = new ArrayList<>();
if (sourceFlowElement instanceof Gateway) {
Gateway gateway = (Gateway) sourceFlowElement;
flowElements.stream()
.filter(i -> Objects.equals(i.getSourceRef(), gateway.getDefaultFlow()))
.findAny().ifPresent(defaultFlows::add);
} else {
// 如果 conditionExpression 为空, 则认为是默认流
defaultFlows.addAll(flowElements.stream().filter(i -> Objects.isNull(i.getConditionExpression())).collect(Collectors.toList()));
}
if (!CollectionUtils.isEmpty(defaultFlows) && defaultFlows.size() == 1) {
return Lists.newArrayList(defaultFlows.get(0));
}
return super.calcRealOutgoingNodes(flowElements, processInstanceId);
return super.calcRealOutgoingNodes(flowElements, sourceFlowElement, processInstanceId);
}
}