|
|
@@ -15,8 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author Administrator
|
|
|
@@ -90,27 +90,74 @@ public class SysDeptInternalAgentServiceImpl extends ServiceImpl<SysDeptInternal
|
|
|
|
|
|
@Override
|
|
|
public List<SysDeptInternalAgent> findTree(String deptId, String comtype) {
|
|
|
- List<SysDeptInternalAgent> sysDeptAll =sysDeptInternalAgentMapper.queryDeptList();
|
|
|
+ String parentIds =null;
|
|
|
+ if(StringUtils.isNotBlank(deptId)){
|
|
|
+ SysDeptInternalAgent sysDeptInternalAgent = sysDeptInternalAgentMapper.selectById(deptId);
|
|
|
+ parentIds=sysDeptInternalAgent.getParentIds();
|
|
|
+ }
|
|
|
+ List<SysDeptInternalAgent> sysDeptAll =sysDeptInternalAgentMapper.queryDeptList(parentIds,comtype);
|
|
|
List<SysDeptInternalAgent> resultList =new ArrayList<SysDeptInternalAgent>();
|
|
|
- List<SysDeptInternalAgent> sysDeptTop = sysDeptAll.stream().filter(item ->"0".equals(item.getParentId())).collect(Collectors.toList());
|
|
|
+ List<SysDeptInternalAgent> sysDeptTop = getTopDeptList(sysDeptAll);
|
|
|
for (SysDeptInternalAgent dept : sysDeptTop) {
|
|
|
- resultList.add(buildDeptTree(dept,sysDeptAll));
|
|
|
+ if(StringUtils.isNotBlank(comtype)){
|
|
|
+ resultList.add(buildDeptTree(dept,sysDeptAll));
|
|
|
+ }else{
|
|
|
+ resultList.add(buildDeptTreeOne(dept,sysDeptAll));
|
|
|
+ }
|
|
|
}
|
|
|
return resultList;
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* @version
|
|
|
* @author: hxl
|
|
|
- * @Date: 2024/6/27 8:42
|
|
|
- * @Description: 获取顶级机构的数据
|
|
|
+ * @Date: 2024/6/28 19:19
|
|
|
+ * @Description: 处理上下级关系
|
|
|
+ */
|
|
|
+ private SysDeptInternalAgent buildDeptTreeOne(SysDeptInternalAgent dept, List<SysDeptInternalAgent> deptList){
|
|
|
+ for (SysDeptInternalAgent d : deptList) {
|
|
|
+ if (dept.getId().equals(d.getParentId())) {
|
|
|
+ if (null == dept.getChildren()) {
|
|
|
+ dept.setChildren(new ArrayList<SysDeptInternalAgent>());
|
|
|
+ }
|
|
|
+ //递归调用
|
|
|
+ dept.getChildren().add(buildDeptTreeOne(d, deptList));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dept;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/6/28 18:17
|
|
|
+ * @Description: 获取顶级机构
|
|
|
*/
|
|
|
+ private static List<SysDeptInternalAgent> getTopDeptList(List<SysDeptInternalAgent> sysDeptAll) {
|
|
|
+ Integer min;
|
|
|
+ List<Integer> levelList =new ArrayList<>();
|
|
|
+ List<SysDeptInternalAgent> sysDeptTop=new ArrayList<>();
|
|
|
+ if(sysDeptAll !=null && sysDeptAll.size()>0){
|
|
|
+ for(SysDeptInternalAgent sysDeptInternalAgent: sysDeptAll){
|
|
|
+ levelList.add(Integer.parseInt(sysDeptInternalAgent.getComlevel()));
|
|
|
+ }
|
|
|
+ min = Collections.min(levelList);
|
|
|
+ for(SysDeptInternalAgent sysDeptInternalAgent: sysDeptAll){
|
|
|
+ if(Integer.parseInt(sysDeptInternalAgent.getComlevel())==min){
|
|
|
+ sysDeptTop.add(sysDeptInternalAgent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sysDeptTop;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
- * 递归构建树形结构
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/6/27 8:42
|
|
|
+ * @Description: 处理爷孙关系
|
|
|
*/
|
|
|
private SysDeptInternalAgent buildDeptTree(SysDeptInternalAgent dept, List<SysDeptInternalAgent> deptList){
|
|
|
for (SysDeptInternalAgent d : deptList) {
|
|
|
- if (dept.getId().equals(d.getParentId())) {
|
|
|
+ if (d.getParentIds().contains(dept.getParentIds()) && !d.getParentIds().equals(dept.getParentIds()) ) {
|
|
|
if (null == dept.getChildren()) {
|
|
|
dept.setChildren(new ArrayList<SysDeptInternalAgent>());
|
|
|
}
|
|
|
@@ -120,6 +167,8 @@ public class SysDeptInternalAgentServiceImpl extends ServiceImpl<SysDeptInternal
|
|
|
}
|
|
|
return dept;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|