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.enums.CONSTRAINT_TYPE;
import cn.estsh.i3plus.pojo.aps.holders.EOperInput;
import com.fasterxml.jackson.annotation.JsonBackReference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;

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
@Entity
@Table(name = "APS_OPER_INPUT")
@Api("工序输入")
public class OperInput extends BaseAPS {
    @Column(name="INPUT_COUNT")
    @ApiParam(value ="输入数量")
    private Double inputCount;

    @Column(name="YIELD")
    @ApiParam(value ="成品率")
    private Double yield;

    @Column(name="FIX_SCRAP_COUNT")
    @ApiParam(value ="固定报废数")
    private Double fixScrapCount;

    @Column(name="CONS_TYPE")
    @ApiParam(value ="接续方式")
    private CONSTRAINT_TYPE consType;

    @Column(name="MAX_SPACE_TIME")
    @ApiParam(value ="最大时间间隔")
    private String maxSpaceTime;

    @Column(name="MIN_SPACE_TIME")
    @ApiParam(value ="最小时间间隔")
    private String minSpaceTime;

    @Column(name="OPERATION_ID")
    @ApiParam(value ="工序")
    @FieldAnnotation(property = false)
    private Long operationId;

    @Column(name="MATERIAL_ID")
    @ApiParam(value ="物料")
    @FieldAnnotation(property = false)
    private Long materialId;

    public Operation getOperation() {
        return BeanRelation.get(this, EOperInput.Operation);
    }

    public void setOperation(Operation oper) {
        this.operationId = oper != null ? oper.getId() : 0l;
        BeanRelation.set(this, EOperInput.Operation, oper);
    }

    public Material getMaterial() {
        return BeanRelation.get(this, EOperInput.Material);
    }

    public void setMaterial(Material material) {
        this.materialId = material != null ? material.getId() : 0l;
        BeanRelation.set(this, EOperInput.Material, material);
    }

    @JsonBackReference
    public List<WorkInput> getWorkInputs() {
        return BeanRelation.list(this, EOperInput.WorkInputs);
    }
}
