flowable加签和转签
加签
同时让多人处理任务,但是不同于网关操作。
1、向前加签
任务在A这里,A这个时候需要BCD核对一下,等BCD核对之后又回到A这里
2、向后加签
任务在A这里,A这个时候需要BCD处理这个事情,处理完毕之后就不用管了,继续后面的审批环节
创建一个新的流程:就一个简单的流程,员工请假申请,总经理审批
<?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://www.flowable.org/processdef">
<process id="加签流程" name="加签流程" isExecutable="true">
<startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
<userTask id="sid-A79D6824-4FE7-439F-AA6E-07759A2D9936" name="请假申请单" flowable:assignee="员工" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-1628515E-BD6B-4287-A887-FCA6E346CE28" sourceRef="startEvent1" targetRef="sid-A79D6824-4FE7-439F-AA6E-07759A2D9936"></sequenceFlow>
<userTask id="sid-837CF8BA-F593-4696-A0B2-B114F7367097" name="总经理审批" flowable:assignee="总经理" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-DCBE07F5-B1C2-4672-8EBF-63604B8A8442" sourceRef="sid-A79D6824-4FE7-439F-AA6E-07759A2D9936" targetRef="sid-837CF8BA-F593-4696-A0B2-B114F7367097"></sequenceFlow>
<endEvent id="sid-537241A8-1CCA-4DAC-A8DA-20A29E5F381E"></endEvent>
<sequenceFlow id="sid-C6547CB7-FD01-417E-8843-95C7B0861CDB" sourceRef="sid-837CF8BA-F593-4696-A0B2-B114F7367097" targetRef="sid-537241A8-1CCA-4DAC-A8DA-20A29E5F381E"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_加签流程">
<bpmndi:BPMNPlane bpmnElement="加签流程" id="BPMNPlane_加签流程">
<bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
<omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-A79D6824-4FE7-439F-AA6E-07759A2D9936" id="BPMNShape_sid-A79D6824-4FE7-439F-AA6E-07759A2D9936">
<omgdc:Bounds height="80.0" width="99.99999999999997" x="195.00000000000003" y="138.00000000000003"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-837CF8BA-F593-4696-A0B2-B114F7367097" id="BPMNShape_sid-837CF8BA-F593-4696-A0B2-B114F7367097">
<omgdc:Bounds height="80.0" width="100.0" x="390.00000000000006" y="138.00000000000003"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-537241A8-1CCA-4DAC-A8DA-20A29E5F381E" id="BPMNShape_sid-537241A8-1CCA-4DAC-A8DA-20A29E5F381E">
<omgdc:Bounds height="28.0" width="28.0" x="600.0000000000001" y="164.00000000000003"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-DCBE07F5-B1C2-4672-8EBF-63604B8A8442" id="BPMNEdge_sid-DCBE07F5-B1C2-4672-8EBF-63604B8A8442">
<omgdi:waypoint x="294.95000000000005" y="178.00000000000003"></omgdi:waypoint>
<omgdi:waypoint x="390.00000000000006" y="178.00000000000003"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-C6547CB7-FD01-417E-8843-95C7B0861CDB" id="BPMNEdge_sid-C6547CB7-FD01-417E-8843-95C7B0861CDB">
<omgdi:waypoint x="489.95000000000005" y="178.00000000000003"></omgdi:waypoint>
<omgdi:waypoint x="600.0000000000001" y="178.00000000000003"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-1628515E-BD6B-4287-A887-FCA6E346CE28" id="BPMNEdge_sid-1628515E-BD6B-4287-A887-FCA6E346CE28">
<omgdi:waypoint x="129.94999891869114" y="178.00000000000003"></omgdi:waypoint>
<omgdi:waypoint x="194.99999999994475" y="178.00000000000003"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
部署流程并启动:
/**
* 部署流程
*/
@Test
public void deployment() {
//获取流程引擎
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//获取RepositoryService部署流程
RepositoryService repositoryService = processEngine.getRepositoryService();
repositoryService.createDeployment().name("加签流程").addClasspathResource("加签流程.bpmn20.xml").deploy();
}
/**
* 启动流程定义
*/
@Test
public void startProcess() {
//获取流程引擎
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//获取RuntimeService启动流程
RuntimeService runtimeService = processEngine.getRuntimeService();
//参数是act_re_procdef表的主键
runtimeService.startProcessInstanceById("加签流程:1:85004");
}
员工完成任务:
/**
* 员工完成任务
*/
@Test
public void completeTask() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
//为了方便,直接去库里找到该数据
taskService.complete("87505");
}
正常流程,员工完成任务后到总经理审批
但,实际中会出现特殊情况,还需要董事长审批,但在流程设计中并没有董事长这个流程节点。所以需要用到加签的功能。
加签功能
/**
* 加签任务给董事长
* 假如流程中出现特殊情况,需要特定的人员进行审批后才可以正常的把流程走下去,而这个特定的人员一开始
* 并没有在流程设计中体现出来,所以这时候就需要加签这个功能,在某一节点处添加一个新的人员来处理这个流程
*/
@Test
public void countersignTask() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
//通过delegateTask实现加签
taskService.delegateTask("90002", "董事长");
}
任务的负责人变更为董事长了
完成加签任务
/**
* 完成加签任务
* 加签任务不能用completeTask来完成,这个加签的任务并不属于正常流程中的一个节点任务
* 加签任务完后,任务还会回到加签前的人员手里
*/
@Test
public void resolveTask() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
//需要通过resolveTask完成加签任务,可以看到这里的taskId他没有改变,也就是加签任务他并没有更改任务的基本信息
//只是将assignee更新了
taskService.resolveTask("90002");
}
//后面正常完成流程任务即可,不写了。。
转签
/**
* 转签
* 就是把任务转办给他人
*/
@Test
public void transferTask() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
//直接setAssignee即可
taskService.setAssignee("90002", "总监");
}