From cccbfadcb6e96c23a33c40c0687a27c2f6efa1db Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 09 十一月 2026 13:16:42 +0800
Subject: [PATCH] feat(seal): 添加印章详情及图片预览功能

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/wm/productsales/MesWmProductSalesController.java |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 105 insertions(+), 10 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..f4efd0f 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,16 +8,24 @@
 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.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.productsales.MesWmProductSalesLineDO;
 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.document.MesWmDocumentRenderer;
+import cn.iocoder.yudao.module.mes.service.wm.productsales.MesWmProductSalesLineService;
 import cn.iocoder.yudao.module.mes.service.wm.productsales.MesWmProductSalesService;
 import cn.iocoder.yudao.module.mes.service.wm.salesnotice.MesWmSalesNoticeService;
+import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi;
+import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO;
+import cn.iocoder.yudao.module.mdm.api.unit.MdmUnitMeasureApi;
+import cn.iocoder.yudao.module.mdm.api.unit.dto.MdmUnitMeasureRespDTO;
+import cn.iocoder.yudao.module.system.service.companyconfig.SystemCompanyConfigService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -29,11 +37,16 @@
 import org.springframework.web.bind.annotation.*;
 
 import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 
 import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
+import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_PRODUCT_SALES_NOT_EXISTS;
 
 @Tag(name = "绠$悊鍚庡彴 - MES 閿�鍞嚭搴撳崟")
 @RestController
@@ -44,9 +57,17 @@
     @Resource
     private MesWmProductSalesService productSalesService;
     @Resource
-    private MesMdClientService clientService;
+    private MesWmProductSalesLineService productSalesLineService;
+    @Resource
+    private CrmCustomerApi crmCustomerApi;
     @Resource
     private MesWmSalesNoticeService salesNoticeService;
+    @Resource
+    private MdmItemApi mdmItemApi;
+    @Resource
+    private MdmUnitMeasureApi mdmUnitMeasureApi;
+    @Resource
+    private SystemCompanyConfigService companyConfigService;
 
     @PostMapping("/create")
     @Operation(summary = "鍒涘缓閿�鍞嚭搴撳崟")
@@ -75,7 +96,6 @@
     @GetMapping("/get")
     @Operation(summary = "鑾峰緱閿�鍞嚭搴撳崟")
     @Parameter(name = "id", description = "缂栧彿", required = true, example = "1024")
