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.EProductOrder;
import cn.estsh.i3plus.pojo.aps.holders.EProductRouting;
import cn.estsh.i3plus.pojo.base.enumutil.ApsEnumUtil;
import com.fasterxml.jackson.annotation.JsonBackReference;
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_PRODUCT_ORDER")
@Api("生产订单")
public class ProductOrder extends BaseOrder {
    private static final long serialVersionUID = 6900226668783662736L;
    @Column(name="EST")
    @ApiParam(value ="最早开始时间")
    private Date est;

    @Column(name="SPECIFY_EST")
    @ApiParam(value ="指定最早开始时间")
    private Date specifyEst;

    @Column(name="SPECIFY_LET")
    @ApiParam(value ="指定最晚结束时间")
    private Date specifyLet;

    @Column(name="LOW_EST")
    @ApiParam(value ="底阶最早开始时间")
    private Date lowEst;

    @Column(name="SPECIFY_LOW_EST")
    @ApiParam(value ="指定底阶最早开始时间")
    private Date specifyLowEst;

    @Column(name="SPECIFY_ROUTING")
    @ApiParam(value ="指定工艺路线")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.OBJECT, typeName = "ProductRouting")
    private String specifyRouting;

    @Column(name="RECALC_COUNT")
    @ApiParam(value ="是否重新计算数量")
    @FieldAnnotation(defaultValue = "true")
    private Boolean recalcCount;

    @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 ="已分配数量")
    private Double assignCount;

    @Column(name="SPECIFY_LEAD_TIME")
    @ApiParam(value ="指定提前期")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String specifyLeadTime;

    @Column(name="CALC_LEAD_TIME")
    @ApiParam(value ="提前期计算值")
    @FieldAnnotation(modify = false)
    private String calcLeadTime;

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

    @Column(name="LACK_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="缺少量")
    @FieldAnnotation(modify = false)
    private Double lackCount;

    @Column(name="AUTO_SUPPLY")
    @ApiParam(value ="物料计算时自动补充")
    @FieldAnnotation(defaultValue = "false", display = false)
    private Boolean autoSupply;

    @Column(name="PRODUCT_ROUTING_ID")
    @ApiParam(value ="工艺路线")
    @FieldAnnotation(property = false)
    private Long productRoutingId;

    public ProductRouting getProductRouting() {
        return BeanRelation.get(this, EProductOrder.ProductRouting);
    }

    public void setProductRouting(ProductRouting routing) {
        this.productRoutingId = routing != null ? routing.getId() : 0l;
        BeanRelation.set(this, EProductOrder.ProductRouting, routing);
    }

    @JsonBackReference
    public List<ParentWork> getParentWorks() { return BeanRelation.list(this, EProductOrder.ParentWorks); }
}
