优化组织人员树

This commit is contained in:
sxu 2024-11-04 15:39:32 +08:00
parent ca002de02b
commit 5fcd300883
1 changed files with 15 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package com.bonus.system.service.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import com.bonus.common.core.web.domain.BaseEntity;
@ -86,9 +87,23 @@ public class SysDeptServiceImpl implements ISysDeptService
public List<TreeSelect> selectDeptUserTree(SysUser sysUser)
{
List<SysDept> depts = deptMapper.selectDeptUserList(sysUser.getRoleIds());
for (int i = 0; i < 5; i++) {
depts = getFilterDepts(depts);
}
return buildDeptTreeSelect(depts);
}
private static List<SysDept> getFilterDepts(List<SysDept> depts) {
List<SysDept> newDepts = new ArrayList<>();
Set<Long> pids = depts.stream().map(SysDept::getParentId).collect(Collectors.toSet());
for (SysDept sysDept : depts) {
if (sysDept.getLevel().equals(99) || pids.contains(sysDept.getDeptId())) {
newDepts.add(sysDept);
}
}
return newDepts;
}
/**
* 构建前端所需要树结构
*