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.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.*;
import java.util.Objects;

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

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

    /**
     * 是否免费: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 = "SRC_AREA_NO")
    @ApiParam("源库存地代码")
    public String srcAreaNo;

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

    @Column(name = "LOT_NO")
    @ApiParam("批次")
    public String lotNo;
    @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;

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

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

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

    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();
    }

    @Version
    @Column(name = "LOCK_VERSION")
    @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;


    public WmsDocMovementDetails () {

    }

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

}
