From 87bf4a997a1aeff9b9b89172b574bb4017f16b3c Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期二, 08 九月 2026 17:22:47 +0800
Subject: [PATCH] fix(crm): 合同导出补全客户/商机等关联名称

---
 yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java
index 4de695d..45b5f89 100644
--- a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java
+++ b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java
@@ -26,6 +26,7 @@
 import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
 import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
 import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
+import cn.iocoder.yudao.module.crm.service.invoice.CrmInvoiceService;
 import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService;
 import cn.iocoder.yudao.module.system.api.dept.DeptApi;
 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
@@ -71,6 +72,8 @@
     private CrmBusinessService businessService;
     @Resource
     private CrmReceivableService receivableService;
+    @Resource
+    private CrmInvoiceService invoiceService;
 
     @Resource
     private MdmItemApi mdmItemApi;
@@ -160,7 +163,8 @@
     public void exportContractExcel(@Valid CrmContractPageReqVO exportReqVO,
                                     HttpServletResponse response) throws IOException {
         PageResult<CrmContractDO> pageResult = contractService.getContractPage(exportReqVO, getLoginUserId());
-        List<CrmContractRespVO> list = BeanUtils.toBean(pageResult.getList(), CrmContractRespVO.class);
+        // 鎷兼帴瀹㈡埛銆佸晢鏈恒�佺绾︿汉銆佸洖娆鹃噾棰濈瓑鍏宠仈淇℃伅
+        List<CrmContractRespVO> list = buildContractDetailList(pageResult.getList());
         // 璁$畻鏈洖娆鹃噾棰濄�佽浆鎹㈠鎵圭姸鎬佷负涓枃
         list.forEach(vo -> {
             if (vo.getTotalPrice() != null && vo.getTotalReceivablePrice() != null) {
@@ -218,6 +222,9 @@
         // 1.5 鑾峰緱宸插洖娆鹃噾棰�
         Map<Long, BigDecimal> receivablePriceMap = receivableService.getReceivablePriceMapByContractId(
                 convertSet(contractList, CrmContractDO::getId));
+        // 1.6 鑾峰緱宸插紑绁ㄩ噾棰濓紙瀹℃壒閫氳繃 + 瀹℃壒涓紝涓庡紑绁ㄩ槻瓒呮牎楠屽彛寰勪竴鑷达級
+        Map<Long, BigDecimal> invoicePriceMap = invoiceService.getInvoicePriceMapByContractId(
+                convertSet(contractList, CrmContractDO::getId));
         // 2. 鎷兼帴鏁版嵁
         return BeanUtils.toBean(contractList, CrmContractRespVO.class, contractVO -> {
             // 2.1 璁剧疆瀹㈡埛淇℃伅
@@ -235,6 +242,12 @@
             findAndThen(businessMap, contractVO.getBusinessId(), business -> contractVO.setBusinessName(business.getName()));
             // 2.5 璁剧疆宸插洖娆鹃噾棰�
             contractVO.setTotalReceivablePrice(receivablePriceMap.getOrDefault(contractVO.getId(), BigDecimal.ZERO));
+            // 2.6 璁剧疆宸插紑绁ㄩ噾棰�
+            contractVO.setTotalInvoicePrice(invoicePriceMap.getOrDefault(contractVO.getId(), BigDecimal.ZERO));
+            // 2.7 璁剧疆鏈紑绁ㄩ噾棰�
+            if (contractVO.getTotalPrice() != null && contractVO.getTotalInvoicePrice() != null) {
+                contractVO.setUnInvoicePrice(contractVO.getTotalPrice().subtract(contractVO.getTotalInvoicePrice()));
+            }
         });
     }
 
@@ -266,10 +279,13 @@
         // 鎷兼帴鏁版嵁
         Map<Long, BigDecimal> receivablePriceMap = receivableService.getReceivablePriceMapByContractId(
                 convertSet(pageResult.getList(), CrmContractDO::getId));
+        Map<Long, BigDecimal> invoicePriceMap = invoiceService.getInvoicePriceMapByContractId(
+                convertSet(pageResult.getList(), CrmContractDO::getId));
         return success(convertList(pageResult.getList(), contract -> new CrmContractRespVO() // 鍙繑鍥� id銆乶ame 绛夌簿绠�瀛楁
                 .setId(contract.getId()).setName(contract.getName()).setAuditStatus(contract.getAuditStatus())
                 .setTotalPrice(contract.getTotalPrice())
-                .setTotalReceivablePrice(receivablePriceMap.getOrDefault(contract.getId(), BigDecimal.ZERO))));
+                .setTotalReceivablePrice(receivablePriceMap.getOrDefault(contract.getId(), BigDecimal.ZERO))
+                .setTotalInvoicePrice(invoicePriceMap.getOrDefault(contract.getId(), BigDecimal.ZERO))));
     }
 
     @PostMapping("/generate-sale-order")

--
Gitblit v1.9.3