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

import cn.estsh.i3plus.pojo.aps.annotation.FieldAnnotation;
import cn.estsh.i3plus.pojo.aps.annotation.MainKey;
import cn.estsh.i3plus.pojo.aps.common.BaseAPS;
import cn.estsh.i3plus.pojo.aps.common.BeanRelation;
import cn.estsh.i3plus.pojo.aps.holders.EResource;
import cn.estsh.i3plus.pojo.aps.validator.InsertGroup;
import cn.estsh.i3plus.pojo.aps.validator.UpdateGroup;
import cn.estsh.i3plus.pojo.base.enumutil.ApsEnumUtil;
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 javax.persistence.Transient;
import java.util.List;

/**
 * @Description :资源
 * @Reference :
 * @Author : jason.niu
 * @CreateDate : 2019-09-17
 * @Modify:
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "APS_RESOURCE")
@Api("资源")
@MainKey(groups = {InsertGroup.class, UpdateGroup.class})
public class Resource extends BaseAPS {
    private static final long serialVersionUID = 3304084329600816457L;
    @Column(name="CODE")
    @ApiParam(value ="编码")
    @FieldAnnotation(popSearch = true, mainkey = true)
    private String code;

    @Column(name="NAME")
    @ApiParam(value ="名称")
    @FieldAnnotation(popSearch = true)
    private String name;

    @Column(name="TYPE")
    @ApiParam(value ="资源类型")
    @FieldAnnotation(defaultValue = "MAIN")
    private ApsEnumUtil.RESOURCE_TYPE type;

    @Column(name="RES_CLASS")
    @ApiParam(value ="资源区分")
    @FieldAnnotation(defaultValue = "SINGLE")
    private ApsEnumUtil.RESOURCE_CLASS resClass;

    @Column(name="EFFICIENCY", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="生产效率")
    @FieldAnnotation(defaultValue = "1.0", notEmpty = true)
    private Double efficiency;

    @Column(name="PREV_BUFFER")
    @ApiParam(value ="前缓冲时间")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String prevBuffer;

    @Column(name="POST_BUFFER")
    @ApiParam(value ="后缓冲时间")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String postBuffer;

    @Column(name="MAX_PRODUCE_BATCH", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="最大生产批量")
    private Double maxProduceBatch;

    @Column(name="TIME_TAIL_ADJUST")
    @ApiParam(value ="时间尾数圆整")
    private String timeTailAdjust;

    @Column(name="TIME_ADJUST")
    @ApiParam(value ="时间圆整")
    private String timeAdjust;

    @Column(name="MAX_PREV_SD_TIME")
    @ApiParam(value ="最大前设置中断时间")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String maxPrevSdTime;

    @Column(name="MAX_PRODUCE_SD_TIME")
    @ApiParam(value ="最大生产中断时间")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String maxProduceSdTime;

    @Column(name="MAX_POST_SD_TIME")
    @ApiParam(value ="最大后设置中断时间")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String maxPostSdTime;

    @Column(name="ROUND_TYPE")
    @ApiParam(value ="圆整类型")
    @FieldAnnotation(defaultValue = "ROUNDING")
    private ApsEnumUtil.TIME_ROUND_TYPE roundType;

    @Column(name="EFFICIENCY_EFFECT")
    @ApiParam(value ="效率影响类型")
    @FieldAnnotation(multiEnumClass = ApsEnumUtil.EFFICIENCY_EFFECT.class)
    private Integer EfficiencyEffect;

    @Column(name="TIME_ROUND")
    @ApiParam(value ="时间圆整影响")
    @FieldAnnotation(multiEnumClass = ApsEnumUtil.EFFICIENCY_EFFECT.class)
    private Integer timeRound;

    @Column(name="TIME_TAIL_ROUND")
    @ApiParam(value ="时间尾数影响")
    @FieldAnnotation(multiEnumClass = ApsEnumUtil.EFFICIENCY_EFFECT.class)
    private Integer timeTailRound;

    @Column(name="LOCK_TYPE")
    @ApiParam(value ="锁定类型")
    @FieldAnnotation(defaultValue = "NONE")
    private ApsEnumUtil.RESOURCE_LOCK_TYPE lockType;

    @Column(name="LOCK_TIME")
    @ApiParam(value ="锁定时间长度")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String lockTime;

    @ApiParam(value ="是否存在任务冲突")
    @FieldAnnotation(property = false)
    @Transient
    private boolean hasConflict;

    @JsonBackReference
    public List<WorkPlan> getWorkPlans() { return BeanRelation.list(this, EResource.WorkPlans); }
}
