1. 内嵌子流程
(1)说明
内嵌子流程又叫嵌入式子流程,它是一个可以包含其它活动、分支、事件,等的活动。我们通常意义上说的子流程通常就是指的内嵌子流程,它表现为将一个流程(子流程)定义在另一个流程(父流程)的内部,子流程作为父流程的一部分。子流程是主流程中的一部分流程片段,并非独立的流程定义,一般作为局部通用逻辑处理,或者因为特定业务需要,使比较复杂的单个主流程设计清晰直观。
主流程执行到子流程时启动子流程,当子流程结束后继续执行主流程。
(2)示例
<process id="demo" name="demo" isExecutable="true"><startEvent id="sid-507da2f8-ca68-4e25-a256-c9e4e98a8e30"/><endEvent id="sid-312fd1bd-1a79-46f1-956c-b89aab8a03af"/><userTask id="sid-2b45eebc-75fa-465c-b870-4159a15df689" name="业务1" flowable:assignee="zj1"/><subProcess id="sid-b8b56b6f-35ae-4367-8c40-628321034b15" flowable:exclusive="true" name="子流程"><startEvent id="sid-fa9462e7-e72f-4489-a0d8-6d4aef4a8709"/><userTask id="sid-4774809a-d1b2-4c1b-96d5-86b9faf8c0f6" name="业务2" flowable:assignee="zj2"/><endEvent id="sid-39a81a5f-b2ae-4a3a-aea4-750eead4229b"/><sequenceFlow id="sid-1cf422bf-075b-49d0-8480-bc26859431cf" sourceRef="sid-fa9462e7-e72f-4489-a0d8-6d4aef4a8709" targetRef="sid-4774809a-d1b2-4c1b-96d5-86b9faf8c0f6"/><sequenceFlow id="sid-10847d4f-0f3f-4032-9116-9c14bbcef60e" sourceRef="sid-4774809a-d1b2-4c1b-96d5-86b9faf8c0f6" targetRef="sid-39a81a5f-b2ae-4a3a-aea4-750eead4229b"/></subProcess><sequenceFlow id="sid-c0064993-d7bc-4b80-97cd-18a3aef704c5" sourceRef="sid-2b45eebc-75fa-465c-b870-4159a15df689" targetRef="sid-b8b56b6f-35ae-4367-8c40-628321034b15"/><sequenceFlow id="sid-5a6e8042-f8d6-4df5-a9e1-8d2ebdb782a0" sourceRef="sid-507da2f8-ca68-4e25-a256-c9e4e98a8e30" targetRef="sid-2b45eebc-75fa-465c-b870-4159a15df689"/><sequenceFlow id="sid-38d41002-c4d5-4e24-94dd-f783a76eafac" sourceRef="sid-b8b56b6f-35ae-4367-8c40-628321034b15" targetRef="sid-312fd1bd-1a79-46f1-956c-b89aab8a03af"/></process>
2. 事件子流程
(1)说明
和内嵌子流程类似,把一系列的活动归结到一起处理,不同之处在于事件子流程不能直接启动,要被动地由其它的事件触发启动。事件子流程可以通过消息事件、错误事件、信号事件、定时器事件或补偿事件等触发。不能在事件子流程中使用空启动事件。
(2)示例
<error id="errorName" errorCode="500"/><process id="demo" name="demo" isExecutable="true"><startEvent id="sid-507da2f8-ca68-4e25-a256-c9e4e98a8e30"/><userTask id="sid-2b45eebc-75fa-465c-b870-4159a15df689" name="业务1" flowable:assignee="zj1"/><sequenceFlow id="sid-5a6e8042-f8d6-4df5-a9e1-8d2ebdb782a0" sourceRef="sid-507da2f8-ca68-4e25-a256-c9e4e98a8e30" targetRef="sid-2b45eebc-75fa-465c-b870-4159a15df689"/><sequenceFlow id="sid-6f4a2116-6f18-4bd6-b65c-c8fe7206e0ed" sourceRef="sid-2b45eebc-75fa-465c-b870-4159a15df689" targetRef="sid-312fd1bd-1a79-46f1-956c-b89aab8a03af"/><endEvent id="sid-312fd1bd-1a79-46f1-956c-b89aab8a03af"><errorEventDefinition errorRef="errorName"/></endEvent><subProcess triggeredByEvent="true" id="sid-45854983-401e-4b42-a19b-c7b1b329fea7" flowable:exclusive="true"><startEvent id="sid-9e7d64f5-69d6-4a3a-a91f-c0fadd2f85d4"><errorEventDefinition errorRef="errorName"/></startEvent><userTask id="sid-272840fa-915e-4fc6-a118-9d5b3357f438" name="业务2" flowable:assignee="zj2"/><endEvent id="sid-7cb94afc-5c74-4195-ba9f-6782b0797c8f"/><sequenceFlow id="sid-98cedd4b-0da3-493e-9645-97ec51404bde" sourceRef="sid-9e7d64f5-69d6-4a3a-a91f-c0fadd2f85d4" targetRef="sid-272840fa-915e-4fc6-a118-9d5b3357f438"/><sequenceFlow id="sid-926b5b9c-ea1d-4000-a3fe-2af432a2021e" sourceRef="sid-272840fa-915e-4fc6-a118-9d5b3357f438" targetRef="sid-7cb94afc-5c74-4195-ba9f-6782b0797c8f"/></subProcess></process>
3. 调用活动
(1)说明
调用活动可以引用流程定义外部的流程,当执行到调用活动时启动引用的外部流程,当外部流程执行完后转到当前流程下一节点。
(2)示例
<process id="demo" name="demo" isExecutable="true"><startEvent id="sid-507da2f8-ca68-4e25-a256-c9e4e98a8e30"/><userTask id="sid-2b45eebc-75fa-465c-b870-4159a15df689" name="业务1" flowable:assignee="zj1"/><sequenceFlow id="sid-5a6e8042-f8d6-4df5-a9e1-8d2ebdb782a0" sourceRef="sid-507da2f8-ca68-4e25-a256-c9e4e98a8e30" targetRef="sid-2b45eebc-75fa-465c-b870-4159a15df689"/><callActivity id="sid-bb4cd254-3b40-4c57-a27d-a7f855001cd7" name="调用活动" calledElement="processId"/><sequenceFlow id="sid-31dc97ee-52a5-4d1d-b62a-cb4609102abf" sourceRef="sid-2b45eebc-75fa-465c-b870-4159a15df689" targetRef="sid-bb4cd254-3b40-4c57-a27d-a7f855001cd7"/><userTask id="sid-b4291f3a-0b40-46e3-9048-480904d956bc"/><endEvent id="sid-91b8b5a7-e377-426b-9380-6557d2199343"/><sequenceFlow id="sid-246011bc-4109-4857-9f91-bdfefec621f7" sourceRef="sid-b4291f3a-0b40-46e3-9048-480904d956bc" targetRef="sid-91b8b5a7-e377-426b-9380-6557d2199343"/><sequenceFlow id="sid-a52c08d4-99e0-4925-9ed5-3b6b5f482f7a" sourceRef="sid-bb4cd254-3b40-4c57-a27d-a7f855001cd7" targetRef="sid-b4291f3a-0b40-46e3-9048-480904d956bc"/></process>
4. 自组织子流程
(1)说明
自组织子流程是子流程的一种,其内部包含一组无需定义先后顺序和依赖的活动。在流程中事先定义好一组活动,但活动的执行顺序是活动的执行者确定。
completionCondition标签需要在内部任务的最后面,可在代码中指定要实现的任务,该表达式成立时退出子流程流转到主流程下一节点。
(2)示例
<process id="demo" name="demo" isExecutable="true"><startEvent id="sid-507da2f8-ca68-4e25-a256-c9e4e98a8e30"/><userTask id="sid-2b45eebc-75fa-465c-b870-4159a15df689" name="业务1" flowable:assignee="zj1"/><sequenceFlow id="sid-5a6e8042-f8d6-4df5-a9e1-8d2ebdb782a0" sourceRef="sid-507da2f8-ca68-4e25-a256-c9e4e98a8e30" targetRef="sid-2b45eebc-75fa-465c-b870-4159a15df689"/><endEvent id="sid-91b8b5a7-e377-426b-9380-6557d2199343"/><adHocSubProcess id="sid-4d483bad-7247-49ca-bea6-75d0d0c6ee04"><userTask id="sid-1c48808c-00c4-45bb-96c2-db7e3db810b7"/><serviceTask id="sid-45246be8-bdc2-4951-979e-cece074d5f1a" flowable:exclusive="true"/><completionCondition>${flag}</completionCondition></adHocSubProcess><sequenceFlow id="sid-7fa29c4a-91d0-4104-9454-09f48c38267c" sourceRef="sid-2b45eebc-75fa-465c-b870-4159a15df689" targetRef="sid-4d483bad-7247-49ca-bea6-75d0d0c6ee04"/><sequenceFlow id="sid-d08ed212-288a-4c17-b228-6691774bd2cc" sourceRef="sid-4d483bad-7247-49ca-bea6-75d0d0c6ee04" targetRef="sid-91b8b5a7-e377-426b-9380-6557d2199343"/></process>
// 查询子流程的执行流 Execution exe = runtimeService.createExecutionQuery().processInstanceId(String instanceId).activityId(String activityId).singleResult(); // 让执行流到指定任务 runtimeService.executeActivityInAdhocSubProcess(String executionId,String activityId);