Search in sources :

Example 1 with UserMenuChildrenDto

use of com.paascloud.provider.model.dto.menu.UserMenuChildrenDto in project paascloud-master by paascloud.

the class UacUserServiceImpl method queryUserMenuDtoData.

@Override
@Transactional(readOnly = true, rollbackFor = Exception.class)
public List<UserMenuDto> queryUserMenuDtoData(LoginAuthDto authResDto) {
    // 返回的结果集
    List<UserMenuDto> list = Lists.newArrayList();
    // 该用户下所有的菜单集合
    List<MenuVo> menuList;
    Long userId = authResDto.getUserId();
    List<Long> ownerMenuIdList = Lists.newArrayList();
    Preconditions.checkArgument(!PubUtils.isNull(authResDto, userId), "无访问权限");
    // 查询该用户下所有的菜单Id集合
    UacUserMenu query = new UacUserMenu();
    query.setUserId(userId);
    List<UacUserMenu> userMenus = uacUserMenuMapper.select(query);
    for (UacUserMenu userMenu : userMenus) {
        if (PublicUtil.isEmpty(userMenu.getUserId())) {
            continue;
        }
        ownerMenuIdList.add(userMenu.getMenuId());
    }
    // 判断是否为admin用户 如果是则返回所有菜单, 如果不是走下面流程
    menuList = uacMenuService.getMenuVoList(userId, 1L);
    for (MenuVo menuVo : menuList) {
        // 一级菜单
        UserMenuDto userMenuDto = new UserMenuDto();
        userMenuDto.setFistMenuIcon(menuVo.getIcon());
        userMenuDto.setFistMenuName(menuVo.getMenuName());
        List<MenuVo> sub2Menu = menuVo.getSubMenu();
        List<UserMenuChildrenDto> children = Lists.newArrayList();
        for (MenuVo vo2 : sub2Menu) {
            // 二级菜单 如果没有子节直接放入
            if (!vo2.isHasMenu()) {
                UserMenuChildrenDto userMenuChildrenDto = new UserMenuChildrenDto(vo2);
                // 判断是否含有该菜单, 含有为true, 不含有为false
                if (ownerMenuIdList.contains(vo2.getId())) {
                    userMenuChildrenDto.setChecked(true);
                }
                children.add(userMenuChildrenDto);
                continue;
            }
            // 如果二级节点有子节继续循环三级菜单
            List<MenuVo> sub3Menu = vo2.getSubMenu();
            for (MenuVo vo3 : sub3Menu) {
                UserMenuChildrenDto dto = new UserMenuChildrenDto(vo3);
                // 判断是否含有该菜单, 含有为true, 不含有为false
                if (ownerMenuIdList.contains(vo3.getId())) {
                    dto.setChecked(true);
                }
                children.add(dto);
            }
        }
        userMenuDto.setChildren(children);
        list.add(userMenuDto);
    }
    return list;
}
Also used : MenuVo(com.paascloud.provider.model.vo.MenuVo) UserMenuDto(com.paascloud.provider.model.dto.menu.UserMenuDto) UserMenuChildrenDto(com.paascloud.provider.model.dto.menu.UserMenuChildrenDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserMenuChildrenDto (com.paascloud.provider.model.dto.menu.UserMenuChildrenDto)1 UserMenuDto (com.paascloud.provider.model.dto.menu.UserMenuDto)1 MenuVo (com.paascloud.provider.model.vo.MenuVo)1 Transactional (org.springframework.transaction.annotation.Transactional)1