activiti5.22 全局工作流节点监听器

适合在每个节点处理特定的事项,包含获取审批人

 1、流程节点中配置监听器

activiti5.22 全局工作流节点监听器_第1张图片

2、配置监听类型,和监听类

activiti5.22 全局工作流节点监听器_第2张图片

说明:事件监听类型有三种,start、end、take,start表示任务刚流转到该节点,end表示节点审批完毕,take表示节点审批过程中。

3、监听类MyExecutionListener内容如下

package com.jeeplus.modules.act.listener;

import java.util.Set;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.impl.task.TaskDefinition;
/**
 * 工作流各节点监听器
 * @author Lenovo
 *
 */
public class MyExecutionListener implements ExecutionListener,TaskListener {
	private static final long serialVersionUID = 7960387497099642910L;
	@Override
	public void notify(DelegateTask delegateTask) {
		// TODO Auto-generated method stub
		String eventName = delegateTask.getEventName();
		if ("create".endsWith(eventName)) {
			System.out.println("create=========");
		}else if ("assignment".endsWith(eventName)) {
			System.out.println("assignment========");
		}else if ("complete".endsWith(eventName)) {
			System.out.println("complete===========");
		}else if ("delete".endsWith(eventName)) {
			System.out.println("delete=============");
		}
	}
	@Override
	public void notify(DelegateExecution execution) throws Exception {
		//获取审批人信息 start
		String activityId = execution.getCurrentActivityId();
		String processDefinitionId=execution.getProcessDefinitionId(); // 获取流程定义id 

		ProcessDefinitionEntity processDefinitionEntity=(ProcessDefinitionEntity) execution.getEngineServices().getRepositoryService()
				.getProcessDefinition(processDefinitionId); 

		ActivityImpl activityImpl=processDefinitionEntity.findActivity(activityId); // 根据活动id获取活动实例 
		TaskDefinition taskDef = (TaskDefinition)activityImpl.getProperties().get("taskDefinition");
		String zpr = taskDef.getAssigneeExpression()==null?"":taskDef.getAssigneeExpression().getExpressionText();//代理人
		Set userCodes = taskDef.getCandidateUserIdExpressions();//候选人
		Set roleCodes = taskDef.getCandidateGroupIdExpressions();//候选组
		//获取审批人信息 end

		String eventName = execution.getEventName();
		//start
		if ("start".equals(eventName)) {
			System.out.println("start=========");
		}else if ("end".equals(eventName)) {
			System.out.println("end=========");
		}
		else if ("take".equals(eventName)) {
			System.out.println("take=========");
		}
	}
}

 

你可能感兴趣的:(activiti)