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.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List;

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

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

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

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

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

    @Lob
    @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 = "BUSI_TYPE_CODE")
    @ApiParam(value = "业务类型编码")
    @AnnoOutputColumn(refClass = WmsEnumUtil.OUT_MOVEMENT_BUSI_TYPE.class, refForeignKey = "value", value = "description")
    private Integer busiTypeCode;

    @Column(name = "REF_ORDER_NO")
    @ApiParam("关联移动单号")
    public String refOrderNo;

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

    @Transient
    @ApiParam("明细状态")
    @AnnoOutputColumn(refClass = WmsEnumUtil.MOVE_ORDER_STATUS.class)
    private String itemStatus;

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

    @Transient
    @ApiParam("关联单号")
    private String refSrc;

    @Transient
    @ApiParam("目标仓库")
    private String destWhNo;

    @Transient
    @ApiParam("存储区")
    private String destZoneNo;

    @Transient
    @ApiParam("供应商编码")
    private String vendorNo;

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

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

    @Transient
    @ApiParam("单位")
    private String unit;

    @Transient
    @ApiParam("源仓库")
    private String srcWhNo;

    @Transient
    @ApiParam("源存储区代码")
    private String srcZoneNo;

    @Transient
    @ApiParam("需求数量")
    private Double transQty;

    @Transient
    @ApiParam("处理数量")
    private Double handledQty;

    @Transient
    @ApiParam("不合格处理数量")
    private Double rejectQty;

    @Transient
    @ApiParam("库位")
    private String destLocateNo;

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

    @Column(name = "FIX_ID")
    @ApiParam(value = "设备编号")
    public String fixId;

    @Transient
    @ApiParam("获取数量大于0")
    private Integer qtyIdentity;

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

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

    @Transient
    private Integer isSnapshot;

    @Transient
    @ApiParam("总行数")
    private Long itemQty;

    @Transient
    @ApiParam("存储区")
    private String zoneNo;

    @Transient
    @ApiParam("仓库")
    private String whNo;

    @Transient
    @ApiParam("状态集合")
    private List<Integer> orderStatusList;

    @Transient
    @ApiParam("交易类型集合")
    private List<String> filterTransTypeCodeList;

    @Transient
    @ApiParam("交易类型集合")
    private List<String> transTypeCodeList;


