package com.liangjian.dataplatform.member.entity.po;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Date;

/**
 * @Author: 黄子奇
 * @Date: 2019/10/7 11:41
 */
@MappedSuperclass
public abstract class BasicEntity implements LifeCycleObject {
    @Id
    @GeneratedValue(generator = "metaRelGenerator")
    @GenericGenerator(name = "metaRelGenerator", strategy = "com.liangjian.dataplatform.member.entity.genernator.SnowflakeGenernator")
    @ApiModelProperty("序号，唯一标识")
    private String id;

    @Column(name = "crt_date")
    @ApiModelProperty("创建日期")
    private Date crtDate;

    @Column(name = "last_update")
    @ApiModelProperty("更新日期")
    private Date lastUpdate;

    @Column(name = "crt_user")
    @ApiModelProperty("创建用户")
    private String crtUser;

    @JsonIgnore
    @Override
    public boolean isNew() {
        return id == null || id.isEmpty();
    }

    @Override
    public void beforeCreate() {
        this.crtDate = new Date();
        this.lastUpdate = new Date();
    }

    @Override
    public void beforeUpdate() {
        this.lastUpdate = new Date();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Date getCrtDate() {
        return crtDate;
    }

    public void setCrtDate(Date crtDate) {
        this.crtDate = crtDate;
    }

    public Date getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    public String getCrtUser() {
        return crtUser;
    }

    public void setCrtUser(String crtUser) {
        this.crtUser = crtUser;
    }
}
