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

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

/**
 * @Description : 库位物料表
 * @Reference :
 * @Author : jimmy.zeng
 * @CreateDate : 2018-11-07 10:51
 * @Modify:
 **/
@Data
@Entity
@Table(name = "WMS_LOCATE_PART")
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Api(value = "库位物料表", description = "库位物料表")
public class WmsLocatePart extends BaseBean {

    private static final long serialVersionUID = 9134745988014340144L;
    @Column(name = "LOCATE_NO")
    @ApiParam(value = "库位编码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, isRequire = 2, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
            dataSrc = "cn.estsh.i3plus.pojo.wms.bean.WmsLocate",
            searchColumnName = "locateNo,locateName", listColumnName = "locateNo,locateName", explicitColumnName = "locateNo")
    private String locateNo;

    @Column(name = "PART_NO")
    @ApiParam(value = "物料代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST,  getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
            dataSrc = "cn.estsh.i3plus.pojo.wms.bean.WmsPart",
            searchColumnName = "partNo,partName", listColumnName = "partNo,partName", explicitColumnName = "partNo")
    private String partNo;

    @Column(name = "PART_NAME_RDD")
    @ApiParam(value = "物料名称")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, isRequire = 2,  getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
            dataSrc = "cn.estsh.i3plus.pojo.wms.bean.WmsPart",
            searchColumnName = "partNo,partName", listColumnName = "partNo,partName", explicitColumnName = "partName")
    private String partNameRdd;

    @Column(name = "PULL_QTY", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "拉动数量", example = "0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER)
    private Double pullQty;

    @Column(name = "MAX", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "最大值", example = "0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER)
    private Double max;

    @Column(name = "MIN", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "最小值", example = "0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER)
    private Double min;

    @Column(name = "IS_GENERATE_PICKLIST")
    @ApiParam(value = "是否生成领料单", example = "2")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "TRUE_OR_FALSE")
    private Integer isGeneratePicklist;

    @Column(name = "SAFETY_STOCK", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "安全库存", example = "0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER)
    private Double safetyStock;

    @Column(name = "MOQ", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "起订量", example = "0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double moq;

    @Transient
    @ApiParam("库位类型")
    private Integer locateType;

    @Transient
    @ApiParam("库位类型")
    private List<Integer> locateTypeList;

    @Transient
    @ApiParam("物料类型")
    private List<String> partTypeList;

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

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

    @Transient
    @ApiParam(value = "库存单位")
    private String stockUnit;

    public Double getMin() {
        return this.min == null ? 0 : this.min;
    }

    public Integer getIsGeneratePicklist() {
        return this.isGeneratePicklist == null ? 0 : this.isGeneratePicklist;
    }

    public double getPullQtyValue(){
        return this.pullQty ==null?0d:this.pullQty.doubleValue();
    }

    public double getMaxValue(){
        return this.max ==null?0:this.max.doubleValue();
    }

    public double getMinValue(){
        return this.min ==null?0:this.min.doubleValue();
    }
    public double getSafetyStockVal(){
        return this.safetyStock ==null?0:this.safetyStock.doubleValue();
    }

    public WmsLocatePart() {
    }

    public WmsLocatePart(String locateNo, String partNo, String partNameRdd, Double pullQty, Double max, Double min,
                         Integer isGeneratePicklist, Double safetyStock, Double moq, String zoneNo, String whNo,
                         String stockUnit) {
        this.locateNo = locateNo;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.pullQty = pullQty;
        this.max = max;
        this.min = min;
        this.isGeneratePicklist = isGeneratePicklist;
        this.safetyStock = safetyStock;
        this.moq = moq;
        this.zoneNo = zoneNo;
        this.whNo = whNo;
        this.stockUnit = stockUnit;
    }
}
