/*** * 根據bpmnmodel獲取流程節點的順序信息 * @param processInstanceId * @param taskList * @param flowElements * @param workflowRequestFormData * @param curFlowElement */ private void getTaskList(String processInstanceId, List<Object> taskList, Collection<FlowElement> flowElements, Map<String, Object> workflowRequestFormData, FlowElement curFlowElement) { if (curFlowElement == null && taskList.size() == 0) { // 獲取第一個UserTask FlowElement startElement = flowElements.stream().filter(flowElement -> flowElement instanceof StartEvent).collect(Collectors.toList()).get(0); List<SequenceFlow> outgoingFlows = ((StartEvent) startElement).getOutgoingFlows(); String targetRef = outgoingFlows.get(0).getTargetRef(); // 根據ID找到FlowElement FlowElement targetElementOfStartElement = getFlowElement(flowElements, targetRef); if (targetElementOfStartElement instanceof UserTask) { this.getTaskList(processInstanceId, taskList, flowElements, workflowRequestFormData, targetElementOfStartElement); } } else if (curFlowElement instanceof UserTask) { // 只有Usertask才添加到列表中 taskList.add(curFlowElement); String targetRef = ""; List<SequenceFlow> outgoingFlows = ((UserTask) curFlowElement).getOutgoingFlows(); if (outgoingFlows.size() == 1) { targetRef = outgoingFlows.get(0).getTargetRef(); } else { // 找到表達式成立的sequenceFlow的 SequenceFlow sequenceFlow = getSequenceFlow(workflowRequestFormData, outgoingFlows); if (sequenceFlow != null) { targetRef = sequenceFlow.getTargetRef(); } } // 根據ID找到FlowElement FlowElement targetElement = getFlowElement(flowElements, targetRef); this.getTaskList(processInstanceId, taskList, flowElements, workflowRequestFormData, targetElement); } else if (curFlowElement instanceof ExclusiveGateway) { String targetRef = ""; // 若是爲排他網關,獲取符合條件的sequenceFlow的目標FlowElement List<SequenceFlow> exclusiveGatewayOutgoingFlows = ((ExclusiveGateway) curFlowElement).getOutgoingFlows(); // 找到表達式成立的sequenceFlow的 SequenceFlow sequenceFlow = getSequenceFlow(workflowRequestFormData, exclusiveGatewayOutgoingFlows); if (sequenceFlow != null) { targetRef = sequenceFlow.getTargetRef(); } // 根據ID找到FlowElement FlowElement targetElement = getFlowElement(flowElements, targetRef); this.getTaskList(processInstanceId, taskList, flowElements, workflowRequestFormData, targetElement); } } /*** * 根據ID找到FlowElement * @param flowElements * @param targetRef * @return */ private FlowElement getFlowElement(Collection<FlowElement> flowElements, String targetRef) { List<FlowElement> targetFlowElements = flowElements.stream().filter( flowElement -> !StringUtils.isEmpty(flowElement.getId()) && flowElement.getId().equals(targetRef) ).collect(Collectors.toList()); if (targetFlowElements.size() > 0) { return targetFlowElements.get(0); } return null; } /*** * 找到表達式成立的sequenceFlow的 * @param workflowRequestFormData * @param outgoingFlows * @return */ private SequenceFlow getSequenceFlow(Map workflowRequestFormData, List<SequenceFlow> outgoingFlows) { List<SequenceFlow> sequenceFlows = outgoingFlows.stream().filter(item -> { Object execConditionExpressionResult = null; boolean re = false; try { execConditionExpressionResult = this.getElValue(item.getConditionExpression(), workflowRequestFormData); } catch (Exception e) { e.printStackTrace(); } if (execConditionExpressionResult.equals("true")) { re = true; } return (Boolean) execConditionExpressionResult; }).collect(Collectors.toList()); if (sequenceFlows.size() > 0) { return sequenceFlows.get(0); } return null; }