Exemple #1
0
  /**
   * 保存报表权限页面
   *
   * @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();
  }
Exemple #2
0
 /**
  * 请求报表权限页面
  *
  * @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";
 }
Exemple #3
0
  /**
   * 保存用户权限
   *
   * @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();
  }
Exemple #4
0
 /**
  * 请求用户授权页面
  *
  * @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";
 }
Exemple #5
0
 /**
  * 递归选中报表权限
  *
  * @param reportList
  * @param reportRights
  * @return
  */
 private List<ReportDesign> reportChecked(List<ReportDesign> reportList, String reportRights) {
   if (reportList != null && reportList.size() > 0 && Tools.notEmpty(reportRights)) {
     for (ReportDesign report : reportList) {
       report.setHasReport(RightsHelper.testRights(reportRights, report.getReportId()));
       if (null != report.getSubReport()) {
         reportChecked(report.getSubReport(), reportRights);
       }
     }
   }
   return reportList;
 }