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.ColumnDefault;
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 : dragon.xu
 * @CreateDate : 2018-11-07 16:06
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "WMS_PART")
@Api("物料表")
public class WmsPart extends BaseBean {
    private static final long serialVersionUID = 4849044986767609346L;
    @Column(name = "PART_NO")
    @ApiParam(value = "物料编码")
    private String partNo;

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

    @Column(name = "PART_SPEC")
    @ApiParam(value = "物料规格")
    private String partSpec;

    @Column(name = "PART_TYPE")
    @ApiParam(value = "物料类型")
    @AnnoOutputColumn(refClass = WmsEnumUtil.WMS_PART_TYPE_STR.class, refForeignKey = "value", value = "description")
    private String partType;

    @Column(name = "PART_TYPE_DESC")
    @ApiParam(value = "物料类型描述")
    private String partTypeDesc;

    @Column(name = "GRAPHI_NO")
    @ApiParam(value = "图号")
    private String graphiNo;

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

    @Column(name = "COLOR")
    @ApiParam(value = "颜色")
    private String color;

    @Column(name = "STOCK_UNIT")
    @ApiParam(value = "库存单位")
    private String stockUnit;

    @Column(name = "ABC")
    @ApiParam(value = "分类")
    private String abc;

    @Column(name = "BUY_UNIT")
    @ApiParam(value = "采购单位")
    private String buyUnit;

    @Column(name = "BU2SU", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "换算率1", example = "1")
    private Double bu2su;

    @Column(name = "PRICE_UNIT")
    @ApiParam(value = "计价单位")
    private String priceUnit;

    @Column(name = "PU2SU", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "换算率2", example = "1")
    private Double pu2su;

    @Column(name = "SNP", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "标准包装", example = "1")
    private Double snp;

    @ColumnDefault("2")
    @Column(name = "IQC")
    @ApiParam(value = "是否免检", example = "1")
    private Integer iqc;

    @Column(name = "MIN", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "最低库存", example = "1")
    private Double min;

    @Column(name = "MAX", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "最高库存", example = "1")
    private Double max;

    @Column(name = "PART_GROUP")
    @ApiParam(value = "物料组")
    private String partGroup;

    @Column(name = "LOT_CHECK_RULE")
    @ApiParam(value = "批次校验规则")
    private String lotCheckRule;

    @Column(name = "SN_CONTROL")
    @ApiParam(value = "是否条码管理", example = "1")
    private Integer snControl;

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

    @Column(name = "IN_LOCATE_NO")
    @ApiParam(value = "默认入库库位")
    private String inLocateNo;

    @Column(name = "PROD_CFG_TYPE_CODE")
    @ApiParam("项目代码")
    private String prodCfgTypeCode;

    @Column(name = "PROD_CFG_TYPE_NAME")
    @ApiParam("项目名称")
    private String prodCfgTypeName;

    @Column(name = "OUT_CLOSE_FLAG")
    @ApiParam("項目结算标识")
    private String outCloseFlag = "2";

    @Column(name = "OUT_CLOSE_TYPE")
    @ApiParam("结算方式")
    private String outCloseType;

    @Column(name = "OUT_CLOSE_VENDOR")
    @ApiParam("结算供应商")
    private String outCloseVendor;

    @Column(name = "QUALITY_DAYS")
    @ApiParam("保质期天数")
    private Integer qualityDays;

    @Column(name = "IS_REPORT_PARTNO")
    @ApiParam("是否报工零件")
    private Integer isReportPartNo;

    @Column(name = "REPORT_LOCATE_NO")
    @ApiParam("报工库位")
    private String reportLocateNo;

    @Column(name = "REPORT_ZONE_NO")
    @ApiParam("报工存储区")
    private String reportZoneNo;

    @Column(name = "PRODUCT_LINES")
    @ApiParam("报工产线")
    private String productLines;

    @Column(name = "PROPORTION", columnDefinition = "decimal(10,5)")
    @ApiParam(value = "待质检比例", example = "1")
    private Double proportion;

    @Column(name = "IS_VALUABLE", columnDefinition = "int default 2")
    @ApiParam(value = "贵重物料")
    @AnnoOutputColumn(refClass = WmsEnumUtil.IS_VALUABLE.class, refForeignKey = "value", value = "description")
    private Integer isValuable;

    @Transient
    @ApiParam("总数量")
    private Double qty;

    @Transient
    @ApiParam("库存水平")
    @AnnoOutputColumn(refClass = WmsEnumUtil.STOCK_LEVEL_STATUS.class, refForeignKey = "value", value = "description")
    private String stockLevelStatus;

    @Column(name="verb_num")
    @ApiParam(value = "单次拆包数")
    private Double verbNum;

    @Column(name = "IS_PROD_LOT")
    @ApiParam(value = "是否录入生产批次", example = "1")
    private Integer isProdLot = 2;

    @Column(name = "PULL_WAY")
    @ApiParam(value = "拉动方式", example = "0")
    private Integer pullWay = 0;

    @Column(name = "CYCLE_RQUEST_PERIOD")
    @ApiParam(value = "循环补货周期", example = "0")
    private Integer cycleRquestPeriod = 0;

    @Column(name = "CYCLE_RQUEST_QTY")
    @ApiParam(value = "循环补货数量", example = "0")
    private Double cycleRquestQty = 0d;

    public int getIqcVal(){
        return this.iqc == null ? 0 : this.iqc.intValue();
    }

    public int getCycleRquestPeriod(){
        return this.cycleRquestPeriod == null ? 0 : this.cycleRquestPeriod.intValue();
    }

    public WmsPart() {
    }

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

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

    public Double getMax() {
        return max == null? 0:max;
    }

    public Double getCycleRquestQty() {
        return this.cycleRquestQty == null? 0d:this.cycleRquestQty.doubleValue();
    }


    public WmsPart(String partNo, String partName, Double maxQty, Double minQty, Double cqty, String partType) {
        this.partNo = partNo;
        this.partName = partName;
        this.max = maxQty;
        this.min = minQty;
        this.qty = cqty;
        this.partType = partType;
    }
}
