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

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
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 javax.persistence.*;

/**
 * @Description : 库存移动单明细信息
 * @Reference :
 * @Author : silliter.yuan
 * @CreateDate : 2018-11-06 15:58
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name="WMS_MOVE_DETAILS_SNAPSHOT", indexes = {
        @Index(columnList = "PART_NO"),
        @Index(columnList = "ORDER_NO"),
        @Index(columnList = "ORGANIZE_CODE"),
        @Index(columnList = "SNAPSHOT_TIME")
})
@Api("库存移动单明细信息")
public class WmsMoveDetailsSnapshot extends BaseBean {

    private static final long serialVersionUID = -4095410692227226944L;

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

    @Column(name="ORDER_NO")
    @ApiParam("单号")
    public String orderNo;

    @Column(name="ITEM")
    @ApiParam(value = "行号", example = "0")
    public Integer item;

    @Column(name="PART_NO")
    @ApiParam("物料编码")
    public String partNo;

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

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

    @Column(name="CUST_NO")
    @ApiParam("客户编号")
    public String custNo;

    @Column(name="TRANS_QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ApiParam(value = "处理数量", example = "0")
    @ColumnDefault("0")
    public Double transQty;

    public Double getTransQty(){
        return this.transQty == null ? 0 : this.transQty.doubleValue();
    }

    @Column(name="REJECT_QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ApiParam(value = "不合格处理数量", example = "0")
    @ColumnDefault("0")
    public Double rejectQty;

    public Double getRejectQty(){
        return this.rejectQty == null ? 0 : this.rejectQty.doubleValue();
    }

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

    @Column(name="SRC_WH_NO")
    @ApiParam("源仓库代码")
    public String srcWhNo;

    @Column(name="SRC_ZONE_NO")
    @ApiParam("源存储区代码")
    public String srcZoneNo;

    @Column(name="SRC_LOCATE_NO")
    @ApiParam("源库位代码")
    public String srcLocateNo;

    @Column(name="DEST_WH_NO")
    @ApiParam("目标仓库代码")
    public String destWhNo;

    @Column(name="DEST_ZONE_NO")
    @ApiParam("目标存储区代码")
    public String destZoneNo;

    @Column(name="DEST_LOCATE_NO")
    @ApiParam("目标库位代码")
    public String destLocateNo;

    /**
     * 状态:1=创建,10=待处理,20=已处理
     */
    @Column(name="ITEM_STATUS")
    @ApiParam(value = "状态", example = "0")
    @AnnoOutputColumn(refClass = WmsEnumUtil.MOVE_ORDER_STATUS.class,refForeignKey = "value",value = "description")
    public Integer itemStatus;

    @Column(name="REF_ITEM")
    @ApiParam("关联单据行号")
    public String refItem;

    /**
     * ASN,PO,SO
     */
    @Column(name="REF_TYPE")
    @ApiParam("关联单据类型")
    public String refType;

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

    @ApiParam(value = "待出库数量", example = "0")
    @Transient
    private Long waitingCounts;

    @ApiParam(value = "已出库数量", example = "0")
    @Transient
    private Long finishedCounts;

    @Transient
    @ApiParam("交易类型")
    private String transTypeCode;

    @Transient
    @ApiParam("erp库存地")
    private String ZoneNo;

    @Transient
    @ApiParam("条码")
    private String sn;

    @Transient
    @ApiParam("交易类型名称")
    private String transTypeName;

    @Transient
    @ApiParam("业务类型编码")
    @AnnoOutputColumn(refClass = WmsEnumUtil.OUT_MOVEMENT_BUSI_TYPE.class,refForeignKey = "value",value = "description")
    private Integer busiTypeCode;

    @Transient
    @ApiParam("生产线")
    private String workCenterCode;

    @Transient
    @ApiParam("父物料编码")
    private String fpartNo;

    @Transient
    @ApiParam("父物料名称")
    private String fpartName;

    @Transient
    @ApiParam("数量")
    private Double qty;

    @Transient
    @ApiParam("创建时间")
    private String createDateTime;

    @Version
    @Column(name = "LOCK_VERSION")
    @ApiParam(value = "乐观锁", example = "1")
    public transient Integer lockVersion;
   /* @JSONField(name="fPartNo")
    public String getfPartNo() {
        return fPartNo;
    }

    @JSONField(name="fPartName")
    public String getfPartName() {
        return fPartName;
    }*/

    public WmsMoveDetailsSnapshot(){}

    public WmsMoveDetailsSnapshot(String partNo, Long waitingCounts , Long finishedCounts){
        this.partNo = partNo;
        this.waitingCounts = waitingCounts;
        this.finishedCounts = finishedCounts;
    }

    public WmsMoveDetailsSnapshot(String partNo, double transQty){
        this.partNo = partNo;
        this.transQty = transQty;
    }

    public WmsMoveDetailsSnapshot(String orderNo){
        this.orderNo = orderNo;
    }

    public Long getWaitingCounts() {
        return waitingCounts == null ? 0L : this.waitingCounts;
    }

    public Long getFinishedCounts() {
        return finishedCounts == null ? 0L : this.finishedCounts;
    }

    public WmsMoveDetailsSnapshot(String organizeCode, String partNo, String partNameRdd, String workCenterCode, String fPartNo, String fPartName, String unit, Double qty,
                                  String createDateTime, String sn, String srcZoneNo){
        this.organizeCode = organizeCode;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.workCenterCode = workCenterCode;
        this.fpartNo = fPartNo;
        this.fpartName = fPartName;
        this.unit = unit;
        this.qty = qty;
        this.createDateTime = createDateTime;
        this.sn = sn;
        this.srcZoneNo = srcZoneNo;

    }

    public WmsMoveDetailsSnapshot(String organizeCode, String orderNo, Integer item, String partNo, String partNameRdd, String transTypeCode
            , String transTypeName, Integer itemStatus, String unit, String srcWhNo, String destWhNo,
                                  String srcZoneNo, String destZoneNo, String srcLocateNo, String destLocateNo,
                                  Double transQty, Double rejectQty, String refSrc, String vendorNo, String custNo, Integer busiTypeCode,
                                  String createUser, String createDatetime, String modifyUser, String modifyDatetime){
        this.organizeCode = organizeCode;
        this.partNo = partNo;
        this.orderNo = orderNo;
        this.item = item;
        this.partNameRdd = partNameRdd;
        this.transTypeCode = transTypeCode;
        this.transTypeName = transTypeName;
        this.itemStatus = itemStatus;
        this.unit = unit;
        this.srcWhNo = srcWhNo;
        this.destWhNo = destWhNo;
        this.srcZoneNo = srcZoneNo;
        this.destZoneNo = destZoneNo;
        this.srcLocateNo = srcLocateNo;
        this.destLocateNo = destLocateNo;
        this.transQty = transQty;
        this.rejectQty = rejectQty;
        this.refSrc = refSrc;
        this.vendorNo = vendorNo;
        this.custNo = custNo;
        this.busiTypeCode = busiTypeCode;
        this.createUser = createUser;
        this.createDatetime = createDatetime;
        this.modifyDatetime =modifyDatetime;
        this.modifyUser =modifyUser;
    }
}
