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

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
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.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @Description : 库存移动单处理成功后的记录，通过监听交易成功队列写入
 * @Reference :
 * @Author : Rock.Yu
 * @CreateDate : 2019-06-20 14:09
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "WMS_MOVE_TO_ERP", indexes = {
        @Index(columnList = "TRANS_TYPE_CODE"),
        @Index(columnList = "ORDER_NO"),
        @Index(columnList = "ITEM"),
        @Index(columnList = "ORGANIZE_CODE"),
        @Index(columnList = "PART_NO")
})
@Api("库存移动单处理成功后的记录")
public class WmsMoveToERP extends BaseBean {

    private static final long serialVersionUID = -6223527594941733060L;
    @Column(name = "ORDER_NO")
    @ApiParam("单号")
    public String orderNo;

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

    @Column(name = "REMARK")
    @ApiParam("备注")
    public String remark;

    @Column(name = "TRANS_TYPE_CODE")
    @ApiParam(value = "交易类型代码")
    private String transTypeCode;

    @Column(name = "ERROR_MESSAGE")
    @ApiParam(value = "错误信息")
    private String errorMessage;

    @Column(name="IS_URGENT")
    @ApiParam(value = "是否紧急", example = "0")
    public Integer isUrgent;

    @Column(name = "CAR_NO")
    @ApiParam(value = "车牌号")
    private String carNo;

    @Column(name = "DRIVER_NO")
    @ApiParam("司机")
    public String driverNo;

    @Column(name = "TMS_CAR_NO")
    @ApiParam(value = "TMS车牌号")
    private String tmsCarNo;

    @Column(name = "TMS_DRIVER_NO")
    @ApiParam("TMS司机")
    public String tmsDriverNo;

    @Column(name="ITEM")
    @ApiParam(value = "行号")
    public String 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;

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

    @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")
    public Integer itemStatus;

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

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

    @Column(name="REF_UNIT")
    @ApiParam("关联单位")
    public String refUnit;

    @Column(name="REF_QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ApiParam("关联数量")
    @ColumnDefault("0")
    public Double refQty;

    @Column(name = "SRC_AREA_NO")
    @ApiParam("来源库存地")
    public String srcAreaNo;

    @Column(name = "DEST_AREA_NO")
    @ApiParam("目标库存地")
    public String destAreaNo;

    @Column(name = "BUSI_TYPE_CODE")
    @ApiParam("交易类型")
    public Integer busiTypeCode;

    @Column(name = "IS_SYNC", nullable = false)
    @ApiParam("是否同步")
    public Integer isSync = CommonEnumUtil.FALSE;

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

    @Column(name="IS_LOCK")
    @ApiParam(value = "是否锁定", example = "2")
    public Integer isLock= CommonEnumUtil.FALSE;

    @Column(name = "YEAR")
    @ApiParam("年度")
    public String year;

    @Column(name = "IS_CONSIGNMENT")
    @ApiParam("是否寄售")
    public Integer isConsignment = 2;

    @Column(name = "PRIOR_RC")
    @ApiParam("是否预收货")
    public Integer priorRC = 2;

    @Column(name = "ERP_SRC_NO")
    @ApiParam(value = "ERP单号")
    private String erpSrcNo;


    @Column(name = "ERP_SRC_TYPE",columnDefinition = "varchar(50) default ''")
    @ApiParam(value = "QAD发运单据类型")
    private String erpSrcType;

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

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

    @Column(name = "POD_DIR")
    @ApiParam(value = "方向")
    private Integer podDir;


    @Column(name = "COST_CENTER")
    @ApiParam(value = "成本中心")
    private String costCenter;

    @Column(name = "SECONDARY_REMAKE")
    @ApiParam(value = "备注2")
    private String secondaryRemake;

    @Column(name = "QUEUE_GROUP_NO")
    @ApiParam(value = "jis料架号")
    private String queueGroupNo;

    @Column(name = "CUST_ORDER_NO")
    @ApiParam(value = "客户单号")
    private String custOrderNo;

    @Column(name = "IS_SYNC2")
    @ApiParam("同步标识2")
    public Integer isSync2 = CommonEnumUtil.FALSE;

    @Transient
    private Long shippingId;

    @Transient
    private Double transQtySum;

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

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

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

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

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

    public WmsMoveToERP() {}

    public WmsMoveToERP(String partNo, String partNameRdd, String vendorNo, String unit, String destAreaNo, Double transQtySum) {
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.vendorNo = vendorNo;
        this.unit = unit;
        this.destAreaNo = destAreaNo;
        this.transQtySum = transQtySum;
    }
}
