Search in sources :

Example 1 with MenuEntity

use of com.hb0730.boot.admin.project.system.menu.model.entity.MenuEntity in project boot-admin by hb0730.

the class MenuEventListener method findMenuByUser.

private List<TreeMenuDTO> findMenuByUser(UserDTO user) {
    if (null == user) {
        return null;
    }
    if (user.getIsAdmin() == 1) {
        MenuParams params = new MenuParams();
        params.setSortType(SortTypeEnum.ASC.getValue());
        params.setSortColumn(Collections.singletonList(MenuEntity.SORT));
        QueryWrapper<MenuEntity> query = QueryWrapperUtils.getQuery(params);
        List<MenuEntity> entities = menuService.list(query);
        return BeanUtil.copyToList(entities, TreeMenuDTO.class);
    }
    Collection<Long> permissionIds = user.getPermissionIds();
    if (CollectionUtils.isEmpty(permissionIds)) {
        return Lists.newArrayList();
    }
    LambdaQueryWrapper<PermissionEntity> queryWrapper = Wrappers.lambdaQuery(PermissionEntity.class).in(PermissionEntity::getId, permissionIds).select(PermissionEntity::getMenuId, PermissionEntity::getPermission);
    // 权限
    List<PermissionEntity> permissionEntities = ((UserInfoServiceImpl) userInfoService.getThis()).getPermissionService().list(queryWrapper);
    if (CollectionUtils.isEmpty(permissionEntities)) {
        return Lists.newArrayList();
    }
    Map<Long, List<String>> permissionMapping = permissionEntities.stream().collect(Collectors.groupingBy(PermissionEntity::getMenuId, Collectors.mapping(PermissionEntity::getPermission, Collectors.toList())));
    // 菜单
    List<Long> menuIds = permissionEntities.parallelStream().map(PermissionEntity::getMenuId).collect(Collectors.toList());
    Set<MenuEntity> entities = Sets.newHashSet();
    for (Long menuId : menuIds) {
        entities.addAll(menuService.getSuperior(menuId, Lists.newArrayList()));
    }
    List<MenuEntity> menuEntities = entities.stream().sorted(Comparator.comparing(MenuEntity::getSort)).collect(Collectors.toList());
    List<TreeMenuDTO> treeMenu = BeanUtil.copyToList(menuEntities, TreeMenuDTO.class);
    for (TreeMenuDTO menu : treeMenu) {
        menu.setAuthority(permissionMapping.get(menu.getId()));
    }
    return treeMenu;
}
Also used : MenuParams(com.hb0730.boot.admin.project.system.menu.model.query.MenuParams) MenuEntity(com.hb0730.boot.admin.project.system.menu.model.entity.MenuEntity) TreeMenuDTO(com.hb0730.boot.admin.project.system.menu.model.dto.TreeMenuDTO) List(java.util.List) PermissionEntity(com.hb0730.boot.admin.project.system.permission.model.entity.PermissionEntity)

Example 2 with MenuEntity

use of com.hb0730.boot.admin.project.system.menu.model.entity.MenuEntity in project boot-admin by hb0730.

the class MenuServiceImpl method getSuperior.

@Override
public List<MenuEntity> getSuperior(@Nonnull Long id, List<MenuEntity> entities) {
    if (null == id || -1 == id) {
        return entities;
    }
    MenuEntity menuEntity = super.getById(id);
    entities.add(menuEntity);
    return getSuperior(menuEntity.getParentId(), entities);
}
Also used : MenuEntity(com.hb0730.boot.admin.project.system.menu.model.entity.MenuEntity)

Example 3 with MenuEntity

use of com.hb0730.boot.admin.project.system.menu.model.entity.MenuEntity in project boot-admin by hb0730.

the class MenuServiceImpl method getChildrenByParenId.

