package com.mortals.xhx.module.site.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 *
 * @author: zxfei
 * @date: 2021/10/13 21:08
 */
@Data
public class TreeSelect implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 节点ID
     */
    private Long id;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect(SiteEntity site) {
        this.id = site.getId();
        this.label = site.getSiteName();
        this.children = site.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

}
