package cn.estsh.i3plus.pojo.wms.bean.snapshot;

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.enumutil.WmsEnumUtil;
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 org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * @Description : 库存条码信息
 * @Reference :
 * @Author : dragon.xu
 * @CreateDate : 2018-11-17 14:50
 * @Modify:
 **/
@Data
@Entity
@Table(name = "WMS_STOCK_SN_SNAPSHOT", indexes = {
        @Index(columnList = "PACKAGE_NO"),
        @Index(columnList = "PART_NO"),
        @Index(columnList = "REF_SRC"),
        @Index(columnList = "SN"),
        @Index(columnList = "SN_2D"),
        @Index(columnList = "WH_NO"),
        @Index(columnList = "ZONE_NO"),
        @Index(columnList = "LOCATE_NO"),
        @Index(columnList = "LOT_NO"),
        @Index(columnList = "FIX_LOT_NO"),
        @Index(columnList = "DATE_CODE"),
        @Index(columnList = "VENDOR_NO"),
        @Index(columnList = "ORGANIZE_CODE"),
        @Index(columnList = "SNAPSHOT_TIME")
        })
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Api(value = "库存条码信息", description = "库存条码信息")
public class WmsStockSnSnapshot extends SnapshotBean {

    private static final long serialVersionUID = 8641922373097608315L;

    @Column(name="SNAPSHOT_TIME")
    @ApiParam("快照时间")
    public String snapshotTime;

    @Column(name = "WH_NO")
    @ApiParam(value = "仓库代码")
    private String whNo;

    @Column(name = "ZONE_NO")
    @ApiParam(value = "存储区编号")
    private String zoneNo;

    @Column(name = "LOCATE_NO")
    @ApiParam(value = "库位代码")
    private String locateNo;

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

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

    @Column(name = "LOT_NO", nullable = false)
    @ApiParam("收货日期（批次编码）")
    public String lotNo = "";

    @Column(name = "DATE_CODE", nullable = false)
    @ApiParam(value = "生产日期")
    public String dateCode = "";

    @Column(name = "LEFT_CODE", nullable = false)
    @ApiParam(value = "有效期")
    private String leftCode = "";

    @Column(name = "VENDOR_NO")
    @ApiParam(value = "供应商编码")
    public String vendorNo;

    @Column(name = "FIX_LOT_NO", nullable = false)
    @ApiParam(value = "特殊批次")
    private String fixLotNo = "";

    @Column(name = "CUST_NO")
    @ApiParam(value = "客户编码")
    private String custNo;

    @Column(name = "SHIPPING_FLAG")
    @ApiParam(value = "发往地")
    private String shippingFlag;

    @Column(name = "SN")
    @ApiParam(value = "条码")
    private String sn;

    @Column(name = "SN_2D")
    @ApiParam(value = "二维码")
    private String sn2d;

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

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

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

    /**
     * 质量状态:10=合格,20=不合格,30=隔离
     */
    @Column(name = "QC_STATUS")
    @ApiParam(value = "质检状态", example = "0")
    @AnnoOutputColumn(refClass = WmsEnumUtil.STOCK_SN_QC_STATUS.class,refForeignKey = "value",value = "description")
    private Integer qcStatus;
    /**
     * 条码状态：1=创建，10=质检中，20=待入库，30=入库，40=配料，50=出库，60=报废，70=在途
     */
    @Column(name = "SN_STATUS")
    @ApiParam(value = "条码状态", example = "0")
    @AnnoOutputColumn(refClass = WmsEnumUtil.STOCK_SN_STATUS.class,refForeignKey = "value",value = "description")
    private Integer snStatus;
    /**
     * 1:已打印；2：未打印
     */
    @Column(name = "PRINTED")
    @ApiParam(value = "是否打印", example = "0")
    @AnnoOutputColumn(refClass = WmsEnumUtil.TRUE_OR_FALSE.class,refForeignKey = "value",value = "description")
    private Integer printed;

    @Column(name = "PDATE")
    @ApiParam(value = "打印时间")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date pdate;
    /**
     * 1=ASN,10=PO,20=SO
     */
    @Column(name = "REF_TYPE")
    @ApiParam(value = "关联单据类型")
    private String refType;

    @Column(name = "REF_SRC")
    @ApiParam(value = "关联单号")
    private String refSrc;

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

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

    @Column(name = "SN_TYPE")
    @ApiParam(value = "条码类型", example = "10")
    @AnnoOutputColumn(refClass = WmsEnumUtil.WMS_STOCK_TYPE.class,refForeignKey = "value",value = "description")
    private Integer snType = 10;

    @ApiParam(value = "仓库名称")
    @Transient
    public String whNameRdd;

    @ApiParam(value = "存储区名称")
    @Transient
    public String zoneNameRdd;

    @ApiParam(value = "库位名称")
    @Transient
    public String locateNameRdd;

    @ApiParam(value = "物料类型描述")
    @Transient
    public String partTypeDesc;

    @ApiParam(value = "客户名称")
    @Transient
    public String custNameRdd;

    @ApiParam(value = "供应商名称")
    @Transient
    public String vendorNameRdd;

    @ApiParam(value = "二维码内容")
    @Transient
    public String barCode;

    @ApiParam(value = "散件质检输入不良数量")
    @Transient
    public Double inputNCQty;

    @ApiParam(value = "前端散件表格是否编辑")
    @Transient
    public Boolean isSet = false;

    @ApiParam(value = "加减库容标志")
    @Transient
    public Boolean isAdd;

    @ApiParam(value = "项目名称")
    @Transient
    public String prodCfgTypeName;

    @ApiParam(value = "标签编号")
    @Transient
    public String labelNo;

    @Transient
    @ApiParam(value = "工厂名称")
    public String organizeName;

    @Transient
    @ApiParam(value = "物料数量总和")
    public Double sumPartQty;

    @Transient
    @ApiParam(value = "条码数量总和")
    public Long snCount;

    @Transient
    @ApiParam(value = "物料编码集合")
    public List<String> partNoList;

    @Transient
    @ApiParam(value = "ERP库存地集合")
    public List<String> erpZoneNoList;

    @Transient
    @ApiParam(value = "ERP库存地")
    public String erpZoneNo;

    @Transient
    @ApiParam(value = "目标数量")
    public Double destQty;

    public WmsStockSnSnapshot(){}

    public WmsStockSnSnapshot(String partNo){
        this.partNo = partNo;
    }

    public Integer getSnType() { return snType == null ? 0 : snType.intValue();}

    public Double getQty() {
        return qty == null ? 0L : qty.doubleValue();
    }

    public Double getInputNCQty(){return inputNCQty == null ? 0L : this.inputNCQty.doubleValue();}

    public WmsStockSnSnapshot(Long snCount, Double sumPartQty, String locateNo) {
        this.snCount = snCount;
        this.sumPartQty = sumPartQty;
        this.locateNo = locateNo;
    }
}
