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.Index;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @Description : 库位表
 * @Reference :
 * @Author : jimmy.zeng
 * @CreateDate : 2018-11-07 10:35
 * @Modify:
 **/
@Data
@Entity
@Table(name = "WMS_LOCATE", indexes = {
        @Index(columnList = "LOCATE_NO"),
        @Index(columnList = "ORGANIZE_CODE")
})
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Api(value = "库位表", description = "库位表")
public class WmsLocate extends BaseBean {

    private static final long serialVersionUID = -8425904594036746967L;
    @Column(name = "LOCATE_NO")
    @ApiParam(value = "库位代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    private String locateNo;

    @Column(name = "LOCATE_NAME")
    @ApiParam(value = "库位名称")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    private String locateName;

    /**
     * 库位类型:10=收货库,20=基础库,30=机动库,40=组合库,50=线边库,60=NC库，70=溢料,80=在途库位,90=器具库
     */
    @Column(name = "LOCATE_TYPE")
    @ApiParam(value = "库位类型")
    @AnnoOutputColumn(refClass = WmsEnumUtil.LOCATE_TYPE.class, refForeignKey = "value", value = "description")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "LOCATE_TYPE")
    private Integer locateType;

    @Column(name = "WH_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.WareHouse",
            searchColumnName = "code,name",listColumnName = "code,name", explicitColumnName = "code")
    private String whNo;

    @Column(name = "ZONE_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.WmsZones",
            searchColumnName = "zoneNo,zoneName",listColumnName = "zoneNo,zoneName", explicitColumnName = "zoneNo")
    private String zoneNo;

