Просмотр исходного кода

feat: 订单列表页面相关优化处理;

hanchaolong недель назад: 3
Родитель
Сommit
a16b037998

+ 45 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/controller/BizWaybillOrderController.java

@@ -9,13 +9,16 @@ import com.ruoyi.common.log.annotation.Log;
 import com.ruoyi.common.log.enums.BusinessType;
 import com.ruoyi.common.security.annotation.RequiresPermissions;
 import com.ruoyi.logistics.domain.BizWaybillOrder;
+import com.ruoyi.logistics.domain.dto.JDOrderDTO;
 import com.ruoyi.logistics.service.IBizWaybillOrderService;
 import com.ruoyi.logistics.service.LogisticsOrderService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
+import java.util.ArrayList;
 
 /**
  * PC-运单管理
@@ -27,6 +30,7 @@ import java.util.List;
 @RequestMapping("/order")
 public class BizWaybillOrderController extends BaseController
 {
+    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(BizWaybillOrderController.class);
     @Autowired
     private IBizWaybillOrderService bizWaybillOrderService;
 
@@ -144,5 +148,46 @@ public class BizWaybillOrderController extends BaseController
         return success(bizWaybillOrderService.queryWaybillPdf(bizWaybillOrder));
     }
 
+    /**
+     * 批量下单
+     */
+    @RequiresPermissions("system:order:add")
+    @Log(title = "批量下单", businessType = BusinessType.INSERT)
+    @PostMapping("/batchAdd")
+    public AjaxResult batchAdd(@RequestParam("file") MultipartFile file,
+                                @RequestParam("orderType") Integer orderType) {
+        try {
+            // 校验订单类型
+            if (orderType == null || (orderType != 1 && orderType != 2)) {
+                return AjaxResult.error("订单类型参数错误,必须为 1(京东)或 2(顺丰)");
+            }
+
+            // 检查文件是否为空
+            if (file.isEmpty()) {
+                return AjaxResult.error("上传的 Excel 文件为空");
+            }
+
+            // 使用 ExcelUtil 读取 Excel 数据
+            int[] result = new int[2];
+            if (1 == orderType) {
+                ExcelUtil<JDOrderDTO> util = new ExcelUtil<>(JDOrderDTO.class);
+                List<JDOrderDTO> orderList = util.importExcel(file.getInputStream());
+
+                // 校验数据
+                if (orderList == null || orderList.isEmpty()) {
+                    return AjaxResult.error("Excel 文件中没有有效的订单数据");
+                }
+
+                // 调用批量下单方法
+                result = bizWaybillOrderService.batchInsertBizWaybillOrder(orderList, orderType);
+            }
+
+            return AjaxResult.success(String.format("批量下单完成!成功 %d 单,失败 %d 单", result[0], result[1]));
+
+        } catch (Exception e) {
+            log.error("批量下单异常", e);
+            return AjaxResult.error("批量下单失败:" + e.getMessage());
+        }
+    }
 
 }

+ 290 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/domain/dto/JDOrderDTO.java

