1. 可视化编辑器编辑


2. XML文件
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://flowable.org/test">
<process id="Multiple" name="ygw-多实例测试Demo" isExecutable="true">
<startEvent id="start" name="开始" flowable:initiator="startUser"></startEvent>
<userTask id="parallelTask" name="并行多实例" flowable:assignee="${parallel}">
<documentation>并行多实例测试 指分配给多个用户之后,只要其中一个用户完成即可下一步</documentation>
<multiInstanceLoopCharacteristics isSequential="false" flowable:collection="parallelList" flowable:elementVariable="parallel">
<completionCondition>${nrOfCompletedInstances == 1}</completionCondition>
</multiInstanceLoopCharacteristics>
</userTask>
<sequenceFlow id="sid-FE8385CC-9AC8-49BA-86FC-5D6D1F98528B" sourceRef="start" targetRef="parallelTask"></sequenceFlow>
<userTask id="sequentialTask" name="串行多实例" flowable:assignee="${sequential}">
<documentation>串行多实例,值分配给多个用户之后,必须一个一个去完成才能进入下一步节点</documentation>
<multiInstanceLoopCharacteristics isSequential="true" flowable:collection="sequentialList" flowable:elementVariable="sequential">
</multiInstanceLoopCharacteristics>
</userTask>
<sequenceFlow id="sid-2DA034C8-47A5-4A7A-8641-3BD09E16BCE3" sourceRef="parallelTask" targetRef="sequentialTask"></sequenceFlow>
<endEvent id="end" name="结束"></endEvent>
<sequenceFlow id="sid-3AC0C29B-B286-4780-87A9-0A816C8F9A13" sourceRef="sequentialTask" targetRef="end"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_Multiple">
<bpmndi:BPMNPlane bpmnElement="Multiple" id="BPMNPlane_Multiple">
<bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
<omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelTask" id="BPMNShape_parallelTask">
<omgdc:Bounds height="80.0" width="100.0" x="240.0" y="138.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sequentialTask" id="BPMNShape_sequentialTask">
<omgdc:Bounds height="80.0" width="100.0" x="450.0" y="138.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="end" id="BPMNShape_end">
<omgdc:Bounds height="28.0" width="28.0" x="675.0" y="164.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-2DA034C8-47A5-4A7A-8641-3BD09E16BCE3" id="BPMNEdge_sid-2DA034C8-47A5-4A7A-8641-3BD09E16BCE3">
<omgdi:waypoint x="339.94999999995036" y="178.0"></omgdi:waypoint>
<omgdi:waypoint x="449.99999999999704" y="178.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-3AC0C29B-B286-4780-87A9-0A816C8F9A13" id="BPMNEdge_sid-3AC0C29B-B286-4780-87A9-0A816C8F9A13">
<omgdi:waypoint x="549.9499999999675" y="178.0"></omgdi:waypoint>
<omgdi:waypoint x="675.0" y="178.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-FE8385CC-9AC8-49BA-86FC-5D6D1F98528B" id="BPMNEdge_sid-FE8385CC-9AC8-49BA-86FC-5D6D1F98528B">
<omgdi:waypoint x="129.94999940317362" y="178.0"></omgdi:waypoint>
<omgdi:waypoint x="239.99999999993753" y="178.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
3. 并行主要内容
<userTask id="parallelTask" name="并行多实例" flowable:assignee="${parallel}">
<documentation>并行多实例测试 指分配给多个用户之后,只要其中一个用户完成即可下一步</documentation>
<multiInstanceLoopCharacteristics isSequential="false" flowable:collection="parallelList" flowable:elementVariable="parallel">
<completionCondition>${nrOfCompletedInstances == 1}</completionCondition>
</multiInstanceLoopCharacteristics>
</userTask>
4. 串行主要内容
<userTask id="sequentialTask" name="串行多实例" flowable:assignee="${sequential}">
<documentation>串行多实例,值分配给多个用户之后,必须一个一个去完成才能进入下一步节点</documentation>
<multiInstanceLoopCharacteristics isSequential="true" flowable:collection="sequentialList" flowable:elementVariable="sequential">
</multiInstanceLoopCharacteristics>
</userTask>
5. 参数讲解
flowable:collection=“parallelList” 传入List参数,一般为用户ID集合
flowable:elementVariable=“parallel” List中单个参数的名称
flowable:assignee="${parallel}" 当前任务的用户参数
6 并行参数讲解
1.nrOfInstances 实例总数。
2.nrOfCompletedInstances 当前还没有完成的实例 nr是number单词缩写 。
3.loopCounter 已经循环的次数。
4.nrOfActiveInstances 已经完成的实例个数。
下图代码为并行通过条件,我这边是值 只要一人通过,该节点就通过
<completionCondition>${nrOfCompletedInstances == 1}</completionCondition>
还有按照百分比来的
<completionCondition>${nrOfCompletedInstances/nrOfInstances >= 0.25}</completionCondition>
7.如何填入参数
public static final List<String> USER_ID_LIST = new ArrayList<String>() {{
add("10086");
add("10010");
add("10000");
}};
public void start() {
// 启动流程
Map<String, Object> variables = new HashMap<>();
// 创建用户
variables.put("parallelList", USER_ID_LIST);
variables.put("sequentialList", USER_ID_LIST);
Flow flow = flowService.startProcessInstanceById("流程ID", "流程标识Key", variables);
if (flow != null) {
System.out.println("流程已启动,流程ID:" + flow.getProcessInstanceId());
} else {
System.out.println("开启流程失败");
}
}
8 flowService中的内容
public Flow startProcessInstanceById(String processDefinitionId, String businessKey, Map<String, Object> variables) {
// 设置流程启动用户
identityService.setAuthenticatedUserId("当前登录用户ID");
// 开启流程
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionId, businessKey, variables);
// 组装流程通用类
Flow flow = new Flow();
flow.setProcessInstanceId(processInstance.getId());
return flow;
}
版权声明:本文为qq_35401216原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。