/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.youchain.businessdata.domain;

import com.youchain.base.BaseEntity;
import com.youchain.basicdata.domain.Area;
import com.youchain.basicdata.domain.Item;
import com.youchain.basicdata.domain.Point;
import com.youchain.basicdata.domain.Stock;
import com.youchain.businessdata.domain.ItemKey;
import com.youchain.modules.system.domain.Dept;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;

/**
* @website https://eladmin.vip
* @description /
* @author houjianlan
* @date 2023-08-16
**/
@Entity
@Data
@Table(name="data_task")
public class Task  extends BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    @ApiModelProperty(value = "ID")
    private Long id;

    @OneToOne
    @JoinColumn(name = "`item_id`")
    @ApiModelProperty(value = "物料序号")
    private Item item;

    @OneToOne
    @JoinColumn(name = "`item_key_id`")
    @ApiModelProperty(value = "物料属性")
    private ItemKey itemKey;

    @Column(name = "`bill_code`")
    @ApiModelProperty(value = "单据号")
    private String billCode;

    @Column(name = "`task_type`")
    @ApiModelProperty(value = "任务类型")
    private String taskType;

    @OneToOne(cascade = CascadeType.PERSIST)
    @JoinColumn(name = "asn_detail_id")
    @ApiModelProperty(value = "收货明细序号")
    private AsnDetail asnDetail;

    @Column(name = "`move_detail_id`")
    @ApiModelProperty(value = "移位明细序号")
    private Long moveDetailId;

    @Column(name = "`wave_detail_id`")
    @ApiModelProperty(value = "波次明细序号")
    private Long waveDetailId;

    @OneToOne
    @JoinColumn(name = "pick_detail_id")
    @ApiModelProperty(value = "发货明细序号")
    private PickDetail pickDetail;

    @OneToOne
    @JoinColumn(name = "`src_stock_id`")
    @ApiModelProperty(value = "源容器")
    private Stock srcStock;

    @OneToOne
    @JoinColumn(name = "`dst_stock_id`")
    @ApiModelProperty(value = "目标容器")
    private Stock dstStock;

    @OneToOne
    @JoinColumn(name = "`src_point_id`")
    @ApiModelProperty(value = "源点位")
    private Point srcPoint;

    @OneToOne
    @JoinColumn(name = "`dst_point_id`")
    @ApiModelProperty(value = "目标点位")
    private Point dstPoint;

    @Column(name = "`src_stock_code`")
    @ApiModelProperty(value = "源容器编码")
    private String srcStockCode;

    @Column(name = "`dst_stock_code`")
    @ApiModelProperty(value = "目标容器编码")
    private String dstStockCode;

    @Column(name = "`src_point_code`")
    @ApiModelProperty(value = "源点位编码")
    private String srcPointCode;

    @Column(name = "`dst_point_code`")
    @ApiModelProperty(value = "目标点位编码")
    private String dstPointCode;

    @Column(name = "`inv_status`")
    @ApiModelProperty(value = "库存状态")
    private String invStatus;

    @Column(name = "`task_status`")
    @ApiModelProperty(value = "任务状态")
    private String taskStatus;

    @Column(name = "`be_skip`")
    @ApiModelProperty(value = "跳过")
    private Integer beSkip=0;

    @Column(name = "`be_back`")
    @ApiModelProperty(value = "退回")
    private Boolean beBack=false;

    @Column(name = "`plan_qty`")
    @ApiModelProperty(value = "计划数量")
    private Double planQty=0d;

    @Column(name = "`move_qty`")
    @ApiModelProperty(value = "移位数量")
    private Double moveQty=0d;

    @Column(name = "`put_code`")
    @ApiModelProperty(value = "上架号")
    private String putCode;

    @Column(name = "`inv_id`")
    @ApiModelProperty(value = "库存ID")
    private Long invId;

    @OneToOne
    @JoinColumn(name = "dept_id")
    @ApiModelProperty(value = "仓库ID")
    private Dept dept;

    @OneToOne
    @JoinColumn(name = "`area_id`")
    @ApiModelProperty(value = "库区")
    private Area area;

    @OneToOne
    @JoinColumn(name = "`zzkw`")
    @ApiModelProperty(value = "制造库位")
    private Point zzkw;

    @OneToOne
    @JoinColumn(name = "agv_task_id")
    @ApiModelProperty(value = "AGV任务")
    private AgvTask agvTask;

    public void copy(Task source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }

    /**
     *
     * @param item-物料
     * @param itemKey-物料属性
     * @param billCode-单据编号
     * @param taskType-任务类型
     * @param asnDetail-入库明细
     * @param moveDetailId-移位明细ID
     * @param waveDetailId-波次明细ID
     * @param pickDetail-出库明细
     * @param srcStock-原容器
     * @param dstStock-目标容器
     * @param srcPoint-原点位
     * @param dstPoint-目标点位
     * @param srcStockCode-原容器编号
     * @param dstStockCode-目标容器编号
     * @param srcPointCode-原点位
     * @param dstPointCode-目标点位
     * @param invStatus-库存状态
     * @param taskStatus-任务状态
     * @param planQty-计划数量
     * @param putCode-上架号
     * @param invId-库存ID
     * @param dept-仓库
     */
    public Task(Item item, ItemKey itemKey, String billCode, String taskType, AsnDetail asnDetail, Long moveDetailId, Long waveDetailId, PickDetail pickDetail, Stock srcStock, Stock dstStock, Point srcPoint, Point dstPoint, String srcStockCode, String dstStockCode, String srcPointCode, String dstPointCode, String invStatus, String taskStatus, Double planQty, String putCode, Long invId, Dept dept) {
        this.item = item;
        this.itemKey = itemKey;
        this.billCode = billCode;
        this.taskType = taskType;
        this.asnDetail = asnDetail;
        this.moveDetailId = moveDetailId;
        this.waveDetailId = waveDetailId;
        this.pickDetail = pickDetail;
        this.srcStock = srcStock;
        this.dstStock = dstStock;
        this.srcPoint = srcPoint;
        this.dstPoint = dstPoint;
        this.srcStockCode = srcStockCode;
        this.dstStockCode = dstStockCode;
        this.srcPointCode = srcPointCode;
        this.dstPointCode = dstPointCode;
        this.invStatus = invStatus;
        this.taskStatus = taskStatus;
        this.planQty = planQty;
        this.putCode = putCode;
        this.invId = invId;
        this.dept = dept;
        this.dept = dept;
    }

    public  Task(){

    }
}
