package com.leanwo.activiti.delegate.base;

import java.util.List;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 会签分配权限
 * 使用任务监听器进行权限分配
 * @author Jack
 *
 */
public class UserTaskListener2 implements TaskListener {
	private static Logger logger = LoggerFactory.getLogger(UserTaskListener2.class);
	
	@Override
	public void notify(DelegateTask delegateTask) {
//		String assignee = (String)delegateTask.getVariable("USER_ID");
//		logger.debug("开始分配用户权限,用户id:" + assignee);
//		delegateTask.setAssignee(assignee);
		Object assignee = delegateTask.getVariable("USER_TASK_DTOS_" + delegateTask.getTaskDefinitionKey());
		//logger.debug("开始分配用户权限,用户id:" + assignee);
		if(assignee instanceof String){
			delegateTask.setAssignee((String)assignee);
			
		}else if(assignee instanceof List){
			if(((List) assignee).size() > 0){
				delegateTask.setAssignee((String)((List)assignee).get(0));
			}
		}
	}
}
