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

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @Description : 质检单主表信息
 * @Reference :
 * @Author : silliter.yuan
 * @CreateDate : 2018-11-06 15:58
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "WMS_QC_MASTER")
@Api("质检单主表信息")
public class WmsQCMaster extends BaseBean {

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

    /**
     * 业务类型:IQC=进料检验,IPQC=在线检验,
     * FQC=成品检验,OQC=出货检验
     */
    @Column(name = "ORDER_TYPE")
    @ApiParam(value = "业务类型", example = "0")
    @AnnoOutputColumn(refClass = WmsEnumUtil.QC_INFO_TYPE.class, refForeignKey = "value", value = "description")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "QC_INFO_TYPE")
    public Integer orderType;

    /**
     * 状态:1=创建,5=待处理,10=已完成,90=已关闭,91=已取消
     */
    @Column(name = "ORDER_STATUS")
    @ApiParam(value = "状态", example = "1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.QC_INFO_STATUS.class, refForeignKey = "value", value = "description")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "MASTER_ORDER_STATUS")
    public Integer orderStatus;

    @Column(name = "REMARK")
    @ApiParam("备注")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    public String remark;

    @Column(name = "CUST_NO")
    @ApiParam("客户编号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, 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 = "VENDOR_NO")
    @ApiParam("供应商编号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, 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 = "VERSION")
    @ApiParam(value = "版本", example = "1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER)
    public Integer version;

    @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 = "CUST_NAME")
    @ApiParam(value = "客户简称")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
            dataSrc = "cn.estsh.i3plus.pojo.wms.bean.BasCustomer",
            searchColumnName = "custNo,custName", listColumnName = "custNo,custName", explicitColumnName = "custNo")
    private String custName;

    @Column(name = "VENDOR_DESC")
    @ApiParam(value = "供应商全称")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
            dataSrc = "cn.estsh.i3plus.pojo.wms.bean.BasVendor",
            searchColumnName = "vendorNo,vendorDesc", listColumnName = "vendorNo,vendorDesc", explicitColumnName = "vendorNo")
    private String vendorDesc;

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

    @Column(name = "IS_PART")
    @ApiParam(value = "是否散件", example = "2")
    @AnnoOutputColumn(refClass = WmsEnumUtil.TRUE_OR_FALSE.class, refForeignKey = "value", value = "description")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "TRUE_OR_FALSE")
    public Integer isPart;

    @Transient
    @ApiParam(value = "零件号")
    public String partNo;

    @Transient
    @ApiParam(value = "零件名称")
    public String partNameRdd;

    @Transient
    @ApiParam(value = "收货数量")
    public Double qty;

    public int getOrderStatusVal() {
        return this.orderStatus == null ? 0 : this.orderStatus;
    }

    public WmsQCMaster () {

    }

    public WmsQCMaster (String orderNo, String vendorNo, String refType, String refSrc, String partNo) {
        this.orderNo = orderNo;
        this.vendorNo = vendorNo;
        this.refType = refType;
        this.refSrc = refSrc;
        this.partNo = partNo;
    }

    public WmsQCMaster(String orderNo, String vendorNo, String vendorDesc, String refType, String refSrc, String partNo, String partNameRdd, String createDatetime) {
        this.orderNo = orderNo;
        this.vendorNo = vendorNo;
        this.vendorDesc = vendorDesc;
        this.refType = refType;
        this.refSrc = refSrc;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.createDatetime = createDatetime;
    }

    public WmsQCMaster(String orderNo, Double qty, String vendorNo, String vendorDesc, String refType, String refSrc, String partNo, String partNameRdd, String createDatetime) {
        this.orderNo = orderNo;
        this.qty = qty;
        this.vendorNo = vendorNo;
        this.vendorDesc = vendorDesc;
        this.refType = refType;
        this.refSrc = refSrc;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.createDatetime = createDatetime;
    }
}
