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

import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.i18n.core.I18nMessage;
import cn.iocoder.yudao.module.depository.dto.LogisticsInfoDto;
import cn.iocoder.yudao.module.order.enums.OrderAbnormalStateEnum;
import cn.iocoder.yudao.module.order.enums.OrderStatusEnum;
import cn.iocoder.yudao.module.order.enums.OrderStatusMsgEnum;
import cn.iocoder.yudao.module.order.vo.order.CostVO;
import cn.iocoder.yudao.module.order.vo.order.CustomDraweeVO;
import cn.iocoder.yudao.module.order.vo.order.GuanLianOrderStatusVO;
import cn.iocoder.yudao.module.order.vo.orderConsignee.OrderConsigneeBackVO;
import cn.iocoder.yudao.module.order.vo.orderConsignor.OrderConsignorBackVO;
import cn.iocoder.yudao.module.order.vo.orderDeparture.OrderDepartureBackVO;
import cn.iocoder.yudao.module.order.vo.orderItem.OrderItemBackVO;
import cn.iocoder.yudao.module.order.vo.orderObjective.OrderObjectiveBackVO;
import cn.iocoder.yudao.module.order.vo.orderTime.OrderTimeBackVO;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

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

/**
 * 订单 Response VO
 *
 * @author 系统管理员
 */
@Data
@ApiModel("管理后台 - 订单 OrderBackInfoDto ")
public class OrderBackInfoDto {

    // 基础信息
    @ExcelProperty("主键ID")
    @ApiModelProperty(value = "主键ID", required = true)
    private Long orderId;

    @ExcelProperty("订单编号")
    @ApiModelProperty(value = "订单编号", required = true)
    private String orderNo;

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

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

    @ApiModelProperty(value = "提单状态")
    private boolean ladingState;

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

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

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

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

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

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

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

    @ExcelProperty("线路ID")
    @ApiModelProperty(value = "线路ID", required = true)
    private Long lineId;

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

    @ExcelProperty("渠道名称")
    @ApiModelProperty(value = "渠道名称")
    private String channelName;

    @ExcelProperty("渠道可出特性id")
    @ApiModelProperty(value = "渠道可出特性id")
    private String channelAttrId;

    @ApiModelProperty(value = "订单类型(可多选)：1 集运服务 2 海外仓")
    private String type;

    @ExcelProperty("订单类型")
    @ApiModelProperty(value = "订单类型", required = true)
    private Integer orderType;

    @ExcelProperty("泡货类型 1 默认值 2 半泡(当订单为泡货时才使用此字段)")
    @ApiModelProperty(value = "泡货类型 1 默认值 2 半泡(当订单为泡货时才使用此字段)", required = true)
    private Integer pickleType;


    @ExcelProperty("泡重比例，默认100%")
    @ApiModelProperty(value = "泡重比例，默认100%", required = true)
    private BigDecimal bubbleWeightRatio = BigDecimal.ONE;


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

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

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

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

    @ExcelProperty("0 控货中；1 已放完货；2 部分控货")
    @ApiModelProperty(value = "0 控货中；1 已放完货；2 部分控货")
    private Integer cargoControlStatus;

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


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

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

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

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

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

    /**
     * 状态说明
     */
    @ApiModelProperty(value = "状态说明")
    private String statusMsg;

    /**
     * 状态key(前端在订单列表做权限按钮判断)
     */
    @ApiModelProperty(value = "订单列表权限按钮判断状态key")
    private Integer statusKey;

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

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

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

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

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

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

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

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

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

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

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

    @ApiModelProperty(value = "转换使用重货体积")
    private BigDecimal weVolume;

    @ApiModelProperty(value = "转换使用泡货重量")
    private BigDecimal voWeight;

    @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;

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

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

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

    @ApiModelProperty(value = "自定义付款人清单(name 详见字典 自定义付款人(custom_drawee), value 1 发货人 2 收货人)")
    private List<CustomDraweeVO> customDraweeVOList;

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

    @ApiModelProperty(value = "费用清单VO")
    private CostVO costVO;

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

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

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

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

