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 com.fasterxml.jackson.annotation.JsonFormat;
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 : bom历史记录
 * @Reference :
 * @Author : jason
 * @CreateDate : 2020-04-14
 * @Modify:
 **/
@Data
@Entity
@Table(name = "WMS_BOM_HISTORY")
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Api(value = "bom历史记录", description = "bom历史记录")
public class WmsBomHistory extends BaseBean {
    private static final long serialVersionUID = -2781401699752981565L;
    @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 = "UNIT")
    @ApiParam(value = "计量单位")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String unit;

    @Column(name = "QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ApiParam(value = "数量")
    @ColumnDefault("0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double qty;

    @Column(name = "ITEM_PART_NO")
    @ApiParam(value = "子物料号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    private String itemPartNo;

    @Column(name = "ITEM_PART_NAM")
    @ApiParam(value = "子料物料描述")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT)
    private String itemPartNam;

    @Column(name = "ITEM_UNIT")
    @ApiParam(value = "子计量单位")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String itemUnit;

    @Column(name = "ITEM_QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ApiParam(value = "子用量")
    @ColumnDefault("0")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.NUMBER, isRequire = 2)
    private Double itemQty;

    @Column(name = "BOM_NUM")
    @ApiParam(value = "BOM编号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String bomNum;

    @Column(name = "BOM_VERSION")
    @ApiParam(value = "BOM版本号")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String bomVersion;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiParam(value = "有效起始日期", example = "2018-12-31 23:59:59")
    @AnnoOutputColumn(hidden = true)
    @Column(name = "EFF_START_TIME")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.DATETIME, isRequire = 2)
    private String effStartTime;


    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiParam(value = "有效截止日期", example = "2018-12-31 23:59:59")
    @AnnoOutputColumn(hidden = true)
    @Column(name = "EFF_END_TIME")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.DATETIME, isRequire = 2)
    private String effEndTime;

    @Column(name = "LOCATE_NO")
    @ApiParam(value = "线边库位代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String locateNo;

    @Column(name = "TERMINAL_NO")
    @ApiParam(value = "工位代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String terminalNo;

    @Column(name = "NEW_BOM_VERSION")
    @ApiParam(value = "工位代码")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.TEXT, isRequire = 2)
    private String newBomVersion;

    @Column(name = "BOM_TYPE")
    @ApiParam(value = "BOM类型")
    @ColumnDefault("10")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, isRequire = 1)
    @AnnoOutputColumn(refClass = WmsEnumUtil.BOM_TYPE.class, refForeignKey = "value", value = "description")
    private Integer bomType;

    @ApiParam(value = "目标存储区")
    @Transient
    public String destZoneNo;

    @ApiParam(value = "交易类型")
    @Transient
    public String transTypeCode;

    @ApiParam(value = "线路代码")
    @Transient
    public String routingCode;

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

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

    public WmsBomHistory() {
    }

    public WmsBomHistory(String itemPartNo, String itemPartNam, String itemUnit, String bomNum, Double itemQty) {
        this.itemPartNo = itemPartNo;
        this.itemPartNam = itemPartNam;
        this.itemUnit = itemUnit;
        this.bomNum = bomNum;
        this.itemQty = itemQty;
    }

    public WmsBomHistory(String itemPartNo, String itemPartNam, String itemUnit, String bomNum, Double itemQty,String effStartTime) {
        this.itemPartNo = itemPartNo;
        this.itemPartNam = itemPartNam;
        this.itemUnit = itemUnit;
        this.bomNum = bomNum;
        this.itemQty = itemQty;
        this.effStartTime = effStartTime;
    }
}
