package com.yiqi.common.core.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.yiqi.common.utils.DateUtils;
import com.yiqi.common.utils.SecurityUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;

/**
 * @author xiaohei
 * @date 2023/7/20
 */
@Data
public class BaseEntity {

    /**
     * 创建者ID
     */
    @ApiModelProperty("创建者ID")
    private Long createById;

    /**
     * 创建者
     */
    @ApiModelProperty("创建者")
    private String createBy;

    /**
     * 创建时间
     */
    @ApiModelProperty("创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    /**
     * 更新者ID
     */
    @ApiModelProperty("更新者ID")
    private Long updateById;

    public String getUpdateBy() {
        return updateBy;
    }

    /**
     * 更新者
     */
    @ApiModelProperty("更新者")
    private String updateBy;

    /**
     * 更新时间
     */
    @ApiModelProperty("更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty("备注")
    private String remark;

    public void buildCreateData() {
        setCreateById(AuthHolder.userId());
        setCreateBy(AuthHolder.userName());
        setCreateTime(DateUtils.getNowDate());
    }

    public void buildUpdateData() {
        setUpdateById(AuthHolder.userId());
        setUpdateBy(AuthHolder.userName());
        setUpdateTime(DateUtils.getNowDate());
    }


}
