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

import cn.estsh.i3plus.pojo.aps.annotation.FieldAnnotation;
import cn.estsh.i3plus.pojo.aps.annotation.RippleAnnotation;
import cn.estsh.i3plus.pojo.aps.common.BaseAPS;
import cn.estsh.i3plus.pojo.aps.common.BeanRelation;
import cn.estsh.i3plus.pojo.aps.holders.EWorkPlan;
import cn.estsh.i3plus.pojo.base.enumutil.ApsEnumUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Date;
import java.util.List;

/**
 * @Description :工作计划
 * @Reference :
 * @Author : jason.niu
 * @CreateDate : 2019-10-17
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name="APS_WORK_PLAN")
@Api("工作计划")
public class WorkPlan extends BaseAPS {

    private static final long serialVersionUID = 5489548115780676195L;
    @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="TYPE")
    @ApiParam(value ="工作计划类型")
    @FieldAnnotation(modify = false, display = false)
    private ApsEnumUtil.WORK_PLAN_TYPE type;

    @Column(name="PREV_SET_BEGIN")
    @ApiParam(value ="前设置开始时间")
    @FieldAnnotation(modify = false)
    private Date prevSetBegin;

    @Column(name="PREV_SET_END")
    @ApiParam(value ="前设置结束时间")
    @FieldAnnotation(modify = false)
    private Date prevSetEnd;

    @Column(name="PREV_SET_TIME")
    @ApiParam(value ="前设置时间")
    @FieldAnnotation(modify = false, editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private Integer prevSetTime;

    @Column(name="PRODUCE_BEGIN")
    @ApiParam(value ="生产开始时间")
    @FieldAnnotation(modify = false)
    @RippleAnnotation(dependence = {"MainWork.PrevRelations.PrevWork.MainPlan.produceBegin",
        "PrevPlan.produceBegin"}, method = "calcPositive")
    private Date produceBegin;

    @Column(name="PRODUCE_END")
    @ApiParam(value ="生产结束时间")
    @FieldAnnotation(modify = false)
    private Date produceEnd;

    @Column(name="PRODUCE_TIME")
    @ApiParam(value ="生产时间")
    @FieldAnnotation(modify = false, editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private Integer produceTime;

    @Column(name="POST_SET_BEGIN")
    @ApiParam(value ="后设置开始时间")
    @FieldAnnotation(modify = false)
    private Date postSetBegin;

    @Column(name="POST_SET_END")
    @ApiParam(value ="后设置结束时间")
    @FieldAnnotation(modify = false)
    private Date postSetEnd;

    @Column(name="POST_SET_TIME")
    @ApiParam(value ="后设置时间")
    @FieldAnnotation(modify = false, editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private Integer postSetTime;

    @Column(name="LOCK_BEGIN")
    @ApiParam(value ="锁定开始时间")
    @FieldAnnotation(modify = false)
    @RippleAnnotation(dependence = {"MainWork.PostRelations.PostWork.MainPlan.produceBegin", "produceBegin"}, method = "calcPositiveLock")
    private Date lockBegin;

    @Column(name="LOCK_END")
    @ApiParam(value ="锁定结束时间")
    @FieldAnnotation(modify = false)
    private Date lockEnd;

    @Column(name="LOCK_TIME")
    @ApiParam(value ="锁定时间")
    @FieldAnnotation(modify = false, editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private Integer lockTime;

    @Column(name="FORCE_POST_SET_ZERO")
    @ApiParam(value ="是否将后设置时间强制设置成0")
    @FieldAnnotation(property = false)
    private Boolean forcePostSetZero;

    @Column(name="WORK_RESOURCE_ID")
    @ApiParam(value ="工作资源对象id")
    @FieldAnnotation(property = false)
    private Long workResourceId;

    @Column(name="FURNACE_PLAN_ID")
    @ApiParam(value ="炉资源计划对象id")
    @FieldAnnotation(property = false)
    private Long furnacePlanId;

    @Transient
    private boolean hasCominbed = false;

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

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

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

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

    public WorkResource getWorkResource() { return BeanRelation.get(this, EWorkPlan.WorkResource); }

    public void setWorkResource(WorkResource workResource) {
        this.workResourceId = workResource != null ? workResource.getId() : 0l;
        BeanRelation.set(this, EWorkPlan.WorkResource, workResource);
    }

    public FurnacePlan getFurnacePlan() { return BeanRelation.get(this, EWorkPlan.FurnacePlan); }

    public void setFurnacePlan(FurnacePlan plan) {
        this.furnacePlanId = plan != null ? plan.getId() : 0;
        BeanRelation.set(this, EWorkPlan.FurnacePlan, plan);
    }

    public Work getMainWork() {
        return BeanRelation.get(this, EWorkPlan.MainWork);
    }

    public void setMainWork(Work work) {

    }
}
