| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.entity.TDept; |
| | |
| | | import com.ruoyi.system.service.TDeptService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | return buildDeptTree(depts); |
| | | } |
| | | |
| | | @Override |
| | | public List<Integer> getAllSubDeptIds(String deptId) { |
| | | List<Integer> allSubIds = new ArrayList<>(); |
| | | allSubIds.add(Integer.valueOf(deptId)); |
| | | getSubDeptIdsRecursive(Integer.valueOf(deptId), allSubIds); |
| | | return allSubIds.stream().distinct().collect(Collectors.toList()); |
| | | } |
| | | private void getSubDeptIdsRecursive(Integer parentId, List<Integer> allSubIds) { |
| | | // 查询直接下级 |
| | | List<Integer> directSubIds = this.baseMapper.selectList(new LambdaQueryWrapper<TDept>().eq(TDept::getParentId, parentId)).stream() |
| | | .map(TDept::getId).collect(Collectors.toList()); |
| | | for (Integer subId : directSubIds) { |
| | | allSubIds.add(subId); |
| | | // 递归查询下级的下级 |
| | | getSubDeptIdsRecursive(subId, allSubIds); |
| | | } |
| | | } |
| | | /** |
| | | * 构建部门树结构 |
| | | * @param depts 部门列表 |