package com.unis.base.common.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.unis.common.utils.CurrentUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;

/**
 * @author by PIG
 * 2023/6/30 09
 */
@AllArgsConstructor(access = AccessLevel.PACKAGE)
@NoArgsConstructor
@Builder
@Data
@Table(name = "tz_slqy_update_log")
public class TzSlqyUpdateLogVO implements Serializable {
    private static final long serialVersionUID = -1;

    private Long fid;
    @ApiModelProperty(value="数据状态")
    private Integer status = 0;

    /**
     * 创建人
     */
    @ApiModelProperty(value="创建者")
    private String creator;

    /**
     * 创建人编号
     */
    @ApiModelProperty(value="创建人编号")
    private String creatorCode;

    /**
     * 创建时间
     */
    @JSONField(format="yyyy-MM-dd HH:mm")
    @DateTimeFormat( pattern = "yyyy-MM-dd HH:mm")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    @ApiModelProperty(value="创建时间")
    private Date createDate;

    /**
     * 刷新时间
     */
    @JSONField(format="yyyy-MM-dd HH:mm")
    @DateTimeFormat( pattern = "yyyy-MM-dd HH:mm")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    @ApiModelProperty(value="刷新时间")
    @Column(name = "refresh_time")
    private Date refreshTime;

    /**
     * 刷新人
     */
    @ApiModelProperty(value="更新人")
    private String refresher;

    /**
     * 刷新人编号
     */
    @ApiModelProperty(value="更新人编号")
    @Column(name = "refresher_code")
    private String refresherCode;


    @Column(name = "tyshxydm")
    private String tyshxydm;
    @Column(name = "update_col")
    private String updateCol;
    @Column(name = "before_data")
    private String beforeData;
    @Column(name = "after_data")
    private String afterData;

    @Column(name = "data_ver")
    private Integer dataVer;

    /**
     * 备注
     */
    @ApiModelProperty(value="备注")
    private String remark;

    public TzSlqyUpdateLogVO buildInsertData(){
        this.status=1;
        this.creator= CurrentUtil.getUserAccount();
        this.creatorCode= CurrentUtil.getUserId();
        this.createDate = new Date();
        return this;
    }

    /**
     *
     * @param tyshxydm tyshxydm
     * @param updateCol 更新字段
     * @param beforeData 当前值
     * @param afterData 更新之后的值
     */
    public TzSlqyUpdateLogVO(String tyshxydm, String updateCol, String beforeData, String afterData) {
        this.tyshxydm = tyshxydm;
        this.updateCol = updateCol;
        this.afterData = afterData;
        this.beforeData = beforeData;
        this.status = 0; // 初始化为0 信息审核通过改成 1
//        this.creator = CurrentUtil.getUserAccount();
//        this.creatorCode = CurrentUtil.getUserId();
        this.createDate = new Date();
        this.refreshTime = new Date();
    }

    public enum COL{
        /** 企业名称*/
        QYMC("企业名称"),
        /** 单位性质*/
        QYXZ("单位性质"),
        /** 法定代表人*/
        FDDBR("法定代表人");

        @Getter
        private String name;

        COL(String name){
            this.name = name;
        }
        public boolean equName(String name){
            return this.name.equals(name);
        }
    }
}