//    @Version
//    @Column(name = "LOCK_VERSION")
//    @ApiParam(value = "乐观锁", example = "1")
//    public  Integer lockVersion;

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

    public WmsMoveMaster() {
    }

    public WmsMoveMaster(String orderNo, Integer orderStatus, String transTypeCode, String errorMessage,
                         Integer isUrgent, String carNo, Integer busiTypeCode, String refOrderNo, String refSrc, String partNo, Integer itemStatus, String remark,
                         String organizeCode, String createDatetime, String createUser, String modifyDatetime, String modifyUser, String fixId,
                         Double sumTranQty) {
        this.orderNo = orderNo;
        this.orderStatus = orderStatus;
        this.remark = remark;
        this.isUrgent = isUrgent;
        this.transTypeCode = transTypeCode;
        this.errorMessage = errorMessage;
        this.busiTypeCode = busiTypeCode;
        this.partNo = partNo;
        this.itemStatus = itemStatus.toString();
        this.refOrderNo = refOrderNo;
        this.carNo = carNo;
        this.refSrc = refSrc;
        this.organizeCode = organizeCode;
        this.createDatetime = createDatetime;
        this.createUser = createUser;
        this.modifyDatetime = modifyDatetime;
        this.modifyUser = modifyUser;
        this.fixId = fixId;
        this.transQty = sumTranQty;
    }

    public WmsMoveMaster(Long id, String orderNo, String organizeCode, String partNo, String partNameRdd, String transTypeCode, String transTypeName, Integer itemStatus,
                         String unit, String srcWhNo, String srcZoneNo, String destWhNo, String destZoneNo, Double transQty, Double rejectQty, String fixId, Integer busiTypeCode, String refSrc,
                         String createDatetime, String createUser, String modifyUser, String modifyDatetime) {
        this.id = id;
        this.orderNo = orderNo;
        this.organizeCode = organizeCode;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.transTypeCode = transTypeCode;
        this.transTypeName = transTypeName;
        this.itemStatus = itemStatus.toString();
        this.unit = unit;
        this.srcWhNo = srcWhNo;
        this.srcZoneNo = srcZoneNo;
        this.destWhNo = destWhNo;
        this.destZoneNo = destZoneNo;
        this.transQty = transQty;
        this.rejectQty = rejectQty;
        this.fixId = fixId;
        this.busiTypeCode = busiTypeCode;
        this.refSrc = refSrc;
        this.createDatetime = createDatetime;
        this.createUser = createUser;
        this.modifyUser = modifyUser;
        this.modifyDatetime = modifyDatetime;
    }

    public WmsMoveMaster(String orderNo, String organizeCode, String partNo, String partNameRdd, String transTypeCode,
                         String transTypeName, Integer itemStatus,String unit, String srcWhNo, String srcZoneNo,
                         String destWhNo, String destZoneNo, Double transQty,Double handledQty,Double rejectQty,
                         String fixId, Integer busiTypeCode,String createDatetime, String createUser, String modifyUser,
                         String modifyDatetime, String refSrc) {
        this.orderNo = orderNo;
        this.organizeCode = organizeCode;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.transTypeCode = transTypeCode;
        this.transTypeName = transTypeName;
        this.itemStatus = itemStatus.toString();
        this.unit = unit;
        this.srcWhNo = srcWhNo;
        this.srcZoneNo = srcZoneNo;
        this.destWhNo = destWhNo;
        this.destZoneNo = destZoneNo;
        this.transQty = transQty;
        this.handledQty = handledQty;
        this.rejectQty = rejectQty;
        this.fixId = fixId;
        this.busiTypeCode = busiTypeCode;
        this.createDatetime = createDatetime;
        this.createUser = createUser;
        this.modifyUser = modifyUser;
        this.modifyDatetime = modifyDatetime;
        this.refSrc = refSrc;
    }

    public WmsMoveMaster(String orderNo, String organizeCode, String partNo, String partNameRdd, String transTypeCode, String transTypeName, Integer itemStatus,
                         String unit, String srcWhNo, String srcZoneNo, String destWhNo, String destZoneNo, Double transQty, Double rejectQty, String fixId, Integer busiTypeCode,
                         String createDatetime, String createUser, String modifyUser, String modifyDatetime) {
        this.orderNo = orderNo;
        this.organizeCode = organizeCode;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.transTypeCode = transTypeCode;
        this.transTypeName = transTypeName;
        this.itemStatus = itemStatus.toString();
        this.unit = unit;
        this.srcWhNo = srcWhNo;
        this.srcZoneNo = srcZoneNo;
        this.destWhNo = destWhNo;
        this.destZoneNo = destZoneNo;
        this.transQty = transQty;
        this.rejectQty = rejectQty;
        this.fixId = fixId;
        this.busiTypeCode = busiTypeCode;
        this.createDatetime = createDatetime;
        this.createUser = createUser;
        this.modifyUser = modifyUser;
        this.modifyDatetime = modifyDatetime;
    }
    public WmsMoveMaster(Long itemQty , String transTypeCode , Integer orderStatus){
        this.itemQty = itemQty;
        this.transTypeCode = transTypeCode;
        this.orderStatus = orderStatus;
    }


    public WmsMoveMaster(String orderNo, Integer orderStatus, String transTypeCode, String errorMessage,
                         Integer isUrgent, String carNo, Integer busiTypeCode, String refOrderNo, String remark,
                         String organizeCode, String createDatetime, String createUser, String modifyDatetime, String modifyUser, String fixId
    ) {
        this.orderNo = orderNo;
        this.orderStatus = orderStatus;
        this.remark = remark;
        this.isUrgent = isUrgent;
        this.transTypeCode = transTypeCode;
        this.errorMessage = errorMessage;
        this.busiTypeCode = busiTypeCode;
        this.refOrderNo = refOrderNo;
        this.carNo = carNo;
        this.organizeCode = organizeCode;
        this.createDatetime = createDatetime;
        this.createUser = createUser;
        this.modifyDatetime = modifyDatetime;
        this.modifyUser = modifyUser;
        this.fixId = fixId;
    }

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

    public int getBusiTypeCodeVal() {
        return this.busiTypeCode == null ? 0 : this.busiTypeCode.intValue();
    }
}
