/*
 *  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.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 org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.sql.Timestamp;
import java.io.Serializable;

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

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

    @Column(name = "`pick_id`")
    @ApiModelProperty(value = "指示单生成订单序号")
    private Long pickId;

    @OneToOne
    @JoinColumn(name = "`item_id`", nullable = false)
    @NotNull
    @ApiModelProperty(value = "物料")
    private Item item;

    @Column(name = "`line_no`")
    @ApiModelProperty(value = "行号")
    private Long lineNo;

    @Column(name = "`po`")
    @ApiModelProperty(value = "po订单号")
    private String po;

    @Column(name = "`status`")
    @ApiModelProperty(value = "状态")
    private String status;

    @Column(name = "`order_qty`")
    @ApiModelProperty(value = "订单数量")
    private Double orderQty = 0d;

    @Column(name = "`allocated_qty`")
    @ApiModelProperty(value = "分配数量")
    private Double allocatedQty = 0d;

    @Column(name = "`picked_qty`")
    @ApiModelProperty(value = "拣货数量")
    private Double pickedQty = 0d;

    @Column(name = "`shipped_qty`")
    @ApiModelProperty(value = "发运数量")
    private Double shippedQty = 0d;

    @Column(name = "`weight`")
    @ApiModelProperty(value = "重量")
    private Double weight = 0d;

    @Column(name = "`volume`")
    @ApiModelProperty(value = "体积")
    private Double volume = 0d;

    @Column(name = "`remark`")
    @ApiModelProperty(value = "备注")
    private String remark;

    @Column(name = "`prop_c1`")
    @ApiModelProperty(value = "批次号")
    private String propC1;

    @Column(name = "`prop_c2`")
    @ApiModelProperty(value = "序列号")
    private String propC2;

    @Column(name = "`prop_c3`")
    @ApiModelProperty(value = "属性3")
    private String propC3;

    @Column(name = "`prop_c4`")
    @ApiModelProperty(value = "纯需求")
    private Double propC4=0d;

    @Column(name = "`prop_c5`")
    @ApiModelProperty(value = "属性5")
    private String propC5;

    @Column(name = "`prop_c6`")
    @ApiModelProperty(value = "属性6")
    private String propC6;

    @Column(name = "`prop_d1`")
    @ApiModelProperty(value = "生产日期")
    private Timestamp propD1;

    @Column(name = "`prop_d2`")
    @ApiModelProperty(value = "到期日期")
    private Timestamp propD2;

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

    @Column(name = "`source_name`")
    @ApiModelProperty(value = "来源名称,波次补料中的备货单号")
    private String sourceName;

    @Column(name = "`source_id`")
    @ApiModelProperty(value = "来源序号，波次补料中的明细ID")
    private Long sourceId;
    @OneToOne
    @JoinColumn(name = "`pick_ticket_id`")
    @NotFound(action= NotFoundAction.IGNORE)
    @ApiModelProperty(value = "出库管理主表")
    private PickTicket pickTicket;

    @OneToOne
    @JoinColumn(name = "`point_id`")
    @ApiModelProperty(value = "点位")
    private Point point;

    @Column(name = "`xq_qty`")
    @ApiModelProperty(value = "需求数量")
    private Double xqQty = 0d;

    @Column(name = "`pure_req_qty`")
    @ApiModelProperty(value = "纯需求数量,批次需求数取BOM")
    private Double pureReqQty = 0d;

    @Column(name = "`pure_xq_bz`")
    @ApiModelProperty(value = "纯需求不足")
    private Double pureXqBz = 0d;

    @Column(name = "`xb_qty`")
    @ApiModelProperty(value = "线边数量")
    private Double xbQty = 0d;

    @Column(name = "`y_stk_demand_qty`")
    @ApiModelProperty(value = "原备货需求数量")
    private Double yStkDemandQty = 0d;

    @Column(name = "`y_req_qty`")
    @ApiModelProperty(value = "原纯需求数")
    private Double yReqQty = 0d;

    @Column(name = "`contents`")
    @ApiModelProperty(value = "加工内容")
    private String contents ;

    @Column(name = "`ac`")
    @ApiModelProperty(value = "ac")
    private String ac ;

    @Column(name = "`supplier`")
    @ApiModelProperty(value = "供应商名")
    private String supplier;


    @Column(name = "`tl_qty`")
    @ApiModelProperty(value = "投料数量")
    private Double tlQty=0d;

    @Column(name = "`js_qty`")
    @ApiModelProperty(value = "接收数量")
    private Double jsQty=0d;

    @Column(name = "`bc_qty`")
    @ApiModelProperty(value = "波次补货数量")
    private Double bcQty=0d;

    @Column(name = "`bom_id`")
    @ApiModelProperty(value = "BOM序号")
    private Long bomId;

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

    @OneToOne
    @JoinColumn(name = "`sh_area_id`")
    @ApiModelProperty(value = "收货库区")
    private Area shArea;


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