package com.ruoyi.demo.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.ruoyi.demo.entity.bo.PlanBo;
import lombok.Data;

import java.time.LocalDateTime;
import java.time.ZoneId;

@Data
@TableName("dl_plan_audit")
public class PlanAudit {
    @TableId(value = "audit_id",type = IdType.ASSIGN_ID)
    private String auditId;
    @TableField("plan_id")
    private String planId;
    @TableField("user_id")
    private String userId;
    @TableField("user_name")
    private String userName;
    @TableField("state")
    private Integer state;
    @TableField("audit_comment")
    private String auditComment;
    @TableField("audit_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime auditTime;

    @TableField("deleted")
    private int deleted;

    public PlanAudit (){}
    public PlanAudit(PlanBo bo,String userId,String userName){
        this.setPlanId(bo.getPlanId());
        this.setUserId(userId);
        this.userName = userName;
        this.setState(bo.getState());
//        this.setAuditComment(bo.getAuditComment());
        if (bo.getState() == 1)
            this.setAuditComment("审核通过");
        else if (bo.getState() == 0)
            this.setAuditComment("未进行审核");
        else this.setAuditComment("审核不通过");
        this.setAuditTime(LocalDateTime.now(ZoneId.of("Asia/Shanghai")));
    }
}
