/*
 *  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.Item;
import com.youchain.basicdata.service.dto.ItemDto;
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;

/**
 * @author huojin
 * @website https://eladmin.vip
 * @description /
 * @date 2024-04-10
 **/
@Entity
@Data
@Table(name = "data_mo")
public class Mo extends BaseEntity implements Serializable {

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

    @Column(name = "`label_no`", unique = true)
    @ApiModelProperty(value = "MO票")
    private String labelNo;

    @Column(name = "`label_type`")
    @ApiModelProperty(value = "标签类型")
    private String labelType;

    @Column(name = "`label_state`")
    @ApiModelProperty(value = "标签状态")
    private String labelState;

    @Column(name = "`delivery_header_id`")
    @ApiModelProperty(value = "送货单头ID；通过该字段能找到002接口送货单")
    private Integer deliveryHeaderId;

    @Column(name = "`source_system`")
    @ApiModelProperty(value = "来源系统")
    private String sourceSystem;

    @Column(name = "`qty`")
    @ApiModelProperty(value = "可用数量")
    private Double qty;

    @Column(name = "`work_order_id`")
    @ApiModelProperty(value = "工单Id")
    private Integer workOrderId;

    @Column(name = "`work_order_name`")
    @ApiModelProperty(value = "工单编号")
    private String workOrderName;

    @Column(name = "`self_work_order_id`")
    @ApiModelProperty(value = "自制件工单id")
    private Integer selfWorkOrderId;

    @Column(name = "`self_work_order_name`")
    @ApiModelProperty(value = "自制件工单编号")
    private String selfWorkOrderName;

    @Column(name = "`order_no`")
    @ApiModelProperty(value = "工单号")
    private String orderNo;


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

    @Column(name = "`check_result`")
    @ApiModelProperty(value = "检验状态")
    private String checkResult;

    @Column(name = "`delete_flag`")
    @ApiModelProperty(value = "数据有效性")
    private Boolean deleteFlag;

    @Column(name = "`workshop_code`")
    @ApiModelProperty(value = "车间编号")
    private String workshopCode;

    @Column(name = "`workshop_name`")
    @ApiModelProperty(value = "车间描述")
    private String workshopName;

    @Column(name = "`mo_line_code`")
    @ApiModelProperty(value = "产线编码")
    private String moLineCode;

    @Column(name = "`mo_line_name`")
    @ApiModelProperty(value = "产线描述")
    private String moLineName;

    @Column(name = "`inv_code`")
    @ApiModelProperty(value = "MLS子库")
    private String invCode;

    @Column(name = "`goods_area_code`")
    @ApiModelProperty(value = "MLS货区")
    private String goodsAreaCode;

    @Column(name = "`goods_location_code`")
    @ApiModelProperty(value = "MLS货位")
    private String goodsLocationCode;

    @Column(name = "`datetime_stock_in`")
    @ApiModelProperty(value = "MLS入库时间")
    private Timestamp datetimeStockIn;

    @Column(name = "`mls_create_time`")
    @ApiModelProperty(value = "MLS创建时间")
    private Timestamp mlsCreateTime;

    @Column(name = "`mls_update_time`")
    @ApiModelProperty(value = "MLS修改时间")
    private Timestamp mlsUpdateTime;

    @Column(name = "`create_user_code`")
    @ApiModelProperty(value = "MLS创建人")
    private String createUserCode;

    @Column(name = "`update_user_code`")
    @ApiModelProperty(value = "MLS修改人")
    private String updateUserCode;


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

    public Mo(){

    }

    public Mo(String labelNo, String labelType, String labelState, Integer deliveryHeaderId, String sourceSystem, Double qty, Integer workOrderId, String workOrderName, Integer selfWorkOrderId, String selfWorkOrderName, String orderNo, Item item, String checkResult, Boolean deleteFlag, String workshopCode, String workshopName, String moLineCode, String moLineName, String invCode, String goodsAreaCode, String goodsLocationCode, Timestamp datetimeStockIn, Timestamp mlsCreateTime, Timestamp mlsUpdateTime, String createUserCode, String updateUserCode) {
        this.labelNo = labelNo;
        this.labelType = labelType;
        this.labelState = labelState;
        this.deliveryHeaderId = deliveryHeaderId;
        this.sourceSystem = sourceSystem;
        this.qty = qty;
        this.workOrderId = workOrderId;
        this.workOrderName = workOrderName;
        this.selfWorkOrderId = selfWorkOrderId;
        this.selfWorkOrderName = selfWorkOrderName;
        this.orderNo = orderNo;
        this.item = item;
        this.checkResult = checkResult;
        this.deleteFlag = deleteFlag;
        this.workshopCode = workshopCode;
        this.workshopName = workshopName;
        this.moLineCode = moLineCode;
        this.moLineName = moLineName;
        this.invCode = invCode;
        this.goodsAreaCode = goodsAreaCode;
        this.goodsLocationCode = goodsLocationCode;
        this.datetimeStockIn = datetimeStockIn;
        this.mlsCreateTime = mlsCreateTime;
        this.mlsUpdateTime = mlsUpdateTime;
        this.createUserCode = createUserCode;
        this.updateUserCode = updateUserCode;
    }
}
