Activiti 分配任务责任人
Activiti 分配任务责任人
固定分配
在进行业务流程建模时指定固定的任务负责人 Assignee
表达式分配
由于固定分配方式任务只管一步一步执行任务,执行到每一个任务将按照 bpmn 的配置去分配任务负责人,不够灵活,基本不使用
UEL 表达式
Activiti 使用 UEL 表达式, UEL 是 java EE6 规范的一部分, UEL(Unified Expression Language)即 统一表达式语言, activiti 支持两个 UEL 表达式: UEL-value 和 UEL-method
UEL-value 定义
指定任务负责人 Assignee 为 ${变量}
UEL-method 方式
指定任务负责人 Assignee 为 ${对象.get方法}
UEL-method 与 UEL-value 结合
指定任务负责人 Assignee 为 ${对象.get方法(参数)}
案例
流程定义文件如下
<?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/processdef">
<process id="evection-uel" name="evection-uel" isExecutable="true">
<startEvent id="sid-d387c3a7-23c6-4771-9405-644746c6c799" name="出差申请流程开始"/>
<!--设置申请出差任务负责人为变量assignee0,依次类推-->
<userTask id="sid-18d3fd04-3ca3-444b-a23f-93b9f5bac6a9" name="申请出差" activiti:assignee="${assignee0}"/>
<userTask id="sid-d822e097-2cad-4e53-866a-79f2c31c28b4" name="经理审批" activiti:assignee="${assignee1}"/>
<userTask id="sid-df38a84b-6018-40da-bf2a-511484fcdf60" name="财务审批" activiti:assignee="${assignee3}"/>
<userTask id="sid-edb1fa75-c042-46a7-b5e9-dae94d027163" name="总经理审批" activiti:assignee="${assignee2}"/>
<sequenceFlow id="sid-ba4b8230-cc49-4e94-8066-a5c39e239879" sourceRef="sid-d387c3a7-23c6-4771-9405-644746c6c799" targetRef="sid-18d3fd04-3ca3-444b-a23f-93b9f5bac6a9"/>
<sequenceFlow id="sid-d8046b6c-d629-418e-a33d-61c4d667bce7" sourceRef="sid-18d3fd04-3ca3-444b-a23f-93b9f5bac6a9" targetRef="sid-d822e097-2cad-4e53-866a-79f2c31c28b4"/>
<sequenceFlow id="sid-4f21d03e-6123-457b-b70e-f568faa3be48" sourceRef="sid-d822e097-2cad-4e53-866a-79f2c31c28b4" targetRef="sid-edb1fa75-c042-46a7-b5e9-dae94d027163"/>
<sequenceFlow id="sid-bd4106d3-d02a-413a-87f3-faca04a69255" sourceRef="sid-edb1fa75-c042-46a7-b5e9-dae94d027163" targetRef="sid-df38a84b-6018-40da-bf2a-511484fcdf60"/>
<endEvent id="sid-2fb54bb2-3794-48dc-8ef0-16d827a14d71" name="出差申请流程结束"/>
<sequenceFlow id="sid-6fbe134e-73d7-437f-87cc-45fff8a1c53b" sourceRef="sid-df38a84b-6018-40da-bf2a-511484fcdf60" targetRef="sid-2fb54bb2-3794-48dc-8ef0-16d827a14d71"/>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_evection-uel">
<bpmndi:BPMNPlane bpmnElement="evection-uel" id="BPMNPlane_evection-uel">
<bpmndi:BPMNShape id="shape-6d957468-1a2b-4fb2-a3bb-fe2be24ea0a4" bpmnElement="sid-d387c3a7-23c6-4771-9405-644746c6c799">
<omgdc:Bounds x="-570.0" y="-280.0" width="30.0" height="30.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape-713a0420-df03-4077-bd2d-0578f684e57e" bpmnElement="sid-18d3fd04-3ca3-444b-a23f-93b9f5bac6a9">
<omgdc:Bounds x="-470.0" y="-300.0" width="100.0" height="80.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape-87052603-fd47-43fe-95f3-2dd12c2668f7" bpmnElement="sid-d822e097-2cad-4e53-866a-79f2c31c28b4">
<omgdc:Bounds x="-270.0" y="-295.0" width="100.0" height="80.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape-4e38b71b-168c-4c4d-bff2-f39a5e703845" bpmnElement="sid-df38a84b-6018-40da-bf2a-511484fcdf60">
<omgdc:Bounds x="-260.0" y="40.0" width="100.0" height="80.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape-90ee8e50-f089-450a-bbc3-c4b0cfcad964" bpmnElement="sid-edb1fa75-c042-46a7-b5e9-dae94d027163">
<omgdc:Bounds x="-270.0" y="-130.0" width="100.0" height="80.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="edge-12545edb-6305-4e77-8ffa-c6d771c422f4" bpmnElement="sid-ba4b8230-cc49-4e94-8066-a5c39e239879">
<omgdi:waypoint x="-540.0" y="-257.5"/>
<omgdi:waypoint x="-470.0" y="-260.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge-ab7d2c75-dcae-4f70-8cbd-69e3eb642de3" bpmnElement="sid-d8046b6c-d629-418e-a33d-61c4d667bce7">
<omgdi:waypoint x="-370.0" y="-260.0"/>
<omgdi:waypoint x="-270.0" y="-255.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge-7d438b6b-a94c-468e-925f-cc64798a15bd" bpmnElement="sid-4f21d03e-6123-457b-b70e-f568faa3be48">
<omgdi:waypoint x="-220.0" y="-215.0"/>
<omgdi:waypoint x="-220.0" y="-130.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge-72cc114c-3ae6-4ded-a1da-fc6756da8b27" bpmnElement="sid-bd4106d3-d02a-413a-87f3-faca04a69255">
<omgdi:waypoint x="-220.0" y="-50.0"/>
<omgdi:waypoint x="-210.0" y="40.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="shape-405075bf-9833-43f3-8bb5-fa348549638f" bpmnElement="sid-2fb54bb2-3794-48dc-8ef0-16d827a14d71">
<omgdc:Bounds x="-70.0" y="70.0" width="30.0" height="30.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="edge-f1076d45-45fd-4374-88fc-d2d08d0b39cd" bpmnElement="sid-6fbe134e-73d7-437f-87cc-45fff8a1c53b">
<omgdi:waypoint x="-160.0" y="80.0"/>
<omgdi:waypoint x="-70.0" y="77.5"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
部署流程后,启动流程并设置用户任务负责人
/**
* 启动流程并设置任务负责人
*/
@Test
public void assigneeUEL(){
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
// 存储Assignee变量值
Map<String,Object> assigneeMap = new HashMap<>();
assigneeMap.put("assignee0","张三");
assigneeMap.put("assignee1","李经理");
assigneeMap.put("assignee2","王总经理");
assigneeMap.put("assignee3","赵财务");
// 启动流程实例并设置用户任务的负责人
runtimeService.startProcessInstanceByKey("evection-uel",assigneeMap);
System.out.println(processEngine.getName());
}
流程启动成功后,可以在 act_ru_variable 表看到设置的用户任务负责人变量及变量值相关数据
记得快乐