@@ -0,0 +1,290 @@
+package com.ruoyi.logistics.domain.dto;
+
+import com.ruoyi.common.core.annotation.Excel;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 批量下单 DTO 对象
+ */
+public class JDOrderDTO implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /** 发件人姓名 */
+    @Excel(name = "发件人姓名")
+    private String senderName;
+
+    /** 发件人电话 */
+    private String senderPhone;
+
+    /** 发件省 */
+    private String senderProvince;
+
+    /** 发件市 */
+    private String senderCity;
+
+    /** 发件区县 */
+    private String senderCounty;
+
+    /** 发件详细地址 */
+    private String senderAddress;
+
+    /** 收件人姓名 */
+    private String receiverName;
+
+    /** 收件人电话 */
+    private String receiverPhone;
+
+    /** 收件省 */
+    private String receiverProvince;
+
+    /** 收件市 */
+    private String receiverCity;
+
+    /** 收件区县 */
+    private String receiverCounty;
+
+    /** 收件详细地址 */
+    private String receiverAddress;
+
+    /** 货物名称 */
+    private String goodsName;
+
+    /** 货物重量 */
+    private BigDecimal goodsWeight;
+
+    /** 货物体积 */
+    private BigDecimal goodsVolume;
+
+    /** 货物数量 */
+    private Long goodsQty;
+
+    /** 取件类型 */
+    private Integer pickupType;
+
+    /** 上门取件开始时间 */
+    private Date sendStartTime;
+
+    /** 上门取件结束时间 */
+    private Date sendEndTime;
+
+    /** 产品类型 */
+    private String productCode;
+
+    /** 增值服务 */
+    private String addedService;
+
+    /** 备注 */
+    private String remark;
+
+    /** 是否包装 */
+    private String isPack;
+
+    /** 保价金额 */
+    private String guaranteeMoney;
+
+    /** 签单返还 */
+    private String isReceiptCollect;
+
+    public String getSenderName() {
+        return senderName;
+    }
+
+    public void setSenderName(String senderName) {
+        this.senderName = senderName;
+    }
+
+    public String getSenderPhone() {
+        return senderPhone;
+    }
+
+    public void setSenderPhone(String senderPhone) {
+        this.senderPhone = senderPhone;
+    }
+
+    public String getSenderProvince() {
+        return senderProvince;
+    }
+
+    public void setSenderProvince(String senderProvince) {
+        this.senderProvince = senderProvince;
+    }
+
+    public String getSenderCity() {
+        return senderCity;
+    }
+
+    public void setSenderCity(String senderCity) {
+        this.senderCity = senderCity;
+    }
+
+    public String getSenderCounty() {
+        return senderCounty;
+    }
+
+    public void setSenderCounty(String senderCounty) {
+        this.senderCounty = senderCounty;
+    }
+
+    public String getSenderAddress() {
+        return senderAddress;
+    }
+
+    public void setSenderAddress(String senderAddress) {
+        this.senderAddress = senderAddress;
+    }
+
+    public String getReceiverName() {
+        return receiverName;
+    }
+
+    public void setReceiverName(String receiverName) {
+        this.receiverName = receiverName;
+    }
+
+    public String getReceiverPhone() {
+        return receiverPhone;
+    }
+
+    public void setReceiverPhone(String receiverPhone) {
+        this.receiverPhone = receiverPhone;
+    }
+
+    public String getReceiverProvince() {
+        return receiverProvince;
+    }
+
+    public void setReceiverProvince(String receiverProvince) {
+        this.receiverProvince = receiverProvince;
+    }
+
+    public String getReceiverCity() {
+        return receiverCity;
+    }
+
+    public void setReceiverCity(String receiverCity) {
+        this.receiverCity = receiverCity;
+    }
+
+    public String getReceiverCounty() {
+        return receiverCounty;
+    }
+
+    public void setReceiverCounty(String receiverCounty) {
+        this.receiverCounty = receiverCounty;
+    }
+
+    public String getReceiverAddress() {
+        return receiverAddress;
+    }
+
+    public void setReceiverAddress(String receiverAddress) {
+        this.receiverAddress = receiverAddress;
+    }
+
+    public String getGoodsName() {
+        return goodsName;
+    }
+
+    public void setGoodsName(String goodsName) {
+        this.goodsName = goodsName;
+    }
+
+    public BigDecimal getGoodsWeight() {
+        return goodsWeight;
+    }
+
+    public void setGoodsWeight(BigDecimal goodsWeight) {
+        this.goodsWeight = goodsWeight;
+    }
+
+    public BigDecimal getGoodsVolume() {
+        return goodsVolume;
+    }
+
+    public void setGoodsVolume(BigDecimal goodsVolume) {
+        this.goodsVolume = goodsVolume;
+    }
+
+    public Long getGoodsQty() {
+        return goodsQty;
+    }
+
+    public void setGoodsQty(Long goodsQty) {
+        this.goodsQty = goodsQty;
+    }
+
+    public Integer getPickupType() {
+        return pickupType;
+    }
+
+    public void setPickupType(Integer pickupType) {
+        this.pickupType = pickupType;
+    }
+
+    public Date getSendStartTime() {
+        return sendStartTime;
+    }
+
+    public void setSendStartTime(Date sendStartTime) {
+        this.sendStartTime = sendStartTime;
+    }
+
+    public Date getSendEndTime() {
+        return sendEndTime;
+    }
+
+    public void setSendEndTime(Date sendEndTime) {
+        this.sendEndTime = sendEndTime;
+    }
+
+    public String getProductCode() {
+        return productCode;
+    }
+
+    public void setProductCode(String productCode) {
+        this.productCode = productCode;
+    }
+
+    public String getAddedService() {
+        return addedService;
+    }
+
+    public void setAddedService(String addedService) {
+        this.addedService = addedService;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    public String getIsPack() {
+        return isPack;
+    }
+
+    public void setIsPack(String isPack) {
+        this.isPack = isPack;
+    }
+
+    public String getGuaranteeMoney() {
+        return guaranteeMoney;
+    }
+
+    public void setGuaranteeMoney(String guaranteeMoney) {
+        this.guaranteeMoney = guaranteeMoney;
+    }
+
+    public String getIsReceiptCollect() {
+        return isReceiptCollect;
+    }
+
+    public void setIsReceiptCollect(String isReceiptCollect) {
+        this.isReceiptCollect = isReceiptCollect;
+    }
+}

+ 10 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/service/IBizWaybillOrderService.java

@@ -9,6 +9,7 @@ import com.ruoyi.logistics.domain.BizWaybillCostDetails;
 import com.ruoyi.logistics.domain.BizWaybillOrder;
 import com.ruoyi.logistics.domain.dto.OrderStatisticsDto;
 import com.ruoyi.logistics.domain.dto.DailyOrderStatisticsDto;
+import com.ruoyi.logistics.domain.dto.JDOrderDTO;
 
 import java.util.List;
 
@@ -96,4 +97,13 @@ public interface IBizWaybillOrderService
     JSONObject queryOrderFeeInfo(Integer orderType, String waybillCode);
 
     JSONObject queryWaybillPdf(BizWaybillOrder bizWaybillOrder);
