// 查询全部部门
List<SysDept> deptAllList = deptMapper.selectList(Wrappers.emptyWrapper());
// 查询数据权限内部门
List<Integer> deptOwnIdList = deptMapper.selectListByScope(Wrappers.emptyWrapper(), new DataScope()).stream()
.map(SysDept::getDeptId).collect(Collectors.toList());
// 权限内部门
List<TreeNode<Integer>> collect = deptAllList.stream()
.filter(dept -> dept.getDeptId().intValue() != dept.getParentId())
//排序
.sorted(Comparator.comparingInt(SysDept::getSort)).map(dept -> {
TreeNode<Integer> treeNode = new TreeNode();
treeNode.setId(dept.getDeptId());
treeNode.setParentId(dept.getParentId());
treeNode.setName(dept.getName());
// 有权限不返回标识
treeNode.setExtra(MapUtil.of("isLock", !deptOwnIdList.contains(dept.getDeptId())));
return treeNode;
}).collect(Collectors.toList());
自然序排序一个list
list.stream().sorted()
使用Comparator
来排序一个list
sorted(Comparator.comparingInt(SysDept::getSort))