package com.keyware.shandan.bianmu.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.keyware.shandan.common.entity.BaseEntity;
import com.keyware.shandan.common.util.StringUtils;
import lombok.*;

import java.util.Date;

/**
 * 数据置标标签实体类
 *
 * @author GuoXin
 * @date 2022-12-30
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName("B_DATA_LABELS")
public class DataLabelsVo extends BaseEntity {

    private static final long serialVersionUID = -3043646682400582913L;

    /**
     * 主键
     */
    @TableId(type = IdType.AUTO)
    @TableField("ID")
    private Integer id;

    /**
     * 父级ID
     */
    @TableField("PARENT_ID")
    private Integer parentId;

    /**
     * 标签
     */
    @TableField(value = "TITLE", condition = SqlCondition.LIKE)
    private String title;

    /**
     * 描述
     */
    @TableField(value = "DESCRIPTION", condition = SqlCondition.LIKE)
    private String description;

    /**
     * 主键路径
     */
    @TableField("ID_PATH")
    private String idPath;

    /**
     * 标签路径
     */
    @TableField("TITLE_PATH")
    private String titlePath;

    /**
     * 级别
     */
    @TableField("LEVEL")
    private Integer level;

    /**
     * 是否最后一级
     */
    @TableField("IS_LABEL")
    @OrderBy(isDesc = false, sort = 1)
    private Boolean isLabel;

    /**
     * 渲染顺序
     */
    @TableField(value = "SORT")
    @OrderBy(isDesc = false)
    private Integer sort;

    /**
     * 创建时间
     */
    @TableField(value = "CREATE_TIME", fill = FieldFill.INSERT)
    @OrderBy(isDesc = false)
    protected Date createTime;

    @TableField(exist = false)
    private String createUserName;

    public String getIdPathWithSelf() {
        if (StringUtils.hasText(idPath)) {
            return idPath + id + "/";
        }
        return "";
    }

    public String getTitlePathWithSelf() {
        if (StringUtils.hasText(titlePath)) {
            return titlePath + title + "/";
        }
        return "";
    }
}
