package com.crm.rely.backend.core.pojo;

import lombok.Data;
import org.springframework.beans.BeanUtils;

import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.util.Date;

/**
 * @author houn
 */
@Data
@MappedSuperclass
public class BaseTable implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private Date addTime;

    private Long addUser;

    private String addIp;

    private Date modifyTime;

    private Long modifyUser;

    private String modifyIp;

    private String note;

    public <T> T transferToDto(Class<T> clazz)  throws IllegalAccessException, InstantiationException{
        T t = clazz.newInstance();
        BeanUtils.copyProperties(this,t);
        return t;
    }

    public <T> T transferToEntity(Class<T> clazz) throws IllegalAccessException, InstantiationException {
        T t = clazz.newInstance();
        BeanUtils.copyProperties(this,t);
        return t;
    }
}
