/*
*  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.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 javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;

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

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

    @Column(name = "`log_type`",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "操作类型")
    private String logType;

    @Column(name = "`inc_dec`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "增加/减少")
    private String incDec;

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

    @OneToOne
    @JoinColumn(name = "`item_key_id`")
    @ApiModelProperty(value = "点位")
    private ItemKey itemKey;

    @Column(name = "`storage_date`")
    @ApiModelProperty(value = "存货日期")
    private Timestamp storageDate;

    @Column(name = "`soi`")
    @ApiModelProperty(value = "入库单号")
    private String soi;

    @Column(name = "`occur_quantity`")
    @ApiModelProperty(value = "发生数量")
    private Double occurQuantity;

    @Column(name = "`occur_time`")
    @ApiModelProperty(value = "发生时间")
    private Timestamp occurTime;

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

    @Column(name = "`ref_obj`")
    @ApiModelProperty(value = "引用对象")
    private String refObj;

    @Column(name = "`ref_obj_id`")
    @ApiModelProperty(value = "引用ID")
    private Long refObjId;

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

    @Column(name = "`description`")
    @ApiModelProperty(value = "描述")
    private String description;

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

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

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

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

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

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

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

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

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

    @Column(name = "`src_qty`")
    @ApiModelProperty(value = "源数量")
    private Double srcQty=0d;

    @Column(name = "`dst_qty`")
    @ApiModelProperty(value = "目标数量")
    private Double dstQty=0d;

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

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

    @OneToOne
    @JoinColumn(name = "`zckw`")
    @ApiModelProperty(value = "暂存库位")
    private Point zckw;

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