    @ExcelProperty("调仓目的仓")
    @ApiModelProperty(value = "调仓目的仓")
    private Long adjustToDestWarehouseId;

    @ExcelProperty("目的地调仓始发仓")
    @ApiModelProperty(value = "目的地调仓始发仓")
    private Long destAdjustToStartWarehouseId;

    @ExcelProperty("目的地调仓目的仓")
    @ApiModelProperty(value = "目的地调仓目的仓")
    private Long destAdjustToDestWarehouseId;

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

    @ExcelProperty("入仓件数")
    @ApiModelProperty(value = "入仓件数", required = true)
    private Integer sumNum = 0;

    @ExcelProperty("入仓体积")
    @ApiModelProperty(value = "入仓体积", required = true)
    private BigDecimal sumVolume = BigDecimal.ZERO;

    @ExcelProperty("入仓重量")
    @ApiModelProperty(value = "入仓重量", required = true)
    private BigDecimal sumWeight = BigDecimal.ZERO;


    @ApiModelProperty(value = "最小计量重量")
    private BigDecimal minMeteringWeight = BigDecimal.ZERO;

    @ApiModelProperty(value = "最小计量体积")
    private BigDecimal minMeteringVolume = BigDecimal.ZERO;

    @ApiModelProperty(value = "最小计量个数")
    private BigDecimal minMeteringQuantity = BigDecimal.ZERO;

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

    @ApiModelProperty(value = "外部仓信息")
    private String externalWarehouseJson;

    @ApiModelProperty(value = "外部仓信息")
    private List<ExternalWarehouseDto> externalWarehouseDtoList;

    @ExcelProperty("重货比")
    @ApiModelProperty(value = "重货比", required = true)
    private BigDecimal weightRatio;

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

    @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 = "航空公司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 = "目的港清关：1 我司 2 客户")
    private Integer portDestCustomsClear;

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

    @ApiModelProperty(value = "清关证书备注")
    private String customsClearCertRemarks;

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

    @ApiModelProperty(value = "特价泡重")
    private BigDecimal specialVWeight;

    @ApiModelProperty(value = "是否处理了渠道特性异常")
    private Boolean handlerChannelAttrException;

    @ApiModelProperty(value = "打包前入仓重量")
    private BigDecimal weightBeforePack;


    @ApiModelProperty(value = "打包后入仓重量")
    private BigDecimal weightAfterPack;

    @ApiModelProperty(value = "备货重量阀值")
    private BigDecimal stockOverWeightLimit;

    @ApiModelProperty(value = "拆单子订单是作为独立订单计算(拆单业务只要涉及到空运即将所有拆单后的子订单作为独立订单来计算)")
    private Boolean splitSeparateOrder = false;

    // 发货人信息
    @ApiModelProperty(value = "发货人信息")
    private OrderConsignorBackVO consignorVO;

    // 收货人信息
    @ApiModelProperty(value = "收货人信息")
    private OrderConsigneeBackVO consigneeVO;

    @ApiModelProperty("始发地信息")
    private OrderDepartureBackVO departureVO;

    @ApiModelProperty("目的地信息")
    private OrderObjectiveBackVO objectiveVO;

    // 物流信息
    @ApiModelProperty(value = "初始物流信息相关")
    private LogisticsInfoDto initialLogisticsInfoDto;

    // 物流信息
    @ApiModelProperty(value = "当前物流信息相关")
    private LogisticsInfoDto logisticsInfoDto;

    // 订单商品列表
    @ApiModelProperty(value = "订单商品项列表")
    private List<OrderItemBackVO> orderItemVOList;

    // 订单动态
    @ApiModelProperty(value = "订单动态")
    private List<OrderTimeBackVO> orderTimeVOList;

