前言
camunda 7.18
驳回 并行
一、流程图
测试流程图如下
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_19ztz1h" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.6.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.18.0">
<bpmn:process id="Process_1ponnq0" name="测试驳回" isExecutable="true">
<bpmn:startEvent id="Event_0iw6gxi">
<bpmn:outgoing>Flow_11anzux</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_11anzux" sourceRef="Event_0iw6gxi" targetRef="Activity_06jvxc8" />
<bpmn:exclusiveGateway id="Gateway_1hro0j7" default="Flow_1by26xl">
<bpmn:incoming>Flow_0ai6ch9</bpmn:incoming>
<bpmn:outgoing>Flow_1by26xl</bpmn:outgoing>
<bpmn:outgoing>Flow_0c22b7f</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="Flow_0ai6ch9" sourceRef="Activity_06jvxc8" targetRef="Gateway_1hro0j7" />
<bpmn:sequenceFlow id="Flow_1by26xl" sourceRef="Gateway_1hro0j7" targetRef="Activity_0guygm5" />
<bpmn:sequenceFlow id="Flow_1ppifbg" sourceRef="Activity_0guygm5" targetRef="Activity_08ph592" />
<bpmn:sequenceFlow id="Flow_0c22b7f" sourceRef="Gateway_1hro0j7" targetRef="Activity_1e5ytx7">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{a==1}</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:sequenceFlow id="Flow_0bqldtq" sourceRef="Activity_08ph592" targetRef="Gateway_1fuooy7" />
<bpmn:parallelGateway id="Gateway_1fuooy7">
<bpmn:incoming>Flow_0bqldtq</bpmn:incoming>
<bpmn:outgoing>Flow_0uz23pa</bpmn:outgoing>
<bpmn:outgoing>Flow_0lxkhyk</bpmn:outgoing>
</bpmn:parallelGateway>
<bpmn:sequenceFlow id="Flow_0uz23pa" sourceRef="Gateway_1fuooy7" targetRef="Activity_074zi83" />
<bpmn:sequenceFlow id="Flow_0lxkhyk" sourceRef="Gateway_1fuooy7" targetRef="Activity_1q9hew9" />
<bpmn:sequenceFlow id="Flow_0jbl9r5" sourceRef="Activity_074zi83" targetRef="Gateway_154x94y" />
<bpmn:parallelGateway id="Gateway_154x94y">
<bpmn:incoming>Flow_0jbl9r5</bpmn:incoming>
<bpmn:outgoing>Flow_12l4idr</bpmn:outgoing>
<bpmn:outgoing>Flow_1vrl38f</bpmn:outgoing>
<bpmn:outgoing>Flow_00l0jlm</bpmn:outgoing>
</bpmn:parallelGateway>
<bpmn:sequenceFlow id="Flow_12l4idr" sourceRef="Gateway_154x94y" targetRef="Activity_1fhooq5" />
<bpmn:sequenceFlow id="Flow_1vrl38f" sourceRef="Gateway_154x94y" targetRef="Activity_10osigr" />
<bpmn:sequenceFlow id="Flow_1w06rvu" sourceRef="Activity_1q9hew9" targetRef="Activity_1wxkjsy" />
<bpmn:sequenceFlow id="Flow_0bnfb2o" sourceRef="Activity_1wxkjsy" targetRef="Gateway_1l393n2" />
<bpmn:parallelGateway id="Gateway_1l393n2">
<bpmn:incoming>Flow_0bnfb2o</bpmn:incoming>
<bpmn:incoming>Flow_0e0mjza</bpmn:incoming>
<bpmn:outgoing>Flow_1elex5d</bpmn:outgoing>
</bpmn:parallelGateway>
<bpmn:sequenceFlow id="Flow_0xuk6oo" sourceRef="Activity_1fhooq5" targetRef="Gateway_1di8mfh" />
<bpmn:parallelGateway id="Gateway_1di8mfh">
<bpmn:incoming>Flow_0xuk6oo</bpmn:incoming>
<bpmn:incoming>Flow_0zvg05z</bpmn:incoming>
<bpmn:incoming>Flow_13idoid</bpmn:incoming>
<bpmn:outgoing>Flow_0speild</bpmn:outgoing>
</bpmn:parallelGateway>
<bpmn:sequenceFlow id="Flow_0zvg05z" sourceRef="Activity_10osigr" targetRef="Gateway_1di8mfh" />
<bpmn:sequenceFlow id="Flow_0jmsqxc" sourceRef="Activity_1e5ytx7" targetRef="Activity_0d1w71m" />
<bpmn:sequenceFlow id="Flow_1elex5d" sourceRef="Gateway_1l393n2" targetRef="Activity_1nsgbwi" />
<bpmn:endEvent id="Event_1ed7zfp">
<bpmn:incoming>Flow_1t2xmwi</bpmn:incoming>
<bpmn:incoming>Flow_02xjzjb</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_1t2xmwi" sourceRef="Activity_1nsgbwi" targetRef="Event_1ed7zfp" />
<bpmn:sequenceFlow id="Flow_02xjzjb" sourceRef="Activity_0d1w71m" targetRef="Event_1ed7zfp" />
<bpmn:userTask id="Activity_06jvxc8" name="1">
<bpmn:incoming>Flow_11anzux</bpmn:incoming>
<bpmn:outgoing>Flow_0ai6ch9</bpmn:outgoing>
</bpmn:userTask>
<bpmn:userTask id="Activity_0guygm5" name="1.1">
<bpmn:incoming>Flow_1by26xl</bpmn:incoming>
<bpmn:outgoing>Flow_1ppifbg</bpmn:outgoing>
</bpmn:userTask>
<bpmn:userTask id="Activity_1e5ytx7" name="1.2">
<bpmn:incoming>Flow_0c22b7f</bpmn:incoming>
<bpmn:outgoing>Flow_0jmsqxc</bpmn:outgoing>
</bpmn:userTask>
<bpmn:userTask id="Activity_08ph592" name="1.1.1">
<bpmn:incoming>Flow_1ppifbg</bpmn:incoming>
<bpmn:outgoing>Flow_0bqldtq</bpmn:outgoing>
</bpmn:userTask>
<bpmn:userTask id="Activity_0d1w71m" name="1.2.1">
<bpmn:incoming>Flow_0jmsqxc</bpmn:incoming>
<bpmn:outgoing>Flow_02xjzjb</bpmn:outgoing>
</bpmn:userTask>
<bpmn:userTask id="Activity_074zi83" name="1.3">
<bpmn:incoming>Flow_0uz23pa</bpmn:incoming>
<bpmn:outgoing>Flow_0jbl9r5</bpmn:outgoing>
</bpmn:userTask>
<bpmn:userTask id="Activity_1q9hew9" name="1.4">
<bpmn:incoming>Flow_0lxkhyk</bpmn:incoming>
<bpmn:outgoing>Flow_1w06rvu</bpmn:outgoing>
</bpmn:userTask>
<bpmn:userTask id="Activity_1fhooq5" name="1.3.1">
<bpmn:incoming>Flow_12l4idr</bpmn:incoming>
<bpmn:outgoing>Flow_0xuk6oo</bpmn:outgoing>
</bpmn:userTask>
<bpmn:userTask id="Activity_1wxkjsy" name="1.4.1">
<bpmn:incoming>Flow_1w06rvu</bpmn:incoming>
<bpmn:outgoing>Flow_0bnfb2o</bpmn:outgoing>
</bpmn:userTask>
<bpmn:userTask id="Activity_10osigr" name="1.3.2">
<bpmn:incoming>Flow_1vrl38f</bpmn:incoming>
<bpmn:outgoing>Flow_0zvg05z</bpmn:outgoing>
</bpmn:userTask>
<bpmn:userTask id="Activity_1nsgbwi" name="1.6">
<bpmn:incoming>Flow_1elex5d</bpmn:incoming>
<bpmn:outgoing>Flow_1t2xmwi</bpmn:outgoing>
</bpmn:userTask>
<bpmn:sequenceFlow id="Flow_0speild" sourceRef="Gateway_1di8mfh" targetRef="Activity_0sxu2h9" />
<bpmn:sequenceFlow id="Flow_0e0mjza" sourceRef="Activity_0sxu2h9" targetRef="Gateway_1l393n2" />
<bpmn:userTask id="Activity_0sxu2h9" name="1.5">
<bpmn:incoming>Flow_0speild</bpmn:incoming>
<bpmn:outgoing>Flow_0e0mjza</bpmn:outgoing>
</bpmn:userTask>
<bpmn:sequenceFlow id="Flow_00l0jlm" sourceRef="Gateway_154x94y" targetRef="Activity_0dadd6d" />
<bpmn:sequenceFlow id="Flow_13idoid" sourceRef="Activity_0dadd6d" targetRef="Gateway_1di8mfh" />
<bpmn:userTask id="Activity_0dadd6d" name="1.3.3">
<bpmn:incoming>Flow_00l0jlm</bpmn:incoming>
<bpmn:outgoing>Flow_13idoid</bpmn:outgoing>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1ponnq0">
<bpmndi:BPMNShape id="Event_0iw6gxi_di" bpmnElement="Event_0iw6gxi">
<dc:Bounds x="152" y="402" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_1hro0j7_di" bpmnElement="Gateway_1hro0j7" isMarkerVisible="true">
<dc:Bounds x="395" y="395" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_1d2b8ie_di" bpmnElement="Gateway_1fuooy7">
<dc:Bounds x="825" y="335" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_01rq7dr_di" bpmnElement="Gateway_154x94y">
<dc:Bounds x="1105" y="265" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_09rg4yq_di" bpmnElement="Gateway_1di8mfh">
<dc:Bounds x="1355" y="265" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_02dcebx_di" bpmnElement="Activity_06jvxc8">
<dc:Bounds x="240" y="380" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0d8xksp_di" bpmnElement="Activity_0guygm5">
<dc:Bounds x="500" y="320" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0m74vlc_di" bpmnElement="Activity_1e5ytx7">
<dc:Bounds x="500" y="440" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1vsqkvw_di" bpmnElement="Activity_08ph592">
<dc:Bounds x="660" y="320" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_15bop04_di" bpmnElement="Activity_0d1w71m">
<dc:Bounds x="660" y="440" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0er7dny_di" bpmnElement="Activity_074zi83">
<dc:Bounds x="940" y="250" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_12hs03t_di" bpmnElement="Activity_1q9hew9">
<dc:Bounds x="940" y="390" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1qlx0o4_di" bpmnElement="Activity_1fhooq5">
<dc:Bounds x="1220" y="190" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0gdbgnm_di" bpmnElement="Activity_10osigr">
<dc:Bounds x="1220" y="310" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1ed7zfp_di" bpmnElement="Event_1ed7zfp">
<dc:Bounds x="1792" y="342" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0uuxlao_di" bpmnElement="Activity_1nsgbwi">
<dc:Bounds x="1650" y="320" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_1pufs6q_di" bpmnElement="Gateway_1l393n2">
<dc:Bounds x="1555" y="335" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0qurfv9_di" bpmnElement="Activity_1wxkjsy">
<dc:Bounds x="1350" y="390" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0thfs8z_di" bpmnElement="Activity_0sxu2h9">
<dc:Bounds x="1430" y="250" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0pcqtz6_di" bpmnElement="Activity_0dadd6d">
<dc:Bounds x="1220" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_11anzux_di" bpmnElement="Flow_11anzux">
<di:waypoint x="188" y="420" />
<di:waypoint x="240" y="420" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0ai6ch9_di" bpmnElement="Flow_0ai6ch9">
<di:waypoint x="340" y="420" />
<di:waypoint x="395" y="420" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1by26xl_di" bpmnElement="Flow_1by26xl">
<di:waypoint x="420" y="395" />
<di:waypoint x="420" y="360" />
<di:waypoint x="500" y="360" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0c22b7f_di" bpmnElement="Flow_0c22b7f">
<di:waypoint x="420" y="445" />
<di:waypoint x="420" y="480" />
<di:waypoint x="500" y="480" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0bqldtq_di" bpmnElement="Flow_0bqldtq">
<di:waypoint x="760" y="360" />
<di:waypoint x="825" y="360" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0uz23pa_di" bpmnElement="Flow_0uz23pa">
<di:waypoint x="850" y="335" />
<di:waypoint x="850" y="290" />
<di:waypoint x="940" y="290" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0lxkhyk_di" bpmnElement="Flow_0lxkhyk">
<di:waypoint x="850" y="385" />
<di:waypoint x="850" y="430" />
<di:waypoint x="940" y="430" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0jbl9r5_di" bpmnElement="Flow_0jbl9r5">
<di:waypoint x="1040" y="290" />
<di:waypoint x="1105" y="290" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_12l4idr_di" bpmnElement="Flow_12l4idr">
<di:waypoint x="1130" y="265" />
<di:waypoint x="1130" y="230" />
<di:waypoint x="1220" y="230" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1vrl38f_di" bpmnElement="Flow_1vrl38f">
<di:waypoint x="1130" y="315" />
<di:waypoint x="1130" y="350" />
<di:waypoint x="1220" y="350" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_00l0jlm_di" bpmnElement="Flow_00l0jlm">
<di:waypoint x="1130" y="265" />
<di:waypoint x="1130" y="120" />
<di:waypoint x="1220" y="120" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0xuk6oo_di" bpmnElement="Flow_0xuk6oo">
<di:waypoint x="1320" y="230" />
<di:waypoint x="1380" y="230" />
<di:waypoint x="1380" y="265" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0zvg05z_di" bpmnElement="Flow_0zvg05z">
<di:waypoint x="1320" y="350" />
<di:waypoint x="1380" y="350" />
<di:waypoint x="1380" y="315" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_13idoid_di" bpmnElement="Flow_13idoid">
<di:waypoint x="1320" y="120" />
<di:waypoint x="1380" y="120" />
<di:waypoint x="1380" y="265" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0speild_di" bpmnElement="Flow_0speild">
<di:waypoint x="1405" y="290" />
<di:waypoint x="1430" y="290" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1ppifbg_di" bpmnElement="Flow_1ppifbg">
<di:waypoint x="600" y="360" />
<di:waypoint x="660" y="360" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0jmsqxc_di" bpmnElement="Flow_0jmsqxc">
<di:waypoint x="600" y="480" />
<di:waypoint x="660" y="480" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_02xjzjb_di" bpmnElement="Flow_02xjzjb">
<di:waypoint x="760" y="500" />
<di:waypoint x="1810" y="500" />
<di:waypoint x="1810" y="378" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1w06rvu_di" bpmnElement="Flow_1w06rvu">
<di:waypoint x="1040" y="430" />
<di:waypoint x="1350" y="430" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1t2xmwi_di" bpmnElement="Flow_1t2xmwi">
<di:waypoint x="1750" y="360" />
<di:waypoint x="1792" y="360" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1elex5d_di" bpmnElement="Flow_1elex5d">
<di:waypoint x="1605" y="360" />
<di:waypoint x="1650" y="360" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0bnfb2o_di" bpmnElement="Flow_0bnfb2o">
<di:waypoint x="1450" y="430" />
<di:waypoint x="1580" y="430" />
<di:waypoint x="1580" y="385" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0e0mjza_di" bpmnElement="Flow_0e0mjza">
<di:waypoint x="1530" y="290" />
<di:waypoint x="1580" y="290" />
<di:waypoint x="1580" y="335" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
二、代码
Task task=taskService.createTaskQuery().taskId(taskId).singleResult();
//查找历史结束user task节点
List<HistoricActivityInstance> userTasklist = historyService
.createHistoricActivityInstanceQuery().activityType("userTask")
.processInstanceId(task.getProcessInstanceId())
.finished()
.orderByHistoricActivityInstanceEndTime().desc().list();
//查找历史结束task节点
List<HistoricActivityInstance> list1 = historyService
.createHistoricActivityInstanceQuery()
.processInstanceId(task.getProcessInstanceId())
.finished()
.orderByHistoricActivityInstanceEndTime().desc().list();
//查找历史因取消结束的task节点
List<HistoricActivityInstance> list2 = historyService
.createHistoricActivityInstanceQuery()
.processInstanceId(task.getProcessInstanceId())
.canceled()
.orderByHistoricActivityInstanceEndTime().desc().list();
//取差集
List<HistoricActivityInstance> historyActivities = list1.stream().filter(item -> !list2.stream()
.map(HistoricActivityInstance::getId)
.collect(toList()).contains(item.getId())).collect(toList());
//正在运行的活动节点
List<HistoricActivityInstance> activities = historyService.createHistoricActivityInstanceQuery()
.processInstanceId(task.getProcessInstanceId()).unfinished().list();
if (userTasklist != null && userTasklist.size()>0){
BpmnModelInstance bpmnModelInstance = repositoryService.getBpmnModelInstance(task.getProcessDefinitionId());
FlowNode element = bpmnModelInstance.getModelElementById(task.getTaskDefinitionKey());
List<FlowNode> startNode = new ArrayList<>();
List<FlowNode> cancelNode = new ArrayList<>();
cancelNode.add(element);
selectStartNode(element,startNode,cancelNode,historyActivities,activities,task.getProcessInstanceId());
if (startNode.size()>0){
identityService.setAuthenticatedUserId(userId);
ProcessInstanceModificationBuilder re = runtimeService.createProcessInstanceModification(task.getProcessInstanceId());
for (FlowNode node:cancelNode) {
re.cancelAllForActivity(node.getId());
}
for (FlowNode node:startNode) {
re.startBeforeActivity(node.getId());
}
re.setAnnotation(task.getId()).execute();
}else {
System.out.println("驳回失败");
}
}else {
System.out.println("第一用户节点");
System.out.println("驳回失败");
}
public void selectStartNode(FlowNode element,List<FlowNode> startNode,List<FlowNode> cancelNode,List<HistoricActivityInstance> historyActivities,List<HistoricActivityInstance> activities,String processId){
Collection<SequenceFlow> sequenceFlow=element.getIncoming();
Iterator<SequenceFlow> entries= sequenceFlow.iterator();
List<FlowNode> node = new ArrayList<>(); //暂存前一入线所有的节点
while (entries.hasNext()) {
SequenceFlow flow =entries.next();
FlowNode element1 =flow.getSource();
node.add(element1);
}
List<FlowNode> flowElementList= new ArrayList<>();
if (Objects.equals(element.getElementType().getTypeName(), "parallelGateway")){
flowElementList.addAll(node);
}else {
label:for (HistoricActivityInstance historyActivity: historyActivities){//查找唯一入线
for (FlowNode flowNode:node){
if (Objects.equals(historyActivity.getActivityId(), flowNode.getId())){
flowElementList.add(flowNode);
break label;
}
}
}
}
for (FlowNode flowElement:flowElementList){
if (Objects.equals(flowElement.getElementType().getTypeName(), "startEvent")){
System.out.println("不可驳回");
}else if (Objects.equals(flowElement.getElementType().getTypeName(), "userTask")){
//用户节点
startNode.add(flowElement);
}else if (Objects.equals(flowElement.getElementType().getTypeName(), "exclusiveGateway")){
//排他网关
selectStartNode(flowElement,startNode,cancelNode,historyActivities,activities,processId);
}else if (Objects.equals(flowElement.getElementType().getTypeName(), "parallelGateway")){
//并行网关
selectStartNode(flowElement,startNode,cancelNode,historyActivities,activities,processId);
Collection<SequenceFlow> gateWayIncoming=element.getIncoming();
//暂时默认根据入线数量判断,1条是进 并行网关
if (gateWayIncoming.size()==1){
//查找其他分支要取消的用户节点
Collection<SequenceFlow> sequenceOut =flowElement.getOutgoing();
for (SequenceFlow flow1 :sequenceOut){
FlowNode outElement =flow1.getTarget();
if (Objects.equals(outElement.getId(), flowElement.getId())){
//去除本身分支取消节点
continue;
}
selectCancelNode(outElement,cancelNode,activities,processId);
}
}
}
}
}
public void selectCancelNode(FlowNode element,List<FlowNode> cancelNode,List<HistoricActivityInstance> list,String processId){
//遇到结束节点 退出循环
if (!Objects.equals(element.getElementType().getTypeName(), "noneEndEvent")){
boolean bool = list.stream().anyMatch(obj -> obj.getActivityId().equals(element.getId()));
if (bool){
cancelNode.add(element);
}else {
Collection<SequenceFlow> sequenceOut =element.getOutgoing();
for (SequenceFlow flow1 :sequenceOut){
FlowNode outElement =flow1.getTarget();
selectCancelNode(outElement,cancelNode,list,processId);
}
}
}
}
总结
用到有用户任务、排他网关和并行网关,其他的并没有测试。