package com.willalp.common.core.domain;

import com.willalp.common.utils.StringUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * Tree基类
 *
 * @author willalp
 */
@EqualsAndHashCode(callSuper = true)
@Data
public abstract class TreeEntity extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 父部门ID
     */
    protected Long parentId = 0L;

    /**
     * 祖级列表
     */
    protected String ancestors = "0,";

    public abstract String getId();

    public String makeSelfAsNewParentIds() {
        if (StringUtils.isEmpty(getAncestors())) {
            return getId() + ",";
        }
        return getAncestors() + getId() + ",";
    }
}
