package xtools.boot.core.utils;

import xtools.boot.api.model.dto.resp.TreeResp;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Title : TreeUtils</p>
 * <p>Description : TreeUtils</p>
 * <p>DevelopTools : Idea_x64_v2026.1</p>
 * <p>DevelopSystem : macOS Sequoia 15.7.5</p>
 * <p>Company : org.xujun</p>
 *
 * @author : XuJun
 * @version : 5.0.0
 * @date : 2026/1/30 09:41
 */
public class TreeUtils {

    /**
     * 获取子节点
     *
     * @param id   父级 ID
     * @param list 数据级
     * @return 子级
     */
    public static List<TreeResp> getChild(Long id, List<TreeResp> list) {
        List<TreeResp> childList = new ArrayList<>();
        list.stream().filter(item -> item.getParentId().equals(id)).forEach(item -> {
            List<TreeResp> child = getChild(item.getValue(), list);
            item.setChildren(child);
            childList.add(item);
        });
        return childList;
    }

}
