xiangpei
2024-11-30 a4c0d9c57dcbc02867bd6f8ca6fd455412605702
system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java
@@ -1,11 +1,10 @@
package com.ycl.system.service.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import com.ycl.common.base.Result;
import com.ycl.common.core.domain.StringTreeSelect;
import com.ycl.system.domain.base.BaseSelect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -64,6 +63,42 @@
        return buildDeptTreeSelect(depts);
    }
    @Override
    public List<StringTreeSelect> flowDeptTree(SysDept dept) {
        List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
        List<StringTreeSelect> list = depts.stream().map(item -> {
            StringTreeSelect d = new StringTreeSelect();
            d.setId("dept:" + item.getDeptId());
            d.setLabel(item.getDeptName());
            d.setParentId("dept:" + item.getParentId());
            return d;
        }).collect(Collectors.toList());
        Map<String, StringTreeSelect> nodeMap = new HashMap<>();
        // 将所有节点放入Map中,方便后续查找
        for (StringTreeSelect node : list) {
            nodeMap.put(node.getId(), node);
        }
        List<StringTreeSelect> treeList = new ArrayList<>();
        // 构建树结构
        for (StringTreeSelect node : list) {
            StringTreeSelect root = null;
            if ("dept:0".equals(node.getParentId()) || node.getParentId().isEmpty()) {
                // 根节点
                root = node;
                treeList.add(root);
            } else {
                // 找到父节点,并将当前节点添加到父节点的children列表中
                StringTreeSelect parentNode = nodeMap.get(node.getParentId());
                if (parentNode != null) {
                    parentNode.getChildren().add(node);
                }
            }
        }
        return treeList;
    }
    /**
     * 构建前端所需要树结构
     *
@@ -90,6 +125,8 @@
        }
        return returnList;
    }
    /**
     * 构建前端所需要下拉树结构
@@ -354,4 +391,16 @@
        ).collect(Collectors.toList());
        return Result.ok().data(vos);
    }
    @Override
    public List<StringTreeSelect> flowableAll() {
        List<StringTreeSelect> list = deptMapper.selectDeptList(new SysDept()).stream().map(sysDept -> {
            StringTreeSelect stringTreeSelect = new StringTreeSelect();
            stringTreeSelect.setId("dept:" + sysDept.getDeptId());
            stringTreeSelect.setLabel(sysDept.getDeptName());
            return stringTreeSelect;
        }).collect(Collectors.toList());
        return list;
    }
}