@Test public void getUserMenu() { SysUser admin = userService.findByUsername("admin"); String uuid = admin.getUuid(); List<MenuTreeDto> menus = menuService.getUserMenu(uuid); System.out.println(menus); }
public List<MenuTreeDto> getUserMenu(String uuid){ Assert.notNull(uuid,"uuid is not null"); List<SysRole> roles = roleService.selectByUuid(uuid); boolean isAdmin = roles.stream().anyMatch(role -> "ROLE_ADMIN".equals(role.getRoleKey())); if(isAdmin) { return getMenuTreeEnabled(); } List<SysPermission> permissions = permissionService.selectByUuidAndType(uuid, TYPE_MENU); List<Menu> collect = permissions.stream().map(this::toMenu).collect(Collectors.toList()); return buildMenuTree(collect,-1); }
MenuService { public List<MenuTreeDto> getUserMenu(String uuid){ Assert.notNull(uuid,"uuid is not null"); List<SysRole> roles = roleService.selectByUuid(uuid); boolean isAdmin = roles.stream().anyMatch(role -> "ROLE_ADMIN".equals(role.getRoleKey())); if(isAdmin) { return getMenuTreeEnabled(); } List<SysPermission> permissions = permissionService.selectByUuidAndType(uuid, TYPE_MENU); List<Menu> collect = permissions.stream().map(this::toMenu).collect(Collectors.toList()); return buildMenuTree(collect,-1); } }
MenuService { public List<MenuTreeDto> getUserMenu(String uuid){ Assert.notNull(uuid,"uuid is not null"); List<SysRole> roles = roleService.selectByUuid(uuid); boolean isAdmin = roles.stream().anyMatch(role -> "ROLE_ADMIN".equals(role.getRoleKey())); if(isAdmin) { return getMenuTreeEnabled(); } List<SysPermission> permissions = permissionService.selectByUuidAndType(uuid, TYPE_MENU); List<Menu> collect = permissions.stream().map(this::toMenu).collect(Collectors.toList()); return buildMenuTree(collect,-1); }  }
MenuService { public List<MenuTreeDto> getUserMenu(String uuid){ Assert.notNull(uuid,"uuid is not null"); List<SysRole> roles = roleService.selectByUuid(uuid); boolean isAdmin = roles.stream().anyMatch(role -> "ROLE_ADMIN".equals(role.getRoleKey())); if(isAdmin) { return getMenuTreeEnabled(); } List<SysPermission> permissions = permissionService.selectByUuidAndType(uuid, TYPE_MENU); List<Menu> collect = permissions.stream().map(this::toMenu).collect(Collectors.toList()); return buildMenuTree(collect,-1); }  List<MenuTreeDto> getMenuTree(); List<MenuTreeDto> getMenuTreeEnabled(); List<MenuTreeDto> getUserMenu(String uuid); @Transactional(rollbackFor = Exception.class) void addMenu(Menu menu); @Transactional(rollbackFor = Exception.class) void updateMenu(Menu menu); @Transactional(rollbackFor = Exception.class) boolean deleteById(Integer id); boolean hasChildren(Integer menuId); Menu getMenu(Integer id); }
MenuService { public List<MenuTreeDto> getUserMenu(String uuid){ Assert.notNull(uuid,"uuid is not null"); List<SysRole> roles = roleService.selectByUuid(uuid); boolean isAdmin = roles.stream().anyMatch(role -> "ROLE_ADMIN".equals(role.getRoleKey())); if(isAdmin) { return getMenuTreeEnabled(); } List<SysPermission> permissions = permissionService.selectByUuidAndType(uuid, TYPE_MENU); List<Menu> collect = permissions.stream().map(this::toMenu).collect(Collectors.toList()); return buildMenuTree(collect,-1); }  List<MenuTreeDto> getMenuTree(); List<MenuTreeDto> getMenuTreeEnabled(); List<MenuTreeDto> getUserMenu(String uuid); @Transactional(rollbackFor = Exception.class) void addMenu(Menu menu); @Transactional(rollbackFor = Exception.class) void updateMenu(Menu menu); @Transactional(rollbackFor = Exception.class) boolean deleteById(Integer id); boolean hasChildren(Integer menuId); Menu getMenu(Integer id);  }