package cn.estsh.i3plus.pojo.wms.bean;

import cn.estsh.i3plus.pojo.base.bean.BaseBean;
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 dragon
 * @CreateDate 2019/6/19 21:23
 * @Modify
 * 2020-09-24 18:58 Rock.Yu 增加 Category 属性，Magna 的 BOM 是多层结构，需要靠这个字段标记是否虚阶
 */
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "WMS_BOM_TOTAL")
@Api("全量BOM")
public class WmsBomTotal extends BaseBean {
    private static final long serialVersionUID = 8196235268344152723L;
    /**
     * 麦格纳 SAP 中表示虚阶BOM的代码
     */
    public static final String MGANA_BOM_HAS_CHILD = "5";

    @Column(name = "PART_NO")
    @ApiParam("父物料号")
    private String partNo;

    @Column(name = "PART_NAME")
    @ApiParam("父物料描述")
    private String partName;

    @Column(name = "UNIT")
    @ApiParam("计量单位")
    private String UNIT;

    @Column(name = "QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ApiParam("数量")
    @ColumnDefault("0")
    private Double qty;

    @Column(name = "ITEM_PART_NO")
    @ApiParam(value = "子物料号")
    private String itemPartNo;

    @Column(name = "ITEM_PART_NAME")
    @ApiParam(value = "子料物料描述")
    private String itemPartName;

    @Column(name = "ITEM_UNIT")
    @ApiParam(value = "子计量单位")
    private String itemUnit;

    @Column(name = "ITEM_QTY", columnDefinition = "decimal(18,8)", nullable = false)
    @ApiParam(value = "子用量")
    @ColumnDefault("0")
    private Double itemQty;

    @Column(name = "BOM_NUM")
    @ApiParam(value = "BOM编号")
    private String bomNum;

    @Column(name = "BOM_VERSION")
    @ApiParam(value = "BOM版本号")
    private String bomVersion;

    @Column(name = "EFF_START_TIME")
    @ApiParam(value = "有效起始日期")
    private String effStartTime;

    @Column(name = "EFF_END_TIME")
    @ApiParam(value = "有效截止日期")
    private String effEndTime;

    @Column(name = "SID")
    @ApiParam(value = "SID")
    private String sid;

    /**
     * SAP Category == 5 表示零件是虚阶
     */
    @Column(name = "CATEGORY")
    @ApiParam(value = "是否虚阶物料")
    private String category;

    /**
     * 是否包含子阶
     * @return
     */
    public boolean hasChild() {
        return category != null && category.trim().equals(MGANA_BOM_HAS_CHILD);
    }

    /**
     * 导入列
     */
    @Transient
    @ApiParam(value = "行数")
    private Integer rows;

    @Transient
    @ApiParam(value = "状态")
    private Integer status;
}
