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

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

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

    private static final long serialVersionUID = -5898637337319011710L;
    @Column(name = "ORDER_NO")
    @ApiParam("单号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    public String orderNo;

    @Column(name = "ITEM")
    @ApiParam(value = "行号", example = "0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER)
    public Integer item;

    @Column(name = "PART_NO")
    @ApiParam("物料编码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, isRequire = 2, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
            dataSrc = "cn.estsh.i3plus.pojo.wms.bean.WmsPart",
            searchColumnName = "partNo,partName", listColumnName = "partNo,partName", explicitColumnName = "partNo")
    public String partNo;

    @Column(name = "PART_NAME_RDD")
    @ApiParam("物料名称")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, isRequire = 2, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
            dataSrc = "cn.estsh.i3plus.pojo.wms.bean.WmsPart",
            searchColumnName = "partNo,partName", listColumnName = "partNo,partName", explicitColumnName = "partName")
    public String partNameRdd;

    @Column(name = "VENDOR_NO")
    @ApiParam("供应商编号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, isRequire = 2, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
            dataSrc = "cn.estsh.i3plus.pojo.wms.bean.BasVendor",
            searchColumnName = "vendorNo,vendorName", listColumnName = "vendorNo,vendorName", explicitColumnName = "vendorNo")
    public String vendorNo;

    @Column(name = "CUST_NO")
    @ApiParam("客户编号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, isRequire = 2, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
            dataSrc = "cn.estsh.i3plus.pojo.wms.bean.BasCustomer",
            searchColumnName = "custNo,custDesc", listColumnName = "custNo,custDesc", explicitColumnName = "custNo")
    public String custNo;

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

    @Column(name = "HANDLED_QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ApiParam(value = "已处理数量", example = "0")
    @ColumnDefault("0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER)
    public Double handledQty;

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

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

    @Column(name = "UNIT")
    @ApiParam("单位")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    public String unit;

    @Column(name = "SRC_WH_NO")
    @ApiParam("源仓库代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, isRequire = 2, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
dataSrc ="cn.estsh.i3plus.pojo.wms.bean.WareHouse",
            searchColumnName = "code,name",listColumnName = "code,name", explicitColumnName = "code")
    public String srcWhNo;

    @Column(name = "SRC_ZONE_NO")
    @ApiParam("源存储区代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, isRequire = 2, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
dataSrc ="cn.estsh.i3plus.pojo.wms.bean.WmsZones",
            searchColumnName = "zoneNo,zoneName",listColumnName = "zoneNo,zoneName", explicitColumnName = "zoneNo")
    public String srcZoneNo;

    @Column(name = "SRC_LOCATE_NO")
    @ApiParam("源库位代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, isRequire = 2, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
dataSrc ="cn.estsh.i3plus.pojo.wms.bean.WmsLocate",
            searchColumnName = "locateNo,locateName",listColumnName = "locateNo,locateName", explicitColumnName = "locateNo")
    public String srcLocateNo;

    @Column(name = "DEST_WH_NO")
    @ApiParam("目标仓库代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, isRequire = 2, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
dataSrc ="cn.estsh.i3plus.pojo.wms.bean.WareHouse",
            searchColumnName = "code,name",listColumnName = "code,name", explicitColumnName = "code")
    public String destWhNo;

    @Column(name = "DEST_ZONE_NO")
    @ApiParam("目标存储区代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, isRequire = 2, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
dataSrc ="cn.estsh.i3plus.pojo.wms.bean.WmsZones",
            searchColumnName = "zoneNo,zoneName",listColumnName = "zoneNo,zoneName", explicitColumnName = "zoneNo")
    public String destZoneNo;

    @Column(name = "DEST_LOCATE_NO")
    @ApiParam("目标库位代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, isRequire = 2, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
dataSrc ="cn.estsh.i3plus.pojo.wms.bean.WmsLocate",
            searchColumnName = "locateNo,locateName",listColumnName = "locateNo,locateName", explicitColumnName = "locateNo")
    public String destLocateNo;

    /**
     * 状态:10:创建,20:待处理,30:已处理,40:处理出错
     */
    @Column(name = "ITEM_STATUS")
    @ApiParam(value = "状态", example = "0")
    @AnnoOutputColumn(refClass = WmsEnumUtil.MOVE_ORDER_STATUS.class, refForeignKey = "value", value = "description")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "MOVE_ORDER_STATUS")
    public Integer itemStatus;

    @Column(name = "REF_ITEM")
    @ApiParam("关联单据行号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    public String refItem;

    /**
     * ASN,PO,SO
     */
    @Column(name = "REF_TYPE")
    @ApiParam("关联单据类型")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "LINK_ORDER_TYPE")
    public String refType;

    @Column(name = "REF_SRC")
    @ApiParam("关联单号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    public String refSrc;

    @Column(name = "REF_SN")
    @ApiParam("关联条码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    public String refSn;

    @Column(name = "GROUP_NO")
    @ApiParam("分组号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    public String groupNo;

    @Column(name = "BOM_VERSION")
    @ApiParam(value = "BOM版本号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String bomVersion;

    @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", columnDefinition = "int default 0")
    @ApiParam(value = "乐观锁", example = "1")
    public Integer lockVersion;

    @Transient
    @ApiParam("项目代码")
    private String prodCfgTypeCode;

    @Transient
    @ApiParam(value = "快照时间")
    private String snapshotTime;

    @Transient
    private Integer isSnapshot;

    @Transient
    @ApiParam(value = "车号")
    private String carNo;

    @Column(name = "CONSIGNATION")
    @ApiParam("是否寄售 1-是 2-否")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "TRUE_OR_FALSE")
    private Integer consignation = 2;

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

    @Transient
    @ApiParam(value = "来源存储区/目标存储区")
    private Integer srcOrDestZoneno;

    public Integer getIsSnapshot() {
        return isSnapshot == null ? 0 : isSnapshot.intValue();
    }

    public WmsMoveDetails() {
    }

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

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

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

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

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

    public WmsMoveDetails(String partNo, String partNameRdd, String unit, Double transQty) {
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.unit = unit;
        this.transQty = transQty;
    }

    public WmsMoveDetails(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 WmsMoveDetails(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;
    }

    public WmsMoveDetails(String refSrc, String prodCfgTypeCode, String createDatetime) {
        this.refSrc = refSrc;
        this.prodCfgTypeCode = prodCfgTypeCode;
        this.createDatetime = createDatetime;
    }

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

}
