activiti 组任务指定办理人三种方式(十一)

1、流程图

activiti 组任务指定办理人三种方式(十一)_第1张图片


2. 实现方法


package com.hxzq.workflow.group;

import java.util.ArrayList;
import java.util.List;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;

/**
 * 指定组任务办理人
 * 
 * @author ZHEN.L
 * 
 */
public class GroupTaskListinerImpl implements TaskListener {

	private static final long serialVersionUID = -3323445775884905692L;

	public void notify(DelegateTask delegateTask) {
		List<String> list = new ArrayList<String>();
		list.add("A1");
		list.add("A2");
		list.add("A3");
		delegateTask.addCandidateUsers(list);
	}

}
package com.hxzq.workflow.group;


import java.io.InputStream;
import java.util.List;


import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.history.HistoricIdentityLink;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.IdentityLink;
import org.activiti.engine.task.Task;
import org.junit.Test;


/**
 * 组任务<br>
 * 1、在cand users设置执行人名称以逗号隔开<br>
 * 2、在设置变量${user}<br>
 * 3、类
 * 
 * select * from act_ru_identitylink; #任务表(个人任务、组任任务)<br>
 * select * from act_hi_identitylink; # 任务历史表
 * 
 * @author ZHEN.L
 */
public class GroupTask {


<span style="white-space:pre">	</span>ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();


<span style="white-space:pre">	</span>@Test
<span style="white-space:pre">	</span>public void deploymentProcessDefinition() {
<span style="white-space:pre">		</span>InputStream bpmn = this.getClass()
<span style="white-space:pre">				</span>.getResourceAsStream("GroupTask.bpmn");
<span style="white-space:pre">		</span>InputStream png = this.getClass().getResourceAsStream("GroupTask.png");
<span style="white-space:pre">		</span>processEngine.getRepositoryService().createDeployment()
<span style="white-space:pre">				</span>.addInputStream("GroupTask.bpmn", bpmn)
<span style="white-space:pre">				</span>.addInputStream("GroupTask.png", png).name("组任务").deploy();
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>@Test
<span style="white-space:pre">	</span>public void startProcessInstance() {
<span style="white-space:pre">		</span>String processInstanceKey = "GroupTask";
<span style="white-space:pre">		</span>ProcessInstance processInstance = processEngine.getRuntimeService()
<span style="white-space:pre">				</span>.startProcessInstanceByKey(processInstanceKey);
<span style="white-space:pre">		</span>System.out.println(processInstance.getId());
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>/**
<span style="white-space:pre">	</span> * 查询当前人的组任务
<span style="white-space:pre">	</span> */
<span style="white-space:pre">	</span>@Test
<span style="white-space:pre">	</span>public void findGroupTask() {
<span style="white-space:pre">		</span>String user = "A1";
<span style="white-space:pre">		</span>List<Task> list = processEngine.getTaskService().createTaskQuery()
<span style="white-space:pre">				</span>.taskCandidateUser(user).list();
<span style="white-space:pre">		</span>if (list != null && list.size() > 0) {
<span style="white-space:pre">			</span>for (Task t : list) {
<span style="white-space:pre">				</span>System.out.println(t.getId() + ", " + t.getName() + ", "
<span style="white-space:pre">						</span>+ t.getCreateTime());
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>/**
<span style="white-space:pre">	</span> * 查询正在执行的任务办理人列表
<span style="white-space:pre">	</span> */
<span style="white-space:pre">	</span>@Test
<span style="white-space:pre">	</span>public void findRunPersonTask() {
<span style="white-space:pre">		</span>String taskId = "4804";
<span style="white-space:pre">		</span>List<IdentityLink> identityLinks = processEngine.getTaskService()
<span style="white-space:pre">				</span>.getIdentityLinksForTask(taskId);
<span style="white-space:pre">		</span>if (identityLinks != null && identityLinks.size() > 0) {
<span style="white-space:pre">			</span>for (IdentityLink l : identityLinks) {
<span style="white-space:pre">				</span>System.out.println(l.getUserId());
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>/**
<span style="white-space:pre">	</span> * 查询历史任务的办理人
<span style="white-space:pre">	</span> */
<span style="white-space:pre">	</span>@Test
<span style="white-space:pre">	</span>public void findHistoricPersonTask() {
<span style="white-space:pre">		</span>String taskId = "4804";
<span style="white-space:pre">		</span>List<HistoricIdentityLink> list = processEngine.getHistoryService()
<span style="white-space:pre">				</span>.getHistoricIdentityLinksForTask(taskId);
<span style="white-space:pre">		</span>if (list != null && list.size() > 0) {
<span style="white-space:pre">			</span>for (HistoricIdentityLink h : list) {
<span style="white-space:pre">				</span>System.out.println(h.getGroupId() + ", " + h.getTaskId());
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>/**
<span style="white-space:pre">	</span> * 将组任务分配给个人任务
<span style="white-space:pre">	</span> */
<span style="white-space:pre">	</span>@Test
<span style="white-space:pre">	</span>public void cliam() {
<span style="white-space:pre">		</span>String taskId = "4804";
<span style="white-space:pre">		</span>String user = "AAA";
<span style="white-space:pre">		</span>processEngine.getTaskService().claim(taskId, user);
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>/**
<span style="white-space:pre">	</span> * 分配给个人后的组任务退回给组任务
<span style="white-space:pre">	</span> */
<span style="white-space:pre">	</span>@Test
<span style="white-space:pre">	</span>public void setAssginee() {
<span style="white-space:pre">		</span>String taskId = "4804";
<span style="white-space:pre">		</span>processEngine.getTaskService().setAssignee(taskId, null);
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>/**
<span style="white-space:pre">	</span> * 完成任务
<span style="white-space:pre">	</span> */
<span style="white-space:pre">	</span>@Test
<span style="white-space:pre">	</span>public void completeTask() {
<span style="white-space:pre">		</span>String taskId = "4804";
<span style="white-space:pre">		</span>processEngine.getTaskService().complete(taskId);
<span style="white-space:pre">	</span>}


}


你可能感兴趣的:(activiti 组任务指定办理人三种方式(十一))