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

import cn.iocoder.yudao.module.order.dto.OrderRemindExceptionDto;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;

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


/**
 * 控货订单 导出封装类
 *
 * @author zhengYi
 */
@Data
@ApiModel("管理后台 - 控货订单 导出封装类")
public class OrderCargoControlExcelVO {

    @ExcelProperty("订单编号")
    private String orderNo;

    @ExcelProperty("唛头")
    private String marks;


    @ExcelProperty("箱数")
    private Integer sumNum;


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

    @ExcelProperty(value = "订单状态")
    private String statusMsg;

    @ExcelProperty("放货人")
    @ApiModelProperty(value = "控货人姓名")
    private String cargoControlName;

    @ExcelProperty(value = "控货状态")
    private String cargoControlStatusMsg;

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

    @ExcelIgnore
    @ApiModelProperty(value = "控货人手机国家区号")
    private String cargoControlCountryCode;

//    @ExcelProperty("始发仓")
//    private String startWarehouseName;
//
//    @ExcelProperty("目的仓")
//    private String destWarehouseName;
//
//    @ExcelProperty(value = "入仓时间")
//    @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
//    private Date rucangTime;
//
//
//    @ExcelProperty("日期(该状态最新日期)")
//    @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
//    @ApiModelProperty(value = "更新日期", required = true)
//    private Date updateTime;

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

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

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

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

    @ExcelIgnore
    @ApiModelProperty(value = "业务员ID")
    private Long salesmanId;

    @ExcelIgnore
    @ApiModelProperty(value = "用户ID")
    private Long userId;


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


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

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

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

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

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

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

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


    @ExcelIgnore
    @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    @ApiModelProperty(value = "创建时间", required = true)
    private Date createTime;

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


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


    public void setCargoControlStatus(Integer cargoControlStatus) {
        this.cargoControlStatus = cargoControlStatus;
        this.cargoControlStatusMsg = (cargoControlStatus == 0 ? "控货中" : (cargoControlStatus == 1 ? "已放完货" : "部分控货"));
    }

//    public void setOrderNo(String orderNo) {
//        this.orderNo = orderNo.contains("DRAFT") ? null : orderNo;
//    }
//
//    public void setStatus(Integer status) {
//        this.status = status;
//        this.getOrderDesc();
//
//    }
//
//    public void setAbnormalState(Integer abnormalState) {
//        this.abnormalState = abnormalState;
//        this.getOrderDesc();
//    }
//
//    public void setInWarehouseState(Integer inWarehouseState) {
//        this.inWarehouseState = inWarehouseState;
//        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 setExceptionReason(String exceptionReason) {
//        this.exceptionReason = exceptionReason;
//        if (StringUtils.isNotBlank(exceptionReason)) {
//            this.remindExceptionDtoList = JSONObject.parseArray(exceptionReason, OrderRemindExceptionDto.class)
//                    .stream()
//                    .peek(ern -> ern.setReason(I18nMessage.getMessage(ern.getReason())))
//                    .collect(Collectors.toList());
//        }
//        this.getOrderDesc();
//    }
//
//    private void getOrderDesc() {
//        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 = I18nMessage.getMessage(message);
//        } else if (null != this.abnormalState && this.abnormalState > 0) {
//            OrderAbnormalStateEnum abnormalStateEnum = OrderAbnormalStateEnum.valueOf(abnormalState);
//            if (Objects.isNull(abnormalStateEnum)) {
//                this.statusMsg = I18nMessage.getLang() == 0 ? "未知异常" : "UNKNOWN_EXCEPTION";
//            } else {
//                this.statusMsg = I18nMessage.getMessage(abnormalStateEnum.getDesc());
//            }
//        } else if (StringUtils.isNotBlank(auditResult)) {
//             this.statusMsg = I18nMessage.getMessage(auditResult);
//        } else if (CollectionUtil.isNotEmpty(this.remindExceptionDtoList) && this.remindExceptionDtoList.size() > 0) {
//            this.statusMsg = remindExceptionDtoList.get(0).getReason();
//        } else if (null != this.status && null != this.inWarehouseState && null != this.shipmentState) {
//            this.statusMsg = OrderStatusMsgEnum.getMsg(this.status, this.inWarehouseState, this.shipmentState, this.userType);
//        }
//    }

}
