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

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.annotation.DynamicField;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.WmsEnumUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List;

/**
 * @Description :移库单实体(用于转储类业务)
 * @Reference :
 * @Author : dragon.xu
 * @CreateDate : 2018-11-13 16:06
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "WMS_DOC_MOVEMENT_MASTER", indexes = {
        @Index(columnList = "ORDER_NO"),
        @Index(columnList = "REF_NO"),
        @Index(columnList = "ERP_SRC_NO"),
        @Index(columnList = "BUSI_TYPE"),
        @Index(columnList = "ORGANIZE_CODE")
})
@Api("移库单表")
@ToString
public class WmsDocMovementMaster extends BaseBean {
    private static final long serialVersionUID = -4459803926536024325L;
    @Column(name = "ORDER_NO")
    @ApiParam(value = "移库单单号")
    private String orderNo;
    /**e
     * 移动类型:IN=入库,OUT=出库,MOVE=移库
     */
    @Column(name = "MOVE_TYPE")
    @ApiParam("移动类型")
    @AnnoOutputColumn(refClass = WmsEnumUtil.OUT_MOVEMENT_MOVE_TYPE.class, refForeignKey = "value", value = "description")
    public Integer moveType;
    /**
     * 业务类型:RC=收货,QC=质检,IN=入库,ZI=杂收,ZO=杂发,
     * VJ=供应商退货,CJ=客户退货,WP=工单领料,WJ=工单退料,
     * MI=移库入库,MO=移库出库,SO=发运
     */
    @Column(name = "BUSI_TYPE")
    @ApiParam("业务类型")
    @AnnoOutputColumn(refClass = WmsEnumUtil.OUT_MOVEMENT_BUSI_TYPE.class, refForeignKey = "value", value = "description")
    public Integer busiType;

    /**
     * 状态:0=新建,10=处理中
     * ,20=已完成,90=已关闭,91=已取消
     */
    @Column(name = "ORDER_STATUS")
    @ApiParam(value = "状态", example = "1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.MASTER_ORDER_STATUS.class, refForeignKey = "value", value = "description")
    public Integer orderStatus;

    @Column(name = "CUST_NO")
    @ApiParam(value = "客户编号")
    private String custNo;

    @Column(name = "VENDOR_NO")
    @ApiParam(value = "供应商编号")
    private String vendorNo;

    @Column(name = "VERSION")
    @ApiParam(value = "版本", example = "1")
    private Integer version;

    /**
     * 关联单据类型:1=ASN,10=PO,20=SO
     */
    @Column(name = "REF_TYPE")
    @ApiParam(value = "关联单据类型")
    private String refType;

    @Column(name = "REF_NO")
    @ApiParam(value = "关联单据")
    private String refNo;

    @Column(name = "ERP_SRC_NO")
    @ApiParam(value = "ERP单号")
    private String erpSrcNo;

    @Column(name = "IS_TASK")
    @ApiParam(value = "是否生产任务", example = "1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.IS_GENERAL_TASK.class, refForeignKey = "value", value = "description")
    public Integer isTask;

    @Column(name = "PRIORITY")
    @AnnoOutputColumn(refClass = WmsEnumUtil.PRIORITY.class, refForeignKey = "value", value = "description")
    @ApiParam(value = "优先级", example = "1")
    public Integer priority;

    @Column(name = "CAR_NO")
    @ApiParam(value = "车牌号")
    private String carNo;

    @Column(name = "DRIVER_NO")
    @ApiParam("司机")
    public String driverNo;

    @Column(name = "TMS_CAR_NO")
    @ApiParam(value = "TMS车牌号")
    private String tmsCarNo;

    @Column(name = "TMS_DRIVER_NO")
    @ApiParam("TMS司机")
    public String tmsDriverNo;

    @Column(name = "CUST_ORDER_NO")
    @ApiParam(value = "客户单号")
    private String custOrderNo;

    @Column(name = "REMARK")
    @ApiParam("备注")
    private String remark;


    @Transient
    private List<WmsDocMovementDetails> movementDetailsList;

    @Transient
    @ApiParam(value = "源库存地代码")
    private String srcAreaNo;

    @Transient
    @ApiParam(value = "目的库存地代码")
    private String desrAreaNo;

    @Column(name = "IS_PART")
    @ApiParam(value = "是否散件", example = "1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.TRUE_OR_FALSE.class, refForeignKey = "value", value = "description")
    private Integer isPart;

    @Column(name = "PRINT_STATUS")
    @ApiParam("打印状态")
    @AnnoOutputColumn(refClass = WmsEnumUtil.PRINT_STATUS.class, refForeignKey = "value", value = "description")
    private Integer printStatus;

    @Column(name = "SRC_WH_NO")
    @ApiParam("源仓库代码")
    public String assignSrcWhNo;

    @Column(name = "SRC_ZONE_NO")
    @ApiParam("源存储区代码")
    public String assignSrcZoneNo;

    @Column(name = "DEST_WH_NO")
    @ApiParam("目标仓库代码")
    public String assignDestWhNo;

    @Column(name = "DEST_ZONE_NO")
    @ApiParam("目标存储区代码")
    public String assignDestZoneNo;

    @Column(name = "PLAN_DATE")
    @ApiParam(value = "计划日期")
    private String assignPlanDate;

    @Column(name = "FLAG_NO")
    @ApiParam(value = "客户发往地编号")
    private String flagNo;

    @Column(name = "PLAN_TIME")
    @ApiParam(value = "计划时间")
    private String assignPlanTime;

    @Column(name = "TAG")
    @ApiParam(value = "标签")
    private String tag;

    @Column(name = "IS_SINGLE_STEP")
    @ApiParam(value = "一步法/两步法")
    @AnnoOutputColumn(refClass = WmsEnumUtil.STEP.class, refForeignKey = "value", value = "description")
    private Integer isSingleStep;

    @Column(name = "ERP_SRC_TYPE",columnDefinition = "varchar(50) default ''")
    @ApiParam(value = "QAD发运单据类型")
    private String erpSrcType;

    @ApiParam("是否正常运输")
    @Column(name = "IS_NORMAL_TRANSPORTATION")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "TRUE_OR_FALSE")
    @AnnoOutputColumn(refClass = WmsEnumUtil.TRUE_OR_FALSE.class)
    private Integer isNormalTransportation;

    @Column(name = "TRANSPORT_TYPE")
    @ApiParam(value = "运输方式")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "TRANSPORT_TYPE")
    @AnnoOutputColumn(refClass = WmsEnumUtil.TRANSPORT_TYPE.class)
    private Integer transportType;

    @Column(name = "LOGISTICS_VENDOR_NO")
    @ApiParam("物流供应商")
    private String logisticsVendorNo;

    //正常运输 和非正常运输
    @Column(name = "BUSINESS_TYPE")
    @ApiParam(value = "运输方式")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "NORMAL_ABNORMAL")
    @AnnoOutputColumn(refClass = WmsEnumUtil.NORMAL_ABNORMAL.class)
    private Integer businessType;

    @Column(name = "IS_TRANSPORTATION_CREATION")
    @ApiParam(value = "运输信息创建")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "TRUE_OR_FALSE")
    @AnnoOutputColumn(refClass = WmsEnumUtil.TRUE_OR_FALSE.class)
    private Integer isTransportationCreation;

    @Column(name = "IS_GOOD_PRODUCT")
    @ApiParam(value = "是否良品")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, dataSrc = "TRUE_OR_FALSE")
    @AnnoOutputColumn(refClass = WmsEnumUtil.TRUE_OR_FALSE.class)
    private Integer isGoodProduct;

    @Column(name = "COST_CENTER")
    @ApiParam(value = "成本中心")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.URL,
            isRequire = 2, dataSrc = "/wms/wms-enum/dictionary/code?code=DOC_COST_CENTER", listColumnName = "name", explicitColumnName = "dictionaryValue")
    private String costCenter;

    @Column(name = "REMAKE")
    @ApiParam(value = "备注1")
    private String remake;


    /**
     * 10=未生成，20=生成成功，30=生成失败
     */
    @Column(name = "PICKING_ORDER_STATUS", columnDefinition = "int default 10")
    @ApiParam(value = "领料单生成状态", example = "1")
    @AnnoOutputColumn(refClass = WmsEnumUtil.PICKING_MASTER_ORDER_STATUS.class, refForeignKey = "value", value = "description")
    public Integer pickingOrderStatus;

    /**
     * 备注2
     **/
    @Column(name = "SECONDARY_REMAKE")
    @ApiParam(value = "单据原因")
    private String secondaryRemake;

    /**备注3**/
    @Column(name = "THIRD_REMAKE")
    @ApiParam(value = "财务类型")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.URL,
            isRequire = 2, dataSrc = "/wms/wms-enum/dictionary/code?code=DOC_MOVEMENT_REMARK_PERSON", listColumnName = "name", explicitColumnName = "dictionaryValue")
    private String thirdRemake;

    @Column(name = "FOURTH_REMAKE")
    @ApiParam(value = "备注4")
    @DynamicField(webFieldType = CommonEnumUtil.FIELD_TYPE.SELECT, getValWay = CommonEnumUtil.DYNAMIC_FIELD_GET_WAY.URL,
            isRequire = 2, dataSrc = "/wms/wms-enum/dictionary/code?code=DOC_MOVEMENT_DEPARTMENT_REMARK", listColumnName = "name", explicitColumnName = "dictionaryValue")
    private String fourthRemake;

    @Transient
    @ApiParam(value = "发运单号")
    private String shipOrderNo;

    @Transient
    @ApiParam(value = "打印时间")
    private String printDate;

    @Transient
    @ApiParam("类型名称")
    public String busiTypeName;

    @Transient
    @ApiParam("物料编号")
    public String partNo;

    @Transient
    @ApiParam(value = "标题")
    public String title;

    @Transient
    @ApiParam(value = "生产小组")
    private String productionGroup;

    @Transient
    @ApiParam(value = "父位置号")
    private String seqNo;

    @Transient
    @ApiParam("物料编号组")
    public String[] partNos;

    @Transient
    @ApiParam("工厂集合")
    private List<String> organizeCodeList;

    @Transient
    @ApiParam("物料名称")
    public String partNameRdd;

    @Transient
    @ApiParam(value = "简称")
    private String partSpec;

    @Transient
    @ApiParam(value = "工单码")
    private String workOrderCode;

    @Transient
    @ApiParam(value = "需求数量", example = "0")
    public Double qty;

    @Transient
    @ApiParam(value = "客户简称")
    private String custName;

    @Transient
    @ApiParam(value = "客户全称")
    private String custDesc;

    @Transient
    @ApiParam(value = "客户地址")
    private String custAddr;

    @Transient
    @ApiParam(value = "联系人")
    private String custOwner;

    @Transient
    @ApiParam(value = "电话号码")
    private String custTel;

    @Transient
    @ApiParam(value = "过滤业务类型")
    private String filterBusiType;

    @Transient
    @ApiParam("源存储区代码")
    public String srcZoneNo;

    @Transient
    @ApiParam("目标库位代码")
    public String destLocateNo;

    @Transient
    @ApiParam("查询状态集合")
    public List<Integer> orderStatusList;

    public int getOrderStatusVal() {
        return this.orderStatus == null ? 0 : this.orderStatus;
    }

    public int getBusiTypeVal() {
        return this.busiType == null ? 0 : this.busiType;
    }

    public WmsDocMovementMaster(WmsPOMaster wmsPoMaster) {
        this.orderNo = wmsPoMaster.getOrderNo();
        this.vendorNo = wmsPoMaster.getVendorNo();
    }

    public WmsDocMovementMaster() {
    }
    public WmsDocMovementMaster(WmsDocMovementMaster wmsDocMovementMaster,String seqNo,String assignSrcZoneNo,String partNo,String partNameRdd,
                                String partSpec,String workOrderCode,Double qty,String productionGroup,Integer busiType,String modifyDatetime,
                                String custName,String custDesc,String custAddr,String custOwner,String custTel) {

        this.id = wmsDocMovementMaster.getId();
        this.orderNo = wmsDocMovementMaster.getOrderNo();
        this.custNo = wmsDocMovementMaster.getCustNo();
        this.organizeCode = wmsDocMovementMaster.getOrganizeCode();
        this.orderStatus = wmsDocMovementMaster.getOrderStatus();
        this.vendorNo = wmsDocMovementMaster.getVendorNo();
        this.erpSrcNo = wmsDocMovementMaster.getErpSrcNo();
        this.seqNo = seqNo;
        this.assignSrcZoneNo = assignSrcZoneNo;
        this.partNo = partNo;
        this.partNameRdd = partNameRdd;
        this.partSpec = partSpec;
        this.workOrderCode = workOrderCode;
        this.qty = qty;
        this.productionGroup = productionGroup;
        this.busiType = busiType;
        this.modifyDatetime = modifyDatetime;
//        this.color = color;
        this.custName = custName;
        this.custDesc = custDesc;
        this.custAddr = custAddr;
        this.custOwner = custOwner;
        this.custTel = custTel;
    }
}
