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.EWorkInput;
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.Date;
import java.util.List;

/**
 * @Description :工作输入
 * @Reference :
 * @Author : jason.niu
 * @CreateDate : 2019-09-17
 * @Modify:
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "APS_WORK_INPUT")
@Api("工作输入")
public class WorkInput extends BaseAPS {
    private static final long serialVersionUID = 2654389476284740183L;
    @Column(name="WORK_ID")
    @ApiParam(value ="工作")
    @FieldAnnotation(relation = "Work")
    private Long workId;

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

    @Column(name="INPUT_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="输入数量")
    @FieldAnnotation(modify = false)
    private Double inputCount;

    @Column(name="SHORT_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="短缺数量")
    @FieldAnnotation(modify = false)
    private Double shortCount;

    @Column(name="INPUT_TIME")
    @ApiParam(value ="输入时间")
    @FieldAnnotation(modify = false)
    private Date inputTime;

    @Column(name="OPER_INPUT_ID")
    @ApiParam(value ="工序输入")
    @FieldAnnotation(property = false)
    private Long operInputId;

    public Work getWork() {
        return BeanRelation.get(this, EWorkInput.Work);
    }

    public void setWork(Work work) {
        this.workId = work != null ? work.getId() : 0l;
        BeanRelation.set(this, EWorkInput.Work, work);
    }

    @JsonBackReference
    public List<WorkRelation> getWorkRelations() {
        return BeanRelation.list(this, EWorkInput.WorkRelations);
    }

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

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

    public OperInput getOperInput() {
        return BeanRelation.get(this, EWorkInput.OperInput);
    }

    public void setOperInput(OperInput input) {
        this.operInputId = input != null ? input.getId() : 0l;
        BeanRelation.set(this, EWorkInput.OperInput, input);
    }
}
