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;
}
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);
}
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;
}
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);
}
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;
}
Aggregations