package com.minpay.huicai.system.action; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import com.minpay.common.bean.User; import com.minpay.common.constant.Constant; import com.minpay.common.constant.IConstant; import com.minpay.common.exception.BusinessCodeException; import com.minpay.common.format.IFormatService; import com.minpay.common.service.ILogService; import com.minpay.common.service.IPublicService; import com.minpay.db.table.mapper.ImBranchMapper; import com.minpay.db.table.mapper.ImItemMapper; import com.minpay.db.table.mapper.ImRoleAuthMapper; import com.minpay.db.table.mapper.ImRoleItemRelMapper; import com.minpay.db.table.mapper.ImRoleMapper; import com.minpay.db.table.mapper.ImUserRoleRelMapper; import com.minpay.db.table.model.ImBranch; import com.minpay.db.table.model.ImBranchExample; import com.minpay.db.table.model.ImItem; import com.minpay.db.table.model.ImItemExample; import com.minpay.db.table.model.ImRole; import com.minpay.db.table.model.ImRoleAuthExample; import com.minpay.db.table.model.ImRoleAuthKey; import com.minpay.db.table.model.ImRoleExample; import com.minpay.db.table.model.ImRoleItemRel; import com.minpay.db.table.model.ImRoleItemRelExample; import com.minpay.db.table.model.ImRoleItemRelKey; import com.minpay.db.table.model.ImUserRoleRelExample; import com.minpay.db.table.model.ImUserRoleRelKey; import com.minpay.db.table.own.mapper.RoleMapper; import com.startup.minpay.frame.business.IMINAction; import com.startup.minpay.frame.business.res.MINActionResult; import com.startup.minpay.frame.constant.IMINBusinessConstant; import com.startup.minpay.frame.constant.IMINTransactionEnum; import com.startup.minpay.frame.data.format.MINCopyFormat; import com.startup.minpay.frame.exception.MINBusinessException; import com.startup.minpay.frame.jdbc.MINRowBounds; import com.startup.minpay.frame.service.base.IMINDataBaseService; import com.startup.minpay.frame.service.base.Service; import com.startup.minpay.frame.session.MINSession; import com.startup.minpay.frame.target.MINAction; import com.startup.minpay.frame.target.MINComponent; import com.startup.minpay.frame.target.MINParam; import com.startup.minpay.util.DateTime; import com.startup.minpay.util.Str; /** * 角色管理 * * @author sunbz * */ @MINComponent public class RoleManageAction implements IMINAction { public final static String ROLE_QUERY = "roleQuery"; public final static String ROLE_QUERY_ALL = "roleQueryAll"; public final static String ROLE_MODIFY = "roleModify"; public final static String ROLE_DELETE = "roleDelete"; public final static String ROLE_ADD = "roleAdd"; public final static String ROLE_AUTH_QUERY = "roleAuthQuery"; public final static String ROLE_AUTH_QUERY_WITHOUT_PWD = "roleAuthQueryWithoutPwd"; public final static String AUTH_MODIFY = "authModify"; public final static String HAVE_AUTH_SHAPE = "isHaveAuthShape"; /** 查询当前机构下的角色信息 */ public final static String ROLE_QUERY_BY_BRANCHID = "roleQueryByBranchId"; /** 查询当前机构及下一级机构下的角色 信息 */ public final static String ROLE_QUERY_BY_PARENTID = "roleQueryByParentId"; /** 查询角色菜单已经设置的权限 */ public final static String ROLE_AUTH_QUERY_BY_ROLEID = "roleAuthQueryByRoleId"; /** 查询角色需要设置权限的菜单和权限列表 */ public final static String ROLE_AUTHSET_QUERY = "roleAuthSetQuery"; /** 给角色设置菜单权限 */ public final static String SET_ITEM_AUTH = "setItemAuth"; /** 查询角色对应的模块权限 */ public final static String GET_ROLE_MODE = "getRoleModule"; /** 修改角色菜单权限 */ public final static String MODIFY_ITEM_AUTH = "modifyItemAuth"; /** 查询所有部门 */ public final static String ROLE_QUERY_BRANCH = "roleQueryBranch"; @MINAction(value = ROLE_QUERY) public MINActionResult roleQuery(MINSession session, @MINParam(key = "page", defaultValue = "1") int page, @MINParam(key = "limit", defaultValue = "3") int limit, @MINParam(key = "rolename") String rolename, @MINParam(key = "roleId") String roleId) throws MINBusinessException { MINActionResult res = new MINActionResult(); // 创建查询条件 ImRoleExample s = new ImRoleExample(); ImRoleExample.Criteria c = s.createCriteria(); User u = session.getUser(); String branchId = u.getBranchId(); if (branchId == null || "".equals(branchId)) { throw new MINBusinessException("获取客户开户机构号失败!"); } Map m = new HashMap(); m.put("rolename", rolename); m.put("roleId", roleId); m.put("branchId", branchId); if (!Str.isEmptyMaskNull(rolename)) { c.andNameEqualTo(rolename); } MINRowBounds rows = new MINRowBounds(page, limit); // 查询 // List ls = // Service.lookup(IMINDataBaseService.class).selectByExample(ImRoleMapper.class, // s, rows); List> ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class) .roleManageQuery(m, rows); // 格式化 ls = Service.lookup(IFormatService.class).formatDateTime(ls, "addtime"); // 设置返回值 res.set(IMINBusinessConstant.F_PAGING_LAY, ls); res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getMaxRows()); res.set("sessionId", u.getId()); return res; } /** * * @param id 角色编号 * @param name 角色名称 * @param desc 描述 * @param itemidStr 菜单 * @param authInputs 权限 * @param moduleType * @param session * @return * @throws MINBusinessException */ @MINAction(value = ROLE_MODIFY, transaction = IMINTransactionEnum.CMT) public MINActionResult roleModify(@MINParam(key = "id") String id, @MINParam(key = "name") String name, @MINParam(key = "desc") String desc, @MINParam(key = "itemidStr") String itemidStr, @MINParam(key = "authInputs") String authInputs, @MINParam(key = "moduleType") String[] moduleType, @MINParam(key = "roleMainPage") String roleMainPage, MINSession session) throws MINBusinessException { if ("".equals(name.trim()) || name == null) { throw new MINBusinessException("请输入角色名称!"); } if ("".equals(desc) || desc == null) { throw new MINBusinessException("请输入角色描述!"); } String[] itemid = itemidStr.split(","); if (itemid.length == 0) { throw new MINBusinessException("至少选择一个菜单!"); } User u = session.getUser(); if (u.getRoleId().equals(id)) { throw new MINBusinessException("不能修改当前登录操作员的相关信息"); } // 当新增用户为客户经理时 校验所选角色有客户经理中心菜单 ImRoleItemRelExample irir = new ImRoleItemRelExample(); irir.createCriteria().andRoleidEqualTo(id).andItemidEqualTo(Constant.CUSTOMER_MANAGER_MENU); List irirNum = Service.lookup(IMINDataBaseService.class) .selectByExample(ImRoleItemRelMapper.class, irir); // 之前未选择客户经理中心菜单 修改也不能选择 /* * if (irirNum.size() == 0){ * if(itemidStr.indexOf(Constant.CUSTOMER_MANAGER_MENU) != -1) { throw new * BusinessCodeException("JINM3154"); } }else { //之前已选择客户经理中心 修改时不能不选 * if(itemidStr.indexOf(Constant.CUSTOMER_MANAGER_MENU) == -1) { throw new * BusinessCodeException("JINM3153"); } } */ MINActionResult res = new MINActionResult(); ImRole role = Service.lookup(IMINDataBaseService.class).selectByPrimaryKey(ImRoleMapper.class, id); role.setName(name); role.setDesc(desc); //role.setIndexpage(roleMainPage); role.setIndexpage("main.html"); Service.lookup(IMINDataBaseService.class).updateByPrimaryKey(ImRoleMapper.class, role); Set set = new HashSet(Arrays.asList(itemid)); set.remove(null); set.remove(""); List sls = new ArrayList(set); // 删除不存在的菜单 ImRoleItemRelExample dex = new ImRoleItemRelExample(); ImRoleItemRelExample.Criteria c = dex.createCriteria(); c.andRoleidEqualTo(id); if (sls.size() > 0) { c.andItemidNotIn(sls); } Service.lookup(IMINDataBaseService.class).deleteByExample(ImRoleItemRelMapper.class, dex); // 过滤已存在的权限 ImRoleItemRelExample ex = new ImRoleItemRelExample(); ex.createCriteria().andRoleidEqualTo(id); List rils = Service.lookup(IMINDataBaseService.class).selectByExample(ImRoleItemRelMapper.class, ex); Set existRoleItem = new HashSet(); for (ImRoleItemRel ri : rils) { existRoleItem.add(ri.getItemid()); } if (sls.size() > 0) { ImItemExample iex = new ImItemExample(); iex.createCriteria().andIdIn(sls); List ils = Service.lookup(IMINDataBaseService.class).selectByExample(ImItemMapper.class, iex); List ls = new ArrayList(); for (ImItem i : ils) { if (existRoleItem.contains(i.getId())) continue; ImRoleItemRel ri = new ImRoleItemRel(); ri.setRoleid(id); ri.setItemid(i.getId()); ri.setAuthtype(i.getAuthtype()); ri.setAuthshape(i.getAuthshape()); ls.add(ri); } ImRoleItemRelMapper im = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(ImRoleItemRelMapper.class); for (ImRoleItemRel i : ls) { im.insertSelective(i); } } // 删除所有权限 ImRoleAuthExample roleAuthEx = new ImRoleAuthExample(); roleAuthEx.createCriteria().andRoleidEqualTo(id); Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImRoleAuthMapper.class).deleteByExample(roleAuthEx); // 添加所有权限 ImRoleAuthKey roleAuth = new ImRoleAuthKey(); roleAuth.setRoleid(id); for (int i = 0; i < authInputs.split(",").length; i++) { String auth = authInputs.split(",")[i]; if (auth != null && !"".equals(auth) && !"undefined".equals(auth)) { roleAuth.setAuthNo(auth); Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImRoleAuthMapper.class).insert(roleAuth); } } // 更新缓存 Service.lookup(IPublicService.class).init(); String logInfo = "操作员" + u.getName() + "修改角色,编号:" + id + ",名称:" + name + ",描述:" + desc; // Service.lookup(ILogService.class).logging(session, logInfo); res.set("roleId", id); res.set("roleName", name); return res; } /** * 角色删除 * * @param id * @param session * @return * @throws MINBusinessException */ @MINAction(value = ROLE_DELETE, transaction = IMINTransactionEnum.CMT) public MINActionResult roleDelete(@MINParam(key = "id") String id, MINSession session) throws MINBusinessException { User u = session.getUser(); if (u.getRoleId().equals(id)) { throw new MINBusinessException("不能修改当前登录操作员的相关信息"); } MINActionResult res = new MINActionResult(); ImRole role = Service.lookup(IMINDataBaseService.class).selectByPrimaryKey(ImRoleMapper.class, id); if (role == null) { throw new MINBusinessException("角色不存在"); } // 判断角色下是否存在操作员 ImUserRoleRelExample ire = new ImUserRoleRelExample(); ire.createCriteria().andRoleidEqualTo(id); List list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(ImUserRoleRelMapper.class).selectByExample(ire); if (list.size() > 0) { throw new MINBusinessException("该角色下存在操作员,不能删除"); } Service.lookup(IMINDataBaseService.class).deleteByPrimaryKey(ImRoleMapper.class, id); ImRoleItemRelExample ex = new ImRoleItemRelExample(); ex.createCriteria().andRoleidEqualTo(id); Service.lookup(IMINDataBaseService.class).deleteByExample(ImRoleItemRelMapper.class, ex); String logInfo = "删除角色id:" + id; Service.lookup(ILogService.class).logging(session, logInfo); return res; } @MINAction(value = ROLE_ADD, transaction = IMINTransactionEnum.CMT, session = true) public MINActionResult roleAdd( // @MINParam(value = "id") String id, @MINParam(key = "name") String name, @MINParam(key = "desc") String desc, @MINParam(key = "itemidStr") String itemidStr, @MINParam(key = "authInputs") String authInputs, @MINParam(key = "moduleType") String[] moduleType, @MINParam(key = "roleMainPage") String roleMainPage, MINSession session) throws MINBusinessException { if ("".equals(name.trim()) || name == null) { throw new MINBusinessException("请输入角色名称!"); } if ("".equals(desc) || desc == null) { throw new MINBusinessException("请输入角色描述!"); } /*if ("".equals(roleMainPage) || roleMainPage == null) { throw new MINBusinessException("请输入角色主页!"); }*/ String[] itemid = itemidStr.split(","); if (itemid.length == 0) { throw new MINBusinessException("至少选择一个菜单!"); } // 校验全先生数据是否选择 String noAuthItem = "";// TODO 添加无权限菜单数据 用,拼接 for (int i = 0; i < itemid.length; i++) { String item_id = itemid[i]; if (authInputs.indexOf(item_id) == -1 && noAuthItem.indexOf(item_id) != -1) {// TODO 存在不无权限的菜单,需要单独列出来 throw new MINBusinessException("存在菜单未选择权限情况,请检查!"); } } String[] auths = authInputs.split(","); User u = session.getUser(); MINActionResult res = new MINActionResult(); String roleId = Service.lookup(IPublicService.class).getSequence("IM_ROLE_NO"); roleId = getRoleId(Integer.valueOf(roleId)); ImRoleExample na = new ImRoleExample(); na.createCriteria().andNameEqualTo(name).andBranchidEqualTo(u.getBranchId()); List list = Service.lookup(IMINDataBaseService.class).selectByExample(ImRoleMapper.class, na); if (list != null && list.size() > 0) { throw new BusinessCodeException("JINM0109"); } ImRole role = new ImRole(); role.setId(roleId); role.setName(name); role.setDesc(desc); role.setBranchid(u.getBranchId()); role.setAddbranch(u.getBranchId()); role.setAddtime(new DateTime().toDateTimeString()); //role.setIndexpage(roleMainPage); role.setIndexpage("main.html"); Service.lookup(IMINDataBaseService.class).insert(ImRoleMapper.class, role); String[] itemIds = new String[itemid.length + 1]; System.arraycopy(itemid, 0, itemIds, 0, itemid.length); itemIds[itemid.length] = "240001"; if (itemIds.length > 0) { ImItemExample iex = new ImItemExample(); iex.createCriteria().andIdIn(Arrays.asList(itemIds)); List ils = Service.lookup(IMINDataBaseService.class).selectByExample(ImItemMapper.class, iex); List ls = new ArrayList(); for (ImItem i : ils) { if (!"".equals(i.getId())) { ImRoleItemRel ri = new ImRoleItemRel(); ri.setRoleid(roleId); ri.setItemid(i.getId()); ri.setAuthtype(i.getAuthtype()); ri.setAuthshape(i.getAuthshape()); ls.add(ri); } } ImRoleItemRelMapper im = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(ImRoleItemRelMapper.class); for (ImRoleItemRel i : ls) im.insert(i); } // 添加角色菜单权限数据 ImRoleAuthKey roleAuth = new ImRoleAuthKey(); roleAuth.setRoleid(roleId); for (int j = 0; j < auths.length; j++) { String authNo = auths[j]; roleAuth.setAuthNo(authNo); Service.lookup(IMINDataBaseService.class).insert(ImRoleAuthMapper.class, roleAuth); } res.set("roleId", roleId); res.set("roleName", name); String logInfo = "新增角色:" + roleId; // Service.lookup(ILogService.class).logging(session, logInfo); return res; } private String getRoleId(int roleId) throws BusinessCodeException, MINBusinessException { ImRole rx = Service.lookup(IMINDataBaseService.class).selectByPrimaryKey(ImRoleMapper.class, String.valueOf(roleId)); if (rx == null) { return String.valueOf(roleId); } else { return getRoleId(roleId + 1); } } @MINAction(value = ROLE_QUERY_ALL) public MINActionResult roleQueryAll() throws MINBusinessException { MINActionResult res = new MINActionResult(); ImRoleExample s = new ImRoleExample(); List ls = Service.lookup(IMINDataBaseService.class).selectByExample(ImRoleMapper.class, s); res.set(IMINBusinessConstant.F_QUERY_RESULT, ls); return res; } @MINAction(value = HAVE_AUTH_SHAPE) public MINActionResult isHaveAuthShape(@MINParam(key = "itemId") String itemId, @MINParam(key = "roleId") String roleId, @MINParam(key = "dataTypeStr") String dataTypeStr, @MINParam(key = "dataShapeStr") String dataShapeStr, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); Map m = new HashMap(); m.put("itemId", itemId); m.put("roleId", roleId); m.put("dataTypeStr", dataTypeStr); m.put("dataShapeStr", dataShapeStr); List> ls = new ArrayList(); ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class).queryHaveAuthShape(m); res.set(IMINBusinessConstant.F_QUERY_RESULT, ls); return res; } @MINAction(value = AUTH_MODIFY, transaction = IMINTransactionEnum.CMT) public MINActionResult authModify(@MINParam(key = "roleid") String roleid, @MINParam(key = "itemid") String itemid, @MINParam(key = "authtype") String authtype, // 要变成的类型 @MINParam(key = "authshape") String authshape, // 要变成的类型 @MINParam(key = "authrole") String[] authrole, @MINParam(key = "autIds") String autIds, @MINParam(key = "nowShape") String nowShape, // 没有修改前的类型 @MINParam(key = "nowType") String nowType, // 没有修改前的类型 MINSession session) throws MINBusinessException { User u = session.getUser(); if (u.getRoleId().equals(roleid)) throw new MINBusinessException("不能修改当前登录操作员的相关信息"); ImItem item = Service.lookup(IMINDataBaseService.class).selectByPrimaryKey(ImItemMapper.class, itemid); if (item == null) throw new MINBusinessException("授权资源不存在"); String auth = item.getAuth(); if (IConstant.AUTH_CANDIDATE_NONE.equals(auth)) { throw new MINBusinessException("该资源不需要授权"); } else if (IConstant.AUTH_CANDIDATE_INTIME.equals(auth)) { if (IConstant.AUTH_TYPE_SPECIFY.equals(authtype) || IConstant.AUTH_SHAPE_AUTH.equals(authshape)) throw new MINBusinessException("授权类型支持即时生效和互为授权,授权类型只支持临柜"); } MINActionResult res = new MINActionResult(); ImRoleItemRelKey key = new ImRoleItemRelKey(); key.setItemid(itemid); key.setRoleid(roleid); ImRoleItemRel ri = Service.lookup(IMINDataBaseService.class).selectByPrimaryKey(ImRoleItemRelMapper.class, key); if (ri == null) throw new MINBusinessException("权限信息不存在"); ri.setAuthtype(authtype); ri.setAuthshape(authshape); if ("2".equals(authtype)) { StringBuffer sb = new StringBuffer(","); if (authrole != null) { for (int i = 0; i < authrole.length; i++) { if (i > 0) sb.append(","); sb.append(authrole[i]); } } ri.setAuthrole(sb.append(",").toString()); } boolean statusType = "1".equals(nowType) || "2".equals(nowType); if (!"".equals(nowType) && !"".equals(nowShape) && (statusType && "0".equals(authtype) || (statusType && "1".equals(authshape) && "0".equals(nowShape)))) { String[] autAry = autIds.split(","); List list = new ArrayList(); for (String string : autAry) { list.add(string); } Map m = new HashMap(); m.put("name", u.getId()); m.put("list", list); if (list.size() > 0) { Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class).updateAuthStatusToFive(m); } } Service.lookup(IMINDataBaseService.class).updateByPrimaryKey(ImRoleItemRelMapper.class, ri); String logInfo = "修改授权规则:" + roleid; // Service.lookup(ILogService.class).logging(session, logInfo); return res; } @MINAction(value = ROLE_AUTH_QUERY_WITHOUT_PWD) public MINActionResult roleAuthQueryWithoutPwd(@MINParam(key = "id") String id, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); Map map = new HashMap(); map.put("roleid", id); List> ls = null; if (id == null || "".equals(id)) {// 新增角色时使用 // ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class).roleMenuWithOutPwd(id); ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class) .roleMenuWithAuthForAdd(map); } else {// 查看角色使用 // ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class).roleMenuWithOutPwdByTemp(map); ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class) .roleMenuWithAuthForDetail(map); } Map> menu = new HashMap>(); for (Map m : ls) { menu.put(m.get("menuid"), m); String s = m.get("authrole"); if (s != null) { ((Map) m).put("authrole", s.split(",")); } } for (Map s : menu.values()) { Map m = new HashMap(); m.put("menuid", s.get("menuid")); m.put("lv1", s.get("lv1")); m.put("menserialno", s.get("menserialno")); m.put("menuparentid", s.get("menuparentid")); ls.add(m); } Collections.sort(ls, new Comparator>() { public int compare(Map o1, Map o2) { String x1 = Str.nvl(o1.get("menserialno")); String x2 = Str.nvl(o2.get("menserialno")); String s1 = Str.nvl(o1.get("itmserialno")); String s2 = Str.nvl(o2.get("itmserialno")); String m1 = Str.nvl(o1.get("menuparentid")); String m2 = Str.nvl(o2.get("menuparentid")); if (m1.equals(m2)) { return x1.equals(x2) ? s1.compareTo(s2) : x1.compareTo(x2); } return m1.compareTo(m2); } }); ls = new MINCopyFormat("{authtype:'authtypeDesc',authshape:'authshapeDesc'}").format(ls); // ls = Service.lookup(IFormatService.class).formatEnum(ls, "{authtypeDesc:'IM_AUTH_TYPE',authshapeDesc:'IM_AUTH_SHAPE'}"); res.set(IMINBusinessConstant.F_QUERY_RESULT, ls); return res; } @MINAction(value = ROLE_AUTH_QUERY) public MINActionResult roleAuthQuery(@MINParam(key = "id") String id, @MINParam(key = "filterbyrole") boolean filterbyrole, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); ImRole role = Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImRoleMapper.class) .selectByPrimaryKey(id); Map map = new HashMap(); map.put("roleid", id); User user = session.getUser(); ImBranch branch = Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImBranchMapper.class) .selectByPrimaryKey(role.getBranchid()); if (!Constant.BRANCH_LEVEL_SYS.equals(branch.getLevel().toString())) {// 非平台用户使用模板菜单数据 // map.put("tempid", branch.getType() ); } // List> ls = // Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class).roleMenu(id); List> ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class) .roleMenuByTemp(map); if (filterbyrole) { for (Iterator> it = ls.iterator(); it.hasNext();) if (it.next().get("roleid") == null) it.remove(); } Map> menu = new HashMap>(); for (Map m : ls) { menu.put(m.get("menuid"), m); String s = m.get("authrole"); if (s != null) ((Map) m).put("authrole", s.split(",")); } for (Map s : menu.values()) { Map m = new HashMap(); m.put("menuid", s.get("menuid")); m.put("lv1", s.get("lv1")); m.put("menserialno", s.get("menserialno")); ls.add(m); } Collections.sort(ls, new Comparator>() { public int compare(Map o1, Map o2) { String x1 = Str.nvl(o1.get("menserialno")); String x2 = Str.nvl(o2.get("menserialno")); String s1 = Str.nvl(o1.get("itmserialno")); String s2 = Str.nvl(o2.get("itmserialno")); return x1.equals(x2) ? s1.compareTo(s2) : x1.compareTo(x2); } }); ls = new MINCopyFormat("{authtype:'authtypeDesc',authshape:'authshapeDesc'}").format(ls); // ls = Service.lookup(IFormatService.class).formatEnum(ls, "{authtypeDesc:'IM_AUTH_TYPE',authshapeDesc:'IM_AUTH_SHAPE'}"); res.set(IMINBusinessConstant.F_QUERY_RESULT, ls); // res.set(IMINBusinessConstant.F_QUERY_RESULT, authList); return res; } /** * 查询当前机构及下一级机构下的角色 信息 * * @param session * @return * @throws MINBusinessException */ @MINAction(value = ROLE_QUERY_BY_PARENTID) public MINActionResult roleQueryByParentId(MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); User user = session.getUser(); String branchId = user.getBranchId(); if (branchId == null || "".equals(branchId)) { // throw new BusinessCodeException("EBIM0009"); } Map m = new HashMap(); m.put("branchId", branchId); List> ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class) .roleQueryByParentId(m); res.set(IMINBusinessConstant.F_QUERY_RESULT, ls); return res; } /** * 查询当前机构下的角色信息 * * @param session * @return * @throws MINBusinessException */ @MINAction(value = ROLE_QUERY_BY_BRANCHID) public MINActionResult roleQueryByBranchId(@MINParam(key = "branchId") String branchId, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); ImRoleExample example = new ImRoleExample(); ImRoleExample.Criteria criteria = example.createCriteria(); User user = session.getUser(); criteria.andBranchidEqualTo(user.getBranchId()); List ls = Service.lookup(IMINDataBaseService.class).selectByExample(ImRoleMapper.class, example); res.set(IMINBusinessConstant.F_QUERY_RESULT, ls); return res; } /** * 查询角色菜单已经设置的权限 * * @param session * @return * @throws MINBusinessException */ @MINAction(value = ROLE_AUTH_QUERY_BY_ROLEID) public MINActionResult roleAuthQueryByRoleId(@MINParam(key = "roleId") String roleId, @MINParam(key = "itemNo") String itemNo, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); /* * ImRoleAuthExample ae = new ImRoleAuthExample(); * ae.createCriteria().andRoleidEqualTo(roleId).andCodeEqualTo(Constant. * ARTICLE_MODULE_CODE).andItemidEqualTo(itemNo); List authList = * Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImRoleAuthMapper. * class).selectByExample(ae); String[] authArr = new String[authList.size()]; * String str = ""; Map mm = new HashMap(); for(int * i=0;i mm = new HashMap(); mm.put("roleId", roleId); // mm.put("btype", br.getType()); List> list = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class) .roleAuthSetQuery(mm); List> authList = new ArrayList>(); String itemId = "";// 缓存菜单Id String codes = ""; String vals = ""; String itemName = ""; for (Map m : list) { String id = m.get("itemId"); String code = m.get("code"); String val = m.get("val"); String name = m.get("name"); if (itemId.equals(id)) {// 相等则itemId已存在 vals += val + ","; } else { if ("".equals(itemId)) {// 第一次 itemId = id; codes = code; itemName = name; vals += val + ","; } else { Map ms = new HashMap(); ms.put("itemNo", itemId); ms.put("codes", codes); ms.put("itemName", itemName); ms.put("vals", vals.substring(0, vals.length() - 1)); authList.add(ms); itemId = id; codes = code; itemName = name; vals = val + ","; } } } Map ms = new HashMap(); ms.put("itemNo", itemId); ms.put("codes", codes); ms.put("itemName", itemName); ms.put("vals", vals.substring(0, vals.length() - 1)); authList.add(ms); res.set("roleId", roleId); res.set(IMINBusinessConstant.F_QUERY_RESULT, authList); return res; } /** * 给角色设置菜单权限 * * @param roleId * @param session * @return * @throws MINBusinessException */ @MINAction(value = SET_ITEM_AUTH) public MINActionResult setItemAuth(@MINParam(key = "roleId") String roleId, @MINParam(key = "parameStr") String parameStr, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); String[] parameArr = parameStr.split("\\|"); for (int i = 0; i < parameArr.length; i++) { String str = parameArr[i]; String itemId = str.substring(0, str.indexOf(":"));// 菜单编号 String code = str.substring(str.indexOf(":") + 1, str.indexOf("="));// 模块编码 String[] types = str.substring(str.indexOf("=") + 1).split(",");// 模块值 // 添加模块控制 /* * List authList = new ArrayList(); for(int * j=0;j * sls = Arrays.asList(types); ImRoleAuthExample ae = new ImRoleAuthExample(); * ImRoleAuthExample.Criteria aec = ae.createCriteria(); * aec.andRoleidEqualTo(roleId).andCodeEqualTo(code).andItemidEqualTo(itemId). * andTypeEqualTo(Constant.MODULE_AUTH_CODE); * * Service.lookup(IMINDataBaseService.class).deleteByExample(ImRoleAuthMapper. * class, ae); //添加模块控制 List authList = new ArrayList(); * for(int j=0;j list = Service.lookup(IMINDataBaseService.class) * .selectByExample(ImRoleAuthMapper.class, example); list = new * MINCopyFormat("{value:'moduleDesc'}").format(list); list = * Service.lookup(IFormatService.class).formatEnum(list, * "{moduleDesc:'ARTICLE_MODULE'}");//状态 * res.set(IMINBusinessConstant.F_QUERY_RESULT, list); */ return res; } /** * 查询所有部门 * * @param session * @return * @throws MINBusinessException */ @MINAction(value = "roleQueryBranch") public MINActionResult roleQueryBranch(MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); ImBranchExample example = new ImBranchExample(); ImBranchExample.Criteria criteria = example.createCriteria(); User user = session.getUser(); criteria.andSttNotEqualTo(Constant.DEPT_STT_DEL); if(!user.getBranchId().equals(Constant.DEFAULT_INSTITUTIONS)){ criteria.andIdEqualTo(user.getBranchId()); } List ls = Service.lookup(IMINDataBaseService.class).selectByExample(ImBranchMapper.class, example); res.set(IMINBusinessConstant.F_QUERY_RESULT, ls); return res; } }