activiti用类来指定个人任务的办理人

/**指定任务办理人*/

public class ManagerAuditTaskListenerImpl implements TaskListener {
	
	/**用来指定任务的办理人*/
	@Override
	public void notify(DelegateTask delegateTask) {
        HistoryService historyService = SpringContextUtils.getBean(HistoryService.class);
		UserLeaderMapper userLeaderMapper = SpringContextUtils.getBean(UserLeaderMapper.class);
		//指定个人任务的办理人,也可以指定组任务的办理人
		//个人任务:通过类去查询数据库,将下一个任务的办理人查询获取,然后通过setAssignee()的方法指定任务的办理人
		//先获取上个任务的办理人
		//获取实例ID
		String processInstanceId = delegateTask.getProcessInstanceId();

		//获取上面的多个任务
		List<HistoricTaskInstance> taskList = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstanceId).orderByTaskCreateTime().desc().list();

		//获取最后面一个任务,即本任务的上一个任务
		HistoricTaskInstance lastTask=taskList.get(0);

		//获取上一个任务的执行人
		String lastTaskAsignee = lastTask.getAssignee();
		// 根据上个任务的办理人查询下个任务的办理人
		UserLeaderExample userLeaderExample = new UserLeaderExample();
		userLeaderExample.createCriteria().andUserIdEqualTo(Long.valueOf(lastTaskAsignee));
		List<UserLeaderKey> userLeaderKeyList = userLeaderMapper.selectByExample(userLeaderExample);
		String currentTaskAssignee = String.valueOf(userLeaderKeyList.get(0).getLeaderId());
		//设置当前任务执行人
		delegateTask.setAssignee(currentTaskAssignee);


	}

}



import org.apache.commons.lang3.Validate;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class SpringContextUtils implements ApplicationContextAware {
	
	public static ApplicationContext applicationContext;
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		SpringContextUtils.applicationContext = applicationContext;
	}
	
	public static Object getBean(String name) {
		return applicationContext.getBean(name);
	}
	
	/**
	 * 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
	 */
	public static <T> T getBean(Class<T> requiredType) {
		assertContextInjected();
		return applicationContext.getBean(requiredType);
	}
	
	/**
	 * 检查ApplicationContext不为空.
	 */
	private static void assertContextInjected() {
		Validate.validState(applicationContext != null, "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.");
	}
	
	public static <T> T getBean(String name, Class<T> requiredType) {
		return applicationContext.getBean(name, requiredType);
	}
	
	public static boolean containsBean(String name) {
		return applicationContext.containsBean(name);
	}
	
	public static boolean isSingleton(String name) {
		return applicationContext.isSingleton(name);
	}
	
	public static Class<? extends Object> getType(String name) {
		return applicationContext.getType(name);
	}
	
}

猜你喜欢

转载自blog.csdn.net/qq_41656943/article/details/86978076
今日推荐