-    @PreAuthorize("@ss.hasPermission('mes:wm-product-sales:query')")
     public CommonResult<MesWmProductSalesRespVO> getProductSales(@RequestParam("id") Long id) {
         MesWmProductSalesDO sales = productSalesService.getProductSales(id);
         if (sales == null) {
@@ -86,7 +106,6 @@
 
     @GetMapping("/page")
     @Operation(summary = "鑾峰緱閿�鍞嚭搴撳崟鍒嗛〉")
-    @PreAuthorize("@ss.hasPermission('mes:wm-product-sales:query')")
     public CommonResult<PageResult<MesWmProductSalesRespVO>> getProductSalesPage(
             @Valid MesWmProductSalesPageReqVO pageReqVO) {
         PageResult<MesWmProductSalesDO> pageResult = productSalesService.getProductSalesPage(pageReqVO);
@@ -105,6 +124,83 @@
                 buildRespVOList(pageResult.getList()));
     }
 
+    @GetMapping("/export-word")
+    @Operation(summary = "瀵煎嚭鎴愬搧鍑哄簱鍗� Word锛堝甫鐢靛瓙绔狅紝鍙墜濉瀛楀悗褰掓。锛�")
+    @Parameter(name = "id", description = "閿�鍞嚭搴撳崟缂栧彿", required = true)
+    @PreAuthorize("@ss.hasPermission('mes:wm-product-sales:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportProductSalesWord(@RequestParam("id") Long id,
+                                       HttpServletResponse response) throws IOException {
+        MesWmProductSalesDO sales = productSalesService.getProductSales(id);
+        if (sales == null) {
+            throw exception(WM_PRODUCT_SALES_NOT_EXISTS);
+        }
+        List<MesWmProductSalesLineDO> lines = productSalesLineService.getProductSalesLineListBySalesId(id);
+        Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap(
+                convertSet(lines, MesWmProductSalesLineDO::getItemId));
+        Map<Long, MdmUnitMeasureRespDTO> unitMap = mdmUnitMeasureApi
+                .getUnitMeasureList(convertSet(itemMap.values(), MdmItemRespDTO::getUnitMeasureId))
+                .getCheckedData().stream()
+                .collect(java.util.stream.Collectors.toMap(MdmUnitMeasureRespDTO::getId, e -> e));
+
+        Map<String, String> fields = new LinkedHashMap<>();
+        fields.put("clientName", resolveClientName(sales.getClientId()));
+        fields.put("code", sales.getCode());
+        fields.put("salesDate", sales.getSalesDate() == null ? null
+                : sales.getSalesDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+        fields.put("saleOrderCode", sales.getSalesOrderCode());
+        fields.put("noticeCode", resolveNoticeCode(sales.getNoticeId()));
+        fields.put("contactName", sales.getContactName());
+        fields.put("contactTelephone", sales.getContactTelephone());
+        fields.put("contactAddress", sales.getContactAddress());
+        fields.put("carrier", sales.getCarrier());
+        fields.put("shippingNumber", sales.getShippingNumber());
+        fields.put("remark", sales.getRemark());
+
+        List<Map<String, String>> items = new ArrayList<>();
+        for (MesWmProductSalesLineDO line : lines) {
+            MdmItemRespDTO item = itemMap.get(line.getItemId());
+            Map<String, String> row = new LinkedHashMap<>();
+            row.put("itemName", item != null ? item.getName() : null);
+            row.put("itemSpecification", item != null ? item.getSpecification() : null);
+            MdmUnitMeasureRespDTO unit = item != null ? unitMap.get(item.getUnitMeasureId()) : null;
+            row.put("unitName", unit != null ? unit.getName() : null);
+            row.put("quantity", line.getQuantity() == null ? null : line.getQuantity().toPlainString());
+            row.put("price", line.getPrice() == null ? null : line.getPrice().toPlainString());
+            row.put("amount", line.getTotalPrice() == null ? null : line.getTotalPrice().toPlainString());
+            row.put("batchCode", line.getBatchCode());
+            items.add(row);
+        }
+
+        var companyConfig = companyConfigService.getCompanyConfig();
+        byte[] content = MesWmDocumentRenderer.renderProductOutbound(fields, items,
+                companyConfig != null ? companyConfig.getCompanyName() : null);
+        writeWord(response, "鎴愬搧鍑哄簱鍗�-" + sales.getCode() + ".docx", content);
+    }
+
+    private String resolveClientName(Long clientId) {
+        if (clientId == null) {
+            return null;
+        }
+        CrmCustomerRespDTO customer = crmCustomerApi.getCustomer(clientId);
+        return customer != null ? customer.getName() : null;
+    }
+
+    private String resolveNoticeCode(Long noticeId) {
+        if (noticeId == null) {
+            return null;
+        }
+        MesWmSalesNoticeDO notice = salesNoticeService.getSalesNotice(noticeId);
+        return notice != null ? notice.getCode() : null;
+    }
+
+    private static void writeWord(HttpServletResponse response, String filename, byte[] content) throws IOException {
+        String encoded = URLEncoder.encode(filename, StandardCharsets.UTF_8).replace("+", "%20");
+        response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
+        response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + encoded);
+        response.getOutputStream().write(content);
+    }
+
     @PutMapping("/submit")
     @Operation(summary = "鎻愪氦閿�鍞嚭搴撳崟")
     @Parameter(name = "id", description = "缂栧彿", required = true)
@@ -117,7 +213,6 @@
     @GetMapping("/check-quantity")
     @Operation(summary = "鏍¢獙閿�鍞嚭搴撳崟鏁伴噺")
     @Parameter(name = "id", description = "缂栧彿", required = true)
-    @PreAuthorize("@ss.hasPermission('mes:wm-product-sales:query')")
     public CommonResult<Boolean> checkProductSalesQuantity(@RequestParam("id") Long id) {
         return success(productSalesService.checkProductSalesQuantity(id));
     }
@@ -164,17 +259,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