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

import cn.estsh.i3plus.pojo.aps.annotation.ExcludeImportExport;
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.EParentWork;
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 : 2019-09-17
 * @Modify:
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "APS_PARENT_WORK")
@Api("父工作")
@ExcludeImportExport
public class ParentWork extends BaseAPS {
    private static final long serialVersionUID = 8792781216193806606L;
    @Column(name="count", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="数量")
    private Double count;

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

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

    public BaseOrder getProductOrder() {
        return BeanRelation.get(this, EParentWork.ProductOrder);
    }

    public void setProductOrder(ProductOrder order) {
        this.productOrderId = order != null ? order.getId() : 0l;
        BeanRelation.set(this, EParentWork.ProductOrder, order);
    }

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

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

    @JsonBackReference
    public List<Work> getWorks() {
        return BeanRelation.list(this, EParentWork.Works);
    }
}
