package com.qmth.sop.business.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.enums.DingExceptionApproveEnum;
import com.qmth.sop.common.enums.InOutTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 考勤补卡申请表
 * </p>
 *
 * @author wangliang
 * @since 2023-08-01
 */
@ApiModel(value = "TBDingApply对象", description = "考勤补卡申请表")
public class TBDingApply implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    @ApiModelProperty(value = "sop编号")
    @NotBlank(message = "sop号不能为空")
    private String sopNo;

    @ApiModelProperty(value = "派单号")
    @NotBlank(message = "crm派单号不能为空")
    private String crmNo;

    @ApiModelProperty(value = "考勤id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long dingId;

    @ApiModelProperty(value = "类型，IN：签到，OUT：签退")
    @NotNull(message = "类型不能为空")
    private InOutTypeEnum type;

    @ApiModelProperty(value = "补卡时间")
    @NotNull(message = "补卡时间不能为空")
    private Long applyTime;

    @ApiModelProperty(value = "补卡原因")
    @NotBlank(message = "补卡原因不能为空")
    private String reason;

    @ApiModelProperty(value = "附件id")
    private String attachmentIds;

    @ApiModelProperty(value = "附件地址")
    private String attachmentPaths;

    @ApiModelProperty(value = "附件id数组")
    @TableField(exist = false)
    @JsonSerialize(using = ToStringSerializer.class)
    @NotEmpty(message = "补卡附件不能为空")
    private List<Long> attachmentIdList;

    @ApiModelProperty(value = "考勤异常编号")
    @JsonSerialize(using = ToStringSerializer.class)
    private String dingExceptionNo;

    @ApiModelProperty(value = "创建人id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long createId;

    @ApiModelProperty(value = "创建时间")
    private Long createTime;

    @ApiModelProperty(value = "审批操作，PASS：通过，NO_PASS：不通过")
    DingExceptionApproveEnum approve;

    @TableField(exist = false)
    @ApiModelProperty(value = "流程部署id")
    @NotBlank(message = "流程部署id不能为空")
    private String flowDeploymentId;

    @ApiModelProperty(value = "流程审批人")
    @TableField(exist = false)
    @JsonSerialize(using = ToStringSerializer.class)
    private List<String> approveUserIds;

    @ApiModelProperty(value = "异常类型")
    @TableField(exist = false)
    private String dingExceptionTypeStr;

    @ApiModelProperty(value = "当前审核人")
    @TableField(exist = false)
    private String approveUserName;

    @ApiModelProperty("异常日期")
    @TableField(exist = false)
    private String exceptionTime;

    public void setCode(String dingExceptionNo, List<Long> attachmentIdList, Long userId) {
        this.dingExceptionNo = dingExceptionNo;
        setId(SystemConstant.getDbUuid());
        setCreateId(userId);
        setCreateTime(System.currentTimeMillis());
        this.attachmentIds = Objects.nonNull(attachmentIdList) ? StringUtils.join(attachmentIdList, SystemConstant.LIST_JOIN_SPLIT) : null;
    }

    public String getExceptionTime() {
        return exceptionTime;
    }

    public void setExceptionTime(String exceptionTime) {
        this.exceptionTime = exceptionTime;
    }

    public String getDingExceptionTypeStr() {
        if (Objects.nonNull(type)) {
            String[] strs = type.getTitle().split("｜");
            return strs[1];
        } else {
            return dingExceptionTypeStr;
        }
    }

    public void setDingExceptionTypeStr(String dingExceptionTypeStr) {
        this.dingExceptionTypeStr = dingExceptionTypeStr;
    }

    public String getApproveUserName() {
        return approveUserName;
    }

    public void setApproveUserName(String approveUserName) {
        this.approveUserName = approveUserName;
    }

    public String getAttachmentPaths() {
        return attachmentPaths;
    }

    public void setAttachmentPaths(String attachmentPaths) {
        this.attachmentPaths = attachmentPaths;
    }

    public String getSopNo() {
        return sopNo;
    }

    public void setSopNo(String sopNo) {
        this.sopNo = sopNo;
    }

    public String getCrmNo() {
        return crmNo;
    }

    public void setCrmNo(String crmNo) {
        this.crmNo = crmNo;
    }

    public DingExceptionApproveEnum getApprove() {
        return approve;
    }

    public void setApprove(DingExceptionApproveEnum approve) {
        this.approve = approve;
    }

    public List<String> getApproveUserIds() {
        return approveUserIds;
    }

    public void setApproveUserIds(List<String> approveUserIds) {
        this.approveUserIds = approveUserIds;
    }

    public List<Long> getAttachmentIdList() {
        return attachmentIdList;
    }

    public void setAttachmentIdList(List<Long> attachmentIdList) {
        this.attachmentIdList = attachmentIdList;
    }

    public String getFlowDeploymentId() {
        return flowDeploymentId;
    }

    public void setFlowDeploymentId(String flowDeploymentId) {
        this.flowDeploymentId = flowDeploymentId;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getDingId() {
        return dingId;
    }

    public void setDingId(Long dingId) {
        this.dingId = dingId;
    }

    public InOutTypeEnum getType() {
        return type;
    }

    public void setType(InOutTypeEnum type) {
        this.type = type;
    }

    public Long getApplyTime() {
        return applyTime;
    }

    public void setApplyTime(Long applyTime) {
        this.applyTime = applyTime;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public String getAttachmentIds() {
        return attachmentIds;
    }

    public void setAttachmentIds(String attachmentIds) {
        this.attachmentIds = attachmentIds;
    }

    public String getDingExceptionNo() {
        return dingExceptionNo;
    }

    public void setDingExceptionNo(String dingExceptionNo) {
        this.dingExceptionNo = dingExceptionNo;
    }

    public Long getCreateId() {
        return createId;
    }

    public void setCreateId(Long createId) {
        this.createId = createId;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }
}
