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;
}
相关推荐
weixin_462446234 分钟前
ubuntu真机安装tljh jupyterhub支持跨域iframe
linux·运维·ubuntu
小码吃趴菜4 分钟前
select/poll/epoll 核心区别
linux
Ghost Face...6 分钟前
深入解析网卡驱动开发与移植
linux·驱动开发
Kingairy9 分钟前
Python面试高频题
java·python·面试
黎雁·泠崖9 分钟前
Java数组入门:定义+静态/动态初始化全解析(隐式转换+案例+避坑指南)
java·开发语言·python
a413244719 分钟前
在CentOS系统上挂载硬盘到ESXi虚拟机
linux·运维·centos
MMME~20 分钟前
Linux下的软件管理
linux·运维·服务器
迷途之人不知返26 分钟前
Linux操作系统的基本指令
linux·服务器
松涛和鸣26 分钟前
DAY49 DS18B20 Single-Wire Digital Temperature Acquisition
linux·服务器·网络·数据库·html
玖釉-34 分钟前
[Vulkan 学习之路] 16 - 最终章:渲染循环与同步 (Rendering & Presentation)
c++·windows·图形渲染