@Override
@Nullable
public List<MenuDTO> getChildrenByParenId(@Nonnull Long id) {
    Assert.notNull(id, "id不为空");
    List<MenuEntity> entities = super.list();
    List<MenuDTO> menu = BeanUtil.copyToList(entities, MenuDTO.class);
    List<MenuDTO> result = Lists.newArrayList();
    for (MenuDTO dto : menu) {
        // 第一级
        if (dto.getParentId().equals(id)) {
            result.add(dto);
            for (MenuDTO item : menu) {
                if (dto.getId().equals(item.getParentId())) {
                    result.add(item);
                }
            }
        }
    }
    return result;
}
Also used : MenuEntity(com.hb0730.boot.admin.project.system.menu.model.entity.MenuEntity) TreeMenuDTO(com.hb0730.boot.admin.project.system.menu.model.dto.TreeMenuDTO) MenuDTO(com.hb0730.boot.admin.project.system.menu.model.dto.MenuDTO) Nullable(javax.annotation.Nullable)

Example 4 with MenuEntity

use of com.hb0730.boot.admin.project.system.menu.model.entity.MenuEntity in project boot-admin by hb0730.

the class MenuServiceImpl method queryTree.

@Override
public List<TreeMenuDTO> queryTree() {
    MenuParams params = new MenuParams();
    params.setSortColumn(Collections.singletonList(MenuEntity.SORT));
    params.setSortType(SortTypeEnum.ASC.getValue());
    QueryWrapper<MenuEntity> query = super.query(params);
    List<MenuEntity> entities = super.list(query);
    List<TreeMenuDTO> treeMenu = BeanUtil.copyToList(entities, TreeMenuDTO.class);
    return buildTree(treeMenu);
}
Also used : MenuEntity(com.hb0730.boot.admin.project.system.menu.model.entity.MenuEntity) TreeMenuDTO(com.hb0730.boot.admin.project.system.menu.model.dto.TreeMenuDTO) MenuParams(com.hb0730.boot.admin.project.system.menu.model.query.MenuParams)

Example 5 with MenuEntity

use of com.hb0730.boot.admin.project.system.menu.model.entity.MenuEntity in project boot-admin by hb0730.

the class MenuServiceImpl method queryMenuPermissionTree.

