⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 secondchargeassignment.java.svn-base

📁 jbpm工作流 jbpm工作流
💻 SVN-BASE
字号:
package com.chinacars.oss.data.appform.workflow.assignment;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.sf.jaype.ext.domain.sys.Organization;
import net.sf.jaype.ext.domain.sys.User;
import net.sf.jaype.ext.services.UserService;

import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.taskmgmt.def.AssignmentHandler;
import org.jbpm.taskmgmt.exe.Assignable;
import org.springframework.web.context.WebApplicationContext;

import com.chinacars.oss.data.appform.exception.ApplicationException;

public class SecondChargeAssignment implements AssignmentHandler {
	private static final long serialVersionUID = 1L;
	private WebApplicationContext WAC;
		
	public void assign(Assignable assignable, ExecutionContext arg1) throws Exception {
		ContextInstance ci = arg1.getTaskInstance().getContextInstance();
		WAC = (WebApplicationContext)ci.getTransientVariable("WEB_APPLICATION_CONTEXT");
		User user = (User)ci.getTransientVariable("LOGIN_USER");		

		String[] actors = getDepartmentCharge(user);		
		if (actors==null) {
			throw new ApplicationException("二级部门主管未设置!");
		}
		
		assignable.setPooledActors(actors);
	}
	
	@SuppressWarnings("unchecked")
	public String[] getDepartmentCharge(User user) {
		//读取用户的部门领导
		UserService userService = (UserService) WAC.getBean("userService");
		Map<String, Object> map = new HashMap<String, Object>();
		Organization o = user.getOrganization();
		String[] result = null;
		map.put("isSManager", "true");
		while (o != null ) {
			List list = userService.findByOrgan(o.getId(), map, Integer.valueOf("0"));
			if (list==null || list.size()==0){
				o = o.getParent();
			}else {
				result = new String[list.size()];
				Iterator<User> it = list.iterator();
				int i = 0;
				while (it.hasNext()) {
					result[i] = it.next().getId();
					i++;
				}
				break;
			}
		}		
		
		return result;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -