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

import cn.estsh.i3plus.pojo.aps.annotation.FieldAnnotation;
import cn.estsh.i3plus.pojo.aps.common.BeanRelation;
import cn.estsh.i3plus.pojo.aps.holders.EBaseOrder;
import cn.estsh.i3plus.pojo.aps.holders.EInventory;
import cn.estsh.i3plus.pojo.base.enumutil.ApsEnumUtil;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
import java.util.List;

/**
 * @Description :库存
 * @Reference :
 * @Author : jason.niu
 * @CreateDate : 2019-09-17
 * @Modify:
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "APS_INVENTORY")
@Api("库存")
public class Inventory extends BaseOrder {
    private static final long serialVersionUID = 2378846162007550439L;

    @Column(name="SPECIFY_TOP_ORDER")
    @ApiParam(value ="指定顶层订单")
    private String specifyTopOrder;

    @Column(name="SPECIFY_UP_ORDER")
    @ApiParam(value ="指定上层订单")
    private String specifyUpOrder;

    @Column(name="ASSIGN_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="已分配量")
    @FieldAnnotation(modify = false)
    private Double assignCount;

    @Column(name="EXCESS_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="多余量")
    @FieldAnnotation(modify = false)
    private Double excessCount;

    @Column(name="SINGLE_SUPPLY_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="单次补充数量")
    private Double singleSupplyCount;

    @Column(name="SAFE_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="安全库存数量")
    private Double safeCount;

    @Column(name="SUPPLY_INTERVAL")
    @ApiParam(value ="补充间隔（天）")
    private Integer supplyInterval;

    @Column(name="LAST_SUPPLY")
    @ApiParam(value ="最后补充时间")
    private Date lastSupply;

    @JsonIgnore
    public Work getWork() {
        return BeanRelation.get(this, EBaseOrder.Works);
    }

    @JsonBackReference
    public List<SafeStockOrder> getSafeStockOrders() { return BeanRelation.list(this, EInventory.SafeStockOrders); }
}
