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

    @Column(name="INPUT_MATERIAL_ID")
    @ApiParam(value ="物料")
    @FieldAnnotation(relation = "InputMaterial", notEmpty = true)
    private Long inputMaterialId;

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

    @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;

    @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 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 getInputMaterial() {
        return BeanRelation.get(this, EOperInput.InputMaterial);
    }

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

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