/** * @param userId * @return @Description:查询所有角色。标记用户已经拥有的角色 */ @ResponseBody @RequestMapping("/getRoles") @Permission(systemSn = "privilege", moduleSn = "user", value = PermissionConatant.R) public String getRoles(String userId, Role role, Query query) { PagerModel<Role> pm = null; List<Role> roles = null; List<Role> uroles = null; try { pm = this.roleService.getPagerModel(role, query); if (pm != null && CollectionUtils.isNotEmpty(pm.getDatas())) { roles = pm.getDatas(); uroles = this.userRoleService.getRolesByUserId(userId); if (uroles != null && uroles.size() > 0) { for (Role ur : uroles) { for (Role r : roles) { if (ur.getId().equals(r.getId())) { r.setChecked(true); break; } } } } } } catch (Exception e) { e.printStackTrace(); logger.debug("UserController-getRoles:" + e.getMessage()); } return JsonUtils.toJson(roles); }
@Override public PagerModel<User> getPagerModel(User user, Query query) throws Exception { PagerModel<User> pm = userDao.getPagerModel(user, query); for (User ur : pm.getDatas()) { List<Role> list = this.userRoleDao.getRolesByUserId(ur.getId()); if (list != null && list.size() > 0) { StringBuffer s = new StringBuffer(); for (int i = 0, len = list.size(); i < len; i++) { if (i != 0) { s.append(","); } s.append(list.get(i).getName()); } ur.setRoles(s.toString()); } } return pm; }