package cn.estsh.i3plus.pojo.aps.bean;

import cn.estsh.i3plus.pojo.aps.annotation.FieldAnnotation;
import cn.estsh.i3plus.pojo.aps.common.BaseCode;
import cn.estsh.i3plus.pojo.aps.common.BeanRelation;
import cn.estsh.i3plus.pojo.aps.enums.WORK_STATUS;
import cn.estsh.i3plus.pojo.aps.enums.WORK_TYPE;
import cn.estsh.i3plus.pojo.aps.holders.EWork;
import com.fasterxml.jackson.annotation.JsonBackReference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;

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
@Entity
@Table(name = "APS_WORK")
@Api("工作")
public class Work extends BaseCode {
    @Column(name="WORK_TYPE")
    @ApiParam(value ="工作类型")
    private WORK_TYPE workType;

    @Column(name="count")
    @ApiParam(value ="数量")
    private Double count;

    @Column(name="SPECIFY_COUNT")
    @ApiParam(value ="指定数量")
    private Double specifyCount;

    @Column(name="SPECIFY_RESOURCE")
    @ApiParam(value ="指定资源")
    private String specifyResource;

    @Column(name="SPECIFY_MANUF_TIME")
    @ApiParam(value ="指定制造时间")
    private String specifyManufTime;

    @Column(name="SPECIFY_PREV_TIME")
    @ApiParam(value ="指定前设置时间")
    private String specifyPrevTime;

    @Column(name="SPECIFY_POST_TIME")
    @ApiParam(value ="指定后设置时间")
    private String specifyPostTime;

    @Column(name="SPECIFY_EST")
    @ApiParam(value ="指定最早开始时间")
    private Date specifyEst;

    @Column(name="SPECIFY_LET")
    @ApiParam(value ="指定最晚结束时间")
    private Date specifyLet;

    @Column(name="SPECIFY_BEGIN")
    @ApiParam(value ="指定开始时间")
    private Date specifyBegin;

    @Column(name="SPECIFY_END")
    @ApiParam(value ="指定结束时间")
    private Date specifyEnd;

    @Column(name="CALC_EST")
    @ApiParam(value ="最早开始时间计算值")
    private Date calcEst;

    @Column(name="CALC_LET")
    @ApiParam(value ="最晚结束时间计算值")
    private Date calcLet;

    @Column(name="WORK_STATUS")
    @ApiParam(value ="工作状态")
    private WORK_STATUS workStatus;

    @Column(name="PLAN_BEGIN")
    @ApiParam(value ="计划开始时间")
    private Date planBegin;

    @Column(name="PLAN_END")
    @ApiParam(value ="计划结束时间")
    private Date planEnd;

    @Column(name="PLAN_RESOURCE")
    @ApiParam(value ="计划主资源")
    private String planResource;

    @Column(name="FIX_SPLIT")
    @ApiParam(value ="已分割的工作是否重新分割")
    private Boolean fixSplit;

    @Column(name="NEED_PREV_COUNT")
    @ApiParam(value ="需要的前工作数量")
    private Double needPrevCount;

    @Column(name="SCH_FAILED")
    @ApiParam(value ="是否排程失败")
    private Boolean schFailed;

    @Column(name="FAILED_REASON")
    @ApiParam(value ="排程失败原因")
    private String failedReason;

    @Column(name="ORDER_ID")
    @ApiParam(value ="订单")
    @FieldAnnotation(property = false)
    private Long orderId;

    @Column(name="OPERATION_ID")
    @ApiParam(value ="工序")
    @FieldAnnotation(property = false)
    private Long operationId;

    @Column(name="PARENT_WORK_ID")
    @ApiParam(value ="父工作")
    @FieldAnnotation(property = false)
    private Long parentWorkId;

    public BaseOrder getOrder() {
        return BeanRelation.get(this, EWork.Order);
    }

    public void setOrder(BaseOrder order) {
        this.orderId = order != null ? order.getId() : 0l;
        BeanRelation.set(this, EWork.Order, order);
    }

    public Operation getOperation() {
        return BeanRelation.get(this, EWork.Operation);
    }

    public void setOperation(Operation oper) {
        this.operationId = oper != null ? oper.getId() : 0l;
        BeanRelation.set(this, EWork.Operation, oper);
    }

    public ParentWork getParentWork() {
        return BeanRelation.get(this, EWork.ParentWork);
    }

    public void setParentWork(ParentWork parentWork) {
        this.parentWorkId = parentWork != null ? parentWork.getId() : 0l;
        BeanRelation.set(this, EWork.ParentWork, parentWork);
    }

    @JsonBackReference
    public List<WorkResource> getWorkResources() {
        return BeanRelation.list(this, EWork.WorkResources);
    }

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

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

    @JsonBackReference
    public List<WorkRelation> getPrevRelations() {
        return BeanRelation.list(this, EWork.PrevRelations);
    }

    @JsonBackReference
    public List<WorkRelation> getPostRelations() {
        return BeanRelation.list(this, EWork.PostRelations);
    }

    @JsonBackReference
    public List<PlanFeedback> getPlanFeedbacks() {
        return BeanRelation.list(this, EWork.PlanFeedbacks);
    }
}
