package cn.reghao.autodop.dmaster.util.db;

import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author reghao
 * @date 2019-10-18 14:42:48
 */
@MappedSuperclass
@Data
public class BaseEntity<T extends Serializable> implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqGen")
    // seq 表
    @SequenceGenerator(name = "seqGen", sequenceName = "seq")
    protected T id;
    // 逻辑删除
    private Boolean isDelete;
    @CreationTimestamp
    @Column(updatable = false)
    protected LocalDateTime createTime;
    @UpdateTimestamp
    protected LocalDateTime updateTime;

    public BaseEntity() {
        // TODO 在 controller 中使用对象接收 formdata 数据时，不能正确初始化 isDelete 字段
        this.isDelete = Boolean.FALSE;
    }
}
