package com.bjtdba.entity.system;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * (Regions)实体类
 *
 * @author makejava
 * @since 2022-10-17 17:36:57
 */
public class Regions implements Serializable {
    private static final long serialVersionUID = 548769596645405174L;
    
    private Integer id;
    
    private String name;
    
    private Integer pid;

    private Integer[] leve;

    @JsonInclude(JsonInclude.Include.NON_DEFAULT)
    private List<Regions> children=new ArrayList<Regions>();


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getPid() {
        return pid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

    public List<Regions> getChildren() {
        return children;
    }

    public void setChildren(List<Regions> children) {
        this.children = children;
    }

    public Integer[] getLeve() {
        return leve;
    }

    public void setLeve(Integer[] leve) {
        this.leve = leve;
    }

    public static Regions findNode(List<Regions> nodes, Integer id) {
        List<Regions> finds = new ArrayList<Regions>();
        findNode(nodes, id, finds);
        return finds.size() != 0 ? finds.get(0) : null;
    }

    public static void findNode(List<Regions> nodes, Integer id, List<Regions> finds) {
        for (Regions node : nodes) {

            if (id.equals(node.getId())||id==node.getId()){
                finds.add(node);
//                System.out.println("id=="+id+"getId=="+node.getId());
            }
            findNode(node.getChildren(), id, finds);
        }
    }

}

