package com.yueqian.xingyun.sc.bo.logistics;

import com.lframework.starter.common.utils.StringUtil;
import com.lframework.starter.web.core.annotations.convert.EnumConvert;
import com.lframework.starter.web.core.bo.BaseBo;
import com.lframework.starter.web.core.utils.ApplicationUtil;
import com.yueqian.xingyun.basedata.entity.LogisticsCompany;
import com.yueqian.xingyun.basedata.service.logistics.LogisticsCompanyService;
import com.lframework.starter.web.inner.entity.SysUser;
import com.yueqian.xingyun.sc.entity.LogisticsSheet;
import com.lframework.starter.web.inner.service.system.SysUserService;
import io.swagger.v3.oas.annotations.media.Schema;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import lombok.Data;

@Data
public class QueryLogisticsSheetBo extends BaseBo<LogisticsSheet> {

  /**
   * ID
   */
  @Schema(description = "ID")
  private String id;

  /**
   * 业务单据号
   */
  @Schema(description = "业务单据号")
  private String code;

  /**
   * 物流单号
   */
  @Schema(description = "物流单号")
  private String logisticsNo;

  /**
   * 物流公司名称
   */
  @Schema(description = "物流公司名称")
  private String logisticsCompanyName;

  /**
   * 总重量
   */
  @Schema(description = "总重量")
  private BigDecimal totalWeight;

  /**
   * 总体积
   */
  @Schema(description = "总体积")
  private BigDecimal totalVolume;

  /**
   * 物流费
   */
  @Schema(description = "物流费")
  private BigDecimal totalAmount;

  /**
   * 状态
   */
  @Schema(description = "状态")
  @EnumConvert
  private Integer status;

  /**
   * 备注
   */
  @Schema(description = "备注")
  private String description;

  /**
   * 创建人
   */
  @Schema(description = "创建人")
  private String createBy;

  /**
   * 创建时间
   */
  @Schema(description = "创建时间")
  private LocalDateTime createTime;

  /**
   * 发货人
   */
  @Schema(description = "发货人")
  private String deliveryBy;

  /**
   * 发货时间
   */
  @Schema(description = "发货时间")
  private LocalDateTime deliveryTime;

  public QueryLogisticsSheetBo(LogisticsSheet dto) {

    super(dto);
  }

  @Override
  public BaseBo<LogisticsSheet> convert(LogisticsSheet dto) {

    return super.convert(dto);
  }

  @Override
  protected void afterInit(LogisticsSheet dto) {
    LogisticsCompanyService logisticsCompanyService = ApplicationUtil.getBean(
        LogisticsCompanyService.class);
    LogisticsCompany logisticsCompany = logisticsCompanyService.findById(
        dto.getLogisticsCompanyId());
    this.logisticsCompanyName = logisticsCompany.getName();

    if (StringUtil.isNotBlank(dto.getDeliveryBy())) {
      SysUserService userService = ApplicationUtil.getBean(SysUserService.class);
      SysUser deliveryBy = userService.findById(dto.getDeliveryBy());
      this.deliveryBy = deliveryBy.getName();
    }
  }
}
