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.EOperOutput;
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_OUTPUT")
@Api("工序输出")
public class OperOutput extends BaseAPS {
    @Column(name="OUTPUT_COUNT")
    @ApiParam(value ="输出数量")
    private Double outputCount;

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

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

    @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, EOperOutput.Operation);
    }

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

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

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

    @JsonBackReference
    public List<WorkOutput> getWorkOutputs() {
        return BeanRelation.list(this, EOperOutput.WorkOutputs);
    }
}
