package com.sw.mes.yb.seed.entity;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 籽晶原料需求任务表
 */
@Data
@Entity
@Table(name = "seed_require_task")
@DynamicUpdate
@DynamicInsert
public class SeedRequireTask {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 任务编码
     */
    @Column
    private String code;
    /**
     * 规则ID
     */
    @Column
    private Long seedRuleId;

    /**
     * 规则名称
     */
    @Column
    private String seedRuleName;

    /**
     * 需求数量
     */
    @Column
    private BigDecimal requireCount;

    /**
     * 需求长度
     */
    @Column
    private BigDecimal requireLength;

    /**
     * 已分配数量
     */
    @Column
    private BigDecimal allocatedQuantity;
    /**
     * 未分配数量
     */
    @Column
    private BigDecimal noAllocatedQuantity;
    /**
     * 逻辑删除，1：删除，0：未删除
     */
    @Column
    private boolean del;

    /**
     * 关联工单号
     */
    @Column
    private String planOrderNo;

    /**
     * 创建人
     */
    @Column
    private String createUser;

    /**
     * 修改人
     */
    @Column
    private String updateUser;

    /**
     * 创建日期
     */
    @Column
    private Date createTime;

    /**
     * 更新时间
     */
    @Column
    private Date updateTime;
    /**
     * 结束时间
     */
    @Column
    private Date endTime;
    public void setDel(BigDecimal requireCount,BigDecimal allocatedQuantity){
        BigDecimal subtract = requireCount.subtract(allocatedQuantity);
        if(subtract.compareTo(new BigDecimal(0)) == 0){
            this.del = true;
        }else {
            this.del = false;
        }
    }

    public void setNoAllocatedQuantity(BigDecimal requireCount,BigDecimal allocatedQuantity){
        if(requireCount.compareTo(allocatedQuantity)==1){
            BigDecimal subtract = requireCount.subtract(allocatedQuantity);
            this.noAllocatedQuantity = subtract;
        }
    }

}
