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.Table;
import javax.persistence.Transient;
import java.util.List;

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

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

    @Column(name = "ASN_TYPE")
    @ApiParam("单据类型")
    public Integer asnType;

    @Column(name = "ASN_STATUS")
    @ApiParam(value = "状态", example = "0")
    @AnnoOutputColumn(refClass = WmsEnumUtil.MASTER_ORDER_STATUS.class, refForeignKey = "value", value = "description")
    public Integer asnStatus;

    @Column(name = "VENDOR_NO")
    @ApiParam("供应商编号")
    public String vendorNo;

    @Column(name = "VERSION")
    @ApiParam("版本")
    public String version;

    @Column(name = "SRC")
    @ApiParam("单据来源")
    public String src;

    @Column(name = "PO_NO")
    @ApiParam("PO单号")
    public String poNo;

    @Column(name = "CONTAINER_NO")
    @ApiParam("集装箱号")
    public String containerNo;

    @Column(name = "IS_TASK")
    @ApiParam(value = "是否生产任务", example = "1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.IS_GENERAL_TASK.class, refForeignKey = "value", value = "description")
    public Integer isTask;

    @Column(name = "REASON")
    @ApiParam(value = "原因", example = "1")
    public String reason;

    @ApiParam("ASN详情列表")
    @Transient
    public List<WmsASNMasterDetails> asnMasterDetailsList;

    @Transient
    @ApiParam(value = "发运单号")
    private String shipOrderNo;

    @Transient
    @ApiParam(value = "打印时间")
    private String printDate;

    @Transient
    @ApiParam(value = "发货人")
    private String sendUser;

    @Transient
    @ApiParam(value = "发货日期")
    private String sendDate;

    @Transient
    @ApiParam(value = "工厂名称")
    public String organizeName;

    @Transient
    @ApiParam("联系人")
    private String vendorOwner;

    @Transient
    @ApiParam("邮箱")
    private String vendorEmail;

    @Transient
    @ApiParam("供应商名称")
    private String vendorName;

    @Column(name = "ACTION_STATUS")
    @ApiParam(value = "处理状态", example = "10")
    public Integer actionStatus;

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

    @Column(name = "DOCK", columnDefinition = "varchar(50) default ''")
    @ApiParam("道口")
    public String dock;

    @ApiParam("泊位")
    @Column(name = "ZDOC", columnDefinition = "varchar(50) default ''")
    public String zdoc;

    @Transient
    @ApiParam("供应商电话")
    private String vendorCall;

    @Transient
    @ApiParam("传真")
    private String vendorFax;

    @Transient
    @ApiParam("手机")
    private String vendorPhone;

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

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

    @Transient
    @ApiParam("收货数量")
    private Double sumRecQty;

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

    @Transient
    @ApiParam("计划日期")
    private String planDate;

    @Transient
    @ApiParam("计划日期开始")
    private String planDateStart;

    @Transient
    @ApiParam("计划日期结束")
    private String planDateEnd;

    @Transient
    @ApiParam("计划时间")
    private String planTime;

    @Transient
    @ApiParam("差异数量")
    private Double diffQty;

    @Transient
    @ApiParam("单据类型") // PO/ASN
    private String orderType;

    @Transient
    @ApiParam("收货状态")
    @AnnoOutputColumn(refClass = WmsEnumUtil.REC_STATUS.class, refForeignKey = "value", value = "description")
    private String recStatus;

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

    @Transient
    private List<String> orderNoList;

    public WmsASNMaster() {
    }

    public WmsASNMaster(String orderNo, Integer asnStatus, String vendorNo, String partNo, String partNameRdd,
                        Double sumQty, Double sumRecQty, String planDate, String planTime, Double diffQty, String orderType,
                        String recStatus) {

        this.orderNo = orderNo;
        this.asnStatus = asnStatus;
        this.vendorNo = vendorNo;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.sumQty = sumQty;
        this.sumRecQty = sumRecQty;
        this.planDate = planDate;
        this.planTime = planTime;
        this.diffQty = diffQty;
        this.orderType = orderType;
        this.recStatus = recStatus;
    }

    public WmsASNMaster(String orderNo, Integer asnStatus, String organizeCode, String vendorNo, String dockCode, String zdoc, String createDateTime, String receiveDateTime) {
        this.orderNo = orderNo;
        this.asnStatus = asnStatus;
        this.organizeCode = organizeCode;
        this.vendorNo = vendorNo;
        this.dock = dockCode;
        this.zdoc = zdoc;
        this.createDatetime = createDateTime;
        this.createDateTimeStart = receiveDateTime;
    }

    public int getAsnStatusVal() {
        return this.asnStatus == null ? 0 : this.asnStatus;
    }
}
