From 46855633ce1809df905efa8e0b03ca94a49a227b Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期六, 31 十月 2026 13:48:21 +0800
Subject: [PATCH] feat(mes): 销售出库单支持 Excel 导入
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/wm/productsales/MesWmProductSalesController.java | 48 +++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 41 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..d4debfe 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,14 +8,16 @@
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;
@@ -27,8 +29,10 @@
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.math.BigDecimal;
import java.util.*;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
@@ -44,7 +48,7 @@
@Resource
private MesWmProductSalesService productSalesService;
@Resource
- private MesMdClientService clientService;
+ private CrmCustomerApi crmCustomerApi;
@Resource
private MesWmSalesNoticeService salesNoticeService;
@@ -103,6 +107,36 @@
PageResult<MesWmProductSalesDO> pageResult = productSalesService.getProductSalesPage(pageReqVO);
ExcelUtils.write(response, "閿�鍞嚭搴撳崟.xls", "鏁版嵁", MesWmProductSalesRespVO.class,
buildRespVOList(pageResult.getList()));
+ }
+
+ @GetMapping("/get-import-template")
+ @Operation(summary = "鑾峰緱閿�鍞嚭搴撳崟瀵煎叆妯℃澘")
+ @PreAuthorize("@ss.hasPermission('mes:wm-product-sales:import')")
+ public void importTemplate(HttpServletResponse response) throws IOException {
+ List<MesWmProductSalesImportExcelVO> list = Arrays.asList(
+ // 鍚屼竴鍑哄簱鍗曞彿鐨勪袱琛� = 鍚屼竴寮犲嚭搴撳崟鐨勪袱鏉℃槑缁�
+ MesWmProductSalesImportExcelVO.builder()
+ .code("PS202610310001").clientName("绀轰緥瀹㈡埛").name("绀轰緥瀹㈡埛-2026-10-31 鍑哄簱")
+ .salesDate("2026-10-31").salesOrderCode("").contactName("寮犱笁")
+ .contactTelephone("13800138000").contactAddress("绀轰緥鏀惰揣鍦板潃")
+ .itemCode("ITEM001").batchCode("").quantity(new BigDecimal("10"))
+ .oqcCheckFlag("鍚�").remark("绀轰緥鏁版嵁锛屽鍏ュ墠璇锋浛鎹�").build(),
+ MesWmProductSalesImportExcelVO.builder()
+ .code("PS202610310001").clientName("绀轰緥瀹㈡埛").name("绀轰緥瀹㈡埛-2026-10-31 鍑哄簱")
+ .salesDate("2026-10-31").salesOrderCode("").contactName("寮犱笁")
+ .contactTelephone("13800138000").contactAddress("绀轰緥鏀惰揣鍦板潃")
+ .itemCode("ITEM002").batchCode("").quantity(new BigDecimal("5"))
+ .oqcCheckFlag("鍚�").remark("绀轰緥鏁版嵁锛屽鍏ュ墠璇锋浛鎹�").build());
+ ExcelUtils.write(response, "閿�鍞嚭搴撳崟瀵煎叆妯℃澘.xls", "閿�鍞嚭搴撳崟", MesWmProductSalesImportExcelVO.class, list);
+ }
+
+ @PostMapping("/import")
+ @Operation(summary = "瀵煎叆閿�鍞嚭搴撳崟", description = "瀵煎叆鍚庣敓鎴愯崏绋跨姸鎬佺殑鍑哄簱鍗曪紝涓嶆彁浜ゃ�佷笉鍗犵敤搴撳瓨")
+ @PreAuthorize("@ss.hasPermission('mes:wm-product-sales:import')")
+ public CommonResult<MesWmProductSalesImportRespVO> importProductSalesExcel(
+ @RequestParam("file") MultipartFile file) throws Exception {
+ List<MesWmProductSalesImportExcelVO> list = ExcelUtils.read(file, MesWmProductSalesImportExcelVO.class);
+ return success(productSalesService.importProductSalesList(list));
}
@PutMapping("/submit")
@@ -164,17 +198,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