码迷,mamicode.com
首页 > 移动开发 > 详细

DozerBeanMapper 工具权限管理递归

时间:2019-01-26 13:21:35      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:list()   list   getmenu   管理   equals   col   child   submenu   ryu   

  @GetMapping("/menu/tree")
  @Timed
  public ResponseEntity<List<MenuInfo>> getMenuTree() {

      List<MenuInfo> list = new ArrayList();

      HashMap<String,Object> result = new  HashMap<String,Object>();

      List<MenuEntity> menulist = menuMapper.getAll();
      if(menulist!=null) {
          DozerBeanMapper mapper = new DozerBeanMapper();
          for (MenuEntity menu : menulist) {
              if(StringUtils.isEmpty(menu.getParentMenuId())) {
                  MenuInfo mi = (MenuInfo) mapper.map(menu, MenuInfo.class);
                  list.add(mi);
                  addSubMenu(mi, menulist);
              }
          }
      }

      HttpHeaders httpHeaders = new HttpHeaders();
      return new ResponseEntity<>(list, httpHeaders, HttpStatus.OK);
  }

  private void addSubMenu(MenuInfo mi,List<MenuEntity> menulist){
      if(menulist!=null&& menulist.size()>0){
          List<MenuEntity> submenus = menulist.stream().filter(s->s.getParentMenuId()!=null && s.getParentMenuId().equals(mi.getMenuId())).collect(Collectors.toList());
          if(submenus!=null &&submenus.size()>0){
              DozerBeanMapper mapper = new DozerBeanMapper();
              mi.subMenu = new ArrayList();
              for (MenuEntity childmenu : submenus){
                  MenuInfo child = (MenuInfo) mapper.map(childmenu, MenuInfo.class);
                  mi.subMenu.add(child);

                  addSubMenu(child, menulist);
              }
          }
      }
  }

//获取三层页面
  @GetMapping("/menu/getmenulist")
  @Timed
  public JsonResult queryUserRole(){
      List<MenuInfo> list = new ArrayList();
      UserEntity user = userService.getUserWithAuthorities();
      List<MenuEntity> menulist = menuMapper.getThreeMenuByUserId(user.getUserId());;
      if(menulist!=null) {
          DozerBeanMapper mapper = new DozerBeanMapper();
          for (MenuEntity menu : menulist) {
              if(StringUtils.isEmpty(menu.getParentMenuId())) {
                  MenuInfo mi = (MenuInfo) mapper.map(menu, MenuInfo.class);
                  list.add(mi);
                  addSubMenu(mi, menulist);
              }
          }
      }
      return new JsonResult(list,true,"0","");
  }

  

DozerBeanMapper 工具权限管理递归

标签:list()   list   getmenu   管理   equals   col   child   submenu   ryu   

原文地址:https://www.cnblogs.com/yijiushengjing/p/10323091.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!