    @Column(name = "FURNITURE_NO")
    @ApiParam(value = "家具代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String furnitureNo;

    @Column(name = "X")
    @ApiParam(value = "X", example = "-1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Integer x;

    @Column(name = "Y")
    @ApiParam(value = "Y", example = "-1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Integer y;

    @Column(name = "Z")
    @ApiParam(value = "Z", example = "-1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Integer z;

    @Column(name = "LC_LENGTH")
    @ApiParam(value = "长")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Integer lcLength;

    @Column(name = "LC_WIDTH")
    @ApiParam(value = "宽")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Integer lcWidth;

    @Column(name = "LC_HEIGHT")
    @ApiParam(value = "高")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Integer lcHeight;

    @Column(name = "SEQ")
    @ApiParam(value = "序号", example = "-1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Integer seq;

    @Column(name = "STATUS")
    @ApiParam(value = "库位状态", example = "-1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.LOCATE_STATUS.class, refForeignKey = "value", value = "description")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, dataSrc = "LOCATE_STATUS")
    private Integer status;

    @Column(name = "MAX_PACKAGE_QTY")
    @ApiParam(value = "最大包装数量", example = "-1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Integer maxPackageQty;

    @Column(name = "MAX_PART_QTY", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "最大零件数量", example = "-1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double maxPartQty;

    @Column(name = "STOCK_UNIT")
    @ApiParam(value = "存放单位")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String stockUnit;

    @Column(name = "LINE_CODE")
    @ApiParam(value = "生产线")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String lineCode;

    @Column(name = "BOX_QTY")
    @ApiParam(value = "箱数", example = "-1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Integer boxQty;

    @Column(name = "PART_QTY", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "零件数", example = "-1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double partQty;

    @Column(name = "ENCRYPTION_NO")
    @ApiParam(value = "加密编码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String encryptionNo;

    @Column(name = "LAST_CS_TIME")
    @ApiParam(value = "末次盘点时间")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.DATETIME, isRequire = 2)
    private String lastCsTime;

    @Column(name = "POSITION")
    @ApiParam(value = "三维位置")
    private String position;

    /**
     * BH库位类型:10:HOLD库位；20：待检测库位；30:待出库库位
     */
    @Column(name = "BH_LOCATE_TYPE")
    @ApiParam(value = "BH库位类型")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "BH_LOCATE_TYPE")
    @AnnoOutputColumn(refClass = WmsEnumUtil.BH_LOCATE_TYPE.class, refForeignKey = "value", value = "description")
    private Integer bhLocateType;

    @Column(name = "DOWN_X")
    @ApiParam(value = "X向下偏移", example = "-1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.DOWN_OR_UP.class, refForeignKey = "value", value = "description")
    private Integer downX;

    @Column(name = "UP_X")
    @ApiParam(value = "X向上偏移", example = "-1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.DOWN_OR_UP.class, refForeignKey = "value", value = "description")
    private Integer upX;

    @Column(name = "DOWN_Y")
    @ApiParam(value = "Y向下偏移", example = "-1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.DOWN_OR_UP.class, refForeignKey = "value", value = "description")
    private Integer downY;

    @Column(name = "UP_Y")
    @ApiParam(value = "Y向上偏移", example = "-1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.DOWN_OR_UP.class, refForeignKey = "value", value = "description")
    private Integer upY;

    @Column(name = "LOCATE_ALIAS")
    @ApiParam(value = "库位别名")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    private String locateAlias;

    // 导入用
    @ApiParam(value = "工厂")
    @Transient
    private String factory;

    @Transient
    @ApiParam(value = "入库箱数", example = "-1")
    private Integer destBoxQty;

    @Transient
    @ApiParam(value = "库位利用率")
    public Integer proportion;

    @Transient
    @ApiParam(value = "错误信息", example = "-1")
    private String errorMsg;

    @Transient
    @ApiParam(value = "末次盘点开始时间")
    private String lastCsTimeStart ;

    @Transient
    @ApiParam(value = "末次盘点结束时间")
    private String lastCsTimeEnd;

    @Transient
    @ApiParam(value = "库位数组集")
    private String[] locateNoArr;

    @Transient
    @ApiParam(value = "移动频次")
    private Long frequency;

    @Transient
    @ApiParam(value = "库龄")
    private String age;

    @Transient
    @ApiParam(value = "库位箱数")
    private Long qty;

    @Transient
    @ApiParam(value = "不等于库位类型")
    private Integer notLocateType;

    @Transient
    @ApiParam(value = "总库位")
    private Integer totalQty;

    @Transient
    @ApiParam(value = "已用库位")
    private Integer usedQty;

    @Transient
    @ApiParam(value = "空库位")
    private Integer emptyQty;

    public WmsLocate() {
    }

    public WmsLocate(String locateNo,Integer destBoxQty) {
        this.locateNo = locateNo;
        this.destBoxQty = destBoxQty;
    }

    public WmsLocate(String locateNo,Integer destBoxQty, Integer y, Integer x, Integer z) {
        this.locateNo = locateNo;
        this.destBoxQty = destBoxQty;
        this.y = y;
        this.x = x;
        this.z = z;
    }

    public WmsLocate(Integer boxQty ,  Double partQty,String locateNo){
        this.boxQty=boxQty;
        this.partQty=partQty;
        this.locateNo=locateNo;
    }
    //3D仓库-库位移动频率热力图
    public WmsLocate(String locateNo,Long frequency,String organizeCode,
                     String whNo,String zoneNo,String furnitureNo,
                     Integer x,Integer y,Integer z){
        this.locateNo=locateNo;
        this.frequency=frequency;
        this.organizeCode=organizeCode;
        this.whNo=whNo;
        this.zoneNo=zoneNo;
        this.furnitureNo=furnitureNo;
        this.x=x;
        this.y=y;
        this.z=z;
    }
    //3D仓库-库龄热力图
    public WmsLocate(String locateNo,String age,String organizeCode,
                     String whNo,String zoneNo,String furnitureNo,
                     Integer x,Integer y,Integer z){
        this.locateNo=locateNo;
        this.age=age;
        this.organizeCode=organizeCode;
        this.whNo=whNo;
        this.zoneNo=zoneNo;
        this.furnitureNo=furnitureNo;
        this.x=x;
        this.y=y;
        this.z=z;
    }

    public WmsLocate(Long qty, Integer status, String zoneNo) {
        this.qty = qty;
        this.status = status;
        this.zoneNo = zoneNo;
    }

    public Integer getMaxPackageQty() {
        return this.maxPackageQty == null ? 0 : this.maxPackageQty.intValue();
    }

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

    public Integer getBoxQty() {
        return this.boxQty == null ? 0 : this.boxQty.intValue();
    }

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

    public Integer getLocateType() {
        return this.locateType== null ? 0 : this.locateType.intValue();
    }

    public Long getFrequencyVal() {
        return this.frequency == null ? 0 : this.frequency.longValue();
    }

    public Integer getLcLengthVal() {
        return this.lcLength == null ? 0 : this.lcLength.intValue();
    }
    public Integer getLcWidthVal() {
        return this.lcWidth == null ? 0 : this.lcWidth.intValue();
    }
    public Integer getLcHeightVal() {
        return this.lcHeight == null ? 0 : this.lcHeight.intValue();
    }

    public Integer getXVal() {
        return this.x == null ? 0 : this.x.intValue();
    }
    public Integer getYVal() {
        return this.y == null ? 0 : this.y.intValue();
    }
    public Integer getZVal() {
        return this.z == null ? 0 : this.z.intValue();
    }


}
