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

import cn.estsh.i3plus.pojo.aps.annotation.FieldAnnotation;
import cn.estsh.i3plus.pojo.aps.common.BaseAPS;
import cn.estsh.i3plus.pojo.aps.common.BeanRelation;
import cn.estsh.i3plus.pojo.aps.holders.EOperation;
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.List;

/**
 * @Description :工序
 * @Reference :
 * @Author : jason.niu
 * @CreateDate : 2019-09-17
 * @Modify:
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "APS_OPERATION")
@Api("工序")
public class Operation extends BaseAPS {
    private static final long serialVersionUID = 4394179144091116858L;
    @Column(name="NUMBER")
    @ApiParam(value ="工序号")
    @FieldAnnotation(notEmpty = true)
    private Integer number;

    @Column(name="PRODUCT_ROUTING_ID")
    @ApiParam(value ="工艺路线")
    @FieldAnnotation(relation = "ProductRouting", notEmpty = true, display = false)
    private Long productRoutingId;

    @Column(name="STAND_OPERATION_ID")
    @ApiParam(value ="标准工序")
    @FieldAnnotation(relation = "StandOperation", notEmpty = true)
    private Long standOperationId;

    @Column(name="PREV_COUNT_RATE", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="前工序数量比")
    @FieldAnnotation(notEmpty = true, defaultValue = "1.0")
    private Double prevCountRate;

    @Column(name="YIELD", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="成品率")
    @FieldAnnotation(notEmpty = true, defaultValue = "1.0")
    private Double yield;

    @Column(name="FIX_SCRAP_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="固定报废数")
    private Double fixScrapCount;

    @Column(name="RATIO")
    @ApiParam(value ="分割比例")
    private String ratio;

    @Column(name="COUNT")
    @ApiParam(value ="分割的工作个数")
    private Integer count;

    @Column(name="BATCH", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="分割批量")
    private Double batch;

    @Column(name="REMAINDER", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="分割余数")
    private Double remainder;

    @Column(name="CONS_TYPE")
    @ApiParam(value ="接续方式")
    @FieldAnnotation(defaultValue = "ES")
    private ApsEnumUtil.CONSTRAINT_TYPE consType;

    @Column(name="MAX_SPACE_TIME")
    @ApiParam(value ="最大时间间隔")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String maxSpaceTime;

    @Column(name="MIN_SPACE_TIME")
    @ApiParam(value ="最小时间间隔")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String minSpaceTime;

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

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

    @JsonBackReference
    public List<OperInput> getOperInputs() {
        return BeanRelation.list(this, EOperation.OperInputs);
    }

    @JsonBackReference
    public List<OperOutput> getOperOutputs() {
        return BeanRelation.list(this, EOperation.OperOutputs);
    }

    @JsonBackReference
    public List<OperResource> getOperResources() {
        return BeanRelation.list(this, EOperation.OperResources);
    }

    public StandOperation getStandOperation() {
        return BeanRelation.get(this, EOperation.StandOperation);
    }

    public void setStandOperation(StandOperation std) {
        this.standOperationId = std != null ? std.getId() : 0l;
        BeanRelation.set(this, EOperation.StandOperation, std);
    }
}
