예제 #1
0
  /**
   * 保存瞭望塔限页面
   *
   * @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 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;
 }