package com.yuchen.saas.integration.feign.api.entity;


import com.yuchen.saas.integration.feign.api.util.IdGen;
import lombok.Data;
import org.nest.springwrap.core.secure.ContextUser;
import org.nest.springwrap.core.tool.utils.Func;

import java.util.Date;

/**
 * 数据Entity类
 *
 * @author
 * @version 2022-10-18
 */
@Data
public abstract class DataEntity<T> extends BaseEntity<T> {

    private static final long serialVersionUID = 1L;

    protected String source; // 渠道
    protected Long createUser; // 创建者
    protected Date createTime; // 创建日期
    protected Long updateUser; // 更新者
    protected Date updateTime; // 更新日期
    protected String remarks; // 备注
    protected String delFlag; // 删除标记（0：正常；1：删除；2：审核）*/
    private String parkId;
    private String tenantId;
    private String deptId;
    public DataEntity() {
        super();
        this.delFlag = DEL_FLAG_NORMAL;
    }

    public DataEntity(String id) {
        super(id);
        this.delFlag = DEL_FLAG_NORMAL;
    }

    /**
     * 插入之前执行方法，需要手动调用
     */
    @Override
    public void preInsert(ContextUser user) {
        if (!this.isNewRecord) {
            this.id= IdGen.uuid();
        }
        if (Func.isNotEmpty(user)&&user.getUserId()!=0) {
            this.createUser = user.getUserId();
            this.updateUser =  user.getUserId();
        }
        this.updateTime = new Date();
        this.createTime = this.updateTime;
    }

    /**
     * 更新之前执行方法，需要手动调用
     */
    @Override
    public void preUpdate(ContextUser user) {
        if (user.getUserId()!=0) {
            this.updateUser = user.getUserId();
        }
        this.updateTime = new Date();
    }

}
