From 7d6825d2344db398b7cd142fea419242db033c54 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 16 十月 2026 14:37:50 +0800
Subject: [PATCH] fix(excel): 修复导入模板下载失败的两个问题

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/wm/productsales/MesWmProductSalesController.java |   46 +++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/wm/productsales/MesWmProductSalesController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/wm/productsales/MesWmProductSalesController.java
index cdd84a8..79e242d 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/wm/productsales/MesWmProductSalesController.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/wm/productsales/MesWmProductSalesController.java
@@ -8,18 +8,21 @@
 import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi;
+import cn.iocoder.yudao.module.crm.api.customer.dto.CrmCustomerRespDTO;
+import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesImportExcelVO;
+import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesImportRespVO;
 import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesPageReqVO;
 import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesRespVO;
 import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesSaveReqVO;
 import cn.iocoder.yudao.module.mes.controller.admin.wm.productsales.vo.MesWmProductSalesShippingReqVO;
-import cn.iocoder.yudao.module.mes.dal.dataobject.md.client.MesMdClientDO;
 import cn.iocoder.yudao.module.mes.dal.dataobject.wm.productsales.MesWmProductSalesDO;
 import cn.iocoder.yudao.module.mes.dal.dataobject.wm.salesnotice.MesWmSalesNoticeDO;
-import cn.iocoder.yudao.module.mes.service.md.client.MesMdClientService;
 import cn.iocoder.yudao.module.mes.service.wm.productsales.MesWmProductSalesService;
 import cn.iocoder.yudao.module.mes.service.wm.salesnotice.MesWmSalesNoticeService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Parameters;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.annotation.Resource;
 import jakarta.servlet.http.HttpServletResponse;
@@ -27,6 +30,7 @@
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
 import java.util.*;
@@ -44,7 +48,7 @@
     @Resource
     private MesWmProductSalesService productSalesService;
     @Resource
-    private MesMdClientService clientService;
+    private CrmCustomerApi crmCustomerApi;
     @Resource
     private MesWmSalesNoticeService salesNoticeService;
 
@@ -157,6 +161,34 @@
         return success(true);
     }
 
+    @GetMapping("/get-import-template")
+    @Operation(summary = "鑾峰緱閿�鍞嚭搴撳崟瀵煎叆妯℃澘")
+    public void importTemplate(HttpServletResponse response) throws IOException {
+        // 鎵嬪姩鍒涘缓瀵煎嚭 demo
+        List<MesWmProductSalesImportExcelVO> list = Collections.singletonList(
+                MesWmProductSalesImportExcelVO.builder()
+                        .code("XS001").name("绀轰緥閿�鍞嚭搴撳崟")
+                        .salesDate(java.time.LocalDateTime.now()).salesOrderCode("SO001")
+                        .contactName("寮犱笁").remark("").build()
+        );
+        // 杈撳嚭
+        ExcelUtils.write(response, "閿�鍞嚭搴撳崟瀵煎叆妯℃澘.xls", "閿�鍞嚭搴撳崟鍒楄〃", MesWmProductSalesImportExcelVO.class, list);
+    }
+
+    @PostMapping("/import")
+    @Operation(summary = "瀵煎叆閿�鍞嚭搴撳崟")
+    @Parameters({
+            @Parameter(name = "file", description = "Excel 鏂囦欢", required = true),
+            @Parameter(name = "updateSupport", description = "鏄惁鏀寔鏇存柊锛岄粯璁や负 false", example = "true")
+    })
+    @PreAuthorize("@ss.hasPermission('mes:wm-product-sales:import')")
+    public CommonResult<MesWmProductSalesImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
+                                                                   @RequestParam(value = "updateSupport", required = false,
+                                                                           defaultValue = "false") Boolean updateSupport) throws Exception {
+        List<MesWmProductSalesImportExcelVO> list = ExcelUtils.read(file, MesWmProductSalesImportExcelVO.class);
+        return success(productSalesService.importProductSalesList(list, updateSupport));
+    }
+
     // ==================== 鎷兼帴 VO ====================
 
     private List<MesWmProductSalesRespVO> buildRespVOList(List<MesWmProductSalesDO> list) {
@@ -164,17 +196,17 @@
             return Collections.emptyList();
         }
         // 1. 鑾峰緱鍏宠仈鏁版嵁
-        Map<Long, MesMdClientDO> clientMap = clientService.getClientMap(
+        Map<Long, CrmCustomerRespDTO> customerMap = crmCustomerApi.getCustomerMap(
                 convertSet(list, MesWmProductSalesDO::getClientId));
         Map<Long, MesWmSalesNoticeDO> noticeMap = salesNoticeService.getSalesNoticeMap(
                 convertSet(list, MesWmProductSalesDO::getNoticeId));
         // 2. 鏋勫缓缁撴灉
         return BeanUtils.toBean(list, MesWmProductSalesRespVO.class, vo -> {
-            MapUtils.findAndThen(clientMap, vo.getClientId(), client ->
-                    vo.setClientName(client.getName()).setClientCode(client.getCode()));
+            MapUtils.findAndThen(customerMap, vo.getClientId(), customer ->
+                    vo.setClientName(customer.getName()));
             MapUtils.findAndThen(noticeMap, vo.getNoticeId(),
                     notice -> vo.setNoticeCode(notice.getCode()));
         });
     }
 
-}
+}
\ No newline at end of file

--
Gitblit v1.9.3