package cn.iocoder.yudao.module.order.vo.order;

import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import java.math.BigDecimal;
import java.util.*;

import io.swagger.annotations.*;
import org.springframework.format.annotation.DateTimeFormat;

import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;

@Data
@ApiModel("管理后台 - 订单查询 VO")
public class OrderQueryVO {
    @ApiModelProperty(value = "OrderId列表，通过多个orderId查询订单时使用")
    private List<Long> orderIdList;

    @ApiModelProperty(value = "订单编号")
    private String orderNo;

    @ApiModelProperty(value = "快递单号")
    private String number;

    @ApiModelProperty(value = "反向搜索快递单号不包含的数据")
    private String notNumber;

    @ApiModelProperty(value = "提单编号")
    private String tidanNo;

    @ApiModelProperty(value = "父编号")
    private String parentNumber;

    /**
     * 父订单id
     */
    @ApiModelProperty(value = "父订单id")
    private Long parentOrderId;
    /**
     * 初始母订单id
     */
    @ApiModelProperty(value = "初始母订单id")
    private Long initialParentOrderId;

    @ApiModelProperty(value = "初始母订单编号")
    private String initialParentOrderNo;

    @ApiModelProperty(value = "旧编号")
    private String oldNumbers;

    @ApiModelProperty(value = "货柜自编号")
    private String containerNumber;

    @ApiModelProperty(value = "运输方式id")
    private Integer transportId;

    @ApiModelProperty(value = "线路ID")
    private Long lineId;

    @ApiModelProperty(value = "渠道ID")
    private Long channelId;

    @ApiModelProperty(value = "订单类型筛选条件：0 普通订单 1 集运服务 2 海外仓")
    private String type;

    @ApiModelProperty(value = "订单类型：1 普货 2 重货 3 泡货")
    private Integer orderType;

    @ApiModelProperty(value = "下单会员id")
    private Long userId;

    @ApiModelProperty(value = "客户经理ID")
    private Long salesmanId;

    @ApiModelProperty(value = "客户经理所属部门ID")
    private Long deptId;

    @ApiModelProperty(value = "客户经理所属部门ID集合")
    private List<Long> deptIdList;

    @ApiModelProperty(value = "唛头")
    private String marks;

    @ApiModelProperty(value = "产品备案属性：1有牌,2无牌,3中性,4混牌")
    private Integer productRecord;

    @ApiModelProperty(value = "是否控货")
    private Boolean isCargoControl;

    @ApiModelProperty(value = "0 控货中；1 已放完货；2 部分控货 3 放货中(此状态值为组合状态，当已放完货，但未全部复核完毕时为此状态，仅供查询条件传参使用)")
    private Integer cargoControlStatus;

    @ApiModelProperty(value = "报关类别：我司全代：1，自单代报：2，混合报关：3")
    private Integer customsType;

    @ApiModelProperty(value = "上传文件")
    private String upFile;

    @ApiModelProperty(value = "付款类型")
    private Integer payType;

    @ApiModelProperty(value = "订单状态详情见字典：order_status")
    private Integer status;

    @ApiModelProperty(value = "订单异常状态(字典 order_abnormal_state)")
    private Integer abnormalState;

    @ApiModelProperty(value = "订单入仓状态(字典 order_warehouse_in_status)")
    private Integer inWarehouseState;

    @ApiModelProperty(value = "订单出货状态(字典 order_shipment_state)")
    private Integer shipmentState;

    @ApiModelProperty(value = "上次订单主状态值")
    private Integer oldStatus;

    @ApiModelProperty(value = "上次订单入仓状态值")
    private Integer oldInWarehouseState;

    @ApiModelProperty(value = "上次订单出货状态值")
    private Integer oldShipmentState;

    @ApiModelProperty(value = "是否被删掉 1 删掉；0正常")
    private Boolean isDel;

    @ApiModelProperty(value = "代收金额")
    private BigDecimal collectionProxy;

    @ApiModelProperty(value = "代收货币ID")
    private Integer collectionProxyCurrency;

    @ApiModelProperty(value = "是否代收货款收款 0为否 1为是")
    private Boolean isCollection;

