package com.sy.coinage.workshop.model;

import com.baomidou.mybatisplus.annotation.*;

import java.io.Serializable;

import com.sy.coinage.core.util.DateUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.Date;
import java.util.List;

import com.alibaba.fastjson2.annotation.JSONField;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;

/**
 * -rfid基础信息登记表实体类
 */
@Data
@EqualsAndHashCode(callSuper = false)

@TableName("rfid_base_info")
@ApiModel(value = "rfid基础信息登记表对象", description = "rfid基础信息登记表")
public class BaseInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "EPC码")
    @TableField(value = "rfid")
    private String rfid;

    @ApiModelProperty(value = "封包线产品来源部门ID")
    @TableField(value = "res_dept_id")
    private Integer resDeptId;

    @ApiModelProperty(value = "封包线产品来源部门名称")
    @TableField(value = "res_dept")
    private String resDept;

    @ApiModelProperty(value = "所属部门ID")
    @TableField(value = "dept_id")
    private Integer deptId;

    @ApiModelProperty(value = "所属部门名称")
    @TableField(value = "dept")
    private String dept;

    @ApiModelProperty(value = "创建人")
    @TableField(value = "create_by")
    private String createBy;

    @ApiModelProperty(value = "创建人id")
    @TableField(value = "create_id")
    private Integer createId;

    @ApiModelProperty(value = "创建时间")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @ApiModelProperty(
            value = "生命周期状态:1初始登记 2:车间入库 3:车间出库 4:总库入库  5:主库抽检出库 6.车间抽检入库确认 7.车间抽检出库8 主库抽检返回确认 9返检总库出库 10:返检车间确认 11拆包 12：已发货 13:返回机台")
    @TableField(value = "status")
    private Integer status;

    @ApiModelProperty(value = "品名ID")
    @TableField(value = "securities_id")
    private Integer securitiesId;

    @ApiModelProperty(value = "品名")
    @TableField(value = "securities")
    private String securities;

    @ApiModelProperty(value = "编号")
    @TableField(value = "serial_number")
    private String serialNumber;

    @ApiModelProperty(value = "冠字号前缀")
    @TableField(value = "crown_prefix")
    private String crownPrefix;

    @ApiModelProperty(value = "皮重")
    @TableField(value = "tare_weight")
    private Double tareWeight;

    @ApiModelProperty(value = "毛重")
    @TableField(value = "gross_weight")
    private Double grossWeight;

    @ApiModelProperty(value = "称重人ID")
    @TableField(value = "weightor_id")
    private Integer weightorId;

    @ApiModelProperty(value = "称重人")
    @TableField(value = "weightor")
    private String weightor;

    @ApiModelProperty(value = "称重日期")
    @TableField(value = "weight_date")
    @JSONField(format = "yyyy-MM-dd")
    private Date weightDate;

    @ApiModelProperty(value = "称重时间 hh:mm:ss")
    @TableField(value = "weight_time")
    private String weightTime;

    @ApiModelProperty(value = "打印状态: 1.未打印 2.已打印")
    @TableField(value = "print_status")
    private Integer printStatus;

    @ApiModelProperty(value = "打印时间")
    @TableField(value = "print_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date printTime;

    @ApiModelProperty(value = "打印操作人ID")
    @TableField(value = "printer_id")
    private Integer printerId;

    @ApiModelProperty(value = "打印操作人")
    @TableField(value = "printer")
    private String printer;

    @ApiModelProperty(value = "抽检状态1:主库出库 2:车间入库 3:车间出库 4:主库入库")
    @TableField(value = "check_status")
    private Integer checkStatus;

    @ApiModelProperty(value = "主库出库抽检时间")
    @TableField(value = "check_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date checkTime;

    @ApiModelProperty(value = "车间确认入库时间")
    @TableField(value = "workshop_check_in_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date workshopCheckInTime;

    @ApiModelProperty(value = "抽检车间出库时间")
    @TableField(value = "workshop_check_out_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date workshopCheckOutTime;

    @ApiModelProperty(value = "抽查返回时间")
    @TableField(value = "check_return_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date checkReturnTime;

    @ApiModelProperty(value = "拆包状态 1:未拆包 2:已拆包")
    @TableField(value = "unpackage_status")
    private Integer unpackageStatus;

    @ApiModelProperty(value = "拆包时间")
    @TableField(value = "unpackage_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date unpackageTime;

    @ApiModelProperty(value = "返检状态 1:未返检 2: 已返检")
    @TableField(value = "return_check_status")
    private Integer returnCheckStatus;

    @ApiModelProperty(value = "车间返检确认状态1:未确认2:已确认接收")
    @TableField(value = "return_check_confirm_status")
    private Integer returnCheckConfirmStatus;

    @ApiModelProperty(value = "车间返检确认时间")
    @TableField(value = "return_check_confirm_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date returnCheckConfirmTime;

    @ApiModelProperty(value = "返检时间")
    @TableField(value = "return_check_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date returnCheckTime;

    @ApiModelProperty(value = "质量状态 1:合格2:待定3:待检")
    @TableField(value = "quality_status")
    private Integer qualityStatus;

    @ApiModelProperty(value = "设置质量时间")
    @TableField(value = "quality_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date qualityTime;

    @ApiModelProperty(value = "发货时间")
    @TableField(value = "delivery_time", updateStrategy = FieldStrategy.DEFAULT)
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date deliveryTime;

    @ApiModelProperty(value = "发货地址id")
    @TableField(value = "address_id")
    private String addressId;

    @ApiModelProperty(value = "发货地址")
    @TableField(value = "address_cn")
    private String addressCn;
    /**
     * -绑定rfid数据的来源类型： 1:封包线整拍数据 2.封包线非整拍数据 3:拆包后新构成的rfid 4:原有物料整拍绑定 5.原有物料整拍绑定（原始非整拍） -10
     */
    @ApiModelProperty(value = "绑定rfid数据的来源类型： 1:封包线整拍数据 2.封包线非整拍数据 3:拆包后新构成的rfid 4:原有物料整拍绑定 5.原有物料整拍绑定（原始非整拍）")
    @TableField(value = "origin_type")
    private Integer originType;

    @ApiModelProperty(value = "来自封包线数据的请求ID,用于判重")
    @TableField(value = "seq_id")
    private String seqId;

    @ApiModelProperty(value = "数量:一个拍子上有多少箱（拆包：表示拆的包有多少箱)，主要用于拆包")
    @TableField(value = "qty")
    private Integer qty;

    @ApiModelProperty(value = "当仅为拆包登记绑定新的rfid时（origin_type=2），将拆出的数据变为字符串保存")
    @TableField(value = "crown_between")
    private String crownBetween;

    @ApiModelProperty(value = "冠字号起始")
    @TableField(value = "crown_from")
    private String crownFrom;

    @ApiModelProperty(value = "冠字号结束点")
    @TableField(value = "crown_to")
    private String crownTo;

    @ApiModelProperty(value = "复核人ID")
    @TableField(value = "check_id")
    private Integer checkId;

    @ApiModelProperty(value = "复核人姓名")
    @TableField(value = "checker")
    private String checker;

    @ApiModelProperty(value = "整拍物料存储在哪个库:201主库一，202主库二,102造币二部临时库")
    @TableField(value = "loc_ware_id")
    private Integer locWareId;

    @ApiModelProperty(value = "当存储在主库一，主库二时，需保存该库库位信息")
    @TableField(value = "loc_area_id")
    private Integer locAreaId;

    @ApiModelProperty(value = "最大净重")
    @TableField(value = "max_weight", select = false, exist = false)
    private Double maxWeight;


    @ApiModelProperty(value = "最小净重")
    @TableField(value = "min_weight", select = false, exist = false)
    private Double minWeight;

    @ApiModelProperty(value = "当仅为拆包登记绑定旧的rfid时（origin_type=2），将拆出的数据变为字符串保存")
    @TableField(select = false, exist = false)
    private String oldCrownBetween;


    @ApiModelProperty(value = "旧的rfid")
    @TableField(select = false, exist = false)
    private String oldRfid;


    @ApiModelProperty(value = "当前位置")
    @TableField(select = false, exist = false)
    private String locWare;

    @ApiModelProperty(value = "err_check:复核异常err_quality:质量异常")
    @TableField(select = false, exist = false)
    private String errType;

    @ApiModelProperty(value = "2: 入库3:出库")
    @TableField(select = false, exist = false)
    private Integer inOrOut;

    @ApiModelProperty(value = "子前缀")
    @TableField(select = false, exist = false)
    private String crownPrefixSub;

    @ApiModelProperty(value = "子冠字号起始")
    @TableField(select = false, exist = false)
    private String crownFromSub;

    @ApiModelProperty(value = "子冠字号结束点")
    @TableField(select = false, exist = false)
    private String crownToSub;

    @ApiModelProperty(value = "rfid子单")
    @TableField(select = false, exist = false)
    private List<BaseInfoSub> child;

    @JSONField(serialize = false)
    public String getCrownBetweenStr() {
        if (StringUtils.isNotBlank(this.crownPrefix)) {
            if (StringUtils.isNotBlank(this.crownPrefixSub)) {
                return this.crownPrefix + this.crownFrom + "-"
                        + this.crownPrefix + this.crownTo + "," +
                        this.crownPrefixSub + this.crownFromSub + "-"
                        + this.crownPrefixSub + this.crownToSub;
            } else {
                return this.crownPrefix + this.crownFrom + "-"
                        + this.crownPrefix + this.crownTo;
            }
        } else {
            return this.crownBetween;
        }
    }

    @JSONField(serialize = false)
    public String getPrintTimeStr() {
        return DateUtils.toString(this.weightDate) + " " + this.weightTime;
    }

    @JSONField(serialize = false)
    public Date getNewPrintTime() {
        return DateUtils.toDate(DateUtils.toString(this.weightDate) + " " + this.weightTime, DateUtils.YY_MM_DD_HH_mm_ss);
    }

}
