package com.usky.system.service.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.usky.system.domain.SysDept;
import com.usky.system.domain.SysUser;
import lombok.Data;

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

/**
 * @description：TODO
 * @author： fu
 * @create： 2024-07-12 13:37
 */
@Data
public class TreeNode implements Serializable {
    private static final long serialVersionUID = 1L;

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

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

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

    public TreeNode() {
    }

    public TreeNode(SysDept dept) {
        this.id = dept.getDeptId();
        this.label = dept.getDeptName();
        this.children = new ArrayList<>();
        if (dept.getChildren() != null && !dept.getChildren().isEmpty()) {
            this.children = dept.getChildren().stream().map(TreeNode::new).collect(Collectors.toList());
        } else if (dept.getUsers() != null && !dept.getUsers().isEmpty()) {
            this.children = dept.getUsers().stream().map(UserTreeNode::new).collect(Collectors.toList());
        }
    }
}



