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.EWorkOutput;
import com.fasterxml.jackson.annotation.JsonBackReference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.context.annotation.Bean;

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_OUTPUT")
@Api("工作输出")
public class WorkOutput extends BaseAPS {

    private static final long serialVersionUID = 6031001499619328313L;
    @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="OUTPUT_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="输出数量")
    @FieldAnnotation(modify = false)
    private Double outputCount;

    @Column(name="REMAIN_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="多余数量")
    @FieldAnnotation(modify = false)
    private Double remainCount;

    @Column(name="OUTPUT_TIME")
    @ApiParam(value ="输出时间")
    @FieldAnnotation(modify = false)
    private Date outputTime;

    @Column(name="OPER_OUTPUT_ID")
    @ApiParam(value ="工序输出")
    @FieldAnnotation(property = false)
    private Long operOutputId;

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

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

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

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

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

    public OperOutput getOperOutput() {
        return BeanRelation.get(this, EWorkOutput.OperOutput);
    }

    public void setOperOutput(OperOutput output) {
        this.operOutputId = output != null ? output.getId() : 0l;
        BeanRelation.set(this, EWorkOutput.OperOutput, output);
    }
}
