/* * 管理员查看所有角色 */ @Action(value = "/role/getAllRole") public String getAllRoles() { result = new JSONObject(); if (page == null) page = 1 + ""; if (rows == null) rows = 20 + ""; List<Role> roles = roleService.pageList( (Integer.parseInt(page) - 1) * Integer.parseInt(rows), Integer.parseInt(rows), -1); JSONArray array = new JSONArray(); Entity2JSONUtil.role2JSON(roles, array); result.put("total", roleService.count(-1)); result.put("rows", array); return "json"; }
/* * ajax修改角色 * 返回json */ @Action( value = "/role/editRole", interceptorRefs = {@InterceptorRef("roleInterceptor")}, results = { @Result(name = "noLogin", type = "chain", location = "loginErrorAjax"), @Result(name = "noRoleAuthority", type = "chain", location = "noAuthorityAjax") }) public String editRole() throws Exception { result = new JSONObject(); role = new Role(false); if (roleName != null && roleId != null) { role.setRoleId(Integer.parseInt(roleId)); role.setRoleName(roleName); if (roleDescription != null) { role.setRoleDescription(roleDescription); } role.setRoleStatus(roleState); StringUtil.String2RoleAuthority(roleAuthority, role); roleService.updateRole(role); result.put("result", 1); if (role.getRoleStatus() == 1) { request.getServletContext().setAttribute("role_" + roleId, role); } } else { result.put("result", 2); } return "json"; }
/* * ajax删除数据 */ @Action(value = "role_delRole") public String delRole() { result = new JSONObject(); if (roleId != null) { result.put("nu", roleService.deleteRole(roleId)); String[] ids = roleId.split(","); for (String str : ids) { request.getServletContext().removeAttribute("role_" + str); } result.put("result", 1); } return "json"; }
/* * 获取角色菜单 */ @Action( value = "/role/getUserRole", results = { @Result( name = "array", type = "json", params = {"root", "array"}) }) public String getUserRoles() { array = new JSONArray(); List<Role> roles = roleService.findAllListForBox((byte) -1); Entity2JSONUtil.role2JSON1(roles, array); return "array"; }
@Action( value = "role_getRoles", results = { @Result(name = "success", location = "WEB-INF/backManage/back.jsp"), @Result( name = "noRole", location = "user_changeRole", params = {"user", "user"}) }) public String getRoles() { role = roleService.find(user.getRoleId()); if (role == null) { return "noRole"; // 该用户的角色不存在,将用户的角色修改为1 } else { if (role.getRoleStatus() == 1) { application.setAttribute("role_" + role.getRoleId(), role); // 该角色存在且状态正常,存入application } else { role = (Role) application.getAttribute("role_1"); // 该角色存在且状态为冻结,转为游客角色 } } return SUCCESS; }