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;

/**
 * @Author: Wynne.Lu
 * @CreateDate: 2019/10/18 1:26 下午
 * @Description:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "MES_PACKAGE", indexes = {
        @Index(columnList = "PACKAGE_NO"),
        @Index(columnList = "PART_NO"),
        @Index(columnList = "WORK_ORDER_NO"),
        @Index(columnList = "WORK_CENTER_CODE"),
        @Index(columnList = "WORK_CELL_CODE"),
        @Index(columnList = "IS_SEALED")
}, uniqueConstraints = {
        @UniqueConstraint(columnNames = {"ORGANIZE_CODE", "PACKAGE_NO"})
})
@Api("包装表")
public class MesPackage extends BaseBean implements Serializable {
    private static final long serialVersionUID = 5275923991324889995L;

    @Column(name = "PACKAGE_NO", nullable = false)
    @ApiParam("包装编号")
    private String packageNo;

    @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 = "PACK_SPEC_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam("包装规格数量")
    private Double packSpecQty;

    @Column(name = "UNIT")
    @ApiParam("单位")
    private String unit;

    @Column(name = "LOT_NO")
    @ApiParam("批号")
    private String lotNo;

    @Column(name = "FIX_LOT_NO")
    @ApiParam("特殊批号")
    private String fixLotNo;

    @Column(name = "PACK_SPEC")
    @ApiParam("包装规格")
    private String packSpec;

    @Column(name = "IS_SEALED")
    @ApiParam("是否封箱")
    private Integer isSealed;

    @Column(name = "PRINT_STATUS")
    @ApiParam("打印状态10：未打印 20：已打印")
    private Integer printStatus;

    @Column(name = "PACK_LEVEL")
    @ApiParam("包装层级 1-第一层，2-第二层，3-第三层，4-第四层")
    private Integer packLevel = 1;

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

    @Column(name = "WORK_CENTER_CODE")
    @ApiParam("工作中心代码")
    private String workCenterCode;

    @Column(name = "WORK_CELL_CODE")
    @ApiParam("工作单元代码")
    private String workCellCode;

    @Column(name = "MEMO")
    @ApiParam("备注")
    private String memo;

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

    @Column(name = "IN_LOCATION_TIME")
    @ApiParam("入库时间")
    private String inLocationTime;

    @Transient
    @ApiParam("封箱状态")
    private String sealStatus;

    @Transient
    @ApiParam("打印状态文字")
    private String printStrStatus;

    @Transient
    @ApiParam("打印缓存id")
    private String printId;

    @Column(name = "CT_NO")
    @ApiParam("容器编号")
    private String ctNo;

    @Column(name = "SAMPLE_TYPE")
    @ApiParam("条码类型")
    private String sampleType = "10";

    @Transient
    @ApiParam("客户发往地")
    private String custDeliveryLocation;

    // 赋值模板代码
    @Column(name = "PACKAGE_LABEL_TEMPLATE")
    @ApiParam("包装标签模板")
    private String packageLabelTemplate;

    // 二维码
    @Column(name = "QR_CODE")
    @ApiParam("包装二维码")
    private String qrCode;

    @Column(name = "LOCATION_CODE")
    @ApiParam("库位代码")
    private String locationCode;

    @Column(name = "ERP_WORK_CENTER_CODE")
    @ApiParam("erp工作中心")
    private String erpWorkCenterCode;

    @Transient
    @ApiParam("目标库位代码")
    private String destLocationCode;

    @Transient
    @ApiParam("不良处理类型")
    private String defectActionType;

    @Transient
    @ApiParam("明细总数")
    private Integer detailTotal = 0;

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

    @Transient
    @ApiParam("过程条码")
    private String serialNumber;

    @Transient
    @ApiParam("班组")
    private String shiftGroup;

    @Transient
    @ApiParam("客户名称")
    private String custName;

    public MesPackage() {
    }

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

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

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

    public MesPackage(String packageNo, String partNo, String partNameRdd, Double qty, Double packSpecQty) {
        this.packageNo = packageNo;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.qty = qty;
        this.packSpecQty = packSpecQty;
    }

    public MesPackage(String partNo, String partNameRdd,String packageNo, Double qty, String defectActionType, String createDatetime) {
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.packageNo = packageNo;
        this.qty = qty;
        this.defectActionType = defectActionType;
        this.createDatetime = createDatetime;
    }

    public MesPackage(String partNo, String partNameRdd,String workCenterCode, String workOrderNo,
                      String packageNo, String lotNo, String custCode, String shiftGroup) {
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.workCenterCode = workCenterCode;
        this.workOrderNo = workOrderNo;
        this.packageNo = packageNo;
        this.lotNo = lotNo;
        this.custCode = custCode;
        this.shiftGroup = shiftGroup;
    }
}