    @ApiModelProperty(value = "重货体积")
    private String wVolume;

    @ApiModelProperty(value = "泡货重量")
    private String vWeight;

    @ApiModelProperty(value = "重货标准基数")
    private BigDecimal weightUnit;

    @ApiModelProperty(value = "泡货标准基数")
    private BigDecimal volumeUnit;


    @ExcelProperty("原重货标准基数")
    @ApiModelProperty(value = "原重货标准基数")
    private BigDecimal orgWeightUnit;

    @ExcelProperty("原重货标准基数")
    @ApiModelProperty(value = "原泡货标准基数")
    private BigDecimal orgVolumeUnit;

    @ApiModelProperty(value = "计算使用的重货标准基数")
    private BigDecimal useWeightUnit;

    @ApiModelProperty(value = "计算使用的泡货标准基数")
    private BigDecimal useVolumeUnit;

    @ApiModelProperty(value = "入仓类型")
    private Integer warehouseType;

    @ApiModelProperty(value = "是否发送过入仓短信 已发送：1，未发送：0")
    private Boolean sendsms;

    @ApiModelProperty(value = "单证资料")
    private String documentsFile;

    @ApiModelProperty(value = "备注")
    private String remarks;

    @ApiModelProperty(value = "调仓始发仓")
    private Long adjustToStartWarehouseId;


    /**
     * 调仓目的仓
     */
    @ApiModelProperty(value = "调仓目的仓id")
    private Long adjustToDestWarehouseId;

    @ApiModelProperty(value = "入仓数量")
    private Integer sumQuantity;

    @ApiModelProperty(value = "入仓件数")
    private Integer sumNum;

    @ApiModelProperty(value = "入仓体积")
    private BigDecimal sumVolume;

    @ApiModelProperty(value = "入仓重量")
    private BigDecimal sumWeight;

    @ApiModelProperty(value = "重货比")
    private BigDecimal weightRatio;

    @ApiModelProperty(value = "发货人的客户id")
    private Long customerId;


    @ApiModelProperty(value = "客户详情页-客户id")
    private Long customerDetailId;

    @ApiModelProperty(value = "用户优惠劵ids")
    private String couponCustomerIds;

    @ApiModelProperty(value = "库域ID")
    private Long wareId;

    @ApiModelProperty(value = "始发仓ID串，eg: 1,2,3")
    private String pdaStartWareIds;
    @ApiModelProperty(value = "目的仓ID串，eg: 1,2,3")
    private String pdaDestWareIds;

    @ApiModelProperty(value = "库区ID")
    private Long areaId;

    @ApiModelProperty(value = "库位ID")
    private Long locationId;

    @ApiModelProperty(value = "仓位名称，多个用(,)号隔开")
    private String locationName;

    @ApiModelProperty(value = "航空公司id")
    private Long airlineCompany;

    @ApiModelProperty(value = "船公司id")
    private Long shippingCompany;

    @ApiModelProperty(value = "清关证书：0 否 1 是")
    private Boolean customsClearCert;

    @ApiModelProperty(value = "出单方式：1 电放 2 正本")
    private Integer issuingMethod;

    @ApiModelProperty(value = "是否拆包：0 否 1 是")
    private Boolean isUnpack;

    @ApiModelProperty(value = "是否单票立刻转运：0 否 1 是")
    private Boolean isSingleTicketTransport;

    @ApiModelProperty(value = "费用清单")
    private String cost;

    @ApiModelProperty(value = "付款人： 1 发货人 2 收货人 3 自定义")
    private Integer drawee;

