package com.keyware.shandan.bianmu.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.keyware.shandan.common.util.MD5Util;
import lombok.*;
import org.apache.ibatis.annotations.One;
import org.springframework.util.StringUtils;

import java.io.Serializable;

/**
 * @author GuoXin
 * @date 2023-01-11
 */
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName("B_DATA_LABEL_ENTITY")
public class LabelEntity implements Serializable {
    private static final long serialVersionUID = -2662996148966576635L;

    @TableId(type = IdType.INPUT)
    @TableField("ID")
    private String id;

    @TableField("ENTITY_ID")
    private String entityId;

    @TableField("ENTITY_TYPE")
    private String entityType;

    @TableField("LABEL_ID")
    private Integer labelId;

    @TableField("FIELD_TITLE")
    private String fieldTitle;

    @TableField("LABEL")
    private String label;

    @TableField(exist = false)
    private DataLabelsVo data;

    public String getId() {
        if (StringUtils.hasText(id)) {
            return id;
        } else if (StringUtils.hasText(entityId) && labelId != null) {
            id = MD5Util.getMD5(entityId + labelId);
        }

        return id;
    }
}
