package com.securitycontrol.entity.system;

import com.securitycontrol.entity.system.vo.OrgVo;
import com.securitycontrol.entity.system.vo.TreeNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author：cwchen
 * @date：2024-02-22-9:46
 * @version：1.0
 * @description：下拉树-工具类
 */
public class TreeBuild {

    private final static String P_ID="0";
    /**
     * 遍历获取
     * @param list
     * @return
     */
    public static  List<TreeNode> transTreeList(List<TreeNode> list){
        //map
        list.stream().map(node -> {
            node.setChildren(fromTree(node, list));
            return node;
        }).collect(Collectors.toList());
        //过滤出最上级的菜单
        return list.stream()
                .filter(ele -> P_ID.equals(ele.getParentId()))
                .collect(Collectors.toList());
    }
    /**
     * 找寻指定菜单的下级菜单
     * @param node 当前菜单
     * @param list       所有的菜单list
     * @return 下级菜单
     */
    public static List<TreeNode> fromTree(TreeNode node, List<TreeNode> list) {
        return list.stream()
                .filter(ele -> node.getId().equals(ele.getParentId()))
                .collect(Collectors.toList());
    }


}
