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.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;

/**
 * @Description :物料实体
 * @Reference :
 * @Author : dragon.xu
 * @CreateDate : 2018-11-07 16:06
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "WMS_PART", indexes = {
        @Index(columnList = "PART_NO"),
        @Index(columnList = "ORGANIZE_CODE")
})
@Api("物料表")
public class WmsPart extends BaseBean {
    private static final long serialVersionUID = 4849044986767609346L;

    @Column(name = "PART_NO")
    @ApiParam(value = "物料编码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    private String partNo;

    @Column(name = "PART_NAME")
    @ApiParam(value = "物料名称")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    private String partName;

    @Column(name = "PART_TYPE_DESC")
    @ApiParam(value = "物料类型描述")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String partTypeDesc;

    @Column(name = "PART_TYPE")
    @ApiParam(value = "物料类型")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "WMS_PART_TYPE")
    @AnnoOutputColumn(refClass = WmsEnumUtil.WMS_PART_TYPE_STR.class)
    private String partType;

    @Column(name = "STOCK_UNIT")
    @ApiParam(value = "库存单位")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.URL,
            isRequire = 2, dataSrc = "/wms/wmsUnit/wms-unit/query", listColumnName = "unitCode", explicitColumnName = "unitCode")
    private String stockUnit;

    @Column(name = "IN_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 inLocateNo;

    @Column(name = "SNP", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "标包", example = "1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double snp;

    @ColumnDefault("2")
    @Column(name = "IQC")
    @ApiParam(value = "是否免检", example = "1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, isRequire = 2, dataSrc = "TRUE_OR_FALSE")
    private Integer iqc;

    @Column(name = "PART_SPEC")
    @ApiParam(value = "物料规格")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    private String partSpec;

    @Column(name = "GRAPHI_NO")
    @ApiParam(value = "图号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String graphiNo;

    @Column(name = "VERSION")
    @ApiParam(value = "版本")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String version;

    @Column(name = "COLOR")
    @ApiParam(value = "颜色")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String color;

    @Column(name = "ABC")
    @ApiParam(value = "分类")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String abc;

    @Column(name = "BUY_UNIT")
    @ApiParam(value = "采购单位")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.URL,
            isRequire = 2, dataSrc = "/wms/wmsUnit/wms-unit/query", listColumnName = "unitCode", explicitColumnName = "unitCode")
    private String buyUnit;

    @Column(name = "BU2SU", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "换算率1", example = "1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double bu2su;

    @Column(name = "PRICE_UNIT")
    @ApiParam(value = "计价单位")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.URL,
            isRequire = 2, dataSrc = "/wms/wmsUnit/wms-unit/query", listColumnName = "unitCode", explicitColumnName = "unitCode")
    private String priceUnit;

    @Column(name = "PU2SU", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "换算率2", example = "1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double pu2su;

    @Column(name = "MIN", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "最低库存", example = "1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double min;

    @Column(name = "MAX", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "最高库存", example = "1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double max;

    @Column(name = "PART_GROUP")
    @ApiParam(value = "物料组")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT,  getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.URL,
            isMultiple = 1, isRequire = 2, dataSrc = "/wms/wms-enum/dictionary/code?code=PART_GROUP_RULE", listColumnName = "name", explicitColumnName = "dictionaryValue")
    private String partGroup;

    @Column(name = "LOT_CHECK_RULE")
    @ApiParam(value = "批次校验规则")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.URL,
            isRequire = 2, dataSrc = "/wms/wms-enum/dictionary/code?code=LOT_CHECK_RULE", listColumnName = "name", explicitColumnName = "dictionaryValue")
    private String lotCheckRule;

    @Column(name = "SN_CONTROL")
    @ApiParam(value = "是否条码管理", example = "1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, isRequire = 2, dataSrc = "TRUE_OR_FALSE")
    private Integer snControl;

    @Column(name = "VENDOR_NO")
    @ApiParam(value = "供应商代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String vendorNo;

    @Column(name = "PROD_CFG_TYPE_CODE")
    @ApiParam("项目代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String prodCfgTypeCode;

    @Column(name = "PROD_CFG_TYPE_NAME")
    @ApiParam("项目名称")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String prodCfgTypeName;

    @Column(name = "OUT_CLOSE_FLAG")
    @ApiParam("項目结算标识")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String outCloseFlag = "2";

    @Column(name = "OUT_CLOSE_TYPE")
    @ApiParam("结算方式")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String outCloseType;

    @Column(name = "OUT_CLOSE_VENDOR")
    @ApiParam("结算供应商")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.LIST, isRequire = 2, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.OBJ,
            dataSrc = "cn.estsh.i3plus.pojo.wms.bean.BasVendor",
            searchColumnName = "vendorNo,vendorName", listColumnName = "vendorNo,vendorName", explicitColumnName = "vendorNo")
    private String outCloseVendor;

    @Column(name = "QUALITY_DAYS")
    @ApiParam("保质期天数")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Integer qualityDays;

    @Column(name = "IS_REPORT_PARTNO")
    @ApiParam("是否报工零件")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, isRequire = 2, dataSrc = "TRUE_OR_FALSE")
    private Integer isReportPartNo;

    @Column(name = "REPORT_LOCATE_NO")
    @ApiParam("报工库位")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String reportLocateNo;

    @Column(name = "REPORT_ZONE_NO")
    @ApiParam("报工存储区")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String reportZoneNo;

    @Column(name = "PRODUCT_LINES")
    @ApiParam("报工产线")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.URL,
            isRequire = 2, dataSrc = "/wms/work-center/list", listColumnName = "workCenterName", explicitColumnName = "workCenterCode")
    private String productLines;

    @Column(name = "PROPORTION", columnDefinition = "decimal(10,8)")
    @ApiParam(value = "待质检比例", example = "1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double proportion;

    @Column(name = "STD_CHECK_TIME", columnDefinition = "decimal(10,2)")
    @ApiParam(value = "标准质检时间")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double stdCheckTime;

    @Column(name = "IS_VALUABLE", columnDefinition = "int default 2")
    @ApiParam(value = "是否贵重")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, isRequire = 2, dataSrc = "IS_VALUABLE")
    @AnnoOutputColumn(refClass = WmsEnumUtil.IS_VALUABLE.class, refForeignKey = "value", value = "description")
    private Integer isValuable;

    @Column(name = "PART_VOL", columnDefinition = "decimal(18,8)")
    @ApiParam(value = "体积", example = "1")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double partVol;

    @Transient
    @ApiParam("总数量")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double qty;

    @Transient
    @ApiParam("库存水平")
    @AnnoOutputColumn(refClass = WmsEnumUtil.STOCK_LEVEL_STATUS.class, refForeignKey = "value", value = "description")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String stockLevelStatus;

    @Column(name = "verb_num")
    @ApiParam(value = "单次拆包数")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double verbNum;

    @Column(name = "IS_PROD_LOT")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, isRequire = 2, dataSrc = "TRUE_OR_FALSE")
    @ApiParam(value = "是否录入生产批次", example = "1")
    private Integer isProdLot = 2;

    @Column(name = "PULL_WAY")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, isMultiple = 1, isRequire = 2, dataSrc = "PULL_WAY_STATUS")
    @ApiParam(value = "拉动方式")
    private String pullWay;

    @Column(name = "TAIL_QTY_MODE")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, isRequire = 2, dataSrc = "TAIL_QTY_MODE")
    @ApiParam(value = "尾数计算方式", example = "1")
    private Integer tailQtyMode;

    @Column(name = "CYCLE_RQUEST_PERIOD")
    @ApiParam(value = "循环补货周期", example = "0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Integer cycleRquestPeriod = 0;

    @Column(name = "CYCLE_RQUEST_QTY")
    @ApiParam(value = "循环补货数量", example = "0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double cycleRquestQty = 0d;

    @Column(name = "CURING_TIME")
    @ApiParam(value = "固化时间", example = "0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double curingTime = 0d;

    @Column(name = "IS_RECYCLE", columnDefinition = "int default 2", nullable = false)
    @ApiParam(value = "是否回收", example = "2")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, isRequire = 2, dataSrc = "TRUE_OR_FALSE")
    @AnnoOutputColumn(refClass = WmsEnumUtil.TRUE_OR_FALSE.class, refForeignKey = "value", value = "description", hidden = true)
    public Integer isRecycle;


    @Column(name = "FREQUENCY")
    @ApiParam(value = "频次", example = "0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, isRequire = 2, dataSrc = "FREQUENCY")
    @AnnoOutputColumn(refClass = WmsEnumUtil.FREQUENCY.class, refForeignKey = "value", value = "description", hidden = true)
    private Integer frequency;

    @Column(name = "LIMIT_QUALITY_DAYS")
    @ApiParam(value = "卡控周期", example = "0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Integer limitQualityDays;


    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 getPartVol() {
        return partVol == null ? 0 : partVol;
    }


    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 Double getCuringTime() {
        return this.curingTime == null ? 0d : this.curingTime.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;
    }

    public WmsPart(String partGroup, Double cqty, String createDateTime) {
        this.partGroup = partGroup;
        this.qty = cqty;
        this.createDatetime = createDateTime;
    }

    public WmsPart(String partNo, String partName, String inLocateNo, String stockUnit, Double snp, String partSpec) {
        this.partNo = partNo;
        this.partName = partName;
        this.inLocateNo = inLocateNo;
        this.stockUnit = stockUnit;
        this.snp = snp;
        this.partSpec = partSpec;
    }

    public WmsPart(String partNo, String partName, String partSpec, Double snp, String buyUnit, Integer snControl, Double qty) {
        this.partNo = partNo;
        this.partName = partName;
        this.partSpec = partSpec;
        this.snp = snp;
        this.buyUnit = buyUnit;
        this.snControl = snControl;
        this.qty = qty;
    }
}
