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 cn.estsh.i3plus.pojo.base.util.StringUtil;
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 : dragon.xu
 * @CreateDate : 2018-11-13 16:06
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "WMS_DOC_MOVEMENT_DETAILS", indexes = {
        @Index(columnList = "ORDER_NO"),
        @Index(columnList = "PART_NO"),
        @Index(columnList = "SRC_NO"),
        @Index(columnList = "ORGANIZE_CODE")
})
@Api("移库单明细表")
public class WmsDocMovementDetails extends BaseBean {
    private static final long serialVersionUID = -4800308354250386102L;
    @Column(name = "PART_NO")
    @ApiParam("物料编码")
    public String partNo;

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

    @Column(name = "ITEM")
    @ApiParam("行号")
    public String item;

    @Column(name = "QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam(value = "需求数量", example = "0")
    public Double qty;

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

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

    @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;

    @Column(name = "PRINT_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam(value = "条码打印数量", example = "1")
    private Double printQty;

    @Column(name = "PLAN_DATE")
    @ApiParam(value = "计划日期")
    private String planDate;

    @Column(name = "PLAN_TIME")
    @ApiParam(value = "计划时间")
    private String planTime;

    @Transient
    @ApiParam(value = "超时时间(单位:分钟)")
    private Integer timeOut;

    @Transient
    @ApiParam(value = "窗口时间")
    private String windowTime;

    @Transient
    @ApiParam(value = "紧急程度")
    private Integer urgentStatus;

    @Column(name = "SRC_NO")
    @ApiParam(value = "源单号")
    private String srcNo;
    /**
     * 状态:N=正常,C=行取消
     */
    @Column(name = "ITEM_STATUS")
    @ApiParam(value = "状态", example = "1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.MASTER_ORDER_STATUS.class, refForeignKey = "value", value = "description")
    private Integer itemStatus;


    @Transient
    @ApiParam(value = "完成状态")
    public Integer orderStatus;

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

    @Transient
    @ApiParam(value = "道口")
    public String dock;

    /**
     * 已创建，已收货，已发运，已拣货
     */
    @Transient
    @ApiParam(value = "状态中文")
    private String itemStatusStr;

    @Transient
    @ApiParam(value = "ERP单号")
    private String erpSrcNo;

    @Transient
    @ApiParam(value = "完成数百分比")
    private String number;

    /**
     * 是否免费:0=计费,1=免费
     */
    @Column(name = "IS_FREE")
    @ApiParam(value = "是否免费", example = "1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.TRUE_OR_FALSE.class, refForeignKey = "value", value = "description")
    public Integer isFree;

    @Column(name = "REMARK")
    @ApiParam(value = "操作原因")
    private String remark;

    /**
     * 配料数量
     **/
    @Column(name = "PICK_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam(value = "已拣货数量", example = "1")
    private Double pickQty;

    @Column(name = "OUT_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam(value = "已出库数量", example = "1")
    private Double outQty;

    @Column(name = "REC_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam(value = "已收货数量", example = "1")
    private Double recQty;

    @Column(name = "MOVE_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam(value = "已移库数量", example = "1")
    private Double moveQty;

    @Column(name = "TASK_GENERATE_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam(value = "任务生成数量", example = "1")
    private Double taskGenerateQty;

    @Column(name = "PRINT_GENERATE_QTY", columnDefinition = "decimal(18,8)")
    @ColumnDefault("0")
    @ApiParam(value = "已打印数量")
    private Double printGenerateQty;

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

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


    @Column(name = "DEST_XB_ZONE_NO")
    @ApiParam("目的线边存储区代码")
    public String destXBZoneNo;

    @Column(name = "LOT_NO")
    @ApiParam("批次")
    public String lotNo;

    @Column(name="SRC_ITEM", columnDefinition="varchar(50) default ''",nullable=false)
    @ApiParam("源单行号")
    public String srcItem;


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

    @Column(name = "ASSIGN_DATE_CODE")
    @ApiParam(value = "指定生产日期")
    private String assignDateCode;

    @Column(name = "SO_ORDER_NO")
    @ApiParam(value = "销售单据号")
    private String soOrderNo;

    @Column(name = "MEL_TYPE")
    @ApiParam(value = "材料类型")
    private String melType;

    @Column(name = "PROJECT_NO")
    @ApiParam(value = "项目号")
    private String projectNo;

    @Column(name = "PRODUCTION_GROUP")
    @ApiParam(value = "生产小组")
    private String productionGroup;

    @Column(name = "CUST_PART_NO")
    @ApiParam(value = "客户零件号")
    private String custPartNo;

    @Column(name = "MATERIAL_TYPE")
    @ApiParam(value = "物料类型")
    private String materialType;

    @Column(name = "PART_SPEC")
    @ApiParam(value = "简称")
    private String partSpec;

    @Column(name = "WORK_ORDER_CODE")
    @ApiParam(value = "工单码")
    private String workOrderCode;

    @Column(name = "SEQ_NO")
    @ApiParam(value = "父位置号")
    private String seqNo;

    @Transient
    @ApiParam(value = "客户编号")
    private String custNo;

    @Transient
    @ApiParam(value = "替代物料编码")
    private String subPartNo;

    @Transient
    @ApiParam(value = "颜色")
    private String color;

    @Transient
    @ApiParam(value = "替代物料名称")
    private String subPartName;

    @Transient
    @ApiParam("实际批次")
    private String actualLot;

    @Transient
    @ApiParam("实际数量")
    private Double actualQty;

    @Transient
    @ApiParam("推荐批次")
    private String recommondLot;

    @Transient
    @ApiParam("推荐库位")
    private String recommondLocateNo;

    @Transient
    @ApiParam("前端表格编辑使用")
    private Boolean isSet = false;

    @Transient
    @ApiParam("生产日期")
    public String dateCode;

    @Transient
    @ApiParam("生产线")
    public String line;

    @ApiParam(value = "散件移库输入移库数量")
    @Transient
    public Double inputMoveQty;

    @Transient
    @ApiParam(value = "标准包装", example = "1")
    private Double snp;

    @Transient
    @ApiParam(value = "订单总数量")
    private Long itemCount;

    @Transient
    @ApiParam(value = "完成订单数量")
    private Integer completeCount;

    @Transient
    @ApiParam(value = "条码总数量", example = "1")
    private Double detailsSnCount;

    @Transient
    @ApiParam(value = "余数", example = "1")
    private Double restQty;

    @Transient
    @ApiParam("任务状态")
    @AnnoOutputColumn(refClass = WmsEnumUtil.IS_GENERAL_TASK.class, refForeignKey = "value", value = "description")
    private Integer isTask;

    @Transient
    @ApiParam("主表单据状态")
    @AnnoOutputColumn(refClass = WmsEnumUtil.MASTER_ORDER_STATUS.class, refForeignKey = "value", value = "description")
    private Integer orderMasterStatus;

    @Transient
    @ApiParam("打印状态")
    @AnnoOutputColumn(refClass = WmsEnumUtil.PRINT_STATUS.class, refForeignKey = "value", value = "description")
    private Integer printStatus;

    @Transient
    @ApiParam("优先级")
    private Integer priority;

    @Transient
    @ApiParam(value = "汇总需求数量", example = "0")
    public Double sumQty;

    @Transient
    @ApiParam(value = "汇总拣货数量", example = "0")
    public Double sumPickQty;

    @Transient
    @ApiParam("执行状态")
    @AnnoOutputColumn(refClass = WmsEnumUtil.PICKING_EXECUTE_STATUS.class, refForeignKey = "value", value = "description")
    private Integer executeStatus;

    @Transient
    @ApiParam(value = "客户发往地编号")
    private String flagNo;

    @Transient
    @ApiParam("执行")
    private Integer isMakeUp;

    @Transient
    @ApiParam(value = "子位置号")
    private String itemSeqNo;

    @ApiParam(value = "最早需求时间")
    private String firstTime;

    @Transient
    @ApiParam(value = "实际发运时间")
    private String actualPlanTime;

    @Transient
    @ApiParam(value = "目的库位名称")
    public String destLocateName;


    public String getRecommondLot() {
        return recommondLot == null ? "无" : this.recommondLot;
    }

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

    public Double getOutQty() {
        return outQty == null ? 0D : this.outQty.doubleValue();
    }

    public Double getPickQty() {
        return pickQty == null ? 0D : this.pickQty.doubleValue();
    }

    public Double getActualQty() {
        return actualQty == null ? 0D : this.actualQty.doubleValue();
    }

    public Double getRecQty() {
        return recQty == null ? 0D : this.recQty.doubleValue();
    }

    public Integer getIsTaskVal() {
        return isTask == null ? 0 : this.isTask.intValue();
    }

    public Integer getOrderMasterStatus() {
        return orderMasterStatus == null ? 0 : this.orderMasterStatus.intValue();
    }

    public String getLine() {
        if (StringUtil.isEmpty(this.line)) {
            return "";
        }
        return this.line;
    }

    @Version
    @Column(name = "LOCK_VERSION", columnDefinition = "int default 0")
    @ApiParam(value = "乐观锁", example = "1")
    public transient Integer lockVersion;

    @Transient
    @ApiParam("移动类型")
    public Integer moveType;

    @Transient
    @ApiParam("业务类型")
    @AnnoOutputColumn(refClass = WmsEnumUtil.OUT_MOVEMENT_BUSI_TYPE.class, refForeignKey = "value", value = "description")
    public Integer busiType;

    @Column(name = "IS_SN")
    @ApiParam(value = "条码生成状态", example = "20")
    public Integer isSn;


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

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

    @Transient
    @ApiParam("箱数")
    private Double boxQty;

    @Transient
    @ApiParam("窗口领料开始时间")
    private String windowPickStartTime;

    @Transient
    @ApiParam("窗口领料结束时间")
    private String windowPickEndTime;

    @Transient
    @ApiParam("项目编号")
    String prodCfgTypeCode;

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


    public WmsDocMovementDetails (String custNo,String planDate,String planTime,String orderNo,String projectNo,String partNo,Integer itemStatus) {
        this.custNo = custNo;
        this.orderNo = orderNo;
        this.planDate = planDate;
        this.planTime = planTime;
        this.itemStatus = itemStatus;
        this.projectNo = projectNo;
        this.partNo=partNo;
    }
    public WmsDocMovementDetails (String orderNo,String projectNo,Double qty,Double pickQty) {
        this.orderNo = orderNo;
        this.qty = qty;
        this.pickQty = pickQty;
        this.projectNo = projectNo;

    }


    public WmsDocMovementDetails (String createDatetime, String srcZoneNo, String srcLocateNo, String destLocateNo, String createUser, Integer itemStatus, String orderNo, String partNo) {
        this.createDatetime = createDatetime;
        this.srcLocateNo = srcLocateNo;
        this.destLocateNo = destLocateNo;
        this.createUser = createUser;
        this.itemStatus= itemStatus;
        this.orderNo = orderNo;
        this.srcZoneNo = srcZoneNo;
        this.partNo=partNo;
    }


    public WmsDocMovementDetails(String createDatetime, String srcZoneNo, String srcLocateNo, String destLocateNo, String createUser, Integer itemStatus, String orderNo, String planDate, String planTime, Long itemCount) {
        this.createDatetime = createDatetime;
        this.srcZoneNo = srcZoneNo;
        this.srcLocateNo = srcLocateNo;
        this.destLocateNo = destLocateNo;
        this.createUser = createUser;
        this.itemStatus = itemStatus;
        this.orderNo = orderNo;
        this.planDate = planDate;
        this.planTime = planTime;
        this.itemCount = itemCount;
    }

    public WmsDocMovementDetails (String orderNo, String srcZoneNo, String destZoneNo, String destLocateNo) {
        this.orderNo = orderNo;
        this.srcZoneNo = srcZoneNo;
        this.destZoneNo = destZoneNo;
        this.destLocateNo = destLocateNo;
    }

    public WmsDocMovementDetails (Double sumQty,Double sumPickQty ,String partNo,Integer priority,String orderNo) {
        this.sumQty = sumQty;
        this.sumPickQty = sumPickQty;
        this.partNo = partNo;
        this.priority = priority;
        this.orderNo = orderNo;
    }
public WmsDocMovementDetails (String partNo,String orderNo) {
        this.partNo = partNo;
        this.orderNo = orderNo;
    }

    public WmsDocMovementDetails (String orderNo,String partNo,Double qty, Double pickQty, int itemStatus, String createDatetime, String modifyDatetime) {
        this.orderNo = orderNo;
        this.partNo = partNo;
        this.qty = qty;
        this.pickQty = pickQty;
        this.itemStatus = itemStatus;
        this.createDatetime = createDatetime;
        this.modifyDatetime = modifyDatetime;
    }


    public WmsDocMovementDetails(WmsPOMasterDetails poMasterDetails) {
        this.orderNo = poMasterDetails.getOrderNo();
        this.planDate = poMasterDetails.getPlanDate();
        this.planTime = poMasterDetails.getPlanTime();
    }

    public WmsDocMovementDetails(WmsDocMovementDetails wmsDocMovementDetails,Integer busiType,String srcZoneNo,String destZoneNo,
                                 String custNo) {
        this.orderNo = wmsDocMovementDetails.getOrderNo();
        this.partNo = wmsDocMovementDetails.getPartNo();
        this.qty = wmsDocMovementDetails.getQty();
        this.taskGenerateQty = wmsDocMovementDetails.getTaskGenerateQty();
        this.partNameRdd = wmsDocMovementDetails.getPartNameRdd();
        this.unit = wmsDocMovementDetails.getUnit();
        this.custNo = wmsDocMovementDetails.getCustNo();
        this.srcZoneNo = wmsDocMovementDetails.getSrcZoneNo();
        this.srcWhNo = wmsDocMovementDetails.getSrcWhNo();
        this.srcLocateNo = wmsDocMovementDetails.getSrcLocateNo();
        this.destWhNo = wmsDocMovementDetails.getDestWhNo();
        this.destZoneNo = wmsDocMovementDetails.getDestZoneNo();
        this.destLocateNo = wmsDocMovementDetails.getDestLocateNo();
        this.srcAreaNo = wmsDocMovementDetails.getSrcAreaNo();
        this.destAreaNo = wmsDocMovementDetails.getDestAreaNo();
        this.destLocateNo = wmsDocMovementDetails.getDestLocateNo();
        this.organizeCode = wmsDocMovementDetails.getOrganizeCode();
        this.busiType = busiType;
        this.srcZoneNo = srcZoneNo;
        this.destZoneNo = destZoneNo;
        this.custNo = custNo;
    }

    public WmsDocMovementDetails(){

    }


    public WmsDocMovementDetails (String orderNo, String srcZoneNo, String destZoneNo, String destLocateNo,Integer priority,String createDatetime) {
        this.orderNo = orderNo;
        this.srcZoneNo = srcZoneNo;
        this.destZoneNo = destZoneNo;
        this.destLocateNo = destLocateNo;
        this.priority = priority;
        this.createDatetime = createDatetime;
    }

    public WmsDocMovementDetails (WmsDocMovementDetails wmsDocMovementDetails, String color) {
        this.id = wmsDocMovementDetails.getId();
        this.orderNo = wmsDocMovementDetails.getOrderNo();
        this.partNo = wmsDocMovementDetails.getPartNo();
        this.qty = wmsDocMovementDetails.getQty();
        this.seqNo = wmsDocMovementDetails.getSeqNo();
        this.partNameRdd = wmsDocMovementDetails.getPartNameRdd();
        this.partSpec = wmsDocMovementDetails.getPartSpec();
        this.workOrderCode = wmsDocMovementDetails.getWorkOrderCode();
        this.productionGroup = wmsDocMovementDetails.getProductionGroup();
        this.item = wmsDocMovementDetails.getItem();
        this.planTime = wmsDocMovementDetails.getPlanTime();
        this.planDate = wmsDocMovementDetails.getPlanDate();
        this.unit = wmsDocMovementDetails.getUnit();
        this.custNo = wmsDocMovementDetails.getCustNo();
        this.srcZoneNo = wmsDocMovementDetails.getSrcZoneNo();
        this.srcWhNo = wmsDocMovementDetails.getSrcWhNo();
        this.srcLocateNo = wmsDocMovementDetails.getSrcLocateNo();
        this.destWhNo = wmsDocMovementDetails.getDestWhNo();
        this.destZoneNo = wmsDocMovementDetails.getDestZoneNo();
        this.destLocateNo = wmsDocMovementDetails.getDestLocateNo();
        this.srcAreaNo = wmsDocMovementDetails.getSrcAreaNo();
        this.destAreaNo = wmsDocMovementDetails.getDestAreaNo();
        this.destLocateNo = wmsDocMovementDetails.getDestLocateNo();
        this.organizeCode = wmsDocMovementDetails.getOrganizeCode();
        this.color = color;
    }

    public WmsDocMovementDetails(String orderNo, Double qty, Double pickQty, String modifyDateTime, String createDateTime, String planDate, String planTime, Integer orderStatus) {
        this.orderNo = orderNo;
        this.qty = qty;
        this.pickQty = pickQty;
        this.modifyDatetime = modifyDateTime;
        this.createDatetime = createDateTime;
        this.planDate = planDate;
        this.planTime = planTime;
        this.orderStatus = orderStatus;
    }

    public WmsDocMovementDetails (WmsDocMovementDetails wmsDocMovementDetails, Double boxQty,String srcLocateNo) {
        this.id = wmsDocMovementDetails.getId();
        this.orderNo = wmsDocMovementDetails.getOrderNo();
        this.partNo = wmsDocMovementDetails.getPartNo();
        this.partNameRdd = wmsDocMovementDetails.getPartNameRdd();
        this.qty = wmsDocMovementDetails.getQty();
        this.unit = wmsDocMovementDetails.getUnit();
        this.srcZoneNo = wmsDocMovementDetails.getSrcZoneNo();
        this.destLocateNo = wmsDocMovementDetails.getDestLocateNo();
        this.createDatetime = wmsDocMovementDetails.getCreateDatetime();
        this.organizeCode = wmsDocMovementDetails.getOrganizeCode();
        this.boxQty = boxQty;
        this.srcLocateNo = srcLocateNo;
    }

    public WmsDocMovementDetails(String orderNo, Integer orderStatus, Double qty, Double pickQty, String modifyDatetime, String planTime) {
        this.orderNo = orderNo;
        this.orderStatus = orderStatus;
        this.qty = qty;
        this.pickQty = pickQty;
        this.modifyDatetime = modifyDatetime;
        this.planTime = planTime;
    }

    public WmsDocMovementDetails (String erpSrcNo,String orderNo,String projectNo,Double qty,Double pickQty,
                                  String planDate,String planTime,String custNo,String partNo,Integer itemStatus ) {
        this.orderNo = orderNo;
        this.qty = qty;
        this.pickQty = pickQty;
        this.projectNo = projectNo;
        this.erpSrcNo = erpSrcNo;
        this.planDate = planDate;
        this.planTime = planTime;
        this.custNo = custNo;
        this.partNo = partNo;
        this.itemStatus = itemStatus;

    }

    public WmsDocMovementDetails (String orderNo,String projectNo,Double qty,Double pickQty,
                                  String planDate,String planTime,String custNo,String partNo,Integer itemStatus ) {
        this.orderNo = orderNo;
        this.qty = qty;
        this.pickQty = pickQty;
        this.projectNo = projectNo;
        this.planDate = planDate;
        this.planTime = planTime;
        this.custNo = custNo;
        this.partNo = partNo;
        this.itemStatus = itemStatus;

    }

    public WmsDocMovementDetails(String erpSrcNo, String orderNo, String prodCfgTypeCode, String prodCfgTypeName,
                                 Double qty, String planDate, String planTime, String custNo) {
        this.erpSrcNo = erpSrcNo;
        this.orderNo = orderNo;
        this.prodCfgTypeCode = prodCfgTypeCode;
        this.prodCfgTypeName = prodCfgTypeName;
        this.qty = qty;
        this.planDate = planDate;
        this.planTime = planTime;
        this.custNo = custNo;
    }

    public WmsDocMovementDetails(String orderNo, String prodCfgTypeCode, String prodCfgTypeName,
                                 Double qty, String planDate, String planTime, String custNo) {
        this.orderNo = orderNo;
        this.prodCfgTypeCode = prodCfgTypeCode;
        this.prodCfgTypeName = prodCfgTypeName;
        this.qty = qty;
        this.planDate = planDate;
        this.planTime = planTime;
        this.custNo = custNo;
    }


    public WmsDocMovementDetails(String orderNo, Double pickQty, String prodCfgTypeCode, String custNo) {
        this.orderNo = orderNo;
        this.pickQty = pickQty;
        this.prodCfgTypeCode = prodCfgTypeCode;
        this.custNo = custNo;
    }

    public WmsDocMovementDetails(String orderNo, String srcZoneNo, String destZoneNo, String destLocateNo, String locateName) {
        this.orderNo = orderNo;
        this.srcZoneNo = srcZoneNo;
        this.destZoneNo = destZoneNo;
        this.destLocateNo = destLocateNo;
        this.destLocateName = locateName;
    }

}
