Java的Flowable工作流之加签转签详解
作者:桐花思雨
1. 加签
顾名思义就是增加一道审批签名,这道审批往往是临时增加的,标准流程没有规定要走的
在现实工作流程中,加签功能使用率颇高;有时,审批人对内容不太确定,不太敢做主,就会找更高层的领导进行加签;这样就可以规避个人风险;出问题大家一起担。有时为了表示对领导尊重,或者让领导知道这回事,也需要使用加签功能
1.1. 向前加签
任务在 A 这里,A 这个时候需要 B 核对一下,等 B 核对之后又回到 A 这里,这时 A 才能继续自己的任务
1.2. 向后加签
任务在 A 这里,A 这个时候需要 B 处理这个事情,处理完毕之后就不用管了,继续后面的审批环节
2. 或签
或签:指同一个任务审批节点设置多个人,如 A、B、C 三人,三人会同时收到审批,只要其中任意一人审批即可流转到下一审批节点
3. 委派和转办的区别
3.1. 委派
委派:是将任务节点分给其他人处理,等其他人处理好之后,委派任务还会 自动回到委派人的任务中

3.2. 转办
直接将办理人assignee 换成别人,这时任务的拥有着不再是转办人,而是为空,相当与将任务转出
直接将 assignee =” zhuanban” taskService.setAssignee(taskId, userId);

4. 向前加签
4.1. 流程图
完成后的流程图如下

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://www.flowable.org/processdef" exporter="Flowable Open Source Modeler"
exporterVersion="6.7.2">
<process id="Countersign" name="Countersign" isExecutable="true">
<documentation>flowable的加签</documentation>
<startEvent id="sid-D7D95537-998F-4DC4-B951-78708D6DBB98" flowable:formFieldValidation="true"></startEvent>
<userTask id="qjsqId" name="请假申请单" flowable:assignee="${user}" 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-6B6AF669-F0E8-4D59-892A-162228D0510D" sourceRef="sid-D7D95537-998F-4DC4-B951-78708D6DBB98"
targetRef="qjsqId"></sequenceFlow>
<userTask id="zjlId" name="总经理审批" flowable:assignee="${Boss}" 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-A5F5DC0C-5E0B-4A14-B748-CBCFFB98696D" sourceRef="qjsqId" targetRef="zjlId"></sequenceFlow>
<endEvent id="sid-2C1AB747-3343-41FC-954C-70B992D32D14"></endEvent>
<sequenceFlow id="sid-8B64D6FD-A229-4E53-B4EB-C86449387AE6" sourceRef="zjlId"
targetRef="sid-2C1AB747-3343-41FC-954C-70B992D32D14"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_Countersign">
<bpmndi:BPMNPlane bpmnElement="Countersign" id="BPMNPlane_Countersign">
<bpmndi:BPMNShape bpmnElement="sid-D7D95537-998F-4DC4-B951-78708D6DBB98"
id="BPMNShape_sid-D7D95537-998F-4DC4-B951-78708D6DBB98">
<omgdc:Bounds height="30.0" width="30.0" x="74.0" y="117.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="qjsqId" id="BPMNShape_qjsqId">
<omgdc:Bounds height="80.0" width="100.0" x="225.0" y="92.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="zjlId" id="BPMNShape_zjlId">
<omgdc:Bounds height="80.0" width="100.0" x="450.0" y="92.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-2C1AB747-3343-41FC-954C-70B992D32D14"
id="BPMNShape_sid-2C1AB747-3343-41FC-954C-70B992D32D14">
<omgdc:Bounds height="28.0" width="28.0" x="660.0" y="118.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-6B6AF669-F0E8-4D59-892A-162228D0510D"
id="BPMNEdge_sid-6B6AF669-F0E8-4D59-892A-162228D0510D" flowable:sourceDockerX="15.0"
flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
<omgdi:waypoint x="103.94999947166039" y="132.0"></omgdi:waypoint>
<omgdi:waypoint x="225.0" y="132.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-A5F5DC0C-5E0B-4A14-B748-CBCFFB98696D"
id="BPMNEdge_sid-A5F5DC0C-5E0B-4A14-B748-CBCFFB98696D" flowable:sourceDockerX="50.0"
flowable:sourceDockerY="40.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
<omgdi:waypoint x="324.94999999996566" y="132.0"></omgdi:waypoint>
<omgdi:waypoint x="449.9999999998968" y="132.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-8B64D6FD-A229-4E53-B4EB-C86449387AE6"
id="BPMNEdge_sid-8B64D6FD-A229-4E53-B4EB-C86449387AE6" flowable:sourceDockerX="50.0"
flowable:sourceDockerY="40.0" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0">
<omgdi:waypoint x="549.95" y="132.0"></omgdi:waypoint>
<omgdi:waypoint x="660.0" y="132.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
4.2. 部署并启动
// 部署流程
@Test
public void test1() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
Deployment deploy = repositoryService.createDeployment()
.addClasspathResource("processes/Countersign.bpmn20.xml")
.name("加签流程")
.deploy();
System.out.println("deploy.getId() = " + deploy.getId());
System.out.println("deploy.getName() = " + deploy.getName());
}
// 启动流程
@Test
public void test2() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
// 给请假申请单分配用户
Map<String, Object> variables = new HashMap<>();
variables.put("user", "张三");
ProcessInstance processInstance = runtimeService.startProcessInstanceById("Countersign:2:bf2eeed9-58f1-11ed-8017-005056c00001", variables);
System.out.println("流程定义的ID:" + processInstance.getProcessDefinitionId());
System.out.println("流程实例的ID:" + processInstance.getId());
}
4.3. 完成任务
张三 完成请假申请单任务
// 张三完成请假申请单
@Test
public void test3() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
Task task = taskService.createTaskQuery()
.processInstanceId("57c743b9-58f2-11ed-9a6d-005056c00001")
.taskAssignee("张三")
.singleResult();
// 给总经理审批分配用户
Map<String, Object> variables = new HashMap<>();
variables.put("Boss", "周经理");
if (task != null) {
taskService.complete(task.getId(), variables);
}
}
查看 ACT_RU_TASK 表数据如下,任务节点发生了流转;到了总经理审批节点了