@Override
public List<MenuPermissionVO> queryMenuPermissionTree() {
    List<PermissionEntity> permissionEntities = permissionMapper.selectList(null);
    List<MenuEntity> entities = super.list();
    List<MenuPermissionVO> trees = new ArrayList<>();
    for (MenuEntity menuEntity : entities) {
        MenuPermissionVO menuPermission = new MenuPermissionVO();
        if (menuEntity.getParentId() == null || menuEntity.getParentId() == -1) {
            menuPermission.setId(menuEntity.getId());
            menuPermission.setName(menuEntity.getTitle());
            menuPermission.setIsPermission(false);
            trees.add(menuPermission);
        }
        for (MenuEntity entity : entities) {
            if (menuEntity.getId().equals(entity.getParentId())) {
                if (menuPermission.getChildren() == null) {
                    menuPermission.setChildren(new ArrayList<>());
                }
                MenuPermissionVO menuPermissionInfo = new MenuPermissionVO();
                menuPermissionInfo.setName(entity.getTitle());
                menuPermissionInfo.setId(entity.getId());
                menuPermissionInfo.setIsPermission(false);
                menuPermission.getChildren().add(menuPermissionInfo);
                // 权限
                List<PermissionEntity> permissionList = permissionEntities.stream().filter(e -> e.getMenuId().equals(entity.getId())).collect(Collectors.toList());
                for (PermissionEntity permissionEntity : permissionList) {
                    MenuPermissionVO permission = new MenuPermissionVO();
                    permission.setIsPermission(true);
                    permission.setId(permissionEntity.getId());
                    permission.setName(permissionEntity.getName());
                    if (menuPermissionInfo.getChildren() == null) {
                        menuPermissionInfo.setChildren(new ArrayList<>());
                    }
                    menuPermissionInfo.getChildren().add(permission);
                }
            }
        }
    }
    return trees;
}
Also used : UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) SuperBaseServiceImpl(com.hb0730.boot.admin.domain.service.impl.SuperBaseServiceImpl) SneakyThrows(lombok.SneakyThrows) VueMenuVO(com.hb0730.boot.admin.project.system.menu.model.vo.VueMenuVO) RequiredArgsConstructor(lombok.RequiredArgsConstructor) SortTypeEnum(com.hb0730.boot.admin.commons.enums.SortTypeEnum) SecurityUtils(com.hb0730.boot.admin.security.utils.SecurityUtils) BeanUtil(cn.hutool.core.bean.BeanUtil) HashOperations(org.springframework.data.redis.core.HashOperations) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TreeMenuDTO(com.hb0730.boot.admin.project.system.menu.model.dto.TreeMenuDTO) IPermissionMapper(com.hb0730.boot.admin.project.system.permission.mapper.IPermissionMapper) Lists(com.google.common.collect.Lists) MenuMetaVO(com.hb0730.boot.admin.project.system.menu.model.vo.MenuMetaVO) Service(org.springframework.stereotype.Service) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) EnabledEnum(com.hb0730.boot.admin.commons.enums.EnabledEnum) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) MenuDTO(com.hb0730.boot.admin.project.system.menu.model.dto.MenuDTO) PermissionEntity(com.hb0730.boot.admin.project.system.permission.model.entity.PermissionEntity) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) LoginException(com.hb0730.boot.admin.exceptions.LoginException) CollectionUtil(cn.hutool.core.collection.CollectionUtil) MenuPermissionVO(com.hb0730.boot.admin.project.system.menu.model.vo.MenuPermissionVO) RedisConstant(com.hb0730.boot.admin.commons.constant.RedisConstant) Set(java.util.Set) ResponseStatusEnum(com.hb0730.boot.admin.commons.enums.ResponseStatusEnum) Collectors(java.util.stream.Collectors) ROOT_PATH(com.hb0730.commons.lang.constants.PathConst.ROOT_PATH) Sets(com.google.common.collect.Sets) Serializable(java.io.Serializable) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) User(com.hb0730.boot.admin.security.model.User) IMenuService(com.hb0730.boot.admin.project.system.menu.service.IMenuService) MenuEntity(com.hb0730.boot.admin.project.system.menu.model.entity.MenuEntity) MenuParams(com.hb0730.boot.admin.project.system.menu.model.query.MenuParams) Collections(java.util.Collections) MenuEvent(com.hb0730.boot.admin.event.menu.MenuEvent) IMenuMapper(com.hb0730.boot.admin.project.system.menu.mapper.IMenuMapper) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) MenuEntity(com.hb0730.boot.admin.project.system.menu.model.entity.MenuEntity) MenuPermissionVO(com.hb0730.boot.admin.project.system.menu.model.vo.MenuPermissionVO) ArrayList(java.util.ArrayList) PermissionEntity(com.hb0730.boot.admin.project.system.permission.model.entity.PermissionEntity)

Aggregations

MenuEntity (com.hb0730.boot.admin.project.system.menu.model.entity.MenuEntity)5 TreeMenuDTO (com.hb0730.boot.admin.project.system.menu.model.dto.TreeMenuDTO)4 MenuParams (com.hb0730.boot.admin.project.system.menu.model.query.MenuParams)3 MenuDTO (com.hb0730.boot.admin.project.system.menu.model.dto.MenuDTO)2 PermissionEntity (com.hb0730.boot.admin.project.system.permission.model.entity.PermissionEntity)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)2 BeanUtil (cn.hutool.core.bean.BeanUtil)1 CollectionUtil (cn.hutool.core.collection.CollectionUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)1 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 RedisConstant (com.hb0730.boot.admin.commons.constant.RedisConstant)1 EnabledEnum (com.hb0730.boot.admin.commons.enums.EnabledEnum)1 ResponseStatusEnum (com.hb0730.boot.admin.commons.enums.ResponseStatusEnum)1 SortTypeEnum (com.hb0730.boot.admin.commons.enums.SortTypeEnum)1 SuperBaseServiceImpl (com.hb0730.boot.admin.domain.service.impl.SuperBaseServiceImpl)1