java通过用户id寻找下级

复制代码
private List<Long> getJuniorDeptIds(R<List<SysUser>> userList, List<Long> xiajiId) {
    List<Long> userIds = new ArrayList<>();
    // 创建一个临时列表,用于存储当前层级的下级部门id
    List<Long> currentLevelDeptIds = new ArrayList<>(xiajiId);
    // 直到没有下级部门为止
    while (!currentLevelDeptIds.isEmpty()) {
        List<Long> nextLevelDeptIds = new ArrayList<>();
        // 遍历当前层级的下级部门id
        for (Long deptId : currentLevelDeptIds) {
            for (SysUser datum : userList.getData()) {
                if (Objects.equals(datum.getDeptId(), deptId)) {
                    userIds.add(datum.getUserId());
                    // 将当前部门的所有下级部门id添加到下一层级列表中
                    nextLevelDeptIds.add(datum.getUserId());
                }
            }
        }
        // 更新当前层级的下级部门id为下一层级的部门id
        currentLevelDeptIds = nextLevelDeptIds;
    }
    return userIds;
}
相关推荐
ltl4 小时前
纠删码原理与存储效率
linux
ltl5 小时前
MinIO 原理和架构:机制、AGPL 与上游 archived 风险
linux
mifengxing5 小时前
LeetCode 41.缺失的第一个正数|Hard题O(n)+O(1)最优解法深度解析
java·算法·leetcode·排序算法
wling03015 小时前
vasp虚频计算-python脚本
开发语言·windows·python·vasp计算
林浩杨_5 小时前
linux搜索命令(grep+sed)
linux·命令模式
W.W.H.5 小时前
将驱动编译成模块并安装到rootfs
linux·物联网·wifi·rootfs·驱动
ltl5 小时前
io_uring 在生产环境翻车实录:内核 bug、资源泄漏和你不知道的限制
linux
ltl5 小时前
内存分配器擂台:jemalloc vs tcmalloc vs mimalloc vs glibc
linux
ltl5 小时前
Zero Copy 的肮脏秘密:在什么时候反而更慢
linux
数据知道5 小时前
宽字节注入、二次注入、堆叠注入:高级 SQLi 专题
linux·运维·安全·网络安全