123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854 |
- package com.minpay.huicai.system.action;
- import com.min.util.CommonUtil;
- 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.*;
- import com.minpay.db.table.model.*;
- 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;
- import java.util.*;
- /**
- * 角色管理
- *
- * @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<String, String> m = new HashMap<String, String>();
- 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<ImRole> ls =
- // Service.lookup(IMINDataBaseService.class).selectByExample(ImRoleMapper.class,
- // s, rows);
- List<Map<String, String>> 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<ImRoleItemRel> 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<String> set = new HashSet<String>(Arrays.asList(itemid));
- set.remove(null);
- set.remove("");
- List<String> sls = new ArrayList<String>(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<ImRoleItemRel> rils = Service.lookup(IMINDataBaseService.class).selectByExample(ImRoleItemRelMapper.class,
- ex);
- Set<String> existRoleItem = new HashSet<String>();
- for (ImRoleItemRel ri : rils) {
- existRoleItem.add(ri.getItemid());
- }
- if (sls.size() > 0) {
- ImItemExample iex = new ImItemExample();
- iex.createCriteria().andIdIn(sls);
- List<ImItem> ils = Service.lookup(IMINDataBaseService.class).selectByExample(ImItemMapper.class, iex);
- List<ImRoleItemRel> ls = new ArrayList<ImRoleItemRel>();
- 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<ImUserRoleRelKey> 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,
- @MINParam(key = "branchid") String branchid,
- 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<ImRole> 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(branchid);
- role.setAddbranch(branchid);
- 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<ImItem> ils = Service.lookup(IMINDataBaseService.class).selectByExample(ImItemMapper.class, iex);
- List<ImRoleItemRel> ls = new ArrayList<ImRoleItemRel>();
- 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<ImRole> 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<Map<String, String>> 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<String, String> map = new HashMap<String, String>();
- User user = session.getUser();
- if(!Constant.ADMINISTRATION_SYSTEM_NUMBER.equals(user.getBranchId()) ){ //超級管理員
- map.put("authority", "00");
- }
- map.put("roleid", id);
- List<Map<String, String>> 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<String, Map<String, String>> menu = new HashMap<String, Map<String, String>>();
- for (Map<String, String> m : ls) {
- menu.put(m.get("menuid"), m);
- String s = m.get("authrole");
- if (s != null) {
- ((Map) m).put("authrole", s.split(","));
- }
- }
- for (Map<String, String> s : menu.values()) {
- Map<String, String> m = new HashMap<String, String>();
- 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<Map<String, String>>() {
- public int compare(Map<String, String> o1, Map<String, String> 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<String, String> map = new HashMap<String, String>();
- 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<Map<String, String>> ls =
- // Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class).roleMenu(id);
- List<Map<String, String>> ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class)
- .roleMenuByTemp(map);
- if (filterbyrole) {
- for (Iterator<Map<String, String>> it = ls.iterator(); it.hasNext();)
- if (it.next().get("roleid") == null)
- it.remove();
- }
- Map<String, Map<String, String>> menu = new HashMap<String, Map<String, String>>();
- for (Map<String, String> m : ls) {
- menu.put(m.get("menuid"), m);
- String s = m.get("authrole");
- if (s != null)
- ((Map) m).put("authrole", s.split(","));
- }
- for (Map<String, String> s : menu.values()) {
- Map<String, String> m = new HashMap<String, String>();
- 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<Map<String, String>>() {
- public int compare(Map<String, String> o1, Map<String, String> 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<String, String> m = new HashMap<String, String>();
- m.put("branchId", branchId);
- List<Map<String, String>> 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();
- if(CommonUtil.isEmpty(branchId)){
- criteria.andBranchidEqualTo(user.getBranchId());
- }else{
- criteria.andBranchidEqualTo(branchId);
- }
- List<ImRole> 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<ImRoleAuth> authList =
- * Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImRoleAuthMapper.
- * class).selectByExample(ae); String[] authArr = new String[authList.size()];
- * String str = ""; Map mm = new HashMap<String,String>(); for(int
- * i=0;i<authList.size();i++){ authArr[i] = authList.get(i).getValue(); str =
- * str+authList.get(i).getValue()+","; // } mm.put("authMod", str); //
- * ls.add(mm); res.set(IMINBusinessConstant.F_QUERY_RESULT, authList);
- */
- return res;
- }
- /**
- * 查询角色需要设置权限的菜单和权限列表
- *
- * @param roleId
- * @param session
- * @return
- * @throws MINBusinessException
- */
- @MINAction(value = ROLE_AUTHSET_QUERY)
- public MINActionResult roleAuthSetQuery(@MINParam(key = "roleId") String roleId, MINSession session)
- throws MINBusinessException {
- MINActionResult res = new MINActionResult();
- User u = session.getUser();
- String branchId = u.getBranchId();
- ImBranch br = Service.lookup(IMINDataBaseService.class).selectByPrimaryKey(ImBranchMapper.class, branchId);
- Map<String, String> mm = new HashMap<String, String>();
- mm.put("roleId", roleId);
- // mm.put("btype", br.getType());
- List<Map<String, String>> list = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class)
- .roleAuthSetQuery(mm);
- List<Map<String, String>> authList = new ArrayList<Map<String, String>>();
- String itemId = "";// 缓存菜单Id
- String codes = "";
- String vals = "";
- String itemName = "";
- for (Map<String, String> 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<String, String> ms = new HashMap<String, String>();
- 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<String, String> ms = new HashMap<String, String>();
- 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<ImRoleAuth> authList = new ArrayList<ImRoleAuth>(); for(int
- * j=0;j<types.length;j++){ String authNo =
- * Service.lookup(IPublicService.class).getSequence("IM_ROLE_AUTH_NO");
- * ImRoleAuth ai = new ImRoleAuth(); ai.setNo(authNo); ai.setCode(code);
- * ai.setRoleid(roleId); ai.setType(Constant.MODULE_AUTH_CODE);
- * ai.setValue(types[j]); ai.setItemid(itemId); authList.add(ai); }
- * ImRoleAuthMapper am =
- * Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImRoleAuthMapper.
- * class); for(ImRoleAuth roleAuth:authList){ am.insert(roleAuth); }
- */
- }
- String logInfo = "设置角色菜单权限,角色编号" + roleId;
- // Service.lookup(ILogService.class).logging(session, logInfo);
- return res;
- }
- /**
- * 修改角色菜单权限 菜单模块设置
- *
- * @param roleId
- * @param session
- * @return
- * @throws MINBusinessException
- */
- @MINAction(value = MODIFY_ITEM_AUTH)
- public MINActionResult modifyItemAuth(@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<String>
- * 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<ImRoleAuth> authList = new ArrayList<ImRoleAuth>();
- * for(int j=0;j<types.length;j++){ String authNo =
- * Service.lookup(IPublicService.class).getSequence("IM_ROLE_AUTH_NO");
- * ImRoleAuth ai = new ImRoleAuth(); ai.setNo(authNo); ai.setCode(code);
- * ai.setRoleid(roleId); ai.setType(Constant.MODULE_AUTH_CODE);
- * ai.setValue(types[j]); ai.setItemid(itemId); authList.add(ai); }
- * ImRoleAuthMapper am =
- * Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImRoleAuthMapper.
- * class); for(ImRoleAuth roleAuth:authList){ am.insert(roleAuth); } }
- */
- String logInfo = "修改角色菜单权限:" + roleId;
- // Service.lookup(ILogService.class).logging(session, logInfo);
- return res;
- }
- /**
- * 查询角色对应的模块权限
- *
- * @param roleId
- * @param session
- * @return
- * @throws MINBusinessException
- */
- @MINAction(value = GET_ROLE_MODE)
- public MINActionResult getRoleModule(@MINParam(key = "roleId") String roleId,
- @MINParam(key = "MIN_context_itemId") String itemId, @MINParam(key = "businessCode") String businessCode,
- MINSession session) throws MINBusinessException {
- MINActionResult res = new MINActionResult();
- /*
- * User user = session.getUser(); roleId = user.getRoleId();
- *
- * String sessionItemId = (String)session.get("sessionItemId");
- *
- * ImRoleAuthExample example = new ImRoleAuthExample();
- *
- * ImRoleAuthExample.Criteria criteria = example.createCriteria();
- * criteria.andRoleidEqualTo(roleId);
- * criteria.andCodeEqualTo(Constant.ARTICLE_MODULE_CODE);
- * criteria.andItemidEqualTo(sessionItemId);
- * example.setOrderByClause("IRA_VALUE");
- *
- * List<ImRoleAuth> 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<ImBranch> ls = Service.lookup(IMINDataBaseService.class).selectByExample(ImBranchMapper.class, example);
- ImBranchExample exampleb = new ImBranchExample();
- ImBranchExample.Criteria criteriab = exampleb.createCriteria();
- criteria.andSttNotEqualTo(Constant.DEPT_STT_DEL);
- if(!user.getBranchId().equals(Constant.DEFAULT_INSTITUTIONS)){
- criteriab.andParentidEqualTo(user.getBranchId());
- }
- List<ImBranch> lsb = Service.lookup(IMINDataBaseService.class).selectByExample(ImBranchMapper.class, exampleb);
- ls.addAll(lsb);
- res.set(IMINBusinessConstant.F_QUERY_RESULT, ls);
- return res;
- }
- }
|