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.EInterMediateResult;
import cn.estsh.i3plus.pojo.aps.holders.EWorkInput;
import cn.estsh.i3plus.pojo.aps.holders.EWorkPlan;
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 : 2021-04-25
 * @Modify:
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "APS_INTER_MEDIATE_RESULT")
@Api("计算中间结果")
public class InterMediateResult extends BaseAPS {
    private static final long serialVersionUID = -1869359887027950540L;

    @Column(name="WORK_ID")
    @ApiParam(value ="工作编码")
    @FieldAnnotation(relation = "Work")
    private Long workId;

    @Column(name="RESOURCE_ID")
    @ApiParam(value ="资源")
    @FieldAnnotation(relation = "Resource")
    private Long resourceId;

    @Column(name="EVALUATE_VALUE")
    @ApiParam(value ="评估值")
    private Double evaluateValue;

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

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

    public Resource getResource() { return BeanRelation.get(this, EInterMediateResult.Resource); }

    public void setResource(Resource resource) {
        this.resourceId = resource != null ? resource.getId() : 0l;
        BeanRelation.set(this, EInterMediateResult.Resource, resource);
    }

    @JsonBackReference
    public List<InterMediateDetail> getDetails() { return BeanRelation.list(this, EInterMediateResult.Details); }
}