    @ApiModelProperty(value = "自定义付款人信息")
    private String customDrawee;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始送货时间")
    private Date beginDeliveryDate;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束送货时间")
    private Date endDeliveryDate;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始入仓时间")
    private Date beginRucangTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束入仓时间")
    private Date endRucangTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始入仓记录时间")
    private Date beginWarehouseInTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束入仓记录时间")
    private Date endWarehouseInTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始到港时间")
    private Date beginDaogangTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束到港时间")
    private Date endDaogangTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始清关时间")
    private Date beginQingguanTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束清关时间")
    private Date endQingguanTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始已预装时间")
    private Date beginPreLoadTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束已预装时间")
    private Date endPreLoadTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始已装柜时间")
    private Date beginLoadTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始出仓时间")
    private Date beginOutboundTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束出仓时间")
    private Date endOutboundTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始理货时间")
    private Date beginTallyTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束理货时间")
    private Date endTallyTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始出货时间")
    private Date beginShippingTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束出货时间")
    private Date endShippingTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束已装柜时间")
    private Date endLoadTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始已卸柜时间")
    private Date beginUnloadTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束已卸柜时间")
    private Date endUnloadTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始提货时间")
    private Date beginTakeTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束提货时间")
    private Date endTakeTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始提货记录时间")
    private Date beginPickUpTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束提货记录时间")
    private Date endPickUpTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始拆单时间")
    private Date beginSplitTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束拆单时间")
    private Date endSplitTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始创建时间")
    private Date beginCreateTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束创建时间")
    private Date endCreateTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "开始放货时间")
    private Date beginPickTime;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "结束放货时间")
    private Date endPickTime;

    @ApiModelProperty(value = "包装类型ids")
    private String packageType;

    @ApiModelProperty(value = "包装备注")
    private String packageRemarks;

    @ApiModelProperty(value = "是否双清：1 客户自清 2 我司双清")
    private Integer doubleClear;

    @ApiModelProperty(value = "装箱单url")
    private String packingListUrl;

    @ApiModelProperty(value = "语言")
    private Integer lang;

    @ApiModelProperty(value = "始发地id")
    private Long departureId;

    @ApiModelProperty(value = "目的地id")
    private Long objectiveId;

    @ApiModelProperty(value = "始发仓ID")
    private Long startWarehouseId;

    @ApiModelProperty(value = "目的仓ID")
    private Long destWarehouseId;

    /**
     * 目的国
     */
    @ApiModelProperty(value = "目的国id")
    private Long destCountryId ;



    @ApiModelProperty(value = "发货客户ID")
    private Long consignorId;

    @ApiModelProperty(value = "发货客户联系人ID")
    private Long consignorContactsId;

    @ApiModelProperty(value = "发货客户联系人IDs")
    private Collection<Long> consignorContactsIds;

    @ApiModelProperty(value = "收货人手机号")
    private String consignorPhone;

    @ApiModelProperty(value = "收货客户id")
    private Long consigneeId;

    @ApiModelProperty(value = "收货客户联系人id")
    private Long consigneeContactsId;

    @ApiModelProperty(value = "收货客户联系人ids")
    private Collection<Long> consigneeContactsIds;

    @ApiModelProperty(value = "收货人手机号")
    private String consigneePhone;


    @ApiModelProperty(value = "控货人手机号")
    private String cargoControlPhone;

    @ApiModelProperty(value = "创建者", required = true)
    private String creator;

    @ApiModelProperty(value = "发货人姓名、手机号搜索")
    private String consignorKey;

    @ApiModelProperty(value = "发货人姓名、手机号反向搜索不包含的数据")
    private String notConsignorKey;

    @ApiModelProperty(value = "收货人姓名、手机号搜索")
    private String consigneeKey;

    @ApiModelProperty(value = "收货人姓名、手机号反向搜索不包含的数据")
    private String notConsigneeKey;

    @ApiModelProperty(value = "编号关键字搜索(包括订单号，麦头，收货人姓名电话)")
    private String searchKey;

    @ApiModelProperty(value = "编号搜索(包括订单号，麦头，提单号)")
    private String numberKey;

    @ApiModelProperty(value = "反向编号搜索(包括订单号，麦头，提单号)不包含的数据")
    private String notNumberKey;

    @ApiModelProperty(value = "编号搜索强等于(包括订单号，麦头，提单号)")
    private String eqNumberKey;

    @ApiModelProperty(value = "编号搜索强不等于(包括订单号，麦头，提单号)")
    private String notEqNumberKey;

    @ApiModelProperty(value = "商品搜索(商品类型、品名或品牌)")
    private String prodKey;

    @ApiModelProperty(value = "商品反向搜索(商品类型、品名或品牌)不包含的数据")
    private String notProdKey;

    @ApiModelProperty(value = "商品搜索强等于(商品类型、品名或品牌)")
    private String eqProdKey;

    @ApiModelProperty(value = "商品搜索强不等于(商品类型、品名或品牌)")
    private String notEqProdKey;

    @ApiModelProperty(value = "是否齐货")
    private Boolean isNeat;

    @ApiModelProperty(value = "审核类型(字典 order_approval_type) 0 为正常")
    private Integer auditType;

    @ApiModelProperty(value = "审核结果")
    private String auditResult;

    @ApiModelProperty(value = "是否外部仓")
    private Boolean isExternalWarehouse;

    @ApiModelProperty(value = "目的港清关：1 我司 2 客户")
    private Integer portDestCustomsClear;

    @ApiModelProperty(value = "发货方式：1 多票 2 单票")
    private Integer deliveryWay;

    @ApiModelProperty(value = "空运可出货状态：0 默认值 1 待出 2 可出 3 备货中 4 已备货 10 可出、备货中、已备货 11 待出、可出、备货中、已备货 12 可出、备货中")
    private Integer airShipment;

    /**
     * 端口 {@link }
     */
    @ApiModelProperty(value = "端口(默认管理端)")
    private Integer userType = 2;

    @ApiModelProperty(value = "是否显示关联订单状态")
    private Boolean isDisplayGuanlianStatus = false;

    @ApiModelProperty(value = "内部转换状态字段")
    private Integer asStatus;


    @ApiModelProperty(value = "是否在公海")
    private Boolean isInOpenSea;


    public void setStatus(Integer status) {
        this.status = status;
        this.asStatus = status;
        if (Objects.nonNull(this.asStatus) && asStatus > 10000) {
            combinedState(this.asStatus, this.transportId);
        }
    }

    public void setTransportId(Integer transportId) {
        this.transportId = transportId;
        if (Objects.nonNull(transportId) && Objects.nonNull(this.asStatus)) {
            combinedState(this.asStatus, this.transportId);
        }
    }

    private void combinedState(Integer asStatus, Integer transportId) {
        switch (asStatus) {
            case 12325:
                this.status = 12;
                this.shipmentState = 325;
                break;
            case 10501:
                // 空运待出
                this.status = 5;
                this.transportId = 3; // 空运待出查询，只查空运的订单
                this.airShipment = 1;
                this.auditType = 0;
                this.abnormalState = 0;
                break;
            case 10502:
                // 空运可出
                this.status = 5;
                this.transportId = 3; // 空运待出查询，只查空运的订单
                this.airShipment = 12; // 可出、备货中
                break;
            case 10503:
                // 空运已备货
                this.status = 5;
                this.transportId = 3; // 空运待出查询，只查空运的订单
                this.airShipment = 4; // 已备货
                break;
            case 10504:
                // 待排单
                this.status = 5;
                if (Objects.nonNull(transportId) && transportId == 3) {
                    // 空运无需判断备货状态 可出、备货中、已备货
                    this.airShipment = 10;
                }else {
                    // 兼容空运已入仓的可出、备货中、已备货，且无异常无审批，海运的已入仓无异常无审批
                    this.airShipment = 20;
                }
                this.auditType = 0;
                this.abnormalState = 0;
                break;
            case 132411:
                // 空运已出货
                this.status = 32;
                this.transportId = 3; // 空运待出查询，只查空运的订单
                this.shipmentState = 411;
                break;
            case 132412:
                // 空运已出仓
                this.status = 32;
                this.transportId = 3; // 空运待出查询，只查空运的订单
                this.shipmentState = 412;
                break;
            case 132409:
                // 空运已理货
                this.status = 32;
                this.transportId = 3; // 空运待出查询，只查空运的订单
                this.shipmentState = 409;
                break;
            case 118428:
                // 空运已到港
                this.status = 18;
                this.transportId = 3; // 空运待出查询，只查空运的订单
                this.shipmentState = 428;
                break;
        }
    }


    public void setShipmentState(Integer shipmentState) {
        if (Objects.nonNull(shipmentState)) {
            this.shipmentState = shipmentState;
        }
    }
}
