修改查询所有子部门方法
This commit is contained in:
+33
-1
@@ -1,5 +1,6 @@
|
||||
package com.jero.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@@ -24,6 +25,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.jero.modules.system.util.FindsDepartsChildrenUtil.convertSysDepartToSysDepartTreeModel;
|
||||
|
||||
@@ -286,7 +288,37 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
|
||||
|
||||
@Override
|
||||
public List<String> getSubDepIdsByDepId(String departId) {
|
||||
return this.baseMapper.getSubDepIdsByDepId(departId);
|
||||
List<String> idList = new ArrayList<>();
|
||||
if(StringUtils.isNotEmpty(departId)) {
|
||||
// 查询所有部门
|
||||
LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
|
||||
query.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
|
||||
List<SysDepart> listAll = this.list(query);
|
||||
|
||||
List<SysDepart> result = new ArrayList<>();
|
||||
// 递归查询 指定父节点下的所有子节点,包括父节点
|
||||
if (CollectionUtil.isNotEmpty(listAll)) {
|
||||
recursion(listAll, result, departId);
|
||||
}
|
||||
|
||||
|
||||
idList.add(departId); // 加上父节点
|
||||
idList = result.stream().map(SysDepart::getId).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
return idList;
|
||||
}
|
||||
|
||||
// 递归查询子节点
|
||||
private void recursion(List<SysDepart> listAll, List<SysDepart> result, String fatherId) {
|
||||
List<SysDepart> childern = listAll.stream().filter(e-> fatherId.equals(e.getParentId())).collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(childern)) {
|
||||
result.addAll(childern);
|
||||
for(SysDepart depart : childern) {
|
||||
recursion(listAll, result, depart.getId());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user