流程图:
BPMN文件
主流程文件
<?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:activiti="http://activiti.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://www.activiti.org/test">
<process id="main" name="测试流程实例" isExecutable="true">
<startEvent id="startevent1" name="Start" activiti:initiator="applyName"></startEvent>
<userTask id="usertask1" name="申请" activiti:assignee="${applyName}"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<subProcess id="subprocess1" name="子流程一">
<startEvent id="startevent2" name="Start"></startEvent>
<userTask id="usertask2" name="审核1" activiti:assignee="754faff4b3e94963b36a578617c38e7d"></userTask>
<endEvent id="endevent2" name="End"></endEvent>
<sequenceFlow id="flow3" sourceRef="startevent2" targetRef="usertask2"></sequenceFlow>
<sequenceFlow id="flow4" sourceRef="usertask2" targetRef="endevent2"></sequenceFlow>
</subProcess>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="subprocess1"></sequenceFlow>
<userTask id="usertask3" name="审核2(TaskListener指定)" activiti:assignee="754faff4b3e94963b36a578617c38e7d">
<extensionElements>
<activiti:taskListener event="create" class="workflow.TaskListenerImpl"></activiti:taskListener>
</extensionElements>
</userTask>
<sequenceFlow id="flow5" sourceRef="subprocess1" targetRef="usertask3"></sequenceFlow>
<callActivity id="callactivity1" name="调用子流程2(CallActivity节点)" calledElement="child"></callActivity>
<sequenceFlow id="flow6" sourceRef="usertask3" targetRef="callactivity1"></sequenceFlow>
<userTask id="usertask4" name="委托审核" activiti:assignee="754faff4b3e94963b36a578617c38e7d"></userTask>
<sequenceFlow id="flow7" sourceRef="callactivity1" targetRef="usertask4"></sequenceFlow>
<userTask id="并联审核1" name="并联审核1" activiti:assignee="754faff4b3e94963b36a578617c38e7d"></userTask>
<userTask id="usertask5" name="并联审核2" activiti:assignee="754faff4b3e94963b36a578617c38e7d"></userTask>
<userTask id="usertask6" name="会签" activiti:assignee="${user}">
<multiInstanceLoopCharacteristics isSequential="true" activiti:collection="${userList}" activiti:elementVariable="user">
<completionCondition>${完成数/总数==1}</completionCondition>
</multiInstanceLoopCharacteristics>
</userTask>
<endEvent id="endevent3" name="End"></endEvent>
<sequenceFlow id="flow11" sourceRef="usertask6" targetRef="endevent3"></sequenceFlow>
<userTask id="usertask7" name="审核3" activiti:assignee="cd8a925e38614ce29e07b95a13020689"></userTask>
<parallelGateway id="parallelgateway1" name="并行"></parallelGateway>
<sequenceFlow id="flow13" sourceRef="usertask4" targetRef="parallelgateway1"></sequenceFlow>
<sequenceFlow id="flow14" sourceRef="parallelgateway1" targetRef="并联审核1"></sequenceFlow>
<sequenceFlow id="flow15" sourceRef="parallelgateway1" targetRef="usertask5"></sequenceFlow>
<inclusiveGateway id="inclusivegateway1" name="包容网关"></inclusiveGateway>
<sequenceFlow id="flow16" sourceRef="usertask5" targetRef="inclusivegateway1"></sequenceFlow>
<sequenceFlow id="flow17" name="直接执行" sourceRef="inclusivegateway1" targetRef="usertask7"></sequenceFlow>
<sequenceFlow id="flow18" name="当用户为ID=754faff4b3e94963b36a578617c38e7d时执行" sourceRef="inclusivegateway1" targetRef="usertask6">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${user=="754faff4b3e94963b36a578617c38e7d"}]]></conditionExpression>
</sequenceFlow>
<parallelGateway id="parallelgateway2" name="Parallel Gateway"></parallelGateway>
<sequenceFlow id="flow19" sourceRef="并联审核1" targetRef="parallelgateway2"></sequenceFlow>
<sequenceFlow id="flow20" sourceRef="usertask7" targetRef="parallelgateway2"></sequenceFlow>
<userTask id="usertask8" name="审核4" activiti:assignee="754faff4b3e94963b36a578617c38e7d"></userTask>
<sequenceFlow id="flow21" sourceRef="parallelgateway2" targetRef="usertask8"></sequenceFlow>
<serviceTask id="servicetask1" name="审核ServiceTask" activiti:class="workflow.TaskListenerImpl"></serviceTask>
<sequenceFlow id="flow22" sourceRef="usertask8" targetRef="servicetask1"></sequenceFlow>
<endEvent id="endevent4" name="End"></endEvent>
<sequenceFlow id="flow23" sourceRef="servicetask1" targetRef="endevent4"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_main">
<bpmndi:BPMNPlane bpmnElement="main" id="BPMNPlane_main">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="63.0" y="30.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="230.0" y="20.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="subprocess1" id="BPMNShape_subprocess1">
<omgdc:Bounds height="95.0" width="294.0" x="136.0" y="130.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="startevent2" id="BPMNShape_startevent2">
<omgdc:Bounds height="35.0" width="35.0" x="149.0" y="166.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="229.0" y="156.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2">
<omgdc:Bounds height="35.0" width="35.0" x="379.0" y="166.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="145.0" x="460.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="callactivity1" id="BPMNShape_callactivity1">
<omgdc:Bounds height="55.0" width="201.0" x="660.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
<omgdc:Bounds height="55.0" width="105.0" x="708.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="并联审核1" id="BPMNShape_并联审核1">
<omgdc:Bounds height="55.0" width="105.0" x="390.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask5" id="BPMNShape_usertask5">
<omgdc:Bounds height="55.0" width="105.0" x="573.0" y="369.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask6" id="BPMNShape_usertask6">
<omgdc:Bounds height="55.0" width="105.0" x="772.0" y="451.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent3" id="BPMNShape_endevent3">
<omgdc:Bounds height="35.0" width="35.0" x="807.0" y="377.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask7" id="BPMNShape_usertask7">
<omgdc:Bounds height="55.0" width="105.0" x="390.0" y="449.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelgateway1" id="BPMNShape_parallelgateway1">
<omgdc:Bounds height="40.0" width="40.0" x="605.0" y="267.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="inclusivegateway1" id="BPMNShape_inclusivegateway1">
<omgdc:Bounds height="40.0" width="40.0" x="605.0" y="458.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelgateway2" id="BPMNShape_parallelgateway2">
<omgdc:Bounds height="40.0" width="40.0" x="282.0" y="352.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask8" id="BPMNShape_usertask8">
<omgdc:Bounds height="55.0" width="105.0" x="136.0" y="345.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
<omgdc:Bounds height="55.0" width="105.0" x="136.0" y="490.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent4" id="BPMNShape_endevent4">
<omgdc:Bounds height="35.0" width="35.0" x="286.0" y="500.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="98.0" y="47.0"></omgdi:waypoint>
<omgdi:waypoint x="230.0" y="47.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="184.0" y="183.0"></omgdi:waypoint>
<omgdi:waypoint x="229.0" y="183.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="334.0" y="183.0"></omgdi:waypoint>
<omgdi:waypoint x="379.0" y="183.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="282.0" y="75.0"></omgdi:waypoint>
<omgdi:waypoint x="283.0" y="130.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="430.0" y="177.0"></omgdi:waypoint>
<omgdi:waypoint x="460.0" y="177.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="605.0" y="177.0"></omgdi:waypoint>
<omgdi:waypoint x="660.0" y="177.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
<omgdi:waypoint x="760.0" y="205.0"></omgdi:waypoint>
<omgdi:waypoint x="760.0" y="260.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11">
<omgdi:waypoint x="824.0" y="451.0"></omgdi:waypoint>
<omgdi:waypoint x="824.0" y="412.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13">
<omgdi:waypoint x="708.0" y="287.0"></omgdi:waypoint>
<omgdi:waypoint x="645.0" y="287.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow14" id="BPMNEdge_flow14">
<omgdi:waypoint x="605.0" y="287.0"></omgdi:waypoint>
<omgdi:waypoint x="495.0" y="287.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow15" id="BPMNEdge_flow15">
<omgdi:waypoint x="625.0" y="307.0"></omgdi:waypoint>
<omgdi:waypoint x="625.0" y="369.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow16" id="BPMNEdge_flow16">
<omgdi:waypoint x="625.0" y="424.0"></omgdi:waypoint>
<omgdi:waypoint x="625.0" y="458.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow17" id="BPMNEdge_flow17">
<omgdi:waypoint x="605.0" y="478.0"></omgdi:waypoint>
<omgdi:waypoint x="495.0" y="476.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="508.0" y="459.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow18" id="BPMNEdge_flow18">
<omgdi:waypoint x="645.0" y="478.0"></omgdi:waypoint>
<omgdi:waypoint x="772.0" y="478.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="56.0" width="100.0" x="657.0" y="477.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow19" id="BPMNEdge_flow19">
<omgdi:waypoint x="390.0" y="287.0"></omgdi:waypoint>
<omgdi:waypoint x="301.0" y="287.0"></omgdi:waypoint>
<omgdi:waypoint x="302.0" y="352.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow20" id="BPMNEdge_flow20">
<omgdi:waypoint x="390.0" y="476.0"></omgdi:waypoint>
<omgdi:waypoint x="302.0" y="476.0"></omgdi:waypoint>
<omgdi:waypoint x="302.0" y="392.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow21" id="BPMNEdge_flow21">
<omgdi:waypoint x="282.0" y="372.0"></omgdi:waypoint>
<omgdi:waypoint x="241.0" y="372.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow22" id="BPMNEdge_flow22">
<omgdi:waypoint x="188.0" y="400.0"></omgdi:waypoint>
<omgdi:waypoint x="188.0" y="490.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow23" id="BPMNEdge_flow23">
<omgdi:waypoint x="241.0" y="517.0"></omgdi:waypoint>
<omgdi:waypoint x="286.0" y="517.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
子流程文件
<?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:activiti="http://activiti.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://www.activiti.org/test">
<process id="child" name="child" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="子流程审核" activiti:assignee="754faff4b3e94963b36a578617c38e7d"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_child">
<bpmndi:BPMNPlane bpmnElement="child" id="BPMNPlane_child">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="160.0" y="160.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="240.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="390.0" y="160.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="195.0" y="177.0"></omgdi:waypoint>
<omgdi:waypoint x="240.0" y="177.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="345.0" y="177.0"></omgdi:waypoint>
<omgdi:waypoint x="390.0" y="177.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
在设置会签时有两个地方要注意:
1、会签的Collection设置为变量,Sequential参数的true代表必须按照传入的用户顺序一个一个的执行会签,而false则可以并行执行会签,建议设置为false
2、会签有最少有两个地方需要设置,分别是Main config和Collection,在Multi instance面板中的Element variable中设置了变量后,需要在Main Config中设置当前操作人
部署activiti工作流
@Autowired
private RepositoryService rep;
public void deployment() throws Exception {
//bpmn文件必须已经在工作目录下面
//部署子流程
rep.createDeployment().addClasspathResource("child.bpmn").deploy();
//部署主流程
rep.createDeployment().addClasspathResource("MyProcess.bpmn").deploy();
//通过文件流进行部署
FileInputStream stream = new FileInputStream("d:/MyProcess.bpmn");
rep.createDeployment().addInputStream("child", stream).deploy();
}