|
|
@@ -864,45 +864,50 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
|
|
List<SysUserDeptRelationship> relationships = sysUserDeptRelationshipMapper.selectList(new QueryWrapper<SysUserDeptRelationship>().eq("user_id", id));
|
|
|
deptIds.addAll(relationships.stream().map(SysUserDeptRelationship::getDeptId).collect(Collectors.toList()));
|
|
|
}
|
|
|
- sysDeptVo.setDeptIds(deptIds);
|
|
|
- List<SysDept> sysDeptList = baseMapper.getFiveLevelDept(sysDeptVo);
|
|
|
- if("admin".equals(byUserId.getId())){
|
|
|
- sysDept.setComlevel("1");
|
|
|
- sysDeptList.add(sysDept);
|
|
|
- List<SysDeptTreeVo> sysDeptTreeVos = BeanUtil.copyToList(sysDeptList, SysDeptTreeVo.class);
|
|
|
- Map<String, List<SysDeptTreeVo>> map = sysDeptTreeVos.stream().sorted(Comparator.comparing(SysDeptTreeVo::getId))
|
|
|
- .collect(Collectors.groupingBy(SysDeptTreeVo::getParentId));
|
|
|
- sysDeptTreeVos.forEach(i -> {
|
|
|
- if(Integer.parseInt(i.getComlevel())<=5){
|
|
|
- i.setChildren(map.getOrDefault(i.getId(), new ArrayList<>()));
|
|
|
- i.setDeptCount(i.getChildren().size());
|
|
|
+ if(!deptIds.isEmpty()){
|
|
|
+ sysDeptVo.setDeptIds(deptIds);
|
|
|
+ List<SysDept> sysDeptList = baseMapper.getFiveLevelDept(sysDeptVo);
|
|
|
+ if("admin".equals(byUserId.getId())){
|
|
|
+ sysDept.setComlevel("1");
|
|
|
+ sysDeptList.add(sysDept);
|
|
|
+ List<SysDeptTreeVo> sysDeptTreeVos = BeanUtil.copyToList(sysDeptList, SysDeptTreeVo.class);
|
|
|
+ Map<String, List<SysDeptTreeVo>> map = sysDeptTreeVos.stream().sorted(Comparator.comparing(SysDeptTreeVo::getId))
|
|
|
+ .collect(Collectors.groupingBy(SysDeptTreeVo::getParentId));
|
|
|
+ sysDeptTreeVos.forEach(i -> {
|
|
|
+ if(Integer.parseInt(i.getComlevel())<=5){
|
|
|
+ i.setChildren(map.getOrDefault(i.getId(), new ArrayList<>()));
|
|
|
+ i.setDeptCount(i.getChildren().size());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return map.get(sysDept.getParentId());
|
|
|
+ } else {
|
|
|
+ List<SysDept> result = new ArrayList<>();
|
|
|
+ List<SysDept> deptList = sysDeptMapper.getListByIds(deptIds);
|
|
|
+ List<SysDept> filteredDeptList = deptList.stream()
|
|
|
+ .filter(dept -> dept.getComlevel() != null) // 过滤条件:Comlevel 不为 null
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 使用一个Map来快速查找部门节点
|
|
|
+ Map<String, SysDept> deptMap = new HashMap<>();
|
|
|
+ for (SysDept dept : filteredDeptList) {
|
|
|
+ deptMap.put(dept.getId(), dept);
|
|
|
}
|
|
|
- });
|
|
|
- return map.get(sysDept.getParentId());
|
|
|
- } else {
|
|
|
- List<SysDept> result = new ArrayList<>();
|
|
|
- List<SysDept> deptList = sysDeptMapper.getListByIds(deptIds);
|
|
|
- List<SysDept> filteredDeptList = deptList.stream()
|
|
|
- .filter(dept -> dept.getComlevel() != null) // 过滤条件:Comlevel 不为 null
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- // 使用一个Map来快速查找部门节点
|
|
|
- Map<String, SysDept> deptMap = new HashMap<>();
|
|
|
- for (SysDept dept : filteredDeptList) {
|
|
|
- deptMap.put(dept.getId(), dept);
|
|
|
- }
|
|
|
- // 找出顶级部门(即没有父部门的部门)
|
|
|
- for (SysDept dept : filteredDeptList) {
|
|
|
- if (dept.getParentId() == null || deptMap.get(dept.getParentId()) == null) {
|
|
|
- // 添加到结果列表并构建其子树
|
|
|
- buildDeptTreeKzt(dept, deptMap);
|
|
|
- result.add(dept);
|
|
|
+ // 找出顶级部门(即没有父部门的部门)
|
|
|
+ for (SysDept dept : filteredDeptList) {
|
|
|
+ if (dept.getParentId() == null || deptMap.get(dept.getParentId()) == null) {
|
|
|
+ // 添加到结果列表并构建其子树
|
|
|
+ buildDeptTreeKzt(dept, deptMap);
|
|
|
+ result.add(dept);
|
|
|
+ }
|
|
|
}
|
|
|
+ List<SysDeptTreeVo> sysDeptTreeVos = BeanUtil.copyToList(result, SysDeptTreeVo.class);
|
|
|
+ return sysDeptTreeVos;
|
|
|
}
|
|
|
- List<SysDeptTreeVo> sysDeptTreeVos = BeanUtil.copyToList(result, SysDeptTreeVo.class);
|
|
|
- return sysDeptTreeVos;
|
|
|
+ }else {
|
|
|
+ return new ArrayList<SysDeptTreeVo>();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void buildDeptTreeKzt(SysDept dept, Map<String, SysDept> deptMap) {
|