分配组任务方式一(直接指定办理人)
1:流程图中任务节点的配置
分配个人任务方式二(使用流程变量)
1:流程图中任务节点的配置
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: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="task" name="taskProcess" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="审批" activiti:candidateUsers="#{userIDs}"></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_task">
<bpmndi:BPMNPlane bpmnElement="task" id="BPMNPlane_task">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="390.0" y="50.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="355.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="270.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="407.0" y="85.0"></omgdi:waypoint>
<omgdi:waypoint x="407.0" y="150.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="407.0" y="205.0"></omgdi:waypoint>
<omgdi:waypoint x="407.0" y="270.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
public class TaskTest {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
/**部署流程定义(从inputStream)*/
@Test
public void deploymentProcessDefinition_inputStream(){
InputStream inputStreamBpmn = this.getClass().getResourceAsStream("task.bpmn");
InputStream inputStreamPng = this.getClass().getResourceAsStream("task.png");
Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署对象相关的Service
.createDeployment()//创建一个部署对象
.name("任务")//添加部署的名称
.addInputStream("task.bpmn", inputStreamBpmn)//
.addInputStream("task.png", inputStreamPng)//
.deploy();//完成部署
System.out.println("部署ID:"+deployment.getId());//
System.out.println("部署名称:"+deployment.getName());//
}
/**启动流程实例*/
@Test
public void startProcessInstance(){
//流程定义的key
String processDefinitionKey = "task";
/**启动流程实例的同时,设置流程变量,使用流程变量用来指定任务的办理人,对应task.pbmn文件中#{userIDs}*/
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("userIDs", "大大,中中,小小");
ProcessInstance pi = processEngine.getRuntimeService()//与正在执行的流程实例和执行对象相关的Service
.startProcessInstanceByKey(processDefinitionKey,variables);//使用流程定义的key启动流程实例,key对应helloworld.bpmn文件中id的属性值,使用key值启动,默认是按照最新版本的流程定义启动
System.out.println("流程实例ID:"+pi.getId());//流程实例ID
System.out.println("流程定义ID:"+pi.getProcessDefinitionId());//流程定义ID
}
/**查询当前人的个人任务*/
@Test
public void findMyPersonalTask(){
String assignee = "小A";
List<Task> list = processEngine.getTaskService()//与正在执行的任务管理相关的Service
.createTaskQuery()//创建任务查询对象
/**查询条件(where部分)*/
.taskAssignee(assignee)//指定个人任务查询,指定办理人
// .taskCandidateUser(candidateUser)//组任务的办理人查询
/**排序*/
.orderByTaskCreateTime().asc()//使用创建时间的升序排列
/**返回结果集*/
.list();//返回列表
if(list!=null && list.size()>0){
for(Task task:list){
System.out.println("任务ID:"+task.getId());
System.out.println("任务名称:"+task.getName());
System.out.println("任务的创建时间:"+task.getCreateTime());
System.out.println("任务的办理人:"+task.getAssignee());
System.out.println("流程实例ID:"+task.getProcessInstanceId());
System.out.println("执行对象ID:"+task.getExecutionId());
System.out.println("流程定义ID:"+task.getProcessDefinitionId());
System.out.println("########################################################");
}
}
}
/**查询当前人的组任务*/
@Test
public void findMyGroupTask(){
String candidateUser = "大大";
List<Task> list = processEngine.getTaskService()//与正在执行的任务管理相关的Service
.createTaskQuery()//创建任务查询对象
/**查询条件(where部分)*/
.taskCandidateUser(candidateUser)//组任务的办理人查询
/**排序*/
.orderByTaskCreateTime().asc()//使用创建时间的升序排列
/**返回结果集*/
.list();//返回列表
if(list!=null && list.size()>0){
for(Task task:list){
System.out.println("任务ID:"+task.getId());
System.out.println("任务名称:"+task.getName());
System.out.println("任务的创建时间:"+task.getCreateTime());
System.out.println("任务的办理人:"+task.getAssignee());
System.out.println("流程实例ID:"+task.getProcessInstanceId());
System.out.println("执行对象ID:"+task.getExecutionId());
System.out.println("流程定义ID:"+task.getProcessDefinitionId());
System.out.println("########################################################");
}
}
}
/**完成我的任务*/
@Test
public void completeMyPersonalTask(){
//任务ID
String taskId = "6905";
processEngine.getTaskService()//与正在执行的任务管理相关的Service
.complete(taskId);
System.out.println("完成任务:任务ID:"+taskId);
}
/**查询正在执行的任务办理人表*/
@Test
public void findRunPersonTask(){
//任务ID
String taskId = "6204";
List<IdentityLink> list = processEngine.getTaskService()//
.getIdentityLinksForTask(taskId);
if(list!=null && list.size()>0){
for(IdentityLink identityLink:list){
System.out.println(identityLink.getTaskId()+" "+identityLink.getType()+" "+identityLink.getProcessInstanceId()+" "+identityLink.getUserId());
}
}
}
/**查询历史任务的办理人表*/
@Test
public void findHistoryPersonTask(){
//流程实例ID
String processInstanceId = "6201";
List<HistoricIdentityLink> list = processEngine.getHistoryService()//
.getHistoricIdentityLinksForProcessInstance(processInstanceId);
if(list!=null && list.size()>0){
for(HistoricIdentityLink identityLink:list){
System.out.println(identityLink.getTaskId()+" "+identityLink.getType()+" "+identityLink.getProcessInstanceId()+" "+identityLink.getUserId());
}
}
}
/**拾取任务,将组任务分给个人任务,指定任务的办理人字段*/
@Test
public void claim(){
//将组任务分配给个人任务
//任务ID
String taskId = "6905";
//分配的个人任务(可以是组任务中的成员,也可以是非组任务的成员)
String userId = "大大";
processEngine.getTaskService()//
.claim(taskId, userId);
}
/**将个人任务回退到组任务,前提,之前一定是个组任务*/
@Test
public void setAssigee(){
//任务ID
String taskId = "6204";
processEngine.getTaskService()//
.setAssignee(taskId, null);
}
/**向组任务中添加成员*/
@Test
public void addGroupUser(){
//任务ID
String taskId = "6204";
//成员办理人
String userId = "大H";
processEngine.getTaskService()//
.addCandidateUser(taskId, userId);
}
/**从组任务中删除成员*/
@Test
public void deleteGroupUser(){
//任务ID
String taskId = "6204";
//成员办理人
String userId = "小B";
processEngine.getTaskService()//
.deleteCandidateUser(taskId, userId);
}
}
分配个人任务方式三(使用类)
1:流程图中任务节点的配置
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: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="task" name="taskProcess" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="审批">
<extensionElements>
<activiti:taskListener event="create" class="cn.itcast.l_group02.TaskListenerImpl"></activiti:taskListener>
</extensionElements>
</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_task">
<bpmndi:BPMNPlane bpmnElement="task" id="BPMNPlane_task">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="390.0" y="50.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="355.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="270.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="407.0" y="85.0"></omgdi:waypoint>
<omgdi:waypoint x="407.0" y="150.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="407.0" y="205.0"></omgdi:waypoint>
<omgdi:waypoint x="407.0" y="270.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
监听类
@SuppressWarnings("serial")
public class TaskListenerImpl implements TaskListener {
/**用来指定任务的办理人*/
@Override
public void notify(DelegateTask delegateTask) {
//指定个人任务的办理人,也可以指定组任务的办理人
//个人任务:通过类去查询数据库,将下一个任务的办理人查询获取,然后通过setAssignee()的方法指定任务的办理人
//delegateTask.setAssignee("灭绝师太");
//组任务:
delegateTask.addCandidateUser("郭靖");
delegateTask.addCandidateUser("黄蓉");
}
}
public class TaskTest {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
/**部署流程定义(从inputStream)*/
@Test
public void deploymentProcessDefinition_inputStream(){
InputStream inputStreamBpmn = this.getClass().getResourceAsStream("task.bpmn");
InputStream inputStreamPng = this.getClass().getResourceAsStream("task.png");
Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署对象相关的Service
.createDeployment()//创建一个部署对象
.name("任务")//添加部署的名称
.addInputStream("task.bpmn", inputStreamBpmn)//
.addInputStream("task.png", inputStreamPng)//
.deploy();//完成部署
System.out.println("部署ID:"+deployment.getId());//
System.out.println("部署名称:"+deployment.getName());//
}
/**启动流程实例*/
@Test
public void startProcessInstance(){
//流程定义的key
String processDefinitionKey = "task";
ProcessInstance pi = processEngine.getRuntimeService()//与正在执行的流程实例和执行对象相关的Service
.startProcessInstanceByKey(processDefinitionKey);//使用流程定义的key启动流程实例,key对应helloworld.bpmn文件中id的属性值,使用key值启动,默认是按照最新版本的流程定义启动
System.out.println("流程实例ID:"+pi.getId());//流程实例ID
System.out.println("流程定义ID:"+pi.getProcessDefinitionId());//流程定义ID
}
/**查询当前人的个人任务*/
@Test
public void findMyPersonalTask(){
String assignee = "郭靖";
List<Task> list = processEngine.getTaskService()//与正在执行的任务管理相关的Service
.createTaskQuery()//创建任务查询对象
/**查询条件(where部分)*/
.taskAssignee(assignee)//指定个人任务查询,指定办理人
// .taskCandidateUser(candidateUser)//组任务的办理人查询
/**排序*/
.orderByTaskCreateTime().asc()//使用创建时间的升序排列
/**返回结果集*/
.list();//返回列表
if(list!=null && list.size()>0){
for(Task task:list){
System.out.println("任务ID:"+task.getId());
System.out.println("任务名称:"+task.getName());
System.out.println("任务的创建时间:"+task.getCreateTime());
System.out.println("任务的办理人:"+task.getAssignee());
System.out.println("流程实例ID:"+task.getProcessInstanceId());
System.out.println("执行对象ID:"+task.getExecutionId());
System.out.println("流程定义ID:"+task.getProcessDefinitionId());
System.out.println("########################################################");
}
}
}
/**查询当前人的组任务*/
@Test
public void findMyGroupTask(){
String candidateUser = "郭靖";
List<Task> list = processEngine.getTaskService()//与正在执行的任务管理相关的Service
.createTaskQuery()//创建任务查询对象
/**查询条件(where部分)*/
.taskCandidateUser(candidateUser)//组任务的办理人查询
/**排序*/
.orderByTaskCreateTime().asc()//使用创建时间的升序排列
/**返回结果集*/
.list();//返回列表
if(list!=null && list.size()>0){
for(Task task:list){
System.out.println("任务ID:"+task.getId());
System.out.println("任务名称:"+task.getName());
System.out.println("任务的创建时间:"+task.getCreateTime());
System.out.println("任务的办理人:"+task.getAssignee());
System.out.println("流程实例ID:"+task.getProcessInstanceId());
System.out.println("执行对象ID:"+task.getExecutionId());
System.out.println("流程定义ID:"+task.getProcessDefinitionId());
System.out.println("########################################################");
}
}
}
/**完成我的任务*/
@Test
public void completeMyPersonalTask(){
//任务ID
String taskId = "7204";
processEngine.getTaskService()//与正在执行的任务管理相关的Service
.complete(taskId);
System.out.println("完成任务:任务ID:"+taskId);
}
/**查询正在执行的任务办理人表*/
@Test
public void findRunPersonTask(){
//任务ID
String taskId = "6204";
List<IdentityLink> list = processEngine.getTaskService()//
.getIdentityLinksForTask(taskId);
if(list!=null && list.size()>0){
for(IdentityLink identityLink:list){
System.out.println(identityLink.getTaskId()+" "+identityLink.getType()+" "+identityLink.getProcessInstanceId()+" "+identityLink.getUserId());
}
}
}
/**查询历史任务的办理人表*/
@Test
public void findHistoryPersonTask(){
//流程实例ID
String processInstanceId = "6201";
List<HistoricIdentityLink> list = processEngine.getHistoryService()//
.getHistoricIdentityLinksForProcessInstance(processInstanceId);
if(list!=null && list.size()>0){
for(HistoricIdentityLink identityLink:list){
System.out.println(identityLink.getTaskId()+" "+identityLink.getType()+" "+identityLink.getProcessInstanceId()+" "+identityLink.getUserId());
}
}
}
/**拾取任务,将组任务分给个人任务,指定任务的办理人字段*/
@Test
public void claim(){
//将组任务分配给个人任务
//任务ID
String taskId = "7204";
//分配的个人任务(可以是组任务中的成员,也可以是非组任务的成员)
String userId = "郭靖";
processEngine.getTaskService()//
.claim(taskId, userId);
}
/**将个人任务回退到组任务,前提,之前一定是个组任务*/
@Test
public void setAssigee(){
//任务ID
String taskId = "6204";
processEngine.getTaskService()//
.setAssignee(taskId, null);
}
/**向组任务中添加成员*/
@Test
public void addGroupUser(){
//任务ID
String taskId = "6204";
//成员办理人
String userId = "大H";
processEngine.getTaskService()//
.addCandidateUser(taskId, userId);
}
/**从组任务中删除成员*/
@Test
public void deleteGroupUser(){
//任务ID
String taskId = "6204";
//成员办理人
String userId = "小B";
processEngine.getTaskService()//
.deleteCandidateUser(taskId, userId);
}
}
组任务及三种分配方式:
1:在taskProcess.bpmn中直接写 candidate-users=“小A,小B,小C,小D"
2:在taskProcess.bpmn中写 candidate-users =“#{userIDs}”,变量的值要是String的。
使用流程变量指定办理人
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("userIDs", "大大,小小,中中");
3,使用TaskListener接口,使用类实现该接口,在类中定义:
//添加组任务的用户
delegateTask.addCandidateUser(userId1);
delegateTask.addCandidateUser(userId2);
组任务分配给个人任务(认领任务):
processEngine.getTaskService().claim(taskId, userId);
个人任务分配给组任务:
processEngine.getTaskService(). setAssignee(taskId, null);
向组任务添加人员:
processEngine.getTaskService().addCandidateUser(taskId, userId);
向组任务删除人员:
processEngine.getTaskService().deleteCandidateUser(taskId, userId);
个人任务和组任务存放办理人对应的表:
act_ru_identitylink表存放任务的办理人,包括个人任务和组任务,表示正在执行的任务
act_hi_identitylink表存放任务的办理人,包括个人任务和组任务,表示历史任务
区别在于:如果是个人任务TYPE的类型表示participant(参与者)
如果是组任务TYPE的类型表示candidate(候选者)和participant(参与者)
角色组:
分配任务负责的组
使用 candidate groups 属性指定 任务负责组
代码:
<userTask id=“usertask1” name=“审批” activiti:candidateGroups=“部门经理”>
</userTask>
其中部门经理表示一个用户组的角色
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: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="task" name="taskProcess" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="审批" activiti:candidateGroups="部门经理"></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_task">
<bpmndi:BPMNPlane bpmnElement="task" id="BPMNPlane_task">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="390.0" y="50.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="355.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="270.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="407.0" y="85.0"></omgdi:waypoint>
<omgdi:waypoint x="407.0" y="150.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="407.0" y="205.0"></omgdi:waypoint>
<omgdi:waypoint x="407.0" y="270.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
public class TaskTest {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
/**部署流程定义(从inputStream)*/
@Test
public void deploymentProcessDefinition_inputStream(){
InputStream inputStreamBpmn = this.getClass().getResourceAsStream("task.bpmn");
InputStream inputStreamPng = this.getClass().getResourceAsStream("task.png");
Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署对象相关的Service
.createDeployment()//创建一个部署对象
.name("任务")//添加部署的名称
.addInputStream("task.bpmn", inputStreamBpmn)//
.addInputStream("task.png", inputStreamPng)//
.deploy();//完成部署
System.out.println("部署ID:"+deployment.getId());//
System.out.println("部署名称:"+deployment.getName());//
/**添加用户角色组*/
IdentityService identityService = processEngine.getIdentityService();//
//创建角色
identityService.saveGroup(new GroupEntity("总经理"));
identityService.saveGroup(new GroupEntity("部门经理"));
//创建用户
identityService.saveUser(new UserEntity("张三"));
identityService.saveUser(new UserEntity("李四"));
identityService.saveUser(new UserEntity("王五"));
//建立用户和角色的关联关系
identityService.createMembership("张三", "部门经理");
identityService.createMembership("李四", "部门经理");
identityService.createMembership("王五", "总经理");
System.out.println("添加组织机构成功");
}
/**启动流程实例*/
@Test
public void startProcessInstance(){
//流程定义的key
String processDefinitionKey = "task";
ProcessInstance pi = processEngine.getRuntimeService()//与正在执行的流程实例和执行对象相关的Service
.startProcessInstanceByKey(processDefinitionKey);//使用流程定义的key启动流程实例,key对应helloworld.bpmn文件中id的属性值,使用key值启动,默认是按照最新版本的流程定义启动
System.out.println("流程实例ID:"+pi.getId());//流程实例ID
System.out.println("流程定义ID:"+pi.getProcessDefinitionId());//流程定义ID
}
/**查询当前人的个人任务*/
@Test
public void findMyPersonalTask(){
String assignee = "小A";
List<Task> list = processEngine.getTaskService()//与正在执行的任务管理相关的Service
.createTaskQuery()//创建任务查询对象
/**查询条件(where部分)*/
.taskAssignee(assignee)//指定个人任务查询,指定办理人
// .taskCandidateUser(candidateUser)//组任务的办理人查询
/**排序*/
.orderByTaskCreateTime().asc()//使用创建时间的升序排列
/**返回结果集*/
.list();//返回列表
if(list!=null && list.size()>0){
for(Task task:list){
System.out.println("任务ID:"+task.getId());
System.out.println("任务名称:"+task.getName());
System.out.println("任务的创建时间:"+task.getCreateTime());
System.out.println("任务的办理人:"+task.getAssignee());
System.out.println("流程实例ID:"+task.getProcessInstanceId());
System.out.println("执行对象ID:"+task.getExecutionId());
System.out.println("流程定义ID:"+task.getProcessDefinitionId());
System.out.println("########################################################");
}
}
}
/**查询当前人的组任务*/
@Test
public void findMyGroupTask(){
String candidateUser = "李四1";
List<Task> list = processEngine.getTaskService()//与正在执行的任务管理相关的Service
.createTaskQuery()//创建任务查询对象
/**查询条件(where部分)*/
.taskCandidateUser(candidateUser)//组任务的办理人查询
/**排序*/
.orderByTaskCreateTime().asc()//使用创建时间的升序排列
/**返回结果集*/
.list();//返回列表
if(list!=null && list.size()>0){
for(Task task:list){
System.out.println("任务ID:"+task.getId());
System.out.println("任务名称:"+task.getName());
System.out.println("任务的创建时间:"+task.getCreateTime());
System.out.println("任务的办理人:"+task.getAssignee());
System.out.println("流程实例ID:"+task.getProcessInstanceId());
System.out.println("执行对象ID:"+task.getExecutionId());
System.out.println("流程定义ID:"+task.getProcessDefinitionId());
System.out.println("########################################################");
}
}
}
/**完成我的任务*/
@Test
public void completeMyPersonalTask(){
//任务ID
String taskId = "7504";
processEngine.getTaskService()//与正在执行的任务管理相关的Service
.complete(taskId);
System.out.println("完成任务:任务ID:"+taskId);
}
/**查询正在执行的任务办理人表*/
@Test
public void findRunPersonTask(){
//任务ID
String taskId = "6204";
List<IdentityLink> list = processEngine.getTaskService()//
.getIdentityLinksForTask(taskId);
if(list!=null && list.size()>0){
for(IdentityLink identityLink:list){
System.out.println(identityLink.getTaskId()+" "+identityLink.getType()+" "+identityLink.getProcessInstanceId()+" "+identityLink.getUserId());
}
}
}
/**查询历史任务的办理人表*/
@Test
public void findHistoryPersonTask(){
//流程实例ID
String processInstanceId = "6201";
List<HistoricIdentityLink> list = processEngine.getHistoryService()//
.getHistoricIdentityLinksForProcessInstance(processInstanceId);
if(list!=null && list.size()>0){
for(HistoricIdentityLink identityLink:list){
System.out.println(identityLink.getTaskId()+" "+identityLink.getType()+" "+identityLink.getProcessInstanceId()+" "+identityLink.getUserId());
}
}
}
/**拾取任务,将组任务分给个人任务,指定任务的办理人字段*/
@Test
public void claim(){
//将组任务分配给个人任务
//任务ID
String taskId = "7504";
//分配的个人任务(可以是组任务中的成员,也可以是非组任务的成员)
String userId = "张三";
processEngine.getTaskService()//
.claim(taskId, userId);
}
/**将个人任务回退到组任务,前提,之前一定是个组任务*/
@Test
public void setAssigee(){
//任务ID
String taskId = "6204";
processEngine.getTaskService()//
.setAssignee(taskId, null);
}
/**向组任务中添加成员*/
@Test
public void addGroupUser(){
//任务ID
String taskId = "6204";
//成员办理人
String userId = "大H";
processEngine.getTaskService()//
.addCandidateUser(taskId, userId);
}
/**从组任务中删除成员*/
@Test
public void deleteGroupUser(){
//任务ID
String taskId = "6204";
//成员办理人
String userId = "小B";
processEngine.getTaskService()//
.deleteCandidateUser(taskId, userId);
}
}
表结构介绍
act_id_group:角色组表
act_id_user:用户表:
act_id_membership:用户角色表