/**
 * Copyright &copy; 2013-2017 <a href="http://www.rhcncpa.com/">瑞华会计师事务所</a> All rights reserved.
 */
package com.jeeplus.modules.sys.web;

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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.modules.sys.dao.RoleDao;
import com.jeeplus.modules.sys.entity.Menu;
import com.jeeplus.modules.workstaff.entity.WorkStaffBasicInfo;
import com.jeeplus.modules.workstaff.service.WorkStaffBasicInfoService;
import com.sun.org.apache.bcel.internal.generic.I2F;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.utils.Collections3;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.entity.Role;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.service.OfficeService;
import com.jeeplus.modules.sys.service.SystemService;
import com.jeeplus.modules.sys.utils.UserUtils;

/**
 * 岗位Controller
 * @author jeeplus
 * @version 2013-12-05
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/role")
public class RoleController extends BaseController {

	@Autowired
	private SystemService systemService;

	@Autowired
	private OfficeService officeService;
	@Autowired
	private RoleDao roleDao;
	@Autowired
	private WorkStaffBasicInfoService workStaffBasicInfoService;
	private static Map<String,String> officeMap= new HashMap<>();
	private static Map<String,String> roleMap = new HashMap<>();

	@ModelAttribute("role")
	public Role get(@RequestParam(required=false) String id) {
		if (StringUtils.isNotBlank(id)){
			Role role = systemService.getRoleMenu(id);
			return role;
		}else{
			return new Role();
		}
	}

	@RequiresPermissions("sys:role:index")
	@RequestMapping(value = {""})
	public String index(Role role, Model model) {
		return "modules/sys/roleIndex";
	}

	@RequiresPermissions("sys:role:index")
	@RequestMapping(value = {"list"})
	public String list(Role role, Model model, HttpServletRequest request, HttpServletResponse response) {
		//role.setCompany(UserUtils.getSelectCompany());
		//List<Role> list = systemService.findAllRole();
		User user = UserUtils.getUser();
		if(!user.getId().equals("1")){
			role.setCompany(UserUtils.getSelectCompany());
		}
		String roleId = "";
		String officeId = "";
		if (role.isLook()){
			String workStaffBasicInfoName = role.getWorkStaffBasicInfoName();
			String no = role.getNo();
			officeMap.put("officeMap"+user.getId(),"");
			if (role.getOffice()!=null && StringUtils.isBlank(role.getId()) && StringUtils.isNotBlank(role.getOffice().getId())){
				roleId = role.getOffice().getId();
			}else {
				roleId = officeMap.get("roleMap"+user.getId());
			}
			if (StringUtils.isBlank(roleId)){
				roleId = role.getId();
			}
			role = roleDao.get(roleId);
			officeMap.put("roleMap"+user.getId(),roleId);
			WorkStaffBasicInfo workStaffBasicInfo = new WorkStaffBasicInfo();
			workStaffBasicInfo.setNo(no);
			workStaffBasicInfo.setName(workStaffBasicInfoName);
			workStaffBasicInfo.setOffice(role.getWorkStaffBasicInfoOffice());
			workStaffBasicInfo.setGender(role.getGender());
			Page<WorkStaffBasicInfo> page = workStaffBasicInfoService.getByRoleId(new Page<WorkStaffBasicInfo>(request, response),workStaffBasicInfo,roleId);
			/*List<WorkStaffBasicInfo> workStaffBasicInfoList = new ArrayList<>();
			if (users!=null && users.size()!=0){
				for (User user:users){
					WorkStaffBasicInfo workStaffBasicInfo = new WorkStaffBasicInfo();
					workStaffBasicInfo.setCompany(UserUtils.getSelectCompany());
					workStaffBasicInfo.setUserId(user.getId());
					WorkStaffBasicInfo staffBasicInfo = workStaffBasicInfoService.getByCompanyInfo(workStaffBasicInfo);
					if (staffBasicInfo!=null && StringUtils.isNotBlank(staffBasicInfo.getId())){
						workStaffBasicInfoList.add(staffBasicInfo);
					}
				}
			}*/
			role.setWorkStaffBasicInfoName(workStaffBasicInfoName);
			role.setNo(no);
			model.addAttribute("role", role);
			model.addAttribute("page", page);
			return "modules/sys/roleUserList";
		}else {
			officeMap.put("roleMap"+user.getId(),"");
			if (role.getOffice()!=null && StringUtils.isNotBlank(role.getOffice().getId())){
				officeId = role.getOffice().getId();
			}else {
				officeId=UserUtils.getSelectBranchOffice();
				//officeId = officeMap.get("officeMap"+user.getId());
			}
			officeMap.put("officeMap"+user.getId(),officeId);
			if (StringUtils.isNotBlank(officeId)){
				role.setOffice(new Office(officeId));
			}
			Page<Role> page = systemService.findPageRole(new Page<Role>(request, response), role);
			model.addAttribute("page", page);
			return "modules/sys/roleList";
		}

	}

	@RequestMapping(value = {"userRoleList"})
	public String userRoleList(Role role, Model model, HttpServletRequest request, HttpServletResponse response) {
		Office office = UserUtils.getSelectOffice();
		role.setBranchCompany(new Office(office.getBranchOffice()));
		role.setUserId(role.getUserId());
		role.setCompany(UserUtils.getSelectCompany());
		Page<Role> page = systemService.findPageRoleByUser(new Page<Role>(request, response), role);
		model.addAttribute("userId", role.getUserId());
        model.addAttribute("user", UserUtils.get(role.getUserId()));
		model.addAttribute("page", page);
		model.addAttribute("roleStatus", true);
		return "modules/sys/userFormView";
	}

	@RequiresPermissions(value={"sys:role:view","sys:role:add","sys:role:edit"},logical=Logical.OR)
	@RequestMapping(value = "form")
	public String form(Role role, Model model, HttpServletRequest request, HttpServletResponse response) {
//		if (role.getOffice()==null){
//			role.setOffice(UserUtils.getUser().getOffice());
//		}
		Role selectRole = new Role();
		if(role!=null&&StringUtils.isNotBlank(role.getId())){
			selectRole = roleDao.getByRoleActivity(role);
		}else {
			selectRole.setCompany(UserUtils.getSelectCompany());
			String officeId = officeMap.get("officeMap"+UserUtils.getUser().getId());
			if (StringUtils.isBlank(officeId)){
				selectRole.setOffice(UserUtils.getSelectOffice());
			}else {
				Office office = officeService.get(officeId);
				if ("2".equals(office.getType())){
					selectRole.setOffice(office);
				}
			}
		}
		List<Menu> menus = UserUtils.getMenuList(selectRole);
		if(role==null||StringUtils.isBlank(role.getNumber())){
			role.setOffice(selectRole.getOffice());
			Integer number = roleDao.getMaxNumberByOffice(role);
			if (number == null || number<1){
				number = 1;
			}else {
				number += 1;
			}
			selectRole.setNumber(number.toString());
		}

		selectRole.setMenuList(menus);
		model.addAttribute("role", selectRole);
		model.addAttribute("menuList", systemService.findAllMenu());
		model.addAttribute("officeList", officeService.findAll());
		if (StringUtils.isNotBlank(role.getView()) && role.getView().equals("copy")){
			return "modules/sys/roleRelation";
		}else if (StringUtils.isNotBlank(role.getView()) && role.getView().equals("view")){
			return "modules/sys/roleView";
		}else if (StringUtils.isNotBlank(role.getView()) && role.getView().equals("user")){
			String userId = role.getUserId();
			Office office = UserUtils.getSelectOffice();
			role.setBranchCompany(new Office(office.getBranchOffice()));
			role.setUserId(userId);
			role.setCompany(UserUtils.getSelectCompany());
			List<Role> roles = systemService.findListRoleByUser(role);
			WorkStaffBasicInfo workStaffBasicInfo = new WorkStaffBasicInfo();
			workStaffBasicInfo.setUserId(userId);
			workStaffBasicInfo.setCompany(role.getCompany());
			List<WorkStaffBasicInfo> workStaffBasicInfos = workStaffBasicInfoService.getByCompanyInfo(workStaffBasicInfo);
			model.addAttribute("userId", userId);
			model.addAttribute("user", UserUtils.get(userId));
			model.addAttribute("list", roles);
			model.addAttribute("workStaffBasicInfo", workStaffBasicInfos==null||workStaffBasicInfos.size()==0?new WorkStaffBasicInfo():workStaffBasicInfos.get(0));
				model.addAttribute("roleStatus", true);
			return "modules/sys/userFormView";
		}

		return "modules/sys/roleForm";
	}

	/**
	 * 查看当前岗位所对应的权限
	 * @param role  岗位信息
	 * @param model
	 * @return
	 */
	@RequiresPermissions("sys:role:auth")
	@RequestMapping(value = "auth")
	public String auth(Role role, Model model) {
		List<Menu> menus = UserUtils.getMenuList(role);
		role.setMenuList(menus);
		model.addAttribute("role", role);
		model.addAttribute("menuList", systemService.findAllMenu());

		model.addAttribute("officeList", officeService.findAll());
		return "modules/sys/roleAuth";
	}

	/**
	 * 保存岗位所对应的权限信息
	 * @param role
	 * @param model
	 * @param redirectAttributes
	 * @return
	 */
	@RequiresPermissions(value={"sys:role:assign","sys:role:auth","sys:role:add","sys:role:edit"},logical=Logical.OR)
	@RequestMapping(value = "save")
	public String save(Role role, Model model, RedirectAttributes redirectAttributes) {
		try {
//		printMenuId(role);
			if (!UserUtils.getUser().isAdmin() && StringUtils.isNotBlank(role.getSysData()) && role.getSysData().equals(Global.YES)) {
				if (!UserUtils.isManager()) {
					addMessage(redirectAttributes, "越权操作，只有超级管理员才能修改此数据！");
					return "redirect:" + adminPath + "/sys/role/?repage";
				}
			}
			if (Global.isDemoMode()) {
				addMessage(redirectAttributes, "演示模式，不允许操作！");
				return "redirect:" + adminPath + "/sys/role/?repage";
			}
			if (!beanValidator(model, role)) {
				return "redirect:" + adminPath + "/sys/role/?repage";
			}
			if (role.getCompany() != null && StringUtils.isBlank(role.getCompany().getId())) {
				addMessage(model, "保存岗位'" + role.getName() + "'失败, 归属公司为空");
				return "redirect:" + adminPath + "/sys/role/?repage";
			}
			//根据不同范围设置不同菜单
			/*if (StringUtils.isNotBlank(role.getDataScope()) && StringUtils.isBlank(role.getId())) {
				//所在公司及以下
				if (role.getDataScope().equals("2") || role.getDataScope().equals("10")) {
					String defalutMenu1 = "1,27,29,e3b80fae59ab4b4099d8349ecaf8c4dc,56,57,58,59,0aa3712414d049a6a24e8bcddeae509a,af0a174b4f424bc09a8cc0db83a64105,95a6a82dc5fc4d07b46e5df57a0606a3,9fdf5971a9e64fac8bbffec2825a5f97,843fdb78b8854bd48e503287f795a7d0,8d369ea660e04241a6c88d75c49a68ce,a90ba79ffbcb40dfa705fe4992e29d22,624c57fb83a54ff686c1e686bebde4c5,78bd8a7958a84617a06bcf72837eae0b,900f410b044542eeba2382d18f5d2704,6fa1a6734aeb4237a22b61b10f0affb8,62,b6fa4abb624349918fe531274fc15d23,89,76bdb735faa34667a6cbf13ebe937533,e3b5b7451e164089aba0b9bf844b0398,438c28c3cbe44ed7bff951b2a3dc77cd,59e50eebe56743a78eecbc6eff1ef94c,cc1027689aca41a89302217127253034,200fe6cc80174065b382c961a4379d79,ed9f6c6dbc334d0fb9607a52a818e102,6ca9de739e8b4f8986459307476a32e7,fee6e63e2ec643b8b07d07a902c96021,fb29eb2c5a08491597beadc096a6fbbc,020833fe4fde42fbb8bf05fa18909e31,8aed52b2c1c44ad78d2f7507009c80ef,9d1e25c52de642f985b2e52cc11c0add,befda334dab7410cba3f82fc51b98de1,ad3abaa397c94c1fb2bbfe8ddc62a5d5,3d416bdb98904fb0ba525cfe0d5bcf75,97cbdaacc376458b8c600629ad3e3dcd,5cd3a42a9f0442c3817136d91e1788f1,5b0c61a977134c42ae808f59cdd71307,b7c88056d64f48d784e6f2205d09a481,5d98b8662939442588f31eb6de73341d,d23aabe5d20541d3aa93053c42e7196a,0170ce29a5c6476b9ccf950d9ab9a8eb,dd876aae95244be4a9770ad012492cf6,f36b8695989a45f48ec0135fc695fb58,5cd0f0473ae74e22bb08a31389919217,1e28195f02c243daa730d0ac4d0542fa,1d998622704849b8ac888a421fdf689c,a870258fc8784788b4d967bfce039515,4c13ca96376341dfa25980e86964c1a9,638be8b3b5284e5088003917685bc19b,811600aadcb54b098b7dda4bf95ffc51,ce8dc7c97d93481dbd76cabb6e905b55,aa25b3904abb4bd7b779e5be37b4382e,aae6f4c7fd4c4a25afa5285210edfded,84ff9d5c165c4528af9361b6127cf5af,31b349a3624b47f28eb86d614f9f95b5,040b42e395de41d6805a958eb1897863,34874260e6fc4200a76b33c3cfa4d80d,5b6c6ea5ed2d45478e8144351d853e21,7c032c32512847f882a87416359ef0a3,6d30ea8c710a42b89da2f2506059b0ef,2ca7bf4ce6804a1c9e5b331d2df27c72,7717cbb6d71f405d890e9b648cbd2088,bddb0400764c42b08e427059c7752057,23d6c56239804053910e5c5aec481330,7f8b2018113545bcbdbfc87e7a236bec,547e121ffb714d16ae142b6935abb78f,af24101b962444f29d166b638b2fea30,6ea6519ec4d548128aa42f3ce004def3,4379bf54c2a543869abf5031b97b8efe,5e6da3f5368b4f06b7268b31a1157e9f,2bbf0e75f21d42938954391d0776fbde,545b39dacf564a5eb9d1658f80a0b8b0,b4ddedf9b451494a97a1ff9476e3897d,1b145ca23d3e4d81994a84d30a262d18,10a8c7c1d34e46dd8ef461cdad928afc,5ae4911d14bb48b39885b1fe522e999d,7f09def2533b45fdb3c733f1e72ca5fb,9ef29dca19d342b795efcbfe32793602,be72d72ae7034c509c164467b2abddda,ab879705f2354813acf8724404520e28,82487b87b97b475b98892b80cf83c96a,0f4a461b97be48eeab43bd052f630057,72e1a28b7251438a89b0a4f6bd522b89,e1f9a246057347d78a1966d6dc0168e3,5d3645d53ce14c9ab498fd9f050ba264,d361e6890cc84b049fc8268c2a8c4952,5cc0002cbcc14d3485ab8ae6d57368f2,fa7bb243643c44b18e989e3419eeb171,62768b6c65134f1e927b1807bc72115a,2d74c531c4d14056973fd177652e7dc4,1a9e2d47fcfc4a5cb6ea0b2bb4bf24f9,2e1e75dbe28841529576dd1cd48d2437,cdd8829e5976438aaa66ce608f0175f5,71015695cf1445ecacce90669c67d733,31e9dd26b7314d8a9bf97dcf6dbdb22d,e5ecaa091bb0464f8553d4e7aa60647d,39055be3a23945868dbf4b5930043a88,07ba7c9aed104657aac3be87aa346d3b,5a7a9bfff0f44a2089a7d277f2c04557,be53cc152339400ba705c1d1dceff9ab"
							+ ",3b42071536124a9c9dbf2ec319004b29,a966beefe58e4f95b24e89f4172cb7ce,9f94d338d6c94b95814b2c50f9e463d1,6eeec907b4a848f7a873123cf0cf0269,ddfa7cfabbd3478392c62829704addcc,17ea1252358a4d958f6a21779c5ad0ac,386c9efeafc74edb97be3bd2696d661e,f933b35d273f4d53902f064d86859a28,7d1745ce2c444db9bf4b4e100c476fe8,e711e93aadd54eef8feeb0fa07f054d2,0e914774210646f784d02fb22f8df7db,ca0ce5e9eb09477c8c99b7b94e7869ce,760d9072f9bc480fa36fdb876930467c,7242c1847af946b0869f4ac98eadee34,891109b0849e4dbca125f98fb4e70f3d,22a7c091650d4e5a828dab1cbd9547bc,75d308d6099d4a08a0a8cdf1a0b39eae,f1d9a3e377514f90bc05f6be02fdebc5,63f51059988c4f3087b0da17e3cecece,5dc98a677d3d4754b3cff47cb18d08a5,4574ce3053f94a59a9e6e9e45a8eca81,9f806cf868dc48d398836ebd60bd2ec6,50ff5cdc6c8645b3bb61b8327d204f01,bafb57ea8d84430cbc0c11e5c67643f1,e2c91860b96c46619a74215627560235,f5b68a43bbae44c8a1fe821dfcaca26e,70b771772a0b4f1cb1e592f9a01b08a5,7992a39d64b2483789ae274e2df3c01d,f8d711312da14871a77b58f41a6f6242,673b27b0ab9148b7ae03933c18433971,624886a950bd4d18900a877738696432,685d8d9267f745f39bcc6fc2cc553d31,7d40ad05a1a54165a28ec897ddbcef01,4bcdb5199e8442078999bb8611ea6398,0bf937d745494d998cb8bd2cf3a63f4e,c17feb3860184dd59931f35814ad68b0,4cc68cbd880c48948a1f18fe18ec938c,c37b0691a05c4d659dcd01571f1907da,c1334fe3e8484079bfd62e479307b5b9,ebb58027b6c647b7965eeb31b63ec0c0,b5dcd27f951946e08136f8bfe71f3b83,ec8c120ef1bd4abaa18449042da51b2b,a6ae28d10dc244d2bc96b956bde5c9ad,f11bd4ef5ddd4c82865fad3f1f9d80a9,76ee95093a8748b29d55df1cb8cdebd0,081af742f6384a20b492ca99704f51ca,c26c844bbb2f4746904948f3ecfeb1ae,ba9bbc5581a043d8b9c204b8ddb6aa01,cde1afb048a743bb9caedb5770aabca1,0b2b37a28bb0457bbc4bf33c11b4c6e1,5742a628f13045cda0317c3d4d839bc5,b9309305d94f4ee8b66eebbcae9f2db4,a42216d3eedd48f0ba3d3bef2470605f,9cdcda30da704c21b19ea0616de3ea86,f05ecbf7e4b04b268b38cb6e5c8124bf,788d2c1496874eeeae3b7aabbab95f76,5abae35db6de475e904425af8dc8ecbb,e3bc44b82c3543758d5a6c02b41dd526,89323021918e444bae3537521046d19f,141dd3257f85455d86f3828cc0217b5a,7bc2ad90009a4de2a0fa2947ccc09886,e51874f4b6ac455db76e30582659368b,519dee074e4c48ae9edd58d7c1e330da,060ab186c22f4f42a83f1622bf47ca52,8873bbcf4b42445f8117108769358a5c,46fa5286441a444095b917165c31304c,fa9fdd56222a4ce7ba2b37922afe0eaa,6885932aa4b443babc2b69fdd495889c,be71b947b33a48d8aee36ad0c60d10b8,b52457719429466687a2f228d20571ac,1821c5f9392e4859a829c78ebda44df6,dca21ab79bd14004b94c55e36604c30d,8d96cc3457644378b9b643243464f735,631437054079401fbe2c3c9a3f3bc375,c2f78ab4372243da8775f4d71a16fef5,03792664a45d4f63ac3efb899ce1b61e,fec04c46683a41e5a344f4d057342829,320fa70de6bc4890a0135bbfe8735b49,5a03493dce9f4323a0da7bf4fd5e78ab,b9bd46a1da1846d099566fd5c6db00cb,647021c7f798472889fd82f6c4a27ca2,313e905b78d746cb9e574b9634c3a113,623fd328c4cd4ee8b21eb03425b1f100,4676b4d1130146629fd98e2d2eb9a5b4,34d380813a36481ea2534c46d18b5927,894d87e55ac640b99e966a8786a2392b,477ba74d182a4ec0b86926dc67a0f419,362ca5fdca174fa3bdd6325a947320db,1ac3ad8dfa184fe4b6815950d3d23fdd,fdebee18c71f4a9db60096e75ad34d83,91432be4178a4781917fba0abd51df61,480c71baa65145f4bd037332d68e5e4f,536e3a3702b0453d92939846dc1f33b7,0333aedf1be640c78d2ee02473b7fd97,cbb3a6f1772b4f72a8af1375ef16e914,367ad9c43a6246dfac364ca59874883b,bac18430f6db466195a3a7116cdfb958,c4ec39be11be4b0eae321ee0559be8e6,8f7ffae7e47d462aa4142db7f06633d5,82e3b2423d86425195929fc3810ce7a4,72973e0415004dfea220babc479be082,41d0f568bb1e4fed8ad965a79d9bccef,5854ef1d24784ca0a046514b19286113,04afc3dd1eec4d13bc06cd01e0a5e838,db76e3333da846d5ae55b3b9dd735f26,7aa0ca0bf1514fa6a3a14dcde44cf0b9,9c668726c9b6449a9045d3f78408a2a1,7caf148d68a6431bbe56bcc6472d8720,babd36d1d3484fb99fe4e7ca78560ccf,7507865343e24cff80d55a29ec57f0e1,63f8b7d9b1f34851802e0408bf997ea5,a3369d5dd6b74af7b35edf1f10350881,9b8b8c3f86854416b82d57583896c1ff,881815c772564a8dbd5eb6de65ecbe7a,4b1bcf46753a48258d1d514440140b7f,1ca4c6a49e794954a235a82ee8981ecd,ab381d9129bb4b979fe3774e262524f8,a07d2c98831a4d79bc6c5c4288a24720,d8debd28039d494aa7fe18bc8e81af27,d0402b1f00f94acca96276c6ea8c8397,ebcdebd9639d4ec2b7072ad32bf48f50,636b3211100245919c09177ccea562e0,280c4440e18a487396a81b92cd3efa13,5163cf6740334a7d83375385c3ae2b67,a6083e4fab7a43498bfb3257658f9278,3b5c8b5cfb124ebd8f4a798d2a47d832,9fda332474534f96955b5bce8548947f,b5f5e62aba9842d8b48a28111ca6a372,c0cecff1207c4692a634d7de449d8d6d,e4c6428f1d264544b0eec52214e7b6ae,cbc8c5490a7f46b996fd4c3a9711f2d7,cfbdd82f4ce741a88109353c5fc898e4,6bfb965bc1b240a9ae2bd7a1e884ea51,eb36d63a993148289950af9098727759,f7357c3954d2408facaa6771a758ebcc,c05853b94ab8405eb26e0a8bd481b662,da1e6d3ebfa140b3a645342fd3bb5d95,988f3f6b607d442b8df006c980ddc2cd,b6af3c01968141baa3e99ca4b8d83847,75f669faee5d4023a425f2461e5fc5e9"
							+ ",90,f5b2028cfad9470085c7c846de33193a,28abe4b0cb3b4c8480f84c07a5dfaf06,c7fa36c7142f481397c2cc12e2bc828a,e2efcf80fc3747329fe02d489dbfda95" +
							",3b0c0ffea0cf45db816993baf64b3fb3,ad2d6d9581034e04addcb5b034a88fb3,8440c4fc5056426996e3e488b2261d28,e367c4223d794572a05fd256759d6a53,1b2dc5784c3c41988d5634e566b4a404,11be1538d7f54d7786004503b2e684a7,b462cb8c2ec7485d938416831a9771cc,f747656a36204e9588aba97064332436,78d0b2337b484c6298c9b3afc01fdb85,8a63d1f8d4bc4eb4a4db437491c9983a,2247f64a15e54053abb2e13152003c6b,d78ef9c5997d4e94804b8126cc387ea1,6ce3cd5a86ef43219dbda2b78e974c93,414b5fd5ebee45d98eca809a524dbe93,4b9ea9db5c834b698a78c7052c87b432,8590fa7adc144f49ae3d2575b7280c08,6148e4b152b9494fb9e7035e9b58e624,be1cff2a29f64800a5c4f91009711988,49b85b35bca5461993eac91ffd0b1fe4,";

					role.setMenuIds(defalutMenu1);
					String[] defalutMenus1 = defalutMenu1.split(",");
					ArrayList<String> menuIdList1 = new ArrayList<String>();
					for (int i = 0; i < defalutMenus1.length; i++) {
						menuIdList1.add(defalutMenus1[i]);
					}
					role.setMenuIdList(menuIdList1);
				}
				//所在部门及以下
				else if (role.getDataScope().equals("4") || role.getDataScope().equals("5") || role.getDataScope().equals("3")) {
					String defalutMenu1 = "1,27,29,e3b80fae59ab4b4099d8349ecaf8c4dc,56,57,58,59,0aa3712414d049a6a24e8bcddeae509a,af0a174b4f424bc09a8cc0db83a64105,95a6a82dc5fc4d07b46e5df57a0606a3,9fdf5971a9e64fac8bbffec2825a5f97,843fdb78b8854bd48e503287f795a7d0,8d369ea660e04241a6c88d75c49a68ce,a90ba79ffbcb40dfa705fe4992e29d22,624c57fb83a54ff686c1e686bebde4c5,78bd8a7958a84617a06bcf72837eae0b,900f410b044542eeba2382d18f5d2704,6fa1a6734aeb4237a22b61b10f0affb8,62,b6fa4abb624349918fe531274fc15d23,89,76bdb735faa34667a6cbf13ebe937533,e3b5b7451e164089aba0b9bf844b0398,438c28c3cbe44ed7bff951b2a3dc77cd,59e50eebe56743a78eecbc6eff1ef94c,cc1027689aca41a89302217127253034,200fe6cc80174065b382c961a4379d79,ed9f6c6dbc334d0fb9607a52a818e102,6ca9de739e8b4f8986459307476a32e7,fee6e63e2ec643b8b07d07a902c96021,fb29eb2c5a08491597beadc096a6fbbc,020833fe4fde42fbb8bf05fa18909e31,8aed52b2c1c44ad78d2f7507009c80ef,9d1e25c52de642f985b2e52cc11c0add,befda334dab7410cba3f82fc51b98de1,ad3abaa397c94c1fb2bbfe8ddc62a5d5,3d416bdb98904fb0ba525cfe0d5bcf75,97cbdaacc376458b8c600629ad3e3dcd,5cd3a42a9f0442c3817136d91e1788f1,5b0c61a977134c42ae808f59cdd71307,b7c88056d64f48d784e6f2205d09a481,5d98b8662939442588f31eb6de73341d,d23aabe5d20541d3aa93053c42e7196a,0170ce29a5c6476b9ccf950d9ab9a8eb,dd876aae95244be4a9770ad012492cf6,f36b8695989a45f48ec0135fc695fb58,5cd0f0473ae74e22bb08a31389919217,1e28195f02c243daa730d0ac4d0542fa,1d998622704849b8ac888a421fdf689c,a870258fc8784788b4d967bfce039515,4c13ca96376341dfa25980e86964c1a9,638be8b3b5284e5088003917685bc19b,811600aadcb54b098b7dda4bf95ffc51,ce8dc7c97d93481dbd76cabb6e905b55,aa25b3904abb4bd7b779e5be37b4382e,aae6f4c7fd4c4a25afa5285210edfded,84ff9d5c165c4528af9361b6127cf5af,31b349a3624b47f28eb86d614f9f95b5,040b42e395de41d6805a958eb1897863,34874260e6fc4200a76b33c3cfa4d80d,5b6c6ea5ed2d45478e8144351d853e21,7c032c32512847f882a87416359ef0a3,6d30ea8c710a42b89da2f2506059b0ef,2ca7bf4ce6804a1c9e5b331d2df27c72,7717cbb6d71f405d890e9b648cbd2088,bddb0400764c42b08e427059c7752057,23d6c56239804053910e5c5aec481330,7f8b2018113545bcbdbfc87e7a236bec,547e121ffb714d16ae142b6935abb78f,af24101b962444f29d166b638b2fea30,6ea6519ec4d548128aa42f3ce004def3,4379bf54c2a543869abf5031b97b8efe,5e6da3f5368b4f06b7268b31a1157e9f,2bbf0e75f21d42938954391d0776fbde,545b39dacf564a5eb9d1658f80a0b8b0,b4ddedf9b451494a97a1ff9476e3897d,1b145ca23d3e4d81994a84d30a262d18,10a8c7c1d34e46dd8ef461cdad928afc,5ae4911d14bb48b39885b1fe522e999d,7f09def2533b45fdb3c733f1e72ca5fb,9ef29dca19d342b795efcbfe32793602,be72d72ae7034c509c164467b2abddda,ab879705f2354813acf8724404520e28,82487b87b97b475b98892b80cf83c96a,0f4a461b97be48eeab43bd052f630057,72e1a28b7251438a89b0a4f6bd522b89,e1f9a246057347d78a1966d6dc0168e3,5d3645d53ce14c9ab498fd9f050ba264,d361e6890cc84b049fc8268c2a8c4952,5cc0002cbcc14d3485ab8ae6d57368f2,fa7bb243643c44b18e989e3419eeb171,62768b6c65134f1e927b1807bc72115a,2d74c531c4d14056973fd177652e7dc4,1a9e2d47fcfc4a5cb6ea0b2bb4bf24f9,2e1e75dbe28841529576dd1cd48d2437,cdd8829e5976438aaa66ce608f0175f5,71015695cf1445ecacce90669c67d733,31e9dd26b7314d8a9bf97dcf6dbdb22d,e5ecaa091bb0464f8553d4e7aa60647d,39055be3a23945868dbf4b5930043a88,07ba7c9aed104657aac3be87aa346d3b,5a7a9bfff0f44a2089a7d277f2c04557,be53cc152339400ba705c1d1dceff9ab"
							+ ",3b42071536124a9c9dbf2ec319004b29,a966beefe58e4f95b24e89f4172cb7ce,9f94d338d6c94b95814b2c50f9e463d1,6eeec907b4a848f7a873123cf0cf0269,ddfa7cfabbd3478392c62829704addcc,17ea1252358a4d958f6a21779c5ad0ac,386c9efeafc74edb97be3bd2696d661e,f933b35d273f4d53902f064d86859a28,7d1745ce2c444db9bf4b4e100c476fe8,e711e93aadd54eef8feeb0fa07f054d2,0e914774210646f784d02fb22f8df7db,ca0ce5e9eb09477c8c99b7b94e7869ce,760d9072f9bc480fa36fdb876930467c,7242c1847af946b0869f4ac98eadee34,891109b0849e4dbca125f98fb4e70f3d,22a7c091650d4e5a828dab1cbd9547bc,75d308d6099d4a08a0a8cdf1a0b39eae,f1d9a3e377514f90bc05f6be02fdebc5,63f51059988c4f3087b0da17e3cecece,5dc98a677d3d4754b3cff47cb18d08a5,4574ce3053f94a59a9e6e9e45a8eca81,9f806cf868dc48d398836ebd60bd2ec6,50ff5cdc6c8645b3bb61b8327d204f01,bafb57ea8d84430cbc0c11e5c67643f1,e2c91860b96c46619a74215627560235,f5b68a43bbae44c8a1fe821dfcaca26e,70b771772a0b4f1cb1e592f9a01b08a5,7992a39d64b2483789ae274e2df3c01d,f8d711312da14871a77b58f41a6f6242,673b27b0ab9148b7ae03933c18433971,624886a950bd4d18900a877738696432,685d8d9267f745f39bcc6fc2cc553d31,7d40ad05a1a54165a28ec897ddbcef01,4bcdb5199e8442078999bb8611ea6398,0bf937d745494d998cb8bd2cf3a63f4e,c17feb3860184dd59931f35814ad68b0,4cc68cbd880c48948a1f18fe18ec938c,c37b0691a05c4d659dcd01571f1907da,c1334fe3e8484079bfd62e479307b5b9,ebb58027b6c647b7965eeb31b63ec0c0,b5dcd27f951946e08136f8bfe71f3b83,ec8c120ef1bd4abaa18449042da51b2b,a6ae28d10dc244d2bc96b956bde5c9ad,f11bd4ef5ddd4c82865fad3f1f9d80a9,76ee95093a8748b29d55df1cb8cdebd0,081af742f6384a20b492ca99704f51ca,c26c844bbb2f4746904948f3ecfeb1ae,ba9bbc5581a043d8b9c204b8ddb6aa01,cde1afb048a743bb9caedb5770aabca1,0b2b37a28bb0457bbc4bf33c11b4c6e1,5742a628f13045cda0317c3d4d839bc5,b9309305d94f4ee8b66eebbcae9f2db4,a42216d3eedd48f0ba3d3bef2470605f,9cdcda30da704c21b19ea0616de3ea86,f05ecbf7e4b04b268b38cb6e5c8124bf,788d2c1496874eeeae3b7aabbab95f76,5abae35db6de475e904425af8dc8ecbb,e3bc44b82c3543758d5a6c02b41dd526,89323021918e444bae3537521046d19f,141dd3257f85455d86f3828cc0217b5a,7bc2ad90009a4de2a0fa2947ccc09886,e51874f4b6ac455db76e30582659368b,519dee074e4c48ae9edd58d7c1e330da,060ab186c22f4f42a83f1622bf47ca52,8873bbcf4b42445f8117108769358a5c,46fa5286441a444095b917165c31304c,fa9fdd56222a4ce7ba2b37922afe0eaa,6885932aa4b443babc2b69fdd495889c,be71b947b33a48d8aee36ad0c60d10b8,b52457719429466687a2f228d20571ac,1821c5f9392e4859a829c78ebda44df6,dca21ab79bd14004b94c55e36604c30d,8d96cc3457644378b9b643243464f735,631437054079401fbe2c3c9a3f3bc375,c2f78ab4372243da8775f4d71a16fef5,03792664a45d4f63ac3efb899ce1b61e,fec04c46683a41e5a344f4d057342829,320fa70de6bc4890a0135bbfe8735b49,5a03493dce9f4323a0da7bf4fd5e78ab,b9bd46a1da1846d099566fd5c6db00cb,647021c7f798472889fd82f6c4a27ca2,313e905b78d746cb9e574b9634c3a113,623fd328c4cd4ee8b21eb03425b1f100,4676b4d1130146629fd98e2d2eb9a5b4,34d380813a36481ea2534c46d18b5927,894d87e55ac640b99e966a8786a2392b,477ba74d182a4ec0b86926dc67a0f419,362ca5fdca174fa3bdd6325a947320db,1ac3ad8dfa184fe4b6815950d3d23fdd,fdebee18c71f4a9db60096e75ad34d83,91432be4178a4781917fba0abd51df61,480c71baa65145f4bd037332d68e5e4f,536e3a3702b0453d92939846dc1f33b7,0333aedf1be640c78d2ee02473b7fd97,cbb3a6f1772b4f72a8af1375ef16e914,367ad9c43a6246dfac364ca59874883b,bac18430f6db466195a3a7116cdfb958,c4ec39be11be4b0eae321ee0559be8e6,8f7ffae7e47d462aa4142db7f06633d5,82e3b2423d86425195929fc3810ce7a4,72973e0415004dfea220babc479be082,41d0f568bb1e4fed8ad965a79d9bccef,5854ef1d24784ca0a046514b19286113,04afc3dd1eec4d13bc06cd01e0a5e838,db76e3333da846d5ae55b3b9dd735f26,7aa0ca0bf1514fa6a3a14dcde44cf0b9,9c668726c9b6449a9045d3f78408a2a1,7caf148d68a6431bbe56bcc6472d8720,babd36d1d3484fb99fe4e7ca78560ccf,7507865343e24cff80d55a29ec57f0e1,63f8b7d9b1f34851802e0408bf997ea5,a3369d5dd6b74af7b35edf1f10350881,9b8b8c3f86854416b82d57583896c1ff,881815c772564a8dbd5eb6de65ecbe7a,4b1bcf46753a48258d1d514440140b7f,1ca4c6a49e794954a235a82ee8981ecd,ab381d9129bb4b979fe3774e262524f8,a07d2c98831a4d79bc6c5c4288a24720,d8debd28039d494aa7fe18bc8e81af27,d0402b1f00f94acca96276c6ea8c8397,ebcdebd9639d4ec2b7072ad32bf48f50,636b3211100245919c09177ccea562e0,280c4440e18a487396a81b92cd3efa13,5163cf6740334a7d83375385c3ae2b67,a6083e4fab7a43498bfb3257658f9278,3b5c8b5cfb124ebd8f4a798d2a47d832,9fda332474534f96955b5bce8548947f,b5f5e62aba9842d8b48a28111ca6a372,c0cecff1207c4692a634d7de449d8d6d,e4c6428f1d264544b0eec52214e7b6ae,cbc8c5490a7f46b996fd4c3a9711f2d7,cfbdd82f4ce741a88109353c5fc898e4,6bfb965bc1b240a9ae2bd7a1e884ea51,eb36d63a993148289950af9098727759,f7357c3954d2408facaa6771a758ebcc,c05853b94ab8405eb26e0a8bd481b662,da1e6d3ebfa140b3a645342fd3bb5d95,988f3f6b607d442b8df006c980ddc2cd,b6af3c01968141baa3e99ca4b8d83847,75f669faee5d4023a425f2461e5fc5e9"
							+ ",90,f5b2028cfad9470085c7c846de33193a,28abe4b0cb3b4c8480f84c07a5dfaf06,c7fa36c7142f481397c2cc12e2bc828a,e2efcf80fc3747329fe02d489dbfda95" +
							",3b0c0ffea0cf45db816993baf64b3fb3,ad2d6d9581034e04addcb5b034a88fb3,8440c4fc5056426996e3e488b2261d28,e367c4223d794572a05fd256759d6a53,1b2dc5784c3c41988d5634e566b4a404,11be1538d7f54d7786004503b2e684a7,b462cb8c2ec7485d938416831a9771cc,f747656a36204e9588aba97064332436,78d0b2337b484c6298c9b3afc01fdb85,8a63d1f8d4bc4eb4a4db437491c9983a,2247f64a15e54053abb2e13152003c6b,d78ef9c5997d4e94804b8126cc387ea1,6ce3cd5a86ef43219dbda2b78e974c93,414b5fd5ebee45d98eca809a524dbe93,4b9ea9db5c834b698a78c7052c87b432,8590fa7adc144f49ae3d2575b7280c08,6148e4b152b9494fb9e7035e9b58e624,be1cff2a29f64800a5c4f91009711988,49b85b35bca5461993eac91ffd0b1fe4,";

					role.setMenuIds(defalutMenu1);
					String[] defalutMenus1 = defalutMenu1.split(",");
					ArrayList<String> menuIdList1 = new ArrayList<String>();
					for (int i = 0; i < defalutMenus1.length; i++) {
						menuIdList1.add(defalutMenus1[i]);
					}
					role.setMenuIdList(menuIdList1);
				}
				//仅本人
				else if (role.getDataScope().equals("8")) {
					String defalutMenu1 = "1,27,29,e3b80fae59ab4b4099d8349ecaf8c4dc,56,57,58,59,0aa3712414d049a6a24e8bcddeae509a,af0a174b4f424bc09a8cc0db83a64105,95a6a82dc5fc4d07b46e5df57a0606a3,9fdf5971a9e64fac8bbffec2825a5f97,843fdb78b8854bd48e503287f795a7d0,8d369ea660e04241a6c88d75c49a68ce,a90ba79ffbcb40dfa705fe4992e29d22,624c57fb83a54ff686c1e686bebde4c5,78bd8a7958a84617a06bcf72837eae0b,900f410b044542eeba2382d18f5d2704,6fa1a6734aeb4237a22b61b10f0affb8,62,b6fa4abb624349918fe531274fc15d23,89,76bdb735faa34667a6cbf13ebe937533,e3b5b7451e164089aba0b9bf844b0398,438c28c3cbe44ed7bff951b2a3dc77cd,59e50eebe56743a78eecbc6eff1ef94c,cc1027689aca41a89302217127253034,200fe6cc80174065b382c961a4379d79,ed9f6c6dbc334d0fb9607a52a818e102,6ca9de739e8b4f8986459307476a32e7,fee6e63e2ec643b8b07d07a902c96021,fb29eb2c5a08491597beadc096a6fbbc,020833fe4fde42fbb8bf05fa18909e31,8aed52b2c1c44ad78d2f7507009c80ef,9d1e25c52de642f985b2e52cc11c0add,befda334dab7410cba3f82fc51b98de1,ad3abaa397c94c1fb2bbfe8ddc62a5d5,3d416bdb98904fb0ba525cfe0d5bcf75,97cbdaacc376458b8c600629ad3e3dcd,5cd3a42a9f0442c3817136d91e1788f1,5b0c61a977134c42ae808f59cdd71307,b7c88056d64f48d784e6f2205d09a481,5d98b8662939442588f31eb6de73341d,d23aabe5d20541d3aa93053c42e7196a,0170ce29a5c6476b9ccf950d9ab9a8eb,dd876aae95244be4a9770ad012492cf6,f36b8695989a45f48ec0135fc695fb58,5cd0f0473ae74e22bb08a31389919217,1e28195f02c243daa730d0ac4d0542fa,1d998622704849b8ac888a421fdf689c,a870258fc8784788b4d967bfce039515,4c13ca96376341dfa25980e86964c1a9,638be8b3b5284e5088003917685bc19b,811600aadcb54b098b7dda4bf95ffc51,ce8dc7c97d93481dbd76cabb6e905b55,aa25b3904abb4bd7b779e5be37b4382e,aae6f4c7fd4c4a25afa5285210edfded,84ff9d5c165c4528af9361b6127cf5af,31b349a3624b47f28eb86d614f9f95b5,040b42e395de41d6805a958eb1897863,34874260e6fc4200a76b33c3cfa4d80d,5b6c6ea5ed2d45478e8144351d853e21,7c032c32512847f882a87416359ef0a3,6d30ea8c710a42b89da2f2506059b0ef,2ca7bf4ce6804a1c9e5b331d2df27c72,7717cbb6d71f405d890e9b648cbd2088,bddb0400764c42b08e427059c7752057,23d6c56239804053910e5c5aec481330,7f8b2018113545bcbdbfc87e7a236bec,547e121ffb714d16ae142b6935abb78f,af24101b962444f29d166b638b2fea30,6ea6519ec4d548128aa42f3ce004def3,4379bf54c2a543869abf5031b97b8efe,5e6da3f5368b4f06b7268b31a1157e9f,2bbf0e75f21d42938954391d0776fbde,545b39dacf564a5eb9d1658f80a0b8b0,b4ddedf9b451494a97a1ff9476e3897d,1b145ca23d3e4d81994a84d30a262d18,10a8c7c1d34e46dd8ef461cdad928afc,5ae4911d14bb48b39885b1fe522e999d,7f09def2533b45fdb3c733f1e72ca5fb,9ef29dca19d342b795efcbfe32793602,be72d72ae7034c509c164467b2abddda,ab879705f2354813acf8724404520e28,82487b87b97b475b98892b80cf83c96a,0f4a461b97be48eeab43bd052f630057,72e1a28b7251438a89b0a4f6bd522b89,e1f9a246057347d78a1966d6dc0168e3,5d3645d53ce14c9ab498fd9f050ba264,d361e6890cc84b049fc8268c2a8c4952,5cc0002cbcc14d3485ab8ae6d57368f2,fa7bb243643c44b18e989e3419eeb171,62768b6c65134f1e927b1807bc72115a,2d74c531c4d14056973fd177652e7dc4,1a9e2d47fcfc4a5cb6ea0b2bb4bf24f9,2e1e75dbe28841529576dd1cd48d2437,cdd8829e5976438aaa66ce608f0175f5,71015695cf1445ecacce90669c67d733,31e9dd26b7314d8a9bf97dcf6dbdb22d,e5ecaa091bb0464f8553d4e7aa60647d,39055be3a23945868dbf4b5930043a88,07ba7c9aed104657aac3be87aa346d3b,5a7a9bfff0f44a2089a7d277f2c04557,be53cc152339400ba705c1d1dceff9ab" +
							",3b42071536124a9c9dbf2ec319004b29,a966beefe58e4f95b24e89f4172cb7ce,9f94d338d6c94b95814b2c50f9e463d1,6eeec907b4a848f7a873123cf0cf0269,ddfa7cfabbd3478392c62829704addcc,17ea1252358a4d958f6a21779c5ad0ac,386c9efeafc74edb97be3bd2696d661e,f933b35d273f4d53902f064d86859a28,7d1745ce2c444db9bf4b4e100c476fe8,e711e93aadd54eef8feeb0fa07f054d2,0e914774210646f784d02fb22f8df7db,ca0ce5e9eb09477c8c99b7b94e7869ce,760d9072f9bc480fa36fdb876930467c,7242c1847af946b0869f4ac98eadee34,891109b0849e4dbca125f98fb4e70f3d,22a7c091650d4e5a828dab1cbd9547bc,75d308d6099d4a08a0a8cdf1a0b39eae,f1d9a3e377514f90bc05f6be02fdebc5,63f51059988c4f3087b0da17e3cecece,5dc98a677d3d4754b3cff47cb18d08a5,4574ce3053f94a59a9e6e9e45a8eca81,9f806cf868dc48d398836ebd60bd2ec6,50ff5cdc6c8645b3bb61b8327d204f01,bafb57ea8d84430cbc0c11e5c67643f1,e2c91860b96c46619a74215627560235,f5b68a43bbae44c8a1fe821dfcaca26e,70b771772a0b4f1cb1e592f9a01b08a5,7992a39d64b2483789ae274e2df3c01d,f8d711312da14871a77b58f41a6f6242,673b27b0ab9148b7ae03933c18433971,624886a950bd4d18900a877738696432,685d8d9267f745f39bcc6fc2cc553d31,7d40ad05a1a54165a28ec897ddbcef01,4bcdb5199e8442078999bb8611ea6398,0bf937d745494d998cb8bd2cf3a63f4e,c17feb3860184dd59931f35814ad68b0,4cc68cbd880c48948a1f18fe18ec938c,c37b0691a05c4d659dcd01571f1907da,c1334fe3e8484079bfd62e479307b5b9,ebb58027b6c647b7965eeb31b63ec0c0,b5dcd27f951946e08136f8bfe71f3b83,ec8c120ef1bd4abaa18449042da51b2b,a6ae28d10dc244d2bc96b956bde5c9ad,f11bd4ef5ddd4c82865fad3f1f9d80a9,76ee95093a8748b29d55df1cb8cdebd0,081af742f6384a20b492ca99704f51ca,c26c844bbb2f4746904948f3ecfeb1ae,ba9bbc5581a043d8b9c204b8ddb6aa01,cde1afb048a743bb9caedb5770aabca1,0b2b37a28bb0457bbc4bf33c11b4c6e1,5742a628f13045cda0317c3d4d839bc5,b9309305d94f4ee8b66eebbcae9f2db4,a42216d3eedd48f0ba3d3bef2470605f,9cdcda30da704c21b19ea0616de3ea86,f05ecbf7e4b04b268b38cb6e5c8124bf,788d2c1496874eeeae3b7aabbab95f76,5abae35db6de475e904425af8dc8ecbb,e3bc44b82c3543758d5a6c02b41dd526,89323021918e444bae3537521046d19f,141dd3257f85455d86f3828cc0217b5a,7bc2ad90009a4de2a0fa2947ccc09886,e51874f4b6ac455db76e30582659368b,519dee074e4c48ae9edd58d7c1e330da,060ab186c22f4f42a83f1622bf47ca52,8873bbcf4b42445f8117108769358a5c,46fa5286441a444095b917165c31304c,fa9fdd56222a4ce7ba2b37922afe0eaa,6885932aa4b443babc2b69fdd495889c,be71b947b33a48d8aee36ad0c60d10b8,b52457719429466687a2f228d20571ac,1821c5f9392e4859a829c78ebda44df6,dca21ab79bd14004b94c55e36604c30d,8d96cc3457644378b9b643243464f735,631437054079401fbe2c3c9a3f3bc375,c2f78ab4372243da8775f4d71a16fef5,03792664a45d4f63ac3efb899ce1b61e,fec04c46683a41e5a344f4d057342829,320fa70de6bc4890a0135bbfe8735b49,5a03493dce9f4323a0da7bf4fd5e78ab,b9bd46a1da1846d099566fd5c6db00cb,647021c7f798472889fd82f6c4a27ca2,313e905b78d746cb9e574b9634c3a113,623fd328c4cd4ee8b21eb03425b1f100,4676b4d1130146629fd98e2d2eb9a5b4,34d380813a36481ea2534c46d18b5927,894d87e55ac640b99e966a8786a2392b,477ba74d182a4ec0b86926dc67a0f419,362ca5fdca174fa3bdd6325a947320db,1ac3ad8dfa184fe4b6815950d3d23fdd,fdebee18c71f4a9db60096e75ad34d83,91432be4178a4781917fba0abd51df61,480c71baa65145f4bd037332d68e5e4f,536e3a3702b0453d92939846dc1f33b7,0333aedf1be640c78d2ee02473b7fd97,cbb3a6f1772b4f72a8af1375ef16e914,367ad9c43a6246dfac364ca59874883b,bac18430f6db466195a3a7116cdfb958,c4ec39be11be4b0eae321ee0559be8e6,8f7ffae7e47d462aa4142db7f06633d5,82e3b2423d86425195929fc3810ce7a4,72973e0415004dfea220babc479be082,41d0f568bb1e4fed8ad965a79d9bccef,5854ef1d24784ca0a046514b19286113,04afc3dd1eec4d13bc06cd01e0a5e838,db76e3333da846d5ae55b3b9dd735f26,7aa0ca0bf1514fa6a3a14dcde44cf0b9,9c668726c9b6449a9045d3f78408a2a1,7caf148d68a6431bbe56bcc6472d8720,babd36d1d3484fb99fe4e7ca78560ccf,7507865343e24cff80d55a29ec57f0e1,63f8b7d9b1f34851802e0408bf997ea5,a3369d5dd6b74af7b35edf1f10350881,9b8b8c3f86854416b82d57583896c1ff,881815c772564a8dbd5eb6de65ecbe7a,4b1bcf46753a48258d1d514440140b7f,1ca4c6a49e794954a235a82ee8981ecd,ab381d9129bb4b979fe3774e262524f8,a07d2c98831a4d79bc6c5c4288a24720,d8debd28039d494aa7fe18bc8e81af27,d0402b1f00f94acca96276c6ea8c8397,ebcdebd9639d4ec2b7072ad32bf48f50,636b3211100245919c09177ccea562e0,280c4440e18a487396a81b92cd3efa13,5163cf6740334a7d83375385c3ae2b67,a6083e4fab7a43498bfb3257658f9278,3b5c8b5cfb124ebd8f4a798d2a47d832,9fda332474534f96955b5bce8548947f,b5f5e62aba9842d8b48a28111ca6a372,c0cecff1207c4692a634d7de449d8d6d,e4c6428f1d264544b0eec52214e7b6ae,cbc8c5490a7f46b996fd4c3a9711f2d7,cfbdd82f4ce741a88109353c5fc898e4,6bfb965bc1b240a9ae2bd7a1e884ea51,eb36d63a993148289950af9098727759,f7357c3954d2408facaa6771a758ebcc,c05853b94ab8405eb26e0a8bd481b662,da1e6d3ebfa140b3a645342fd3bb5d95,988f3f6b607d442b8df006c980ddc2cd,b6af3c01968141baa3e99ca4b8d83847,75f669faee5d4023a425f2461e5fc5e9" +
							",3b0c0ffea0cf45db816993baf64b3fb3,ad2d6d9581034e04addcb5b034a88fb3,8440c4fc5056426996e3e488b2261d28,e367c4223d794572a05fd256759d6a53,1b2dc5784c3c41988d5634e566b4a404,11be1538d7f54d7786004503b2e684a7,b462cb8c2ec7485d938416831a9771cc,f747656a36204e9588aba97064332436,78d0b2337b484c6298c9b3afc01fdb85,8a63d1f8d4bc4eb4a4db437491c9983a,2247f64a15e54053abb2e13152003c6b,d78ef9c5997d4e94804b8126cc387ea1,6ce3cd5a86ef43219dbda2b78e974c93,414b5fd5ebee45d98eca809a524dbe93,4b9ea9db5c834b698a78c7052c87b432,8590fa7adc144f49ae3d2575b7280c08,6148e4b152b9494fb9e7035e9b58e624,be1cff2a29f64800a5c4f91009711988,49b85b35bca5461993eac91ffd0b1fe4,";

					role.setMenuIds(defalutMenu1);
					String[] defalutMenus1 = defalutMenu1.split(",");
					ArrayList<String> menuIdList1 = new ArrayList<String>();
					for (int i = 0; i < defalutMenus1.length; i++) {
						menuIdList1.add(defalutMenus1[i]);
					}
					role.setMenuIdList(menuIdList1);
				}
				role.setEnname(StringUtils.getPinYinHeadChar(role.getName(), 1));
				str = "新增岗位";
				Office office = officeService.get(role.getOffice().getId());
				String[] ids = office.getParentIds().split(",");
				Office branchOffice = new Office();
				for (int i = ids.length - 1; i > 0; i--) {
					Office o = officeService.get(ids[i]);
					if (o.getType().equals("3")) {
						branchOffice = o;
						break;
					}
				}
				role.setBranchCompany(branchOffice);
			}*/
			String str = "修改岗位" + systemService.saveRole(role, true,0);
			addMessage(redirectAttributes, str);
		}catch (Exception e){
			logger.error("Exception e:"+e);
			logger.error("role:"+role.getId());
			addMessage(redirectAttributes, "修改岗位失败");
		}
		return "redirect:" + adminPath + "/sys/role/?repage";
	}
	/**
	 * 打印权限信息id到控制台
	 */
	/*private void printMenuId(Role role){
		List<Menu> menuList = role.getMenuList();
		for (Menu menu :menuList){
			System.out.println(","+menu.getId());
		}
	}*/
	@RequiresPermissions("sys:role:del")
	@RequestMapping(value = "delete")
	public String delete(Role role, RedirectAttributes redirectAttributes) {
		if(!UserUtils.getUser().isAdmin() && role.getSysData().equals(Global.YES)){
			if (!UserUtils.isManager()) {
				addMessage(redirectAttributes, "越权操作，只有管理员才能修改此数据！");
				return "redirect:" + adminPath + "/sys/role/?repage";
			}
		}
		if(Global.isDemoMode()){
			addMessage(redirectAttributes, "演示模式，不允许操作！");
			return "redirect:" + adminPath + "/sys/role/?repage";
		}
//		if (Role.isAdmin(id)){
//			addMessage(redirectAttributes, "删除岗位失败, 不允许内置岗位或编号空");
////		}else if (UserUtils.getUser().getRoleIdList().contains(id)){
////			addMessage(redirectAttributes, "删除岗位失败, 不能删除当前用户所在岗位");
//		}else{
		Role selectRole = roleDao.get(role.getId());
		if (StringUtils.isNotBlank(selectRole.getEnname()) && selectRole.getEnname().equals("yg")){
			addMessage(redirectAttributes, "默认角色，不允许操作！");
			return "redirect:" + adminPath + "/sys/role/?repage";
		}
		Boolean b = systemService.deleteRole(role);
		if (b) {
			addMessage(redirectAttributes, "删除岗位成功");
		}else {
			addMessage(redirectAttributes, "删除岗位失败，岗位下存在用户！");
		}
//		}
		return "redirect:" + adminPath + "/sys/role/?repage";
	}

	/**
	 * 批量删除岗位
	 */
	@RequiresPermissions("sys:role:del")
	@RequestMapping(value = "deleteAll")
	public String deleteAll(@RequestParam(required=false,value = "ids") String ids, RedirectAttributes redirectAttributes) {

		if(Global.isDemoMode()){
			addMessage(redirectAttributes, "演示模式，不允许操作！");
			return "redirect:" + adminPath + "/sys/role/list?repage";
		}
		String idArray[] =ids.split(",");
		StringBuffer msg = new StringBuffer();
		for(String id : idArray){
			Role role = systemService.getRole(id);
			/*if(!UserUtils.getUser().isAdmin() && role.getSysData().equals(Global.YES)){
				msg.append( "越权操作，只有超级管理员才能修改["+role.getName()+"]数据！<br/>");
			}else{
				systemService.deleteRole(role);
				msg.append( "删除岗位["+role.getName()+"]成功<br/>");
			}*/
			if (StringUtils.isNotBlank(role.getEnname()) && role.getEnname().equals("yg")){
				msg.append( "删除岗位["+role.getName()+"]未成功，当前岗位为默认岗位,");
			}else {
				Boolean b = systemService.deleteRole(role);
				if (b) {
					msg.append("删除岗位[" + role.getName() + "]成功,");
				} else {
					msg.append("删除岗位[" + role.getName() + "]未成功，当前岗位下存在用户,");
				}
			}
		}
		addMessage(redirectAttributes, msg.toString());
		return "redirect:" + adminPath + "/sys/role/list?repage";
	}
	/**
	 * 批量删除岗位
	 */
	@RequiresPermissions("sys:role:del")
	@ResponseBody
	@RequestMapping(value = "deleteAlls")
	public AjaxJson deleteAlls(@RequestParam(required=false,value = "ids") String ids, RedirectAttributes redirectAttributes) {
		AjaxJson ajaxJson = new AjaxJson();
		String idArray[] =ids.split(",");
		StringBuffer msg = new StringBuffer();
		for(String id : idArray){
			Role role = systemService.getRole(id);
			if (StringUtils.isNotBlank(role.getEnname()) && role.getEnname().equals("yg")){
				msg.append( "删除岗位["+role.getName()+"]未成功，当前岗位为默认岗位,");
			}else {
				Boolean b = systemService.deleteRole(role);
				if (b) {
					msg.append("删除岗位[" + role.getName() + "]成功,");
				} else {
					msg.append("删除岗位[" + role.getName() + "]未成功，当前岗位下存在用户,");
				}
			}
		}
		ajaxJson.setMsg(msg.toString());
		return ajaxJson;
	}

	/**
	 * 岗位分配页面
	 * @param role
	 * @param model
	 * @return
	 */
	@RequiresPermissions("sys:role:assign")
	@RequestMapping(value = "assign")
	public String assign(Role role, Model model) {
		User user = new User();
		user.setRole(role);
		List<User> userList = systemService.findUser(user);
		model.addAttribute("userList", userList);
		return "modules/sys/roleAssign";
	}

	/**
	 * 岗位分配 -- 打开岗位分配对话框
	 * @param role
	 * @param model
	 * @return
	 */
	@RequiresPermissions("sys:role:assign")
	@RequestMapping(value = "usertorole")
	public String selectUserToRole(Role role, Model model) {
		List<User> userList = systemService.findUser(new User(role));
		model.addAttribute("role", role);
		model.addAttribute("userList", userList);
		UserUtils.putCache("roleId", role.getId());
		model.addAttribute("selectIds", Collections3.extractToString(userList, "id", ","));
		model.addAttribute("officeList", officeService.findAll());
		return "modules/sys/selectUserToRole";
	}

	/**
	 * 岗位分配 -- 根据部门编号获取用户列表
	 * @param officeId
	 * @param response
	 * @return
	 */
	@RequiresPermissions("sys:role:assign")
	@ResponseBody
	@RequestMapping(value = "users")
	public List<Map<String, Object>> users(String officeId, HttpServletResponse response) {
		List<Map<String, Object>> mapList = Lists.newArrayList();
		User user = new User();
		user.setOffice(new Office(officeId));
		Page<User> page = systemService.findUserByRoleOffice(new Page<User>(1, -1), user);
		for (User e : page.getList()) {
			Map<String, Object> map = Maps.newHashMap();
			map.put("id", e.getId());
			map.put("pId", 0);
			map.put("name", e.getName());
			mapList.add(map);
		}
		return mapList;
	}

	/**
	 * 岗位分配 -- 从岗位中移除用户
	 * @param userId
	 * @param roleId
	 * @param redirectAttributes
	 * @return
	 */
	@RequiresPermissions("sys:role:assign")
	@RequestMapping(value = "outrole")
	public String outrole(String userId, String roleId,String office,String view,RedirectAttributes redirectAttributes) {
		if(Global.isDemoMode()){
			addMessage(redirectAttributes, "演示模式，不允许操作！");
			return "redirect:" + adminPath + "/sys/role/assign?id="+roleId;
		}
		Role role = systemService.getRole(roleId);
		role.setOffice(new Office(office));
		User user = systemService.getUser(userId);
		if (user.getRoleList().size() <= 1){
			addMessage(redirectAttributes, "用户【" + user.getName() + "】从岗位【" + role.getName() + "】中移除失败！这已经是该用户的唯一岗位，不能移除。");
		}else{
			Boolean flag = systemService.outUserInRole(role, user);
			if (!flag) {
				addMessage(redirectAttributes, "用户【" + user.getName() + "】从岗位【" + role.getName() + "】中移除失败！");
			}else {
				addMessage(redirectAttributes, "用户【" + user.getName() + "】从岗位【" + role.getName() + "】中移除成功！");
			}
		}
		/*if (UserUtils.getUser().getId().equals(userId)) {
			addMessage(redirectAttributes, "无法从岗位【" + role.getName() + "】中移除用户【" + user.getName() + "】自己！");
		}else {
			if (user.getRoleList().size() <= 1){
				addMessage(redirectAttributes, "用户【" + user.getName() + "】从岗位【" + role.getName() + "】中移除失败！这已经是该用户的唯一岗位，不能移除。");
			}else{
				Boolean flag = systemService.outUserInRole(role, user);
				if (!flag) {
					addMessage(redirectAttributes, "用户【" + user.getName() + "】从岗位【" + role.getName() + "】中移除失败！");
				}else {
					addMessage(redirectAttributes, "用户【" + user.getName() + "】从岗位【" + role.getName() + "】中移除成功！");
				}
			}
		}*/
		if (StringUtils.isBlank(view)) {
			return "redirect:" + adminPath + "/sys/role/assign?id=" + roleId + "&view=user";
			//return "redirect:" + adminPath + "/sys/role/list?id=" + role.getId() + "&look=" + true;
		}else {
			if(view.equals("toUser")){
				return "redirect:" + adminPath + "/sys/role/list?look="+true;
			}else {
				return "redirect:" + adminPath + "/sys/role/form?userId=" + userId + "&view=user";
			}
		}
	}

	/**
	 * 岗位分配
	 * @param role
	 * @param idsArr
	 * @param redirectAttributes
	 * @return
	 */
	@RequiresPermissions("sys:role:assign")
	@RequestMapping(value = "assignrole")
	public String assignRole(Role role, String[] idsArr, RedirectAttributes redirectAttributes) {
		if(Global.isDemoMode()){
			addMessage(redirectAttributes, "演示模式，不允许操作！");
			return "redirect:" + adminPath + "/sys/role/assign?id="+role.getId();
		}
		StringBuilder msg = new StringBuilder();
		int newNum = 0;
		for (int i = 0; i < idsArr.length; i++) {
			User u = systemService.getUser(idsArr[i]);
			User user = systemService.assignUserToRole(role, u,0);
			if (null != user && StringUtils.isNotBlank(user.getId()) && !user.getId().equals("1")) {
				msg.append(",新增用户【" + user.getName() + "】到岗位【" + role.getName() + "】成功！");
				newNum++;
			}else if(null == user || StringUtils.isBlank(user.getId())) {
				msg.append(",新增用户【" + systemService.getUser(idsArr[i]).getName() + "】到岗位【" + role.getName() + "】失败！");
			}
		}
		addMessage(redirectAttributes, "已成功分配 "+newNum+" 个用户"+msg);
		return "redirect:" + adminPath + "/sys/role/assign?id="+role.getId();
	}

	/**
	 * 岗位分配
	 * @param roleId
	 * @param ids
	 * @param redirectAttributes
	 * @return
	 */
	@RequestMapping(value = "assignRoleUsers")
	@ResponseBody
	public AjaxJson assignRoleUsers(String roleId, String ids, RedirectAttributes redirectAttributes) {
		AjaxJson ajaxJson = new AjaxJson();
		if(Global.isDemoMode()){
			ajaxJson.setSuccess(false);
			return ajaxJson;
		}
		try {
			StringBuilder msg = new StringBuilder();
			int newNum = 0;
			String[] idsArr = ids.split(",");
			Role role = roleDao.get(roleId);
			List<User> users = new ArrayList<>();
			for (int i = 0; i < idsArr.length; i++) {
				User u = systemService.getUser(idsArr[i]);
				User user = systemService.assignUserToRole(role, u,1);
				if (null != user && StringUtils.isNotBlank(user.getId()) && !user.getId().equals("1")) {
					msg.append(",新增用户【" + user.getName() + "】到岗位【" + role.getName() + "】成功！");
					newNum++;
				}else if(null == user || StringUtils.isBlank(user.getId())) {
					msg.append(",新增用户【" + systemService.getUser(idsArr[i]).getName() + "】到岗位【" + role.getName() + "】失败！");
				}
				users.add(u);
				UserUtils.clearCache(u);
			}
			systemService.removeSession(users);
			ajaxJson.setMsg("已成功分配 "+newNum+" 个用户"+msg);
		}catch (Exception e){
			ajaxJson.setMsg("分配用户岗位失败");
		}
		return ajaxJson;
	}

	/**
	 * 岗位分配
	 * @param roleIds
	 * @param userId
	 * @param redirectAttributes
	 * @return
	 */
	@RequestMapping(value = "assignRoleUserIds")
	@ResponseBody
	public AjaxJson assignRoleUserIds(String roleIds, String userId, RedirectAttributes redirectAttributes) {
		AjaxJson ajaxJson = new AjaxJson();
		if(Global.isDemoMode()){
			ajaxJson.setSuccess(false);
			return ajaxJson;
		}
		try {
			User user = UserUtils.get(userId);
			String[] roles = roleIds.split(",");
			StringBuilder msg = new StringBuilder();
			int newNum = 0;
			for (String id:roles){
				Role role = roleDao.get(id);
				logger.error("------------"+userId);
				User u = systemService.getUser(userId);
				systemService.assignUserToRole(role, u,1);
				if (null != user && StringUtils.isNotBlank(user.getId()) && !user.getId().equals("1")) {
					newNum++;
					msg.append("到岗位【" + role.getName() + "】成功、");
				}else if(null == user || StringUtils.isBlank(user.getId())) {
					msg.append( "到岗位【" + role.getName() + "】失败、");
				}
			}
			UserUtils.clearCache(user);
			systemService.removeSession(user);
			addMessage(redirectAttributes, "已成功分配 "+newNum+" 个岗位，新增用户【" + UserUtils.get(userId).getName() + "】"+msg);
			ajaxJson.setMsg(msg.toString());
		}catch (Exception e){
			ajaxJson.setMsg("分配用户岗位失败");
		}

		return ajaxJson;
	}


	/**
	 * 公司判断 -- 根据用户编号判断是否允许用户添加该企业的岗位
	 * @param userId
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequiresPermissions("sys:role:assign")
	@RequestMapping(value = "checkUserCompany")
	public String checkUserCompany(String userId,String officeId,HttpServletResponse response) {
		String roleId = UserUtils.getCache("roleId")!=null? UserUtils.getCache("roleId").toString():null;
		if(roleId ==null){
			return "false";
		}
		Role role = new Role(roleId);
		role.setOffice(new Office(officeId));
		List<User> userList = systemService.findUser(new User(role));
		for (User user : userList) {
			if(user.getId().equals(userId)){
				return "true";
			}
		}
		return "false";
	}

	/**
	 * 验证岗位名是否有效
	 * @param oldName
	 * @param name
	 * @return
	 */
	/*@RequiresPermissions("user")
	@ResponseBody
	@RequestMapping(value = "checkName")
	public String checkName(String oldName, String name,String comId) {
		if (name!=null && name.equals(oldName)) {
			return "true";
		} else if (name!=null && systemService.getRoleByName(name,comId) == null) {
			return "true";
		}
		return "false";
	}
*/
	/**
	 *
	 * 验证岗位英文名是否有效
	 * @param
	 * @param
	 * @return
	 */
	/*@RequiresPermissions("user")
	@ResponseBody
	@RequestMapping(value = "checkEnname")
	public String checkEnname(String oldEnname, String enname) {
		if (enname!=null && enname.equals(oldEnname)) {
			return "true";
		} else if (enname!=null && systemService.getRoleByEnname(enname) == null) {
			return "true";
		}
		return "false";
	}*/

	/**
	 * 保存流程表
	 */
	@RequestMapping(value = "relation")
	@ResponseBody
	public Map<String,Object> relation(String roleId,String roleActivityIds,Model model, RedirectAttributes redirectAttributes) throws Exception{
		Map<String,Object> map = new HashMap<>();
		try {
			Role role = roleDao.get(roleId);
			role.setRoleActivityIds(roleActivityIds);
			if (StringUtils.isBlank(role.getRoleActivityIds())){
				addMessage(redirectAttributes, "当前没进行角色关联");
			}else {
				Boolean b = systemService.relationRoleActivity(role);
				addMessage(redirectAttributes, "关联角色"+(b?"成功":"失败"));
			}
			map.put("success",true);
		}catch (Exception e){
			map.put("success",false);
		}
		return map;
	}

	/**
	 * 保存流程表
	 */
	@RequestMapping(value = "deleteRoleActivity")
	@ResponseBody
	public Map<String,Object> deleteRoleActivity(String roleId,String roleActivityIds,Model model, RedirectAttributes redirectAttributes) throws Exception{
		Map<String,Object> map = new HashMap<>();
		try {
			Role role = roleDao.get(roleId);
			role.setRoleActivityIds(roleActivityIds);
			if (StringUtils.isBlank(role.getRoleActivityIds())){
				addMessage(redirectAttributes, "当前没进行角色关联");
			}else {
				Boolean b = systemService.deleteRoleActivityOne(roleId,roleActivityIds);
				addMessage(redirectAttributes, "删除角色关联"+(b?"成功":"失败"));
			}
			map.put("success",true);
		}catch (Exception e){
			map.put("success",false);
		}
		return map;
	}

//	@ResponseBody
//	@RequestMapping(value = "treeData")
//	public List<Map<String, Object>> treeData(String officeId) {
//		List<Map<String, Object>> mapList = Lists.newArrayList();
//		List<Role> list = roleDao.getByOfficeId(officeId);
//		for (int i = 0; i < list.size(); i++) {
//			Role e = list.get(i);
//				Map<String, Object> map = Maps.newHashMap();
//				map.put("id", e.getId());
//				map.put("pId", ));
//				map.put("pIds", e.getParentIds());
//				map.put("name", e.getTopCompany());
//				map.put("type", e.getType());
//				if (type != null && "3".equals(type)) {
//					map.put("isParent", true);
//				}
//				mapList.add(map);
//		}
//		return mapList;
//	}

    @ResponseBody
    @RequestMapping("getByOfficeId")
    public Map getByOfficeId(String id,Model model){
	    Map map = new HashMap();
	    List<Role> roles = roleDao.getByOfficeId(id);
	    map.put("data",roles);
	    return map;

    }
}
