/** * 显示用户列表 * * @param user * @return */ @RequestMapping public ModelAndView list(HttpServletRequest request, User user) { if (user.getLastLoginEnd() != null) { Calendar cal = Calendar.getInstance(); cal.setTime(user.getLastLoginEnd()); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); user.setLastLoginEnd(cal.getTime()); // Date d = user.getLastLoginEnd(); // d.setHours(23); // d.setMinutes(59); // d.setSeconds(59); // user.setLastLoginEnd(d); } String loginname = user.getLoginname(); if (!"".equals(loginname) && loginname != null) { user.setLoginname(loginname.trim()); } List<User> userList = userService.listPageUser(user); List<Role> roleList = roleService.listAllRoles(); ModelAndView mv = new ModelAndView(); mv.setViewName("user/users"); mv.addObject("userList", userList); mv.addObject("roleList", roleList); mv.addObject("user", user); this.insertLog(request, "查看用户列表"); return mv; }
/** * 保存报表权限页面 * * @param roleId * @param menuIds * @param out */ @RequestMapping(value = "/authsaveReport") public void saveAuthReport( HttpServletRequest request, @RequestParam int userId, @RequestParam String reportIds, HttpServletResponse response) throws IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); BigInteger reportRights = RightsHelper.sumRights(Tools.str2StrArray(reportIds)); User user = userService.getUserById(userId); if (user == null) { this.sendMsgToClient(isFailed, response); this.logger.warn("修改用户报表权限失败,user为null"); return; } user.setReportRights(reportRights.toString()); try { userService.updateReportRights(user); this.insertLog(request, "修改用户" + user.getLoginname() + "报表权限"); out.write("success"); } catch (Exception e) { e.printStackTrace(); this.logger.error("修改用户报表权限失败:" + e.getMessage(), e); out.write("failed"); } out.close(); }
/** * 保存用户权限 * * @param userId * @param menuIds * @param out */ @RequestMapping(value = "/auth/save") public void saveAuth( @RequestParam int userId, @RequestParam String menuIds, HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); User user = userService.getUserById(userId); if (user != null) { BigInteger rights = RightsHelper.sumRights(Tools.str2StrArray(menuIds)); user.setRights(rights.toString()); try { userService.updateUserRights(user); this.insertLog(request, "修改用户权限"); out.write("success"); } catch (Exception e) { e.printStackTrace(); this.logger.error("修改用户权限失败:" + e.getMessage(), e); out.write("failed"); } } else { out.write("failed"); } out.close(); }
/** * 请求报表权限页面 * * @param roleId * @param model * @return */ @RequestMapping(value = "/authReport{userId}") public String authReport(@PathVariable int userId, Model model) { List<ReportDesign> reportList = reportService.listAllReport(); User user = userService.getUserById(userId); // 获得用户的角色权限 if (user != null) { int roleId = user.getRoleId(); Role role = roleService.getRoleById(roleId); String roleRights = role.getReportRights(); String reportRights = user.getReportRights(); if (reportList != null && reportList.size() > 0 && Tools.notEmpty(reportRights)) { reportChecked(reportList, reportRights); // 角色权限 // roleReportChecked(reportList, roleRights); } } // if (Tools.notEmpty(reportRights)) { // reportChecked(reportList, reportRights); // } JSONArray arr = JSONArray.fromObject(reportList); String json = arr.toString(); json = json.replaceAll("reportId", "id") .replaceAll("reportName", "name") .replaceAll("subReport", "nodes") .replaceAll("hasReport", "checked"); model.addAttribute("zTreeNodes", json); model.addAttribute("userId", userId); return "user/authorizationReport"; }
/** * 请求用户授权页面 * * @param userId * @param model * @return */ @RequestMapping(value = "/auth{userId}") public String auth(@PathVariable int userId, Model model) { List<Menu> menuList = menuService.listAllMenu(); User user = userService.getUserById(userId); String userRights = ""; if (user != null) { userRights = user.getRights(); } if (Tools.notEmpty(userRights) && menuList != null && menuList.size() > 0) { for (Menu menu : menuList) { menu.setHasMenu(RightsHelper.testRights(userRights, menu.getMenuId())); if (menu.isHasMenu()) { List<Menu> subRightsList = menu.getSubMenu(); for (Menu sub : subRightsList) { sub.setHasMenu(RightsHelper.testRights(userRights, sub.getMenuId())); } } } } JSONArray arr = JSONArray.fromObject(menuList); String json = arr.toString(); json = json.replaceAll("menuId", "id") .replaceAll("menuName", "name") .replaceAll("subMenu", "nodes") .replaceAll("hasMenu", "checked"); model.addAttribute("zTreeNodes", json); model.addAttribute("userId", userId); return "user/authorization"; }
/** * 请求经纬仪权限页面 * * @param roleId * @param model * @return */ @RequestMapping(value = "/authDwpas{userId}") public ModelAndView authDwpas(@PathVariable int userId, Model model) { List<DwpasCTemplateInfo> dwpasCTemplateInfoList = dwpasCTemplateInfoService.listAllTemplateInfo(); User user = userService.getUserById(userId); String[] dwpasRights = user.getDwpasRights().split(","); ModelAndView mv = new ModelAndView(); mv.setViewName("/user/authorizationDwpas2"); mv.addObject("dwpasCTemplateInfo", dwpasCTemplateInfoList); mv.addObject("dwpasRights", dwpasRights); mv.addObject("user", user); mv.addObject("userId", userId); return mv; }
/** * 保存经纬仪权限页面 * * @param roleId * @param menuIds * @param out */ @RequestMapping(value = "/saveAuthDwpas", method = RequestMethod.POST) public ModelAndView saveAuthDwpas(HttpServletRequest request, HttpServletResponse response) { ModelAndView mv = new ModelAndView(); Integer userId = Integer.parseInt(request.getParameter("userId")); String[] templateIds = request.getParameterValues("templateIds"); String dwpasRights = "0"; if (templateIds != null && templateIds.length > 0) { for (int i = 0; i < templateIds.length; i++) { if (i == 0) { dwpasRights = templateIds[i]; } else { dwpasRights = dwpasRights + "," + templateIds[i]; } } } User user = new User(); user = userService.getUserById(userId); user.setDwpasRights(dwpasRights); try { userService.updateDwpasRights(user); this.insertLog(request, "修改用户" + user.getLoginname() + "经纬仪权限"); mv.addObject("msg", "success"); } catch (Exception e) { e.printStackTrace(); this.logger.error("保存经纬仪权限失败:" + e.getMessage(), e); mv.addObject("msg", "failed"); } mv.addObject("userId", userId); mv.setViewName(SUCCESS_ACTION); return mv; }
/** * 自服务报表权限页面 hgt date:2012-05-07 * * @param roleId * @param model * @return */ @RequestMapping(value = "/authSelfReport{userId}") public String authSelfReport( @PathVariable int userId, HttpServletRequest request, HttpServletResponse response, Model model) { List<SelfApply> selfApplyList = selfApplyService.querySelfApplyByUsrID(userId); User user = userService.getUserById(userId); this.insertLog(request, "查看用户: " + user.getUsername() + " 的自服务报表权限"); // 获得用户的角色权限 // int roleId=user.getRoleId(); // Role role = roleService.getRoleById(roleId); // String roleRights = role.getReportRights(); // String selfRights = user.getSelfRights(); // if(selfApplyList != null && selfApplyList.size()>0 && // Tools.notEmpty(selfRights)){ // selfApplyChecked(selfApplyList, selfRights,roleRights); // 角色权限 // roleReportChecked(reportList, roleRights); // } // if (Tools.notEmpty(reportRights)) { // reportChecked(reportList, reportRights); // } String json = ""; if (selfApplyList != null && !selfApplyList.isEmpty()) { JSONArray arr = JSONArray.fromObject(selfApplyList); json = arr.toString(); json = json.replaceAll("reportId", "id") .replaceAll("reportName", "name") .replaceAll("hasRights", "checked"); } model.addAttribute("zTreeNodes", json); model.addAttribute("userId", userId); return "user/authorizationSelfApply"; }
/** * 保存瞭望塔限页面 * * @param roleId * @param menuIds * @param out */ @RequestMapping(value = "/saveAuthDwmis", method = RequestMethod.POST) public ModelAndView saveAuthDwmis(HttpServletRequest request, HttpServletResponse response) { ModelAndView mv = new ModelAndView(); String userIdString = request.getParameter("userId"); if (com.infosmart.util.StringUtils.notNullAndSpace(userIdString)) { Integer userId = Integer.parseInt(userIdString); String[] templateIds = request.getParameterValues("templateIds"); User user = new User(); user = userService.getUserById(userId); if (templateIds != null && templateIds.toString() != "") { for (int i = 0; i < templateIds.length; i++) { user.setUserId(userId); user.setDwmisRights(templateIds[i]); try { userService.updateDwmisRights(user); this.insertLog(request, "修改用户" + user.getLoginname() + "瞭望塔权限"); mv.addObject("msg", "success"); } catch (Exception e) { e.printStackTrace(); this.logger.error("保存瞭望塔权限失败:" + e.getMessage(), e); mv.addObject("msg", "failed"); } } } else { try { user.setUserId(userId); user.setDwpasRights("0"); userService.updateDwmisRights(user); this.insertLog(request, "修改用户" + user.getLoginname() + "瞭望塔权限"); mv.addObject("msg", "success"); } catch (Exception e) { e.printStackTrace(); this.logger.error("保存瞭望塔权限失败:" + e.getMessage(), e); mv.addObject("msg", "failed"); } } mv.addObject("userId", userId); mv.setViewName(SUCCESS_ACTION); return mv; } else { this.logger.error("保存瞭望塔权限失败userId为空"); mv.addObject("msg", "failed"); return mv; } }
/** * 保存用户信息 * * @param user * @return */ @RequestMapping(value = "/save", method = RequestMethod.POST) public ModelAndView saveUser(HttpServletRequest request, User user) { ModelAndView mv = new ModelAndView(); mv.setViewName("common/save_result"); if (user == null) { this.logger.warn("保存用户信息时传递的User对象为null"); mv.addObject("msg", isFailed); return mv; } MD5 md = new MD5(); this.logger.info("password:"******""; if (user.getPassword() != null && user.getPassword() != "") { passWord = md.getkeyBeanofStr(user.getPassword()); } user.setPassword(passWord); if (user.getUserId() == null || user.getUserId().intValue() == 0) { if (userService.insertUser(user) == false) { mv.addObject("msg", "failed"); } else { mv.addObject("msg", "success"); this.insertLog(request, "添加用户" + user.getLoginname()); } } else { try { userService.updateUserBaseInfo(user); this.insertLog(request, "修改用户" + user.getLoginname() + "信息"); mv.addObject("msg", "success"); } catch (Exception e) { e.printStackTrace(); this.logger.error("编辑用户保存失败:" + e.getMessage(), e); mv.addObject("msg", "failed"); } } return mv; }
/** * 模板权限 * * @param request * @param response * @return */ @RequestMapping("/managePopedom") public ModelAndView managePopedom(HttpServletRequest request, HttpServletResponse response) { String tid = request.getParameter("templateId"); String[] roleIds = request.getParameterValues("roleIds"); String[] userIds = request.getParameterValues("userIds"); List<Role> rolelist = roleService.listAllRoles(); List<User> userlist = userService.listAllUser(); boolean isSuccess = true; if (roleIds != null && roleIds.toString() != "") { for (int i = 0; i < roleIds.length; i++) { if (rolelist != null && rolelist.size() > 0) { for (Role r : rolelist) { if (r.getRoleId().intValue() == Integer.parseInt(roleIds[i])) { rolelist.remove(r); break; } } } Role role = new Role(); role.setRoleId(Integer.parseInt(roleIds[i])); role.setDwmisRights(tid); try { dwmisPopedomService.updateRoleTemplate(role); } catch (Exception e) { e.printStackTrace(); this.logger.error(e.getMessage(), e); isSuccess = false; break; } role = roleService.getRoleById(role.getRoleId()); this.insertLog(request, "更改角色" + role.getRoleName() + "瞭望台权限"); } if (!isSuccess) { this.logger.warn("保存角色的瞭望台权限失败"); ModelAndView mv = new ModelAndView(); mv.addObject("msg", this.isFailed); mv.setViewName(SUCCESS_ACTION); return mv; } } if (userIds != null && userIds.toString() != "") { for (int i = 0; i < userIds.length; i++) { if (userlist != null && userlist.size() > 0) { for (User u : userlist) { if (u.getUserId().intValue() == Integer.parseInt(userIds[i])) { userlist.remove(u); break; } } } User user = new User(); user.setUserId(Integer.parseInt(userIds[i])); user.setDwmisRights(tid); try { dwmisPopedomService.updateUserTemplate(user); } catch (Exception e) { e.printStackTrace(); this.logger.error(e.getMessage(), e); isSuccess = false; break; } user = userService.getUserById(user.getUserId()); this.insertLog(request, "更改用户" + user.getUsername() + "瞭望台权限"); } if (!isSuccess) { this.logger.warn("保存用户的瞭望台权限失败"); ModelAndView mv = new ModelAndView(); mv.addObject("msg", this.isFailed); mv.setViewName(SUCCESS_ACTION); return mv; } } if (userlist != null && userlist.size() > 0) { for (User u : userlist) { this.logger.info("设置当前用户没有权限:" + u.getLoginname()); this.logger.info("设置当前用户没有权限,原来的模板ID:" + tid); // 没有权限 u.setDwmisRights(tid); try { dwmisPopedomService.updateUserNoTemplate(u); } catch (Exception e) { e.printStackTrace(); this.logger.error(e.getMessage(), e); isSuccess = false; break; } this.insertLog(request, "更改用户" + u.getUsername() + "瞭望台权限"); } if (!isSuccess) { this.logger.warn("保存角色的瞭望台权限失败"); ModelAndView mv = new ModelAndView(); mv.addObject("msg", this.isFailed); mv.setViewName(SUCCESS_ACTION); return mv; } } if (rolelist != null && rolelist.size() > 0) { for (Role r : rolelist) { r.setDwmisRights(tid); try { dwmisPopedomService.updateRoleNpTemplate(r); } catch (Exception e) { e.printStackTrace(); this.logger.error(e.getMessage(), e); isSuccess = false; break; } this.insertLog(request, "更改角色" + r.getRoleName() + "瞭望台权限"); } if (!isSuccess) { this.logger.warn("保存用户的瞭望台权限失败"); ModelAndView mv = new ModelAndView(); mv.addObject("msg", this.isFailed); mv.setViewName(SUCCESS_ACTION); return mv; } } ModelAndView mv = new ModelAndView(); mv.addObject("msg", "success"); mv.setViewName(SUCCESS_ACTION); return mv; }