package cn.wise.sc.energy.power.plant.business.domain;

import cn.wise.sc.energy.power.plant.business.domain.vo.EntityVo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.data.domain.Persistable;

import javax.persistence.MappedSuperclass;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.Transient;

/**
 * @description: 基础实体父类
 * @author: qh
 * @create: 2020-07-14 16:42
 **/
@MappedSuperclass
public abstract class AbstractEntity<ID> implements Persistable<ID> {

    @Transient
    private boolean isNew = true;

    @Override
    @JsonIgnore
    public boolean isNew() {
        return isNew;
    }

    @PrePersist
    @PostLoad
    void markNotNew() {
        this.isNew = false;
    }

    /**
     * toVo方法 需要子类实现
     *
     * @return
     */
    public EntityVo toVo() {
        return null;
    }
}