package cn.estsh.i3plus.pojo.wms.bean;

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 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 java.math.BigDecimal;
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_TASK_DETAILS", indexes = {
        @Index(columnList = "ORDER_NO"),
        @Index(columnList = "PART_NO"),
        @Index(columnList = "ITEM_STATUS")
})
// uniqueConstraints = {@UniqueConstraint(columnNames = {"REF_SRC", "ITEM", "TRANS_TYPE_CODE_RDD"})}
@Api("作业任务明细信息")
public class WmsTaskDetails extends BaseBean {
    private static final long serialVersionUID = 2938720878619662102L;
    @Column(name = "ORDER_NO")
    @ApiParam(value = "单号")
    private String orderNo;

    @Column(name = "ITEM")
    @ApiParam(value = "行号", example = "1")
    private Integer item;

    @Column(name = "PART_NO")
    @ApiParam(value = "物料编码")
    private String partNo;

    @Column(name = "PART_NAME")
    @ApiParam(value = "物料名称")
    private String partName;

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

    @Column(name = "CUST_NO")
    @ApiParam(value = "客户编号")
    private String custNo;

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

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

    @Column(name = "TRANS_QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ColumnDefault("0")
    @ApiParam(value = "处理数量", example = "1")
    private Double transQty;

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

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

    @Column(name = "SRC_WH_NO")
    @ApiParam(value = "源仓库代码")
    private String srcWhNo;
    /**
     * 状态:N=正常,C=行取消
     */
    @Column(name = "ITEM_STATUS")
    @ApiParam(value = "状态", example = "1")
    private Integer itemStatus;

    public Integer getItemStatus() {
        if (itemStatus == null) {
            return null;
        }
        return itemStatus.intValue();
    }

    @Column(name = "SRC_ZONE_NO")
    @ApiParam(value = "源存储区代码")
    private String srcZoneNo;

    @Column(name = "SRC_LOCATE_NO")
    @ApiParam(value = "源库位代码")
    private String srcLocateNo;

    @Column(name = "DEST_ZONE_NO")
    @ApiParam(value = "目的存储区代码")
    private String destZoneNo;

    @Column(name = "DEST_LOCATE_NO")
    @ApiParam(value = "目的库位代码")
    private String destLocateNo;

    @Column(name = "DEST_WH_NO")
    @ApiParam(value = "目的存储区代码")
    private String destWhNo;

    @Column(name = "REF_TYPE")
    @ApiParam(value = "关联单据类型")
    private String refType;

    @Column(name = "REF_SRC")
    @ApiParam(value = "关联单据编号")
    private String refSrc;

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

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

    @Column(name = "BUSI_TYPE_CODE")
    @ApiParam("业务类型代码")
    public String busiTypeCode;

    @Column(name = "TRANS_TYPE_CODE_RDD")
    @ApiParam("交易类型")
    public String transTypeCodeRdd;

    @Column(name = "REF_ITEM")
    @ApiParam("关联单据行号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    public String refItem;

    @Transient
    @ApiParam("工厂代码集合")
    private List<String> organizeCodeList;


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

    public String getQtyTxt() {
        return new BigDecimal(getQty() + "").stripTrailingZeros().toPlainString();
    }

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