+
+    /**
+     * 批量下单
+     * 
+     * @param orderList 订单列表
+     * @param orderType 订单类型 1-京东,2-顺丰
+     * @return 结果数组,每个元素表示对应订单的结果 [0:成功数,1:失败数]
+     */
+    public int[] batchInsertBizWaybillOrder(List<JDOrderDTO> orderList, Integer orderType);
 }

+ 80 - 0
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/service/impl/BizWaybillOrderServiceImpl.java

@@ -22,6 +22,7 @@ import com.ruoyi.logistics.domain.BizAddressBook;
 import com.ruoyi.logistics.domain.BizWaybillCostDetails;
 import com.ruoyi.logistics.domain.dto.OrderStatisticsDto;
 import com.ruoyi.logistics.domain.dto.RecentAddressDto;
+import com.ruoyi.logistics.domain.dto.JDOrderDTO;
 import com.ruoyi.logistics.enums.OrderStatusEnum;
 import com.ruoyi.logistics.mapper.BizAddressBookMapper;
 import com.ruoyi.logistics.mapper.BizWaybillCostDetailsMapper;
@@ -355,4 +356,83 @@ public class BizWaybillOrderServiceImpl implements IBizWaybillOrderService
         }
         return jsonObject;
     }
+
+    /**
+     * 批量下单
+     *
+     * @param orderList 订单列表
+     * @param orderType 订单类型 1-京东,2-顺丰
+     * @return 结果数组,每个元素表示对应订单的结果 [0:成功数,1:失败数]
+     */
+    @Override
+    public int[] batchInsertBizWaybillOrder(List<JDOrderDTO> orderList, Integer orderType) {
+        int successCount = 0;
+        int failCount = 0;
+        List<String> errorMessages = new ArrayList<>();
+
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+
+        for (JDOrderDTO dto : orderList) {
+            try {
+                // 将 JDOrderDTO 转换为 BizWaybillOrder
+                BizWaybillOrder bizWaybillOrder = convertToBizWaybillOrder(dto, orderType, loginUser);
+                this.insertBizWaybillOrder(bizWaybillOrder);
+                successCount++;
+            } catch (Exception e) {
+                log.error("批量下单异常!发件人:{}, 收件人:{}", 
+                    dto.getSenderName(), dto.getReceiverName(), e);
+                failCount++;
+                errorMessages.add(String.format("订单 %s-%s 异常:%s", 
+                    dto.getSenderName(), dto.getReceiverName(), e.getMessage()));
+            }
+        }
+
+        log.info("批量下单完成!总数:{}, 成功:{}, 失败:{}", orderList.size(), successCount, failCount);
+        
+        return new int[]{successCount, failCount};
+    }
+
+    /**
+     * 将 JDOrderDTO 转换为 BizWaybillOrder
+     */
+    private BizWaybillOrder convertToBizWaybillOrder(JDOrderDTO dto, Integer orderType, LoginUser loginUser) {
+        BizWaybillOrder bizWaybillOrder = new BizWaybillOrder();
+        
+        // 设置订单类型
+        bizWaybillOrder.setOrderType(orderType);
+        
+        // 复制基本信息
+        bizWaybillOrder.setSenderName(dto.getSenderName());
+        bizWaybillOrder.setSenderPhone(dto.getSenderPhone());
+        bizWaybillOrder.setSenderProvince(dto.getSenderProvince());
+        bizWaybillOrder.setSenderCity(dto.getSenderCity());
+        bizWaybillOrder.setSenderCounty(dto.getSenderCounty());
+        bizWaybillOrder.setSenderAddress(dto.getSenderAddress());
+        
+        bizWaybillOrder.setReceiverName(dto.getReceiverName());
+        bizWaybillOrder.setReceiverPhone(dto.getReceiverPhone());
+        bizWaybillOrder.setReceiverProvince(dto.getReceiverProvince());
+        bizWaybillOrder.setReceiverCity(dto.getReceiverCity());
+        bizWaybillOrder.setReceiverCounty(dto.getReceiverCounty());
+        bizWaybillOrder.setReceiverAddress(dto.getReceiverAddress());
+        
+        // 货物信息
+        bizWaybillOrder.setGoodsName(dto.getGoodsName());
+        bizWaybillOrder.setGoodsWeight(dto.getGoodsWeight());
+        bizWaybillOrder.setGoodsVolume(dto.getGoodsVolume());
+        bizWaybillOrder.setGoodsQty(dto.getGoodsQty());
+        
+        // 取件时间
+        bizWaybillOrder.setSendStartTime(dto.getSendStartTime());
+        bizWaybillOrder.setSendEndTime(dto.getSendEndTime());
+        
+        // 产品信息和增值服务
+        bizWaybillOrder.setProductCode(dto.getProductCode());
+        bizWaybillOrder.setAddedService(dto.getAddedService());
+        
+        // 备注
+        bizWaybillOrder.setRemark(dto.getRemark());
+        
+        return bizWaybillOrder;
+    }
 }