use of com.hb0730.boot.admin.project.system.menu.model.query.MenuParams 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;
}
use of com.hb0730.boot.admin.project.system.menu.model.query.MenuParams 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);
}
Aggregations