    /**
     * 入仓时间
     */
    @ApiModelProperty(value = "入仓时间")
    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    private Date rucangTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "送货时间")
    private Date deliveryDate;

    @ApiModelProperty(value = "收货方式：1 自提 2 送货上门 ")
    private Integer harvestMethod;

    @ApiModelProperty(value = "收货地址")
    private String consigneeAddress;

    @ApiModelProperty(value = "收货地址的国家")
    private Long country;

    @ApiModelProperty(value = "收货地址的省")
    private Long province;

    @ApiModelProperty(value = "收货地址的市")
    private Long city;

    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "创建人")
    private String creator;

    @ApiModelProperty(value = "创建人昵称")
    private String creatorName;

    @ApiModelProperty(value = "不阻塞流程的异常说明(支持多个异常说明)")
    private String exceptionReason;

    @ApiModelProperty(value = "不阻塞流程的异常说明(支持多个异常说明)")
    private List<OrderRemindExceptionDto> remindExceptionDtoList;

    @ApiModelProperty(value = "是否有异常(此处为不阻塞流程的异常)")
    private Boolean isException = Boolean.FALSE;

    @ApiModelProperty(value = "是否显示提单金额")
    private Boolean displayBillLadingPrice = true;

    /**
     * 业务员ID
     */
    @ApiModelProperty(value = "业务员ID")
    private Long salesmanId;
    /**
     * 业务员昵称
     */
    @ApiModelProperty(value = "业务员昵称")
    private String salesmanName;
    /**
     * 业务员ID
     */
    @ApiModelProperty(value = "部门ID")
    private Long deptId;
    /**
     * 部门名称
     */
    @ApiModelProperty(value = "部门名称")
    private String deptName;
    /**
     * 端口 {@link UserTypeEnum}
     */
    @ApiModelProperty(value = "端口(默认管理端)")
    private Integer userType = 2;

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


    /**
     * 关联订单状态
     */
    @ApiModelProperty(value = "关联订单状态")
    private String guanLianOrderStatus;

    @ApiModelProperty(value = "关联订单状态")
    private List<GuanLianOrderStatusVO> guanLianOrderStatusVOList;


    /**
     * 完成入仓的入仓体积
     */
    @ApiModelProperty(value = "完成入仓的入仓体积")
    private BigDecimal sumVolumeFinishedWarehouseIn;
    /**
     * 完成入仓的入仓重量
     */
    @ApiModelProperty(value = "完成入仓的入仓重量")
    private BigDecimal sumWeightFinishedWarehouseIn;

    /**
     * 完成入仓的箱/件数
     */
    @ApiModelProperty(value = "完成入仓的箱/件数")
    private Integer sumCartonsNumFinishedWarehouseIn;

    /**
     * 完成入仓的所有箱内总货物数量
     */
    @ApiModelProperty(value = "完成入仓的所有箱内总货物数量")
    private Integer sumQuantityAllFinishedWarehouseIn;

    @ApiModelProperty(value = "是否有收货人，1-是，0-否")
    private Boolean hasConsignee = true;

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

    @ApiModelProperty(value = "提货状态：0 未提货 1 部分提货 2 已提货")
    private Integer pickState;

    @ApiModelProperty(value = "'提货率'")
    private BigDecimal pickRatio;

    @ApiModelProperty(value = "'提货箱数'")
    private Integer pickNum;


    @ApiModelProperty(value = "放货率")
    private BigDecimal releaseRatio;

    @ApiModelProperty(value = "放货箱数")
    private Integer releaseNum;

    @ApiModelProperty(value = "到仓件数")
    private Integer checkNum;

    @ApiModelProperty(value = "到仓数量")
    private Integer checkQuantity;

    @ApiModelProperty(value = "到仓体积")
    private BigDecimal checkVolume;

    @ApiModelProperty(value = "到仓重量")
    private BigDecimal checkWeight;

    public void setExceptionReason(String exceptionReason) {
        this.exceptionReason = exceptionReason;
        if (StringUtils.isNotBlank(exceptionReason) && Objects.nonNull(this.lang)) {
            this.remindExceptionDtoList = JSONObject.parseArray(exceptionReason, OrderRemindExceptionDto.class)
                    .stream()
                    .peek(ern -> ern.setReason(lang == 0 ? I18nMessage.getZhMessage(ern.getReason()) : I18nMessage.getEnMessage(ern.getReason())))
                    .collect(Collectors.toList());
        }
        this.getOrderDesc();
    }

    public void setExternalWarehouseJson(String externalWarehouseJson) {
        this.externalWarehouseJson = externalWarehouseJson;
        if (StringUtils.isNotBlank(externalWarehouseJson)) {
            this.externalWarehouseDtoList = JSONObject.parseArray(externalWarehouseJson, ExternalWarehouseDto.class);
        }
    }

    public void setExternalWarehouseDtoList(List<ExternalWarehouseDto> externalWarehouseDtoList) {
        this.externalWarehouseDtoList = externalWarehouseDtoList;
        if (CollectionUtil.isNotEmpty(externalWarehouseDtoList)) {
            this.externalWarehouseJson = JSONObject.toJSONString(externalWarehouseDtoList);
        }
    }


    public void setStatus(Integer status) {
        this.status = status;
        this.getOrderDesc();

    }

    public void setPickState(Integer pickState) {
        this.pickState = pickState;
        if (Objects.nonNull(pickState) && pickState > 0) {
            // 当提货状态不未空时，判断提货状态是否需要转化为对应的原有主状态中的提货状态
            this.status = pickState == 1 ? 21 : 20;
        }
        this.getOrderDesc();
    }

    public void setAbnormalState(Integer abnormalState) {
        this.abnormalState = abnormalState;
        this.getOrderDesc();
    }

    public void setInWarehouseState(Integer inWarehouseState) {
        this.inWarehouseState = inWarehouseState;
        this.getOrderDesc();
    }

    public void setAirShipment(Integer airShipment) {
        this.airShipment = airShipment;
        this.getOrderDesc();
    }

    public void setShipmentState(Integer shipmentState) {
        this.shipmentState = shipmentState;
        this.getOrderDesc();
    }

    public void setAuditType(Integer auditType) {
        this.auditType = auditType;
        this.getOrderDesc();
    }

    public void setAuditResult(String auditResult) {
        this.auditResult = auditResult;
        this.getOrderDesc();

    }

    public void setGuanLianOrderStatus(String guanLianOrderStatus) {
        this.guanLianOrderStatus = guanLianOrderStatus;
        if (StringUtils.isNotBlank(guanLianOrderStatus)) {
            this.guanLianOrderStatusVOList = JSONObject.parseArray(guanLianOrderStatus, GuanLianOrderStatusVO.class);
            this.getOrderDesc();
        }
    }

    public void setGuanLianOrderStatusVOList(List<GuanLianOrderStatusVO> guanLianOrderStatusVOList) {
        this.guanLianOrderStatusVOList = guanLianOrderStatusVOList;
        if (CollectionUtil.isNotEmpty(guanLianOrderStatusVOList)) {
            this.guanLianOrderStatus = JSONObject.toJSONString(guanLianOrderStatusVOList);
        }
    }

    public void setLang(Integer lang) {
        this.lang = lang;
        if (StringUtils.isNotBlank(this.exceptionReason) && Objects.nonNull(lang)) {
            this.remindExceptionDtoList = JSONObject.parseArray(this.exceptionReason, OrderRemindExceptionDto.class)
                    .stream()
                    .peek(ern -> ern.setReason(lang == 0 ? I18nMessage.getZhMessage(ern.getReason()) : I18nMessage.getEnMessage(ern.getReason())))
                    .collect(Collectors.toList());
        }
        this.getOrderDesc();
    }

    private void getOrderDesc() {
        // TODO 这里的文案国际化现在只支持两种语言，如果需要支持更多的语言，需要优化
        Integer lang = Objects.nonNull(this.lang) ? this.lang : I18nMessage.getLang();
        if (null != this.status && this.status.equals(OrderStatusEnum.CANCEL.getValue()) && this.userType != null) {
            String message = this.userType == 2 ? OrderStatusMsgEnum.CANCEL.getAdminSourceName() : OrderStatusMsgEnum.CANCEL.getCustomerSourceName();
            this.statusMsg = lang == 0 ? I18nMessage.getZhMessage(message) : I18nMessage.getEnMessage(message);
        } else if (null != this.abnormalState && this.abnormalState > 0) {
//            this.statusKey = 10000;
            OrderAbnormalStateEnum abnormalStateEnum = OrderAbnormalStateEnum.valueOf(abnormalState);
            if (Objects.isNull(abnormalStateEnum)) {
                this.statusMsg = lang == 0 ? "未知异常" : "UNKNOWN_EXCEPTION";
            } else {
                this.statusMsg = lang == 0 ? I18nMessage.getZhMessage(abnormalStateEnum.getDesc()) : I18nMessage.getEnMessage(abnormalStateEnum.getDesc());
            }
        } else if (StringUtils.isNotBlank(this.auditResult)) {
            this.statusMsg = lang == 0 ? I18nMessage.getZhMessage(auditResult) : I18nMessage.getEnMessage(auditResult);
        } else if (CollectionUtil.isNotEmpty(this.remindExceptionDtoList) && this.remindExceptionDtoList.size() > 0) {
            this.statusMsg = remindExceptionDtoList.get(0).getReason();
        } else if (CollectionUtil.isNotEmpty(this.guanLianOrderStatusVOList)) {
            // 如果查询返回了关联订单状态，表示需要显示关联订单状态，关联订单状态冗余的是国际化key值
            // 排序
            this.guanLianOrderStatusVOList = this.guanLianOrderStatusVOList.stream().sorted(Comparator.comparing(GuanLianOrderStatusVO::getType)).collect(Collectors.toList());
            GuanLianOrderStatusVO guanlianOrderStatusVO = guanLianOrderStatusVOList.get(0);
            switch (guanlianOrderStatusVO.getType()) {
                case 1:
                    // 关联异常状态封装，订单状态显示“关联单#订单号#，#异常名称#”Associated order %s, %s
                    String abnormalMsg = lang == 0 ? I18nMessage.getZhMessage("guanlian.order.abnormalState") : I18nMessage.getEnMessage("guanlian.order.abnormalState");
                    this.statusMsg = String.format(abnormalMsg, guanlianOrderStatusVO.getOrderNo(), I18nMessage.getMessage(guanlianOrderStatusVO.getStatusMsg()));
                    break;
                case 2:
                    // 关联审批状态封装，订单状态显示“关联单#订单号##审核状态#”
                    String auditMsg = lang == 0 ? I18nMessage.getZhMessage("guanlian.order.audit") : I18nMessage.getEnMessage("guanlian.order.audit");
                    this.statusMsg = String.format(auditMsg, guanlianOrderStatusVO.getOrderNo(), I18nMessage.getMessage(guanlianOrderStatusVO.getStatusMsg()));
                    break;
                case 3:
                    // 关联未入仓状态封装，订单状态显示“关联单#订单号#未入仓”
                    String waitWarehouseInMsg = lang == 0 ? I18nMessage.getZhMessage(guanlianOrderStatusVO.getStatusMsg()) : I18nMessage.getEnMessage(guanlianOrderStatusVO.getStatusMsg());
                    this.statusMsg = String.format(waitWarehouseInMsg, guanlianOrderStatusVO.getOrderNo());
                    break;
                default:
                    this.statusMsg = lang == 0 ? I18nMessage.getZhMessage(guanlianOrderStatusVO.getStatusMsg()) : I18nMessage.getEnMessage(guanlianOrderStatusVO.getStatusMsg());
            }
        } else if (null != this.status && null != this.inWarehouseState && null != this.shipmentState && null != this.airShipment && null != this.transportId) {
            this.statusMsg = OrderStatusMsgEnum.getMsg(this.pickState, this.status, this.inWarehouseState, this.shipmentState, this.airShipment, this.transportId, this.userType, lang);
//            this.statusKey = OrderStatusMsgEnum.getStatusKey(this.status, this.inWarehouseState, this.shipmentState);
        }
    }

    public void setCost(String cost) {
        this.cost = cost;
        if (StringUtils.isNotBlank(cost)) {
            this.costVO = JSONObject.parseObject(this.cost, CostVO.class);
        }
    }

    public CostVO getCostVO() {
        return JSONObject.parseObject(this.cost, CostVO.class);
    }

    public void setCustomDrawee(String customDrawee) {
        this.customDrawee = customDrawee;
        if (StringUtils.isNotBlank(customDrawee)) {
            this.customDraweeVOList = JSONObject.parseArray(customDrawee, CustomDraweeVO.class);
        }
    }
}
