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 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_OPER_OUTPUT")
@Api("工序输出")
public class OperOutput extends BaseAPS {
    private static final long serialVersionUID = 3185682762290147209L;
    @Column(name="OPERATION_ID")
    @ApiParam(value ="工序")
    @FieldAnnotation(relation = "Operation", notEmpty = true, display = false)
    private Long operationId;

    @Column(name="OUTPUT_MATERIAL_ID")
    @ApiParam(value ="物料")
    @FieldAnnotation(relation = "Material", notEmpty = true)
    private Long outputMaterialId;

    @Column(name="OUTPUT_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="单位输出量")
    @FieldAnnotation(defaultValue = "1.0")
    private Double outputCount;

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

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

    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 getOutputMaterial() {
        return BeanRelation.get(this, EOperOutput.OutputMaterial);
    }

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

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