4.4. 向前加签实现
在实际中会出现特殊情况,如还需要 董事长 审批,但在流程设计中并没有 董事长 这个流程节点,所以需要用到加签的功能
4.4.1. 添加加签(委派)功能任务
将任务委托给另一个人,修改 ACT_RU_TASK 表记录,硬编码不推荐
- 如果任务所有者字段 OWNER_ 为 null,则将该字段置为任务的当前受理人(如 周经理)
- 委托状态字段 DELEGATION_ 变更为 PENDING;DelegationState 是一个枚举
- 当前审批人字段 ASSIGNEE_ 变更为被委托人(如 孙董事长)

/**
* 假如流程中出现特殊情况,需要特定的人员进行审批后才可以正常的把流程走下去,而这个特定的人员一开始
* 并没有在流程设计中体现出来,所以这时候就需要加签这个功能,在某一节点处添加一个新的人员来处理这个流程
*/
@Test
public void test4() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
Task task = taskService.createTaskQuery()
.processInstanceId("57c743b9-58f2-11ed-9a6d-005056c00001")
.taskAssignee("周经理")
.singleResult();
if (task != null) {
taskService.delegateTask(task.getId(), "孙董事长");
}
}
4.4.1. 加签(委派)任务的完成
@Test
public void test5() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
Task task = taskService.createTaskQuery()
.processInstanceId("57c743b9-58f2-11ed-9a6d-005056c00001")
.taskAssignee("孙董事长")
.singleResult();
if (task != null) {
taskService.resolveTask(task.getId());
}
}
加签任务不能用 completeTask() 方法来完成,因为这个加签的任务并不属于正常流程中的一个节点任务,加签任务完后,任务还会回到加签前的人员手里
查看 ACT_RU_TASK 表数据如下,任务节点发生了流转;又回到了 总经理审批 节点了
- 任务所有者字段 OWNER_ 为 周经理
- 当前审批人字段 ASSIGNEE_ 为 周经理
- 委托状态字段 DELEGATION_ 变更为 RESOLVED

5. 转签(转办)
// 转签:就是把任务转办给他人
@Test
public void transferTask() {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
// 直接setAssignee即可
taskService.setAssignee("90002", "总监");
}
到此这篇关于Java的Flowable工作流之加签转签详解的文章就介绍到这了,更多相关Flowable工作流加签转签内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
