package cn.estsh.i3plus.pojo.mes.bean;

import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.io.Serializable;

/**
 * @Description:
 * @Reference:
 * @Author: Crish
 * @CreateDate:2019-04-16-17:36
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "MES_PRODUCE_SN", indexes = {
        @Index(columnList = "SERIAL_NUMBER"),
        @Index(columnList = "PRODUCT_SN"),
        @Index(columnList = "CREATE_DATE_TIME"),
        @Index(columnList = "MODIFY_DATE_TIME"),
        @Index(columnList = "WORK_ORDER_NO")
}, uniqueConstraints = {
        @UniqueConstraint(columnNames = {"ORGANIZE_CODE", "SERIAL_NUMBER"})
})
@Api("产品条码表")
public class MesProduceSn extends BaseBean implements Serializable {
    private static final long serialVersionUID = -1630924042562178494L;

    @Column(name = "SERIAL_NUMBER", nullable = false)
    @ApiParam("过程条码")
    private String serialNumber;

    @Column(name = "PRODUCT_SN")
    @ApiParam("产品条码")
    private String productSn;

    @Column(name = "PART_NO")
    @ApiParam("物料号")
    private String partNo;

    @Column(name = "PART_NAME_RDD")
    @ApiParam("物料名称")
    private String partNameRdd;

    @Column(name = "QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam("数量")
    private Double qty;

    @Column(name = "QC_STATUS")
    @ApiParam("质量状态")
    private Integer qcStatus;

    @Column(name = "SN_STATUS")
    @ApiParam("条码状态")
    private Integer snStatus;

    @Column(name = "PRINT_COUNT")
    @ApiParam("打印次数")
    private Integer printCount;

    @Column(name = "PRINT_STATUS")
    @ApiParam("打印状态")
    private Integer printStatus;

    @Column(name = "WORK_CENTER_CODE")
    @ApiParam("生产线")
    private String workCenterCode;

    @Column(name = "WORK_CELL_CODE")
    @ApiParam("工位")
    private String workCellCode;

    @Column(name = "ROUTE_CODE")
    @ApiParam("流程代码")
    private String routeCode;

    @Column(name = "PROCESS_CODE")
    @ApiParam("工序代码")
    private String processCode;

    @Column(name = "NEXT_PROCESS_CODE")
    @ApiParam("下一工序代码")
    private String nextProcessCode;

    @Column(name = "IN_WC_TIME")
    @ApiParam("进产线时间")
    private String inWorkCenterTime;

    @Column(name = "OUT_WC_TIME")
    @ApiParam("出产线时间")
    private String outWorkCenterTime;

    @Column(name = "SHIPPING_TIME")
    @ApiParam("发运时间")
    private String shippingTime;

    @Column(name = "WORK_ORDER_NO")
    @ApiParam("生产工单号")
    private String workOrderNo;

    @Column(name = "CUST_SN")
    @ApiParam("客户条码")
    private String custSn;

    @Column(name = "CUST_PART_NO")
    @ApiParam("客户零件号")
    private String custPartNo;

    @Column(name = "CUST_CODE")
    @ApiParam("客户代码")
    private String custCode;

    @Column(name = "SN_TYPE")
    @ApiParam("条码类型 10=正常 20=首检件")
    private Integer snType;

    @Column(name = "TRAY_NO")
    @ApiParam("托盘号")
    private String trayNo;

    @Column(name = "OPERATE_TYPE")
    @ApiParam("操作类型")
    private Integer operateType;

    @Column(name = "PROCESS_LABEL_TEMPLATE")
    @ApiParam("过程标签模板")
    private String processLabelTemplate;

    @Column(name = "PROD_LABEL_TEMPLATE")
    @ApiParam("产品标签模板")
    private String prodLabelTemplate;

    @Column(name = "CUST_LABEL_TEMPLATE")
    @ApiParam("客户标签模板")
    private String custLabelTemplate;

    @Column(name = "LOT_NO")
    @ApiParam("生产批次")
    private String lotNo;

    @Column(name = "DEFECT_ACTION_TYPE")
    @ApiParam("不良处理类型")
    private String defectActionType;

    @Column(name = "VIN_CODE")
    @ApiParam("Vin")
    private String vinCode;

    @Transient
    @ApiParam("返回信息")
    private String resultMsg;

    @Transient
    @ApiParam("下线开始时间")
    private String outWorkCenterTimeStart;

    @Transient
    @ApiParam("下线结束时间")
    private String outWorkCenterTimeEnd;

    @Transient
    @ApiParam("操作类型名称")
    private String operateTypeName;

    @Transient
    @ApiParam("条码状态名称")
    private String snStatusName;

    @Transient
    @ApiParam("质量状态名称")
    private String qcStatusName;

    @Transient
    @ApiParam("条码类型名称")
    private String snTypeName;

    @Transient
    @ApiParam("条码打印状态名称")
    private String printStatusName;

    @Transient
    @ApiParam("设备代码")
    private String equipmentCode;

    @Transient
    @ApiParam("设备名称")
    private String equipmentName;

    @Transient
    @ApiParam("电检结果")
    private String electricResult;

    @Transient
    @ApiParam("包规数量")
    private Double packageQty;

//    @Version
//    @Column(name = "LOCK_VERSION")
//    @ApiParam(value = "乐观锁", example = "1")
//    public Integer lockVersion;

    @Transient
    @ApiParam("缺陷代码")
    private String defectCode;

    @Transient
    @ApiParam("缺陷名称")
    private String defectName;

    @Transient
    @ApiParam("维修状态")
    private Integer repairStatus;

    @Transient
    @ApiParam("颜色名称")
    private String colorName;

    @Transient
    @ApiParam("物料版本号")
    private String versionNo;

    @Transient
    @ApiParam("配方内容")
    private String formulaContent;

    @Transient
    @ApiParam("分组队列编号")
    private String queueGroupNo;

    @Transient
    @ApiParam("组内编号")
    private Integer groupNo;

    @Transient
    @ApiParam("总数")
    private long sumQty;

    public MesProduceSn() {
    }

    public MesProduceSn(String partNo, Integer qcStatus, Double qty) {
        this.partNo = partNo;
        this.qcStatus = qcStatus;
        this.qty = qty;
    }


    public MesProduceSn(String workCenterCode, String partNo, String partNameRdd, long sumQty) {
        this.workCenterCode = workCenterCode;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.sumQty = sumQty;
    }

    public MesProduceSn(Long id, String serialNumber, String productSn, String partNo, String partNameRdd, Double qty, Integer qcStatus, Integer snStatus,
                        Integer printCount, Integer printStatus, String workCenterCode, String workCellCode, String routeCode, String processCode,
                        String nextProcessCode, String inWorkCenterTime, String outWorkCenterTime, String shippingTime, String workOrderNo,
                        String custSn, String custPartNo, String custCode, Integer snType, String trayNo, Integer operateType,
                        String processLabelTemplate, String prodLabelTemplate, String custLabelTemplate, String lotNo,
                        String defectActionType, String vinCode, String versionNo, String createUser, String createDatetime) {
        this.id = id;
        this.serialNumber = serialNumber;
        this.productSn = productSn;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.qty = qty;
        this.qcStatus = qcStatus;
        this.snStatus = snStatus;
        this.printCount = printCount;
        this.printStatus = printStatus;
        this.workCenterCode = workCenterCode;
        this.workCellCode = workCellCode;
        this.routeCode = routeCode;
        this.processCode = processCode;
        this.nextProcessCode = nextProcessCode;
        this.inWorkCenterTime = inWorkCenterTime;
        this.outWorkCenterTime = outWorkCenterTime;
        this.shippingTime = shippingTime;
        this.workOrderNo = workOrderNo;
        this.custSn = custSn;
        this.custPartNo = custPartNo;
        this.custCode = custCode;
        this.snType = snType;
        this.trayNo = trayNo;
        this.operateType = operateType;
        this.processLabelTemplate = processLabelTemplate;
        this.prodLabelTemplate = prodLabelTemplate;
        this.custLabelTemplate = custLabelTemplate;
        this.lotNo = lotNo;
        this.defectActionType = defectActionType;
        this.vinCode = vinCode;
        this.versionNo = versionNo;
        this.createUser = createUser;
        this.createDatetime = createDatetime;
    }

    public double getQtyVal() {
        return this.qty == null ? 0.0d : this.qty;
    }

    public int getQcStatusVal() {
        return this.qcStatus == null ? 0 : this.qcStatus;
    }

    public int getSnStatusVal() {
        return this.snStatus == null ? 0 : this.snStatus;
    }

    public int getPrintCountVal() {
        return this.printCount == null ? 0 : this.printCount;
    }

    public int getPrintStatusVal() {
        return this.printStatus == null ? 0 : this.printStatus;
    }

    public int getSnTypeVal() {
        return this.snType == null ? 0 : this.snType;
    }

    @Override
    public String toString() {
        return "MesProduceSn{" +
                "serialNumber='" + serialNumber + '\'' +
                ", partNo='" + partNo + '\'' +
                ", partNameRdd='" + partNameRdd + '\'' +
                ", qty=" + qty +
                ", qcStatus=" + qcStatus +
                ", snStatus=" + snStatus +
                ", printCount=" + printCount +
                ", printStatus=" + printStatus +
                ", workCenterCode='" + workCenterCode + '\'' +
                ", workCellCode='" + workCellCode + '\'' +
                ", routeCode='" + routeCode + '\'' +
                ", processCode='" + processCode + '\'' +
                ", nextProcessCode='" + nextProcessCode + '\'' +
                ", inWorkCenterTime='" + inWorkCenterTime + '\'' +
                ", outWorkCenterTime='" + outWorkCenterTime + '\'' +
                ", shippingTime='" + shippingTime + '\'' +
                ", workOrderNo='" + workOrderNo + '\'' +
                ", custSn='" + custSn + '\'' +
                ", custPartNo='" + custPartNo + '\'' +
                ", snType=" + snType +
                ", trayNo='" + trayNo + '\'' +
                ", operateType=" + operateType +
                ", resultMsg='" + resultMsg + '\'' +
                '}';
    }
}
