package com.ruoyi.doubledefense.domain.common;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.constant.DeletedEnum;
import com.ruoyi.common.utils.JWTUtil;
import com.ruoyi.common.utils.SecurityUtils;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
public class BaseBean implements Serializable {
    /** 是否删除 */
    @Excel(name = "是否删除")
    @TableField("is_del")
    private Integer isDel;

    /** 创建人 */
    @Excel(name = "创建人")
    @TableField("create_user_id")
    private Long createUserId;

    /** 创建时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @TableField("create_date")
    private Date createDate;

    /** 修改人 */
    @Excel(name = "修改人")
    @TableField("update_user_id")
    private Long updateUserId;

    /** 修改时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "修改时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @TableField("update_date")
    private Date updateDate;

    /** 备注 */
    @Excel(name = "备注")
    @TableField("remark_info")
    private String remarkInfo;

    public void setCreateDefault(){
        this.setCreateUserId(SecurityUtils.getUserId());
        this.setCreateDate(new Date());
        this.setUpdateUserId(SecurityUtils.getUserId());
        this.setUpdateDate(new Date());
        this.setIsDel(DeletedEnum.VALID.getValue());
    }

    public void setCreateDefaultForApp(){
        this.setCreateUserId(Long.parseLong(JWTUtil.getUserId()));
        this.setCreateDate(new Date());
        this.setUpdateUserId(Long.parseLong(JWTUtil.getUserId()));
        this.setUpdateDate(new Date());
        this.setIsDel(DeletedEnum.VALID.getValue());

    }

    public void setUpdateDefaultForApp(){
        this.setUpdateUserId(Long.parseLong(JWTUtil.getUserId()));
        this.setUpdateDate(new Date());
    }

    public void setUpdateDefault(){
        this.setUpdateUserId(SecurityUtils.getUserId());
        this.setUpdateDate(new Date());
    }
}
