Ejemplo n.º 1
0
 /**
  * 树 编辑操作
  *
  * @param model
  * @return
  */
 @RequestMapping(value = "/editTree", produces = "application/json", method = RequestMethod.POST)
 public @ResponseBody ResponseEntity<String> editTree(
     @ModelAttribute SysMenu sysMenu, HttpServletResponse response, HttpServletRequest request) {
   JSONObject result = new JSONObject();
   User loginUser = (User) request.getSession().getAttribute(Constants.CURRENT_USER);
   String msg = "";
   try {
     Map<String, Object> params = new HashMap<String, Object>();
     params.put("name", sysMenu.getName());
     params.put("parent_fk", sysMenu.getParent_fk());
     params.put("level", sysMenu.getLevel());
     params.put("sorter", sysMenu.getSorter());
     params.put("updater_fk", loginUser.getId());
     params.put("id", sysMenu.getId());
     sysMenuService.update(params);
     msg = ResultEntity.KW_STATUS_SUCCESS;
   } catch (ServiceException e) {
     msg = ResultEntity.KW_STATUS_FAIL;
     logger.error(e);
   }
   result.put("msg", msg);
   HttpHeaders headers = new HttpHeaders();
   headers.setContentType(MediaType.APPLICATION_JSON);
   response.setCharacterEncoding("UTF-8");
   return new ResponseEntity<String>(result.toString(), headers, HttpStatus.OK);
 }
Ejemplo n.º 2
0
 /**
  * 增加树节点操作
  *
  * @param model
  * @return
  */
 @RequestMapping(value = "/addTree", produces = "application/json", method = RequestMethod.POST)
 public @ResponseBody ResponseEntity<String> addTree(
     @ModelAttribute SysMenu sysMenu, HttpServletResponse response, HttpServletRequest request) {
   JSONObject result = new JSONObject();
   User loginUser = (User) request.getSession().getAttribute(Constants.CURRENT_USER);
   sysMenu.setUpdater_fk(loginUser.getId());
   sysMenu.setCreator_fk(loginUser.getId());
   String msg = "";
   try {
     sysMenuService.insert(sysMenu);
     msg = ResultEntity.KW_STATUS_SUCCESS;
   } catch (ServiceException e) {
     msg = ResultEntity.KW_STATUS_FAIL;
     logger.error(e);
   }
   result.put("msg", msg);
   HttpHeaders headers = new HttpHeaders();
   headers.setContentType(MediaType.APPLICATION_JSON);
   response.setCharacterEncoding("UTF-8");
   return new ResponseEntity<String>(result.toString(), headers, HttpStatus.OK);
 }
Ejemplo n.º 3
0
  /**
   * 左侧菜单展示
   *
   * @param response
   * @param request
   * @return
   */
  @RequestMapping(value = "/showMenus", produces = "application/json", method = RequestMethod.POST)
  public @ResponseBody ResponseEntity<String> showMenu(
      HttpServletResponse response, HttpServletRequest request) {
    JSONObject result = new JSONObject();
    String msg = "";
    String path = request.getContextPath();
    StringBuffer buffer = new StringBuffer();
    String content = "";
    try {
      Subject subject = SecurityUtils.getSubject();
      Map<String, Object> params = new HashMap<String, Object>();
      params.put("valid", 1);
      List<SysMenu> menuList = sysMenuService.listAll(params);
      String item =
          "<li id=\"%s\" class='menu-item'><a href='"
              + path
              + "%s' ><i class=\"%s\"></i><span class=\"menu-text\"> %s </span></a></li>";
      String folder =
          "<li id=\"%s\"><a href=\"#\" class=\"dropdown-toggle\"><i class=\"%s\"></i><span class=\"menu-text\"> %s</span><b class=\"arrow icon-angle-down\"></b></a>";
      String subitem =
          "<li id=\"%s\"><a href='"
              + path
              + "%s'><i class=\"icon-double-angle-right\"></i> %s</a></li>";
      if (menuList != null && menuList.size() > 0) {
        int size = menuList.size();
        for (int i = 0; i < size; i++) {
          SysMenu menu_1 = menuList.get(i);
          String level_1 = menu_1.getLevel();
          String id_1 = menu_1.getId();
          String permission_fk = menu_1.getPermission_fk();
          if (!checkMenuPermission(subject, permission_fk)) {
            continue;
          }
          if ("1".equals(level_1)) {
            String url = menu_1.getUrl();
            StringBuffer childrens = new StringBuffer();
            for (int j = 0; j < size; j++) {
              SysMenu menu_2 = menuList.get(j);
              String level_2 = menu_2.getLevel();
              if ("2".equals(level_2) && id_1.equals(menu_2.getParent_fk())) {
                String permission_fk_2 = menu_2.getPermission_fk();
                if (!checkMenuPermission(subject, permission_fk_2)) {
                  continue;
                }
                childrens.append(
                    String.format(
                        subitem, menu_2.getActiveId(), menu_2.getUrl(), menu_2.getName()));
              }
            }

            if (url != null && !"".equals(url)) {
              buffer.append(
                  String.format(
                      item,
                      menu_1.getActiveId(),
                      menu_1.getUrl(),
                      menu_1.getStyle(),
                      menu_1.getName()));
            } else {
              buffer
                  .append(
                      String.format(
                          folder, menu_1.getActiveId(), menu_1.getStyle(), menu_1.getName()))
                  .append("<ul class=\"submenu\">")
                  .append(childrens.toString())
                  .append("</ul></li>");
            }
          }
        }
      }
      User loginUser = (User) request.getSession().getAttribute(Constants.CURRENT_USER);
      String menuManager =
          "<li id=\"sys_menu\" class='menu-item'><a href='"
              + path
              + "/menu/toListMenus' ><i class=\"icon-cog\"></i><span class=\"menu-text\"> 菜单管理 </span></a></li>";
      if ("admin".equals(loginUser.getUsername())) {
        buffer.append(menuManager);
      }
      content = buffer.toString();
      msg = ResultEntity.KW_STATUS_SUCCESS;
    } catch (ServiceException e) {
      msg = ResultEntity.KW_STATUS_FAIL;
      logger.error(e);
    }
    result.put("msg", msg);
    result.put("content", content);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    response.setCharacterEncoding("UTF-8");
    return new ResponseEntity<String>(result.toString(), headers, HttpStatus.OK);
  }