请求
ProcessDefinition processDefinition = processEngineService.getProcessDefinitionKey("实例key");
String processDefinitionId = processDefinition.getId();
BpmnModel bpmnModel = processEngineService.getBpmnModel(processDefinitionId);
Process mainProcess = bpmnModel.getMainProcess();
FlowNode currentFlowElement = (FlowNode)mainProcess.getFlowElement("执行节点ID", true);
FlowElement nextFlowElement = ProcessNodeUtils.getNextFlowElement(variables, currentFlowElement);
if (nextFlowElement != null){
String approveId = processDefinitionKey.substring(2);
String nodeId = nextFlowElement.getId();
String nodeName = nextFlowElement.getName();
}
获取审批节点
public static FlowElement getNextFlowElement(Map<String, Object> variables, FlowElement sourceFlowElement) {
FlowElement flowElement = null;
if (sourceFlowElement instanceof FlowNode) {
FlowNode thisFlowNode = (FlowNode) sourceFlowElement;
List<SequenceFlow> outgoingFlows = thisFlowNode.getOutgoingFlows();
if (CollectionUtils.isNotEmpty(outgoingFlows)){
if (outgoingFlows.size() == 1) {
SequenceFlow sequenceFlow = outgoingFlows.get(0);
FlowElement targetFlowElement = sequenceFlow.getTargetFlowElement();
if (targetFlowElement instanceof UserTask) {
flowElement = targetFlowElement;
} else {
flowElement = getNextFlowElement(variables, targetFlowElement);
}
} else if (outgoingFlows.size() > 1) {
for (SequenceFlow sequenceFlow : outgoingFlows) {
boolean result = true;
if (StringUtils.isNotBlank(sequenceFlow.getConditionExpression())) {
ProcessEngineService processEngineService = ApplicationContextHolder.getBean(ProcessEngineService.class);
result = processEngineService.executeCommand(new ImitateExpressionCmd(variables, sequenceFlow.getConditionExpression()));
}
if (result) {
FlowElement targetFlowElement = sequenceFlow.getTargetFlowElement();
if (targetFlowElement instanceof UserTask) {
flowElement = targetFlowElement;
} else {
flowElement = getNextFlowElement(variables, targetFlowElement);
}
}
}
}
}
}
return flowElement;
}
条件规则
import org.flowable.common.engine.api.variable.VariableContainer;
import org.apache.commons.lang3.StringUtils;
import org.flowable.app.engine.impl.util.CommandContextUtil;
import org.flowable.common.engine.api.delegate.Expression;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import java.io.Serializable;
import java.util.Map;
public class ImitateExpressionCmd implements Command<Boolean>, Serializable {
protected Map<String, Object> variables;
protected String exp;
public ImitateExpressionCmd(Map<String, Object> variables, String exp) {
this.variables = variables;
this.exp = exp;
}
@Override
public Boolean execute(CommandContext commandContext) {
if (StringUtils.isBlank(this.exp)) {
return Boolean.TRUE;
}
Expression expression = CommandContextUtil.getExpressionManager().createExpression(this.exp);
ProcessEmptyVariableContainer processEmptyVariableContainer = new ProcessEmptyVariableContainer(variables);
Object value = expression.getValue(processEmptyVariableContainer);
return value != null && "true".equals(value.toString()); }
}
class ProcessEmptyVariableContainer implements VariableContainer {
private Map<String, Object> variables;
public ProcessEmptyVariableContainer(Map<String, Object> variables) {
this.variables = variables;
}
public void setVariables(Map<String, Object> variables) {
this.variables = variables;
}
@Override
public boolean hasVariable(String variableName) {
return variables.containsKey(variableName);
}
@Override
public Object getVariable(String variableName) {
return variables.get(variableName);
}
@Override
public void setVariable(String variableName, Object variableValue) {
throw new UnsupportedOperationException("Empty object, no variables can be set");
}
@Override
public void setTransientVariable(String variableName, Object variableValue) {
throw new UnsupportedOperationException("Empty object, no variables can be set");
}
@Override
public String getTenantId() {
return null;
}
}