activiti参考5-任务TASK
一、概要
1,设计TASK的表主要是:ACT_RU_TASK,ACT_HI_TASKINST(见参考-activiti表);
2,任务主要有:人工任务(usertask),服务任务(servicetask)等;
3,候选人/候选组(candidate):可以执行任务的一类人或者多个组,候选人/候选组中都可以去签收任务,一旦某人签收,就成为受理人,其他人就不能再签收受理此任务;usertask流程图中,candidate标示候选;候选人涉及的表ACT_RU_IDENTITYLINK;
4,受理人(assignee):有两种情况,一种是候选人/组中有人签收任务后成为受理人,另外一种是流程图中直接指定受理人,但是可以指定一个动态受理人;受理人涉及的表ACT_RU_TASK;
5,持有人(owner):持有人设置主要是存入历史表中,用于历史任务的查询,涉及的表ACT_HI_TASKINST;
二、任务操作
1,创建TASK任务与设置权限:可以使用代码创建任务,但是实际操作中都是绘制流程图。绘制TASK后,在属性可以设置候选人和受理人,一般都是设置候选人,因为固定受理人不太符合程序变动;
候选人设置了deptleader,该值将部署在表ACT_RU_IDENTITYLINK中,查看xml看见:
|
1
2
3
|
//设置了候选组 <userTask id="deptLeaderAudit" name="部门领导审批" activiti:candidateGroups="deptLeader"> </userTask> |
完整的XML(无图形位置信息)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
<process id="leave" name="请假流程" isExecutable="true"> <documentation>请假流程演示</documentation> <startEvent id="startevent1" name="Start" activiti:initiator="applyUserId"></startEvent> <userTask id="deptLeaderAudit" name="部门领导审批" activiti:candidateGroups="deptLeader"></userTask> <exclusiveGateway id="exclusivegateway5" name="Exclusive Gateway"></exclusiveGateway> <userTask id="modifyApply" name="调整申请" activiti:assignee="${applyUserId}"> <extensionElements> <activiti:taskListener event="complete" delegateExpression="${afterModifyApplyContentProcessor}"></activiti:taskListener> </extensionElements> </userTask> <userTask id="hrAudit" name="人事审批" activiti:candidateGroups="hr"></userTask> <exclusiveGateway id="exclusivegateway6" name="Exclusive Gateway"></exclusiveGateway> <userTask id="reportBack" name="销假" activiti:assignee="${applyUserId}"> <extensionElements> <activiti:taskListener event="complete" delegateExpression="${reportBackEndProcessor}"></activiti:taskListener> </extensionElements> </userTask> <endEvent id="endevent1" name="End"></endEvent> <exclusiveGateway id="exclusivegateway7" name="Exclusive Gateway"></exclusiveGateway> <sequenceFlow id="flow2" sourceRef="startevent1" targetRef="deptLeaderAudit"></sequenceFlow> <sequenceFlow id="flow3" sourceRef="deptLeaderAudit" targetRef="exclusivegateway5"></sequenceFlow> <sequenceFlow id="flow4" name="不同意" sourceRef="exclusivegateway5" targetRef="modifyApply"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!deptLeaderPass}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="flow5" name="同意" sourceRef="exclusivegateway5" targetRef="hrAudit"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${deptLeaderPass}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="flow6" sourceRef="hrAudit" targetRef="exclusivegateway6"></sequenceFlow> <sequenceFlow id="flow7" name="同意" sourceRef="exclusivegateway6" targetRef="reportBack"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${hrPass}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="flow8" sourceRef="reportBack" targetRef="endevent1"></sequenceFlow> <sequenceFlow id="flow9" name="不同意" sourceRef="exclusivegateway6" targetRef="modifyApply"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!hrPass}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="flow10" name="重新申请" sourceRef="exclusivegateway7" targetRef="deptLeaderAudit"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${reApply}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="flow11" sourceRef="modifyApply" targetRef="exclusivegateway7"></sequenceFlow> <sequenceFlow id="flow12" name="结束流程" sourceRef="exclusivegateway7" targetRef="endevent1"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!reApply}]]></conditionExpression> </sequenceFlow> </process> |
2,查询候选任务
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
//根据候选组ID查询拥有任务List<Task> tasks = taskService .createTaskQuery() .taskCandidateGroup(groupA.getId()) .list();for (Task task : tasks) {System.out.println(task.getName());} //根据用户ID查询任务tasks = taskService .createTaskQuery() .taskCandidateUser(user.getId()) .list();for (Task task : tasks) {System.out.println(task.getName());}//调用taskCandidateGroupInList<String> groupIds = new ArrayList<String>(); groupIds.add(groupA.getId()); groupIds.add(groupB.getId());tasks = taskService .createTaskQuery() .taskCandidateGroupIn(groupIds) .list();for (Task task : tasks) {System.out.println(task.getName());} //查询权限数据List<IdentityLink> links = taskService .getIdentityLinksForTask(tasks.get(0) .getId());System.out.println("关系数据量: " + links.size());} |
作者:木木


浙公网安备 33010602011771号