|
@@ -49,18 +49,19 @@ public class SysDeptServiceImpl implements ISysDeptService |
|
@@ -49,18 +49,19 @@ public class SysDeptServiceImpl implements ISysDeptService |
|
49
|
public List<SysDept> buildDeptTree(List<SysDept> depts)
|
49
|
public List<SysDept> buildDeptTree(List<SysDept> depts)
|
|
50
|
{
|
50
|
{
|
|
51
|
List<SysDept> returnList = new ArrayList<SysDept>();
|
51
|
List<SysDept> returnList = new ArrayList<SysDept>();
|
|
52
|
- if (StringUtils.isNotEmpty(depts) && StringUtils.isNotNull(depts.stream().findFirst()))
|
52
|
+ List<Long> tempList = new ArrayList<Long>();
|
|
|
|
53
|
+ for (SysDept dept : depts)
|
|
53
|
{
|
54
|
{
|
|
54
|
- depts.stream().findFirst().get().setParentId(null);
|
55
|
+ tempList.add(dept.getDeptId());
|
|
55
|
}
|
56
|
}
|
|
56
|
for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext();)
|
57
|
for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext();)
|
|
57
|
{
|
58
|
{
|
|
58
|
- SysDept t = (SysDept) iterator.next();
|
|
|
|
59
|
- // 根据传入的某个父节点ID,遍历该父节点的所有子节点
|
|
|
|
60
|
- if (StringUtils.isNull(t.getParentId()) || t.getParentId() == 0)
|
59
|
+ SysDept dept = (SysDept) iterator.next();
|
|
|
|
60
|
+ // 如果是顶级节点, 遍历该父节点的所有子节点
|
|
|
|
61
|
+ if (!tempList.contains(dept.getParentId()))
|
|
61
|
{
|
62
|
{
|
|
62
|
- recursionFn(depts, t);
|
|
|
|
63
|
- returnList.add(t);
|
63
|
+ recursionFn(depts, dept);
|
|
|
|
64
|
+ returnList.add(dept);
|
|
64
|
}
|
65
|
}
|
|
65
|
}
|
66
|
}
|
|
66
|
if (returnList.isEmpty())
|
67
|
if (returnList.isEmpty())
|