RoleManageAction.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. package com.minpay.huicai.system.action;
  2. import com.min.util.CommonUtil;
  3. import com.minpay.common.bean.User;
  4. import com.minpay.common.constant.Constant;
  5. import com.minpay.common.constant.IConstant;
  6. import com.minpay.common.exception.BusinessCodeException;
  7. import com.minpay.common.format.IFormatService;
  8. import com.minpay.common.service.ILogService;
  9. import com.minpay.common.service.IPublicService;
  10. import com.minpay.db.table.mapper.*;
  11. import com.minpay.db.table.model.*;
  12. import com.minpay.db.table.own.mapper.RoleMapper;
  13. import com.startup.minpay.frame.business.IMINAction;
  14. import com.startup.minpay.frame.business.res.MINActionResult;
  15. import com.startup.minpay.frame.constant.IMINBusinessConstant;
  16. import com.startup.minpay.frame.constant.IMINTransactionEnum;
  17. import com.startup.minpay.frame.data.format.MINCopyFormat;
  18. import com.startup.minpay.frame.exception.MINBusinessException;
  19. import com.startup.minpay.frame.jdbc.MINRowBounds;
  20. import com.startup.minpay.frame.service.base.IMINDataBaseService;
  21. import com.startup.minpay.frame.service.base.Service;
  22. import com.startup.minpay.frame.session.MINSession;
  23. import com.startup.minpay.frame.target.MINAction;
  24. import com.startup.minpay.frame.target.MINComponent;
  25. import com.startup.minpay.frame.target.MINParam;
  26. import com.startup.minpay.util.DateTime;
  27. import com.startup.minpay.util.Str;
  28. import java.util.*;
  29. /**
  30. * 角色管理
  31. *
  32. * @author sunbz
  33. *
  34. */
  35. @MINComponent
  36. public class RoleManageAction implements IMINAction {
  37. public final static String ROLE_QUERY = "roleQuery";
  38. public final static String ROLE_QUERY_ALL = "roleQueryAll";
  39. public final static String ROLE_MODIFY = "roleModify";
  40. public final static String ROLE_DELETE = "roleDelete";
  41. public final static String ROLE_ADD = "roleAdd";
  42. public final static String ROLE_AUTH_QUERY = "roleAuthQuery";
  43. public final static String ROLE_AUTH_QUERY_WITHOUT_PWD = "roleAuthQueryWithoutPwd";
  44. public final static String AUTH_MODIFY = "authModify";
  45. public final static String HAVE_AUTH_SHAPE = "isHaveAuthShape";
  46. /** 查询当前机构下的角色信息 */
  47. public final static String ROLE_QUERY_BY_BRANCHID = "roleQueryByBranchId";
  48. /** 查询当前机构及下一级机构下的角色 信息 */
  49. public final static String ROLE_QUERY_BY_PARENTID = "roleQueryByParentId";
  50. /** 查询角色菜单已经设置的权限 */
  51. public final static String ROLE_AUTH_QUERY_BY_ROLEID = "roleAuthQueryByRoleId";
  52. /** 查询角色需要设置权限的菜单和权限列表 */
  53. public final static String ROLE_AUTHSET_QUERY = "roleAuthSetQuery";
  54. /** 给角色设置菜单权限 */
  55. public final static String SET_ITEM_AUTH = "setItemAuth";
  56. /** 查询角色对应的模块权限 */
  57. public final static String GET_ROLE_MODE = "getRoleModule";
  58. /** 修改角色菜单权限 */
  59. public final static String MODIFY_ITEM_AUTH = "modifyItemAuth";
  60. /** 查询所有部门 */
  61. public final static String ROLE_QUERY_BRANCH = "roleQueryBranch";
  62. @MINAction(value = ROLE_QUERY)
  63. public MINActionResult roleQuery(MINSession session, @MINParam(key = "page", defaultValue = "1") int page,
  64. @MINParam(key = "limit", defaultValue = "3") int limit, @MINParam(key = "rolename") String rolename,
  65. @MINParam(key = "roleId") String roleId) throws MINBusinessException {
  66. MINActionResult res = new MINActionResult();
  67. // 创建查询条件
  68. ImRoleExample s = new ImRoleExample();
  69. ImRoleExample.Criteria c = s.createCriteria();
  70. User u = session.getUser();
  71. String branchId = u.getBranchId();
  72. if (branchId == null || "".equals(branchId)) {
  73. throw new MINBusinessException("获取客户开户机构号失败!");
  74. }
  75. Map<String, String> m = new HashMap<String, String>();
  76. m.put("rolename", rolename);
  77. m.put("roleId", roleId);
  78. m.put("branchId", branchId);
  79. if (!Str.isEmptyMaskNull(rolename)) {
  80. c.andNameEqualTo(rolename);
  81. }
  82. MINRowBounds rows = new MINRowBounds(page, limit);
  83. // 查询
  84. // List<ImRole> ls =
  85. // Service.lookup(IMINDataBaseService.class).selectByExample(ImRoleMapper.class,
  86. // s, rows);
  87. List<Map<String, String>> ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class)
  88. .roleManageQuery(m, rows);
  89. // 格式化
  90. ls = Service.lookup(IFormatService.class).formatDateTime(ls, "addtime");
  91. // 设置返回值
  92. res.set(IMINBusinessConstant.F_PAGING_LAY, ls);
  93. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getMaxRows());
  94. res.set("sessionId", u.getId());
  95. return res;
  96. }
  97. /**
  98. *
  99. * @param id 角色编号
  100. * @param name 角色名称
  101. * @param desc 描述
  102. * @param itemidStr 菜单
  103. * @param authInputs 权限
  104. * @param moduleType
  105. * @param session
  106. * @return
  107. * @throws MINBusinessException
  108. */
  109. @MINAction(value = ROLE_MODIFY, transaction = IMINTransactionEnum.CMT)
  110. public MINActionResult roleModify(@MINParam(key = "id") String id, @MINParam(key = "name") String name,
  111. @MINParam(key = "desc") String desc, @MINParam(key = "itemidStr") String itemidStr,
  112. @MINParam(key = "authInputs") String authInputs, @MINParam(key = "moduleType") String[] moduleType,
  113. @MINParam(key = "roleMainPage") String roleMainPage, MINSession session) throws MINBusinessException {
  114. if ("".equals(name.trim()) || name == null) {
  115. throw new MINBusinessException("请输入角色名称!");
  116. }
  117. if ("".equals(desc) || desc == null) {
  118. throw new MINBusinessException("请输入角色描述!");
  119. }
  120. String[] itemid = itemidStr.split(",");
  121. if (itemid.length == 0) {
  122. throw new MINBusinessException("至少选择一个菜单!");
  123. }
  124. User u = session.getUser();
  125. if (u.getRoleId().equals(id)) {
  126. throw new MINBusinessException("不能修改当前登录操作员的相关信息");
  127. }
  128. // 当新增用户为客户经理时 校验所选角色有客户经理中心菜单
  129. ImRoleItemRelExample irir = new ImRoleItemRelExample();
  130. irir.createCriteria().andRoleidEqualTo(id).andItemidEqualTo(Constant.CUSTOMER_MANAGER_MENU);
  131. List<ImRoleItemRel> irirNum = Service.lookup(IMINDataBaseService.class)
  132. .selectByExample(ImRoleItemRelMapper.class, irir);
  133. // 之前未选择客户经理中心菜单 修改也不能选择
  134. /*
  135. * if (irirNum.size() == 0){
  136. * if(itemidStr.indexOf(Constant.CUSTOMER_MANAGER_MENU) != -1) { throw new
  137. * BusinessCodeException("JINM3154"); } }else { //之前已选择客户经理中心 修改时不能不选
  138. * if(itemidStr.indexOf(Constant.CUSTOMER_MANAGER_MENU) == -1) { throw new
  139. * BusinessCodeException("JINM3153"); } }
  140. */
  141. MINActionResult res = new MINActionResult();
  142. ImRole role = Service.lookup(IMINDataBaseService.class).selectByPrimaryKey(ImRoleMapper.class, id);
  143. role.setName(name);
  144. role.setDesc(desc);
  145. //role.setIndexpage(roleMainPage);
  146. role.setIndexpage("main.html");
  147. Service.lookup(IMINDataBaseService.class).updateByPrimaryKey(ImRoleMapper.class, role);
  148. Set<String> set = new HashSet<String>(Arrays.asList(itemid));
  149. set.remove(null);
  150. set.remove("");
  151. List<String> sls = new ArrayList<String>(set);
  152. // 删除不存在的菜单
  153. ImRoleItemRelExample dex = new ImRoleItemRelExample();
  154. ImRoleItemRelExample.Criteria c = dex.createCriteria();
  155. c.andRoleidEqualTo(id);
  156. if (sls.size() > 0) {
  157. c.andItemidNotIn(sls);
  158. }
  159. Service.lookup(IMINDataBaseService.class).deleteByExample(ImRoleItemRelMapper.class, dex);
  160. // 过滤已存在的权限
  161. ImRoleItemRelExample ex = new ImRoleItemRelExample();
  162. ex.createCriteria().andRoleidEqualTo(id);
  163. List<ImRoleItemRel> rils = Service.lookup(IMINDataBaseService.class).selectByExample(ImRoleItemRelMapper.class,
  164. ex);
  165. Set<String> existRoleItem = new HashSet<String>();
  166. for (ImRoleItemRel ri : rils) {
  167. existRoleItem.add(ri.getItemid());
  168. }
  169. if (sls.size() > 0) {
  170. ImItemExample iex = new ImItemExample();
  171. iex.createCriteria().andIdIn(sls);
  172. List<ImItem> ils = Service.lookup(IMINDataBaseService.class).selectByExample(ImItemMapper.class, iex);
  173. List<ImRoleItemRel> ls = new ArrayList<ImRoleItemRel>();
  174. for (ImItem i : ils) {
  175. if (existRoleItem.contains(i.getId()))
  176. continue;
  177. ImRoleItemRel ri = new ImRoleItemRel();
  178. ri.setRoleid(id);
  179. ri.setItemid(i.getId());
  180. ri.setAuthtype(i.getAuthtype());
  181. ri.setAuthshape(i.getAuthshape());
  182. ls.add(ri);
  183. }
  184. ImRoleItemRelMapper im = Service.lookup(IMINDataBaseService.class)
  185. .getMybatisMapper(ImRoleItemRelMapper.class);
  186. for (ImRoleItemRel i : ls) {
  187. im.insertSelective(i);
  188. }
  189. }
  190. // 删除所有权限
  191. ImRoleAuthExample roleAuthEx = new ImRoleAuthExample();
  192. roleAuthEx.createCriteria().andRoleidEqualTo(id);
  193. Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImRoleAuthMapper.class).deleteByExample(roleAuthEx);
  194. // 添加所有权限
  195. ImRoleAuthKey roleAuth = new ImRoleAuthKey();
  196. roleAuth.setRoleid(id);
  197. for (int i = 0; i < authInputs.split(",").length; i++) {
  198. String auth = authInputs.split(",")[i];
  199. if (auth != null && !"".equals(auth) && !"undefined".equals(auth)) {
  200. roleAuth.setAuthNo(auth);
  201. Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImRoleAuthMapper.class).insert(roleAuth);
  202. }
  203. }
  204. // 更新缓存
  205. Service.lookup(IPublicService.class).init();
  206. String logInfo = "操作员" + u.getName() + "修改角色,编号:" + id + ",名称:" + name + ",描述:" + desc;
  207. // Service.lookup(ILogService.class).logging(session, logInfo);
  208. res.set("roleId", id);
  209. res.set("roleName", name);
  210. return res;
  211. }
  212. /**
  213. * 角色删除
  214. *
  215. * @param id
  216. * @param session
  217. * @return
  218. * @throws MINBusinessException
  219. */
  220. @MINAction(value = ROLE_DELETE, transaction = IMINTransactionEnum.CMT)
  221. public MINActionResult roleDelete(@MINParam(key = "id") String id, MINSession session) throws MINBusinessException {
  222. User u = session.getUser();
  223. if (u.getRoleId().equals(id)) {
  224. throw new MINBusinessException("不能修改当前登录操作员的相关信息");
  225. }
  226. MINActionResult res = new MINActionResult();
  227. ImRole role = Service.lookup(IMINDataBaseService.class).selectByPrimaryKey(ImRoleMapper.class, id);
  228. if (role == null) {
  229. throw new MINBusinessException("角色不存在");
  230. }
  231. // 判断角色下是否存在操作员
  232. ImUserRoleRelExample ire = new ImUserRoleRelExample();
  233. ire.createCriteria().andRoleidEqualTo(id);
  234. List<ImUserRoleRelKey> list = Service.lookup(IMINDataBaseService.class)
  235. .getMybatisMapper(ImUserRoleRelMapper.class).selectByExample(ire);
  236. if (list.size() > 0) {
  237. throw new MINBusinessException("该角色下存在操作员,不能删除");
  238. }
  239. Service.lookup(IMINDataBaseService.class).deleteByPrimaryKey(ImRoleMapper.class, id);
  240. ImRoleItemRelExample ex = new ImRoleItemRelExample();
  241. ex.createCriteria().andRoleidEqualTo(id);
  242. Service.lookup(IMINDataBaseService.class).deleteByExample(ImRoleItemRelMapper.class, ex);
  243. String logInfo = "删除角色id:" + id;
  244. Service.lookup(ILogService.class).logging(session, logInfo);
  245. return res;
  246. }
  247. @MINAction(value = ROLE_ADD, transaction = IMINTransactionEnum.CMT, session = true)
  248. public MINActionResult roleAdd(
  249. // @MINParam(value = "id") String id,
  250. @MINParam(key = "name") String name, @MINParam(key = "desc") String desc,
  251. @MINParam(key = "itemidStr") String itemidStr, @MINParam(key = "authInputs") String authInputs,
  252. @MINParam(key = "moduleType") String[] moduleType, @MINParam(key = "roleMainPage") String roleMainPage,
  253. @MINParam(key = "branchid") String branchid,
  254. MINSession session) throws MINBusinessException {
  255. if ("".equals(name.trim()) || name == null) {
  256. throw new MINBusinessException("请输入角色名称!");
  257. }
  258. if ("".equals(desc) || desc == null) {
  259. throw new MINBusinessException("请输入角色描述!");
  260. }
  261. /*if ("".equals(roleMainPage) || roleMainPage == null) {
  262. throw new MINBusinessException("请输入角色主页!");
  263. }*/
  264. String[] itemid = itemidStr.split(",");
  265. if (itemid.length == 0) {
  266. throw new MINBusinessException("至少选择一个菜单!");
  267. }
  268. // 校验全先生数据是否选择
  269. String noAuthItem = "";// TODO 添加无权限菜单数据 用,拼接
  270. for (int i = 0; i < itemid.length; i++) {
  271. String item_id = itemid[i];
  272. if (authInputs.indexOf(item_id) == -1 && noAuthItem.indexOf(item_id) != -1) {// TODO 存在不无权限的菜单,需要单独列出来
  273. throw new MINBusinessException("存在菜单未选择权限情况,请检查!");
  274. }
  275. }
  276. String[] auths = authInputs.split(",");
  277. User u = session.getUser();
  278. MINActionResult res = new MINActionResult();
  279. String roleId = Service.lookup(IPublicService.class).getSequence("IM_ROLE_NO");
  280. roleId = getRoleId(Integer.valueOf(roleId));
  281. ImRoleExample na = new ImRoleExample();
  282. na.createCriteria().andNameEqualTo(name).andBranchidEqualTo(u.getBranchId());
  283. List<ImRole> list = Service.lookup(IMINDataBaseService.class).selectByExample(ImRoleMapper.class, na);
  284. if (list != null && list.size() > 0) {
  285. throw new BusinessCodeException("JINM0109");
  286. }
  287. ImRole role = new ImRole();
  288. role.setId(roleId);
  289. role.setName(name);
  290. role.setDesc(desc);
  291. role.setBranchid(branchid);
  292. role.setAddbranch(branchid);
  293. role.setAddtime(new DateTime().toDateTimeString());
  294. //role.setIndexpage(roleMainPage);
  295. role.setIndexpage("main.html");
  296. Service.lookup(IMINDataBaseService.class).insert(ImRoleMapper.class, role);
  297. String[] itemIds = new String[itemid.length + 1];
  298. System.arraycopy(itemid, 0, itemIds, 0, itemid.length);
  299. itemIds[itemid.length] = "240001";
  300. if (itemIds.length > 0) {
  301. ImItemExample iex = new ImItemExample();
  302. iex.createCriteria().andIdIn(Arrays.asList(itemIds));
  303. List<ImItem> ils = Service.lookup(IMINDataBaseService.class).selectByExample(ImItemMapper.class, iex);
  304. List<ImRoleItemRel> ls = new ArrayList<ImRoleItemRel>();
  305. for (ImItem i : ils) {
  306. if (!"".equals(i.getId())) {
  307. ImRoleItemRel ri = new ImRoleItemRel();
  308. ri.setRoleid(roleId);
  309. ri.setItemid(i.getId());
  310. ri.setAuthtype(i.getAuthtype());
  311. ri.setAuthshape(i.getAuthshape());
  312. ls.add(ri);
  313. }
  314. }
  315. ImRoleItemRelMapper im = Service.lookup(IMINDataBaseService.class)
  316. .getMybatisMapper(ImRoleItemRelMapper.class);
  317. for (ImRoleItemRel i : ls)
  318. im.insert(i);
  319. }
  320. // 添加角色菜单权限数据
  321. ImRoleAuthKey roleAuth = new ImRoleAuthKey();
  322. roleAuth.setRoleid(roleId);
  323. for (int j = 0; j < auths.length; j++) {
  324. String authNo = auths[j];
  325. roleAuth.setAuthNo(authNo);
  326. Service.lookup(IMINDataBaseService.class).insert(ImRoleAuthMapper.class, roleAuth);
  327. }
  328. res.set("roleId", roleId);
  329. res.set("roleName", name);
  330. String logInfo = "新增角色:" + roleId;
  331. // Service.lookup(ILogService.class).logging(session, logInfo);
  332. return res;
  333. }
  334. private String getRoleId(int roleId) throws BusinessCodeException, MINBusinessException {
  335. ImRole rx = Service.lookup(IMINDataBaseService.class).selectByPrimaryKey(ImRoleMapper.class,
  336. String.valueOf(roleId));
  337. if (rx == null) {
  338. return String.valueOf(roleId);
  339. } else {
  340. return getRoleId(roleId + 1);
  341. }
  342. }
  343. @MINAction(value = ROLE_QUERY_ALL)
  344. public MINActionResult roleQueryAll() throws MINBusinessException {
  345. MINActionResult res = new MINActionResult();
  346. ImRoleExample s = new ImRoleExample();
  347. List<ImRole> ls = Service.lookup(IMINDataBaseService.class).selectByExample(ImRoleMapper.class, s);
  348. res.set(IMINBusinessConstant.F_QUERY_RESULT, ls);
  349. return res;
  350. }
  351. @MINAction(value = HAVE_AUTH_SHAPE)
  352. public MINActionResult isHaveAuthShape(@MINParam(key = "itemId") String itemId,
  353. @MINParam(key = "roleId") String roleId, @MINParam(key = "dataTypeStr") String dataTypeStr,
  354. @MINParam(key = "dataShapeStr") String dataShapeStr, MINSession session) throws MINBusinessException {
  355. MINActionResult res = new MINActionResult();
  356. Map m = new HashMap();
  357. m.put("itemId", itemId);
  358. m.put("roleId", roleId);
  359. m.put("dataTypeStr", dataTypeStr);
  360. m.put("dataShapeStr", dataShapeStr);
  361. List<Map<String, String>> ls = new ArrayList();
  362. ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class).queryHaveAuthShape(m);
  363. res.set(IMINBusinessConstant.F_QUERY_RESULT, ls);
  364. return res;
  365. }
  366. @MINAction(value = AUTH_MODIFY, transaction = IMINTransactionEnum.CMT)
  367. public MINActionResult authModify(@MINParam(key = "roleid") String roleid, @MINParam(key = "itemid") String itemid,
  368. @MINParam(key = "authtype") String authtype, // 要变成的类型
  369. @MINParam(key = "authshape") String authshape, // 要变成的类型
  370. @MINParam(key = "authrole") String[] authrole, @MINParam(key = "autIds") String autIds,
  371. @MINParam(key = "nowShape") String nowShape, // 没有修改前的类型
  372. @MINParam(key = "nowType") String nowType, // 没有修改前的类型
  373. MINSession session) throws MINBusinessException {
  374. User u = session.getUser();
  375. if (u.getRoleId().equals(roleid))
  376. throw new MINBusinessException("不能修改当前登录操作员的相关信息");
  377. ImItem item = Service.lookup(IMINDataBaseService.class).selectByPrimaryKey(ImItemMapper.class, itemid);
  378. if (item == null)
  379. throw new MINBusinessException("授权资源不存在");
  380. String auth = item.getAuth();
  381. if (IConstant.AUTH_CANDIDATE_NONE.equals(auth)) {
  382. throw new MINBusinessException("该资源不需要授权");
  383. } else if (IConstant.AUTH_CANDIDATE_INTIME.equals(auth)) {
  384. if (IConstant.AUTH_TYPE_SPECIFY.equals(authtype) || IConstant.AUTH_SHAPE_AUTH.equals(authshape))
  385. throw new MINBusinessException("授权类型支持即时生效和互为授权,授权类型只支持临柜");
  386. }
  387. MINActionResult res = new MINActionResult();
  388. ImRoleItemRelKey key = new ImRoleItemRelKey();
  389. key.setItemid(itemid);
  390. key.setRoleid(roleid);
  391. ImRoleItemRel ri = Service.lookup(IMINDataBaseService.class).selectByPrimaryKey(ImRoleItemRelMapper.class, key);
  392. if (ri == null)
  393. throw new MINBusinessException("权限信息不存在");
  394. ri.setAuthtype(authtype);
  395. ri.setAuthshape(authshape);
  396. if ("2".equals(authtype)) {
  397. StringBuffer sb = new StringBuffer(",");
  398. if (authrole != null) {
  399. for (int i = 0; i < authrole.length; i++) {
  400. if (i > 0)
  401. sb.append(",");
  402. sb.append(authrole[i]);
  403. }
  404. }
  405. ri.setAuthrole(sb.append(",").toString());
  406. }
  407. boolean statusType = "1".equals(nowType) || "2".equals(nowType);
  408. if (!"".equals(nowType) && !"".equals(nowShape) && (statusType && "0".equals(authtype)
  409. || (statusType && "1".equals(authshape) && "0".equals(nowShape)))) {
  410. String[] autAry = autIds.split(",");
  411. List list = new ArrayList();
  412. for (String string : autAry) {
  413. list.add(string);
  414. }
  415. Map m = new HashMap();
  416. m.put("name", u.getId());
  417. m.put("list", list);
  418. if (list.size() > 0) {
  419. Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class).updateAuthStatusToFive(m);
  420. }
  421. }
  422. Service.lookup(IMINDataBaseService.class).updateByPrimaryKey(ImRoleItemRelMapper.class, ri);
  423. String logInfo = "修改授权规则:" + roleid;
  424. // Service.lookup(ILogService.class).logging(session, logInfo);
  425. return res;
  426. }
  427. @MINAction(value = ROLE_AUTH_QUERY_WITHOUT_PWD)
  428. public MINActionResult roleAuthQueryWithoutPwd(@MINParam(key = "id") String id, MINSession session)
  429. throws MINBusinessException {
  430. MINActionResult res = new MINActionResult();
  431. Map<String, String> map = new HashMap<String, String>();
  432. User user = session.getUser();
  433. if(!Constant.ADMINISTRATION_SYSTEM_NUMBER.equals(user.getBranchId()) ){ //超級管理員
  434. map.put("authority", "00");
  435. }
  436. map.put("roleid", id);
  437. List<Map<String, String>> ls = null;
  438. if (id == null || "".equals(id)) {// 新增角色时使用
  439. // ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class).roleMenuWithOutPwd(id);
  440. ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class)
  441. .roleMenuWithAuthForAdd(map);
  442. } else {// 查看角色使用
  443. // ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class).roleMenuWithOutPwdByTemp(map);
  444. ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class)
  445. .roleMenuWithAuthForDetail(map);
  446. }
  447. Map<String, Map<String, String>> menu = new HashMap<String, Map<String, String>>();
  448. for (Map<String, String> m : ls) {
  449. menu.put(m.get("menuid"), m);
  450. String s = m.get("authrole");
  451. if (s != null) {
  452. ((Map) m).put("authrole", s.split(","));
  453. }
  454. }
  455. for (Map<String, String> s : menu.values()) {
  456. Map<String, String> m = new HashMap<String, String>();
  457. m.put("menuid", s.get("menuid"));
  458. m.put("lv1", s.get("lv1"));
  459. m.put("menserialno", s.get("menserialno"));
  460. m.put("menuparentid", s.get("menuparentid"));
  461. ls.add(m);
  462. }
  463. Collections.sort(ls, new Comparator<Map<String, String>>() {
  464. public int compare(Map<String, String> o1, Map<String, String> o2) {
  465. String x1 = Str.nvl(o1.get("menserialno"));
  466. String x2 = Str.nvl(o2.get("menserialno"));
  467. String s1 = Str.nvl(o1.get("itmserialno"));
  468. String s2 = Str.nvl(o2.get("itmserialno"));
  469. String m1 = Str.nvl(o1.get("menuparentid"));
  470. String m2 = Str.nvl(o2.get("menuparentid"));
  471. if (m1.equals(m2)) {
  472. return x1.equals(x2) ? s1.compareTo(s2) : x1.compareTo(x2);
  473. }
  474. return m1.compareTo(m2);
  475. }
  476. });
  477. ls = new MINCopyFormat("{authtype:'authtypeDesc',authshape:'authshapeDesc'}").format(ls);
  478. // ls = Service.lookup(IFormatService.class).formatEnum(ls, "{authtypeDesc:'IM_AUTH_TYPE',authshapeDesc:'IM_AUTH_SHAPE'}");
  479. res.set(IMINBusinessConstant.F_QUERY_RESULT, ls);
  480. return res;
  481. }
  482. @MINAction(value = ROLE_AUTH_QUERY)
  483. public MINActionResult roleAuthQuery(@MINParam(key = "id") String id,
  484. @MINParam(key = "filterbyrole") boolean filterbyrole, MINSession session) throws MINBusinessException {
  485. MINActionResult res = new MINActionResult();
  486. ImRole role = Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImRoleMapper.class)
  487. .selectByPrimaryKey(id);
  488. Map<String, String> map = new HashMap<String, String>();
  489. map.put("roleid", id);
  490. User user = session.getUser();
  491. ImBranch branch = Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImBranchMapper.class)
  492. .selectByPrimaryKey(role.getBranchid());
  493. if (!Constant.BRANCH_LEVEL_SYS.equals(branch.getLevel().toString())) {// 非平台用户使用模板菜单数据
  494. // map.put("tempid", branch.getType() );
  495. }
  496. // List<Map<String, String>> ls =
  497. // Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class).roleMenu(id);
  498. List<Map<String, String>> ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class)
  499. .roleMenuByTemp(map);
  500. if (filterbyrole) {
  501. for (Iterator<Map<String, String>> it = ls.iterator(); it.hasNext();)
  502. if (it.next().get("roleid") == null)
  503. it.remove();
  504. }
  505. Map<String, Map<String, String>> menu = new HashMap<String, Map<String, String>>();
  506. for (Map<String, String> m : ls) {
  507. menu.put(m.get("menuid"), m);
  508. String s = m.get("authrole");
  509. if (s != null)
  510. ((Map) m).put("authrole", s.split(","));
  511. }
  512. for (Map<String, String> s : menu.values()) {
  513. Map<String, String> m = new HashMap<String, String>();
  514. m.put("menuid", s.get("menuid"));
  515. m.put("lv1", s.get("lv1"));
  516. m.put("menserialno", s.get("menserialno"));
  517. ls.add(m);
  518. }
  519. Collections.sort(ls, new Comparator<Map<String, String>>() {
  520. public int compare(Map<String, String> o1, Map<String, String> o2) {
  521. String x1 = Str.nvl(o1.get("menserialno"));
  522. String x2 = Str.nvl(o2.get("menserialno"));
  523. String s1 = Str.nvl(o1.get("itmserialno"));
  524. String s2 = Str.nvl(o2.get("itmserialno"));
  525. return x1.equals(x2) ? s1.compareTo(s2) : x1.compareTo(x2);
  526. }
  527. });
  528. ls = new MINCopyFormat("{authtype:'authtypeDesc',authshape:'authshapeDesc'}").format(ls);
  529. // ls = Service.lookup(IFormatService.class).formatEnum(ls, "{authtypeDesc:'IM_AUTH_TYPE',authshapeDesc:'IM_AUTH_SHAPE'}");
  530. res.set(IMINBusinessConstant.F_QUERY_RESULT, ls);
  531. // res.set(IMINBusinessConstant.F_QUERY_RESULT, authList);
  532. return res;
  533. }
  534. /**
  535. * 查询当前机构及下一级机构下的角色 信息
  536. *
  537. * @param session
  538. * @return
  539. * @throws MINBusinessException
  540. */
  541. @MINAction(value = ROLE_QUERY_BY_PARENTID)
  542. public MINActionResult roleQueryByParentId(MINSession session) throws MINBusinessException {
  543. MINActionResult res = new MINActionResult();
  544. User user = session.getUser();
  545. String branchId = user.getBranchId();
  546. if (branchId == null || "".equals(branchId)) {
  547. // throw new BusinessCodeException("EBIM0009");
  548. }
  549. Map<String, String> m = new HashMap<String, String>();
  550. m.put("branchId", branchId);
  551. List<Map<String, String>> ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class)
  552. .roleQueryByParentId(m);
  553. res.set(IMINBusinessConstant.F_QUERY_RESULT, ls);
  554. return res;
  555. }
  556. /**
  557. * 查询当前机构下的角色信息
  558. *
  559. * @param session
  560. * @return
  561. * @throws MINBusinessException
  562. */
  563. @MINAction(value = ROLE_QUERY_BY_BRANCHID)
  564. public MINActionResult roleQueryByBranchId(@MINParam(key = "branchId") String branchId, MINSession session)
  565. throws MINBusinessException {
  566. MINActionResult res = new MINActionResult();
  567. ImRoleExample example = new ImRoleExample();
  568. ImRoleExample.Criteria criteria = example.createCriteria();
  569. User user = session.getUser();
  570. if(CommonUtil.isEmpty(branchId)){
  571. criteria.andBranchidEqualTo(user.getBranchId());
  572. }else{
  573. criteria.andBranchidEqualTo(branchId);
  574. }
  575. List<ImRole> ls = Service.lookup(IMINDataBaseService.class).selectByExample(ImRoleMapper.class, example);
  576. res.set(IMINBusinessConstant.F_QUERY_RESULT, ls);
  577. return res;
  578. }
  579. /**
  580. * 查询角色菜单已经设置的权限
  581. *
  582. * @param session
  583. * @return
  584. * @throws MINBusinessException
  585. */
  586. @MINAction(value = ROLE_AUTH_QUERY_BY_ROLEID)
  587. public MINActionResult roleAuthQueryByRoleId(@MINParam(key = "roleId") String roleId,
  588. @MINParam(key = "itemNo") String itemNo, MINSession session) throws MINBusinessException {
  589. MINActionResult res = new MINActionResult();
  590. /*
  591. * ImRoleAuthExample ae = new ImRoleAuthExample();
  592. * ae.createCriteria().andRoleidEqualTo(roleId).andCodeEqualTo(Constant.
  593. * ARTICLE_MODULE_CODE).andItemidEqualTo(itemNo); List<ImRoleAuth> authList =
  594. * Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImRoleAuthMapper.
  595. * class).selectByExample(ae); String[] authArr = new String[authList.size()];
  596. * String str = ""; Map mm = new HashMap<String,String>(); for(int
  597. * i=0;i<authList.size();i++){ authArr[i] = authList.get(i).getValue(); str =
  598. * str+authList.get(i).getValue()+","; // } mm.put("authMod", str); //
  599. * ls.add(mm); res.set(IMINBusinessConstant.F_QUERY_RESULT, authList);
  600. */
  601. return res;
  602. }
  603. /**
  604. * 查询角色需要设置权限的菜单和权限列表
  605. *
  606. * @param roleId
  607. * @param session
  608. * @return
  609. * @throws MINBusinessException
  610. */
  611. @MINAction(value = ROLE_AUTHSET_QUERY)
  612. public MINActionResult roleAuthSetQuery(@MINParam(key = "roleId") String roleId, MINSession session)
  613. throws MINBusinessException {
  614. MINActionResult res = new MINActionResult();
  615. User u = session.getUser();
  616. String branchId = u.getBranchId();
  617. ImBranch br = Service.lookup(IMINDataBaseService.class).selectByPrimaryKey(ImBranchMapper.class, branchId);
  618. Map<String, String> mm = new HashMap<String, String>();
  619. mm.put("roleId", roleId);
  620. // mm.put("btype", br.getType());
  621. List<Map<String, String>> list = Service.lookup(IMINDataBaseService.class).getMybatisMapper(RoleMapper.class)
  622. .roleAuthSetQuery(mm);
  623. List<Map<String, String>> authList = new ArrayList<Map<String, String>>();
  624. String itemId = "";// 缓存菜单Id
  625. String codes = "";
  626. String vals = "";
  627. String itemName = "";
  628. for (Map<String, String> m : list) {
  629. String id = m.get("itemId");
  630. String code = m.get("code");
  631. String val = m.get("val");
  632. String name = m.get("name");
  633. if (itemId.equals(id)) {// 相等则itemId已存在
  634. vals += val + ",";
  635. } else {
  636. if ("".equals(itemId)) {// 第一次
  637. itemId = id;
  638. codes = code;
  639. itemName = name;
  640. vals += val + ",";
  641. } else {
  642. Map<String, String> ms = new HashMap<String, String>();
  643. ms.put("itemNo", itemId);
  644. ms.put("codes", codes);
  645. ms.put("itemName", itemName);
  646. ms.put("vals", vals.substring(0, vals.length() - 1));
  647. authList.add(ms);
  648. itemId = id;
  649. codes = code;
  650. itemName = name;
  651. vals = val + ",";
  652. }
  653. }
  654. }
  655. Map<String, String> ms = new HashMap<String, String>();
  656. ms.put("itemNo", itemId);
  657. ms.put("codes", codes);
  658. ms.put("itemName", itemName);
  659. ms.put("vals", vals.substring(0, vals.length() - 1));
  660. authList.add(ms);
  661. res.set("roleId", roleId);
  662. res.set(IMINBusinessConstant.F_QUERY_RESULT, authList);
  663. return res;
  664. }
  665. /**
  666. * 给角色设置菜单权限
  667. *
  668. * @param roleId
  669. * @param session
  670. * @return
  671. * @throws MINBusinessException
  672. */
  673. @MINAction(value = SET_ITEM_AUTH)
  674. public MINActionResult setItemAuth(@MINParam(key = "roleId") String roleId,
  675. @MINParam(key = "parameStr") String parameStr, MINSession session) throws MINBusinessException {
  676. MINActionResult res = new MINActionResult();
  677. String[] parameArr = parameStr.split("\\|");
  678. for (int i = 0; i < parameArr.length; i++) {
  679. String str = parameArr[i];
  680. String itemId = str.substring(0, str.indexOf(":"));// 菜单编号
  681. String code = str.substring(str.indexOf(":") + 1, str.indexOf("="));// 模块编码
  682. String[] types = str.substring(str.indexOf("=") + 1).split(",");// 模块值
  683. // 添加模块控制
  684. /*
  685. * List<ImRoleAuth> authList = new ArrayList<ImRoleAuth>(); for(int
  686. * j=0;j<types.length;j++){ String authNo =
  687. * Service.lookup(IPublicService.class).getSequence("IM_ROLE_AUTH_NO");
  688. * ImRoleAuth ai = new ImRoleAuth(); ai.setNo(authNo); ai.setCode(code);
  689. * ai.setRoleid(roleId); ai.setType(Constant.MODULE_AUTH_CODE);
  690. * ai.setValue(types[j]); ai.setItemid(itemId); authList.add(ai); }
  691. * ImRoleAuthMapper am =
  692. * Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImRoleAuthMapper.
  693. * class); for(ImRoleAuth roleAuth:authList){ am.insert(roleAuth); }
  694. */
  695. }
  696. String logInfo = "设置角色菜单权限,角色编号" + roleId;
  697. // Service.lookup(ILogService.class).logging(session, logInfo);
  698. return res;
  699. }
  700. /**
  701. * 修改角色菜单权限 菜单模块设置
  702. *
  703. * @param roleId
  704. * @param session
  705. * @return
  706. * @throws MINBusinessException
  707. */
  708. @MINAction(value = MODIFY_ITEM_AUTH)
  709. public MINActionResult modifyItemAuth(@MINParam(key = "roleId") String roleId,
  710. @MINParam(key = "parameStr") String parameStr, MINSession session) throws MINBusinessException {
  711. MINActionResult res = new MINActionResult();
  712. /*
  713. * String[] parameArr = parameStr.split("\\|"); for(int
  714. * i=0;i<parameArr.length;i++){ String str = parameArr[i]; String itemId =
  715. * str.substring(0, str.indexOf(":"));//菜单编号 String code =
  716. * str.substring(str.indexOf(":")+1, str.indexOf("="));//模块编码 String[] types =
  717. * str.substring(str.indexOf("=")+1).split(",");//模块值 //删除原来的菜单权限 List<String>
  718. * sls = Arrays.asList(types); ImRoleAuthExample ae = new ImRoleAuthExample();
  719. * ImRoleAuthExample.Criteria aec = ae.createCriteria();
  720. * aec.andRoleidEqualTo(roleId).andCodeEqualTo(code).andItemidEqualTo(itemId).
  721. * andTypeEqualTo(Constant.MODULE_AUTH_CODE);
  722. *
  723. * Service.lookup(IMINDataBaseService.class).deleteByExample(ImRoleAuthMapper.
  724. * class, ae); //添加模块控制 List<ImRoleAuth> authList = new ArrayList<ImRoleAuth>();
  725. * for(int j=0;j<types.length;j++){ String authNo =
  726. * Service.lookup(IPublicService.class).getSequence("IM_ROLE_AUTH_NO");
  727. * ImRoleAuth ai = new ImRoleAuth(); ai.setNo(authNo); ai.setCode(code);
  728. * ai.setRoleid(roleId); ai.setType(Constant.MODULE_AUTH_CODE);
  729. * ai.setValue(types[j]); ai.setItemid(itemId); authList.add(ai); }
  730. * ImRoleAuthMapper am =
  731. * Service.lookup(IMINDataBaseService.class).getMybatisMapper(ImRoleAuthMapper.
  732. * class); for(ImRoleAuth roleAuth:authList){ am.insert(roleAuth); } }
  733. */
  734. String logInfo = "修改角色菜单权限:" + roleId;
  735. // Service.lookup(ILogService.class).logging(session, logInfo);
  736. return res;
  737. }
  738. /**
  739. * 查询角色对应的模块权限
  740. *
  741. * @param roleId
  742. * @param session
  743. * @return
  744. * @throws MINBusinessException
  745. */
  746. @MINAction(value = GET_ROLE_MODE)
  747. public MINActionResult getRoleModule(@MINParam(key = "roleId") String roleId,
  748. @MINParam(key = "MIN_context_itemId") String itemId, @MINParam(key = "businessCode") String businessCode,
  749. MINSession session) throws MINBusinessException {
  750. MINActionResult res = new MINActionResult();
  751. /*
  752. * User user = session.getUser(); roleId = user.getRoleId();
  753. *
  754. * String sessionItemId = (String)session.get("sessionItemId");
  755. *
  756. * ImRoleAuthExample example = new ImRoleAuthExample();
  757. *
  758. * ImRoleAuthExample.Criteria criteria = example.createCriteria();
  759. * criteria.andRoleidEqualTo(roleId);
  760. * criteria.andCodeEqualTo(Constant.ARTICLE_MODULE_CODE);
  761. * criteria.andItemidEqualTo(sessionItemId);
  762. * example.setOrderByClause("IRA_VALUE");
  763. *
  764. * List<ImRoleAuth> list = Service.lookup(IMINDataBaseService.class)
  765. * .selectByExample(ImRoleAuthMapper.class, example); list = new
  766. * MINCopyFormat("{value:'moduleDesc'}").format(list); list =
  767. * Service.lookup(IFormatService.class).formatEnum(list,
  768. * "{moduleDesc:'ARTICLE_MODULE'}");//状态
  769. * res.set(IMINBusinessConstant.F_QUERY_RESULT, list);
  770. */
  771. return res;
  772. }
  773. /**
  774. * 查询所有部门
  775. *
  776. * @param session
  777. * @return
  778. * @throws MINBusinessException
  779. */
  780. @MINAction(value = "roleQueryBranch")
  781. public MINActionResult roleQueryBranch(MINSession session) throws MINBusinessException {
  782. MINActionResult res = new MINActionResult();
  783. ImBranchExample example = new ImBranchExample();
  784. ImBranchExample.Criteria criteria = example.createCriteria();
  785. User user = session.getUser();
  786. criteria.andSttNotEqualTo(Constant.DEPT_STT_DEL);
  787. if(!user.getBranchId().equals(Constant.DEFAULT_INSTITUTIONS)){
  788. criteria.andIdEqualTo(user.getBranchId());
  789. }
  790. List<ImBranch> ls = Service.lookup(IMINDataBaseService.class).selectByExample(ImBranchMapper.class, example);
  791. ImBranchExample exampleb = new ImBranchExample();
  792. ImBranchExample.Criteria criteriab = exampleb.createCriteria();
  793. criteria.andSttNotEqualTo(Constant.DEPT_STT_DEL);
  794. if(!user.getBranchId().equals(Constant.DEFAULT_INSTITUTIONS)){
  795. criteriab.andParentidEqualTo(user.getBranchId());
  796. }
  797. List<ImBranch> lsb = Service.lookup(IMINDataBaseService.class).selectByExample(ImBranchMapper.class, exampleb);
  798. ls.addAll(lsb);
  799. res.set(IMINBusinessConstant.F_QUERY_RESULT, ls);
  800. return res;
  801. }
  802. }