package cn.iocoder.yudao.framework.common.base;

import lombok.Data;
import lombok.EqualsAndHashCode;
import tk.mybatis.mapper.annotation.Version;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;

/**
 * 功能描述: 完整的实体公共字段
 * <p>
 * 作者: July
 * 日期: 2020-09-24 18:51
 * @author Administrator
 */
@Data
@MappedSuperclass
@EqualsAndHashCode(callSuper = false)
public abstract class BaseFullEntity extends BaseRowEntity {

    private static final long serialVersionUID = 4504019430120156954L;

    /** 是否启用 1 = 启用 0 = 已禁用 */
    @Column(name = "enabled", nullable = false, columnDefinition = "tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否启用 1 = 启用 0 = 已禁用'")
    private boolean enabled;

    /** 是否删除 1 = 删除 0 = 未删除 */
    @Column(name = "deleted", nullable = false, columnDefinition = "tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 1 = 删除 0 = 未删除'")
    private boolean deleted;

    /** 乐观锁版本号 */
    @Version
    @Column(name = "version", nullable = false, columnDefinition = "INT DEFAULT 0 NOT NULL COMMENT '乐观锁版本号'")
    private Long version;

    public void updateVersion() {
        if (version == null) { version = 0L; }
        version++;
    }
}
