From a647bc8a43c0212f482bee0630ebd14dca120a8a Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期一, 28 九月 2026 14:13:28 +0800
Subject: [PATCH] feat: CRM 发票/合同导入、MES 质检批量导入与检测台账、回款与报价校验、权限码细化

---
 yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java |  101 +++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 87 insertions(+), 14 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 a2a70b4..183ce36 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
@@ -13,18 +13,24 @@
 import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractPageReqVO;
 import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractRespVO;
 import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractSaveReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractImportExcelVO;
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractImportRespVO;
 import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractTransferReqVO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractProductDO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
-import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
+import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum;
+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.crm.service.business.CrmBusinessService;
 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.product.CrmProductService;
+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;
@@ -39,9 +45,11 @@
 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.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -69,9 +77,14 @@
     @Resource
     private CrmBusinessService businessService;
     @Resource
-    private CrmProductService productService;
-    @Resource
     private CrmReceivableService receivableService;
+    @Resource
+    private CrmInvoiceService invoiceService;
+
+    @Resource
+    private MdmItemApi mdmItemApi;
+    @Resource
+    private MdmUnitMeasureApi mdmUnitMeasureApi;
 
     @Resource
     private AdminUserApi adminUserApi;
@@ -118,12 +131,18 @@
         CrmContractRespVO contractVO = buildContractDetailList(singletonList(contract)).get(0);
         // 鎷兼帴浜у搧椤�
         List<CrmContractProductDO> businessProducts = contractService.getContractProductListByContractId(contractVO.getId());
-        Map<Long, CrmProductDO> productMap = productService.getProductMap(
-                convertSet(businessProducts, CrmContractProductDO::getProductId));
+        Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap(
+                convertSet(businessProducts, CrmContractProductDO::getItemId));
         contractVO.setProducts(BeanUtils.toBean(businessProducts, CrmContractRespVO.Product.class, businessProductVO ->
-                MapUtils.findAndThen(productMap, businessProductVO.getProductId(),
-                        product -> businessProductVO.setProductName(product.getName())
-                                .setProductNo(product.getNo()).setProductUnit(product.getUnit()))));
+                MapUtils.findAndThen(itemMap, businessProductVO.getItemId(),
+                        item -> businessProductVO.setItemCode(item.getCode())
+                                .setItemName(item.getName()).setBarCode(item.getBarCode())
+                                .setItemSpecification(item.getSpecification()))));
+        // 鎷兼帴璁¢噺鍗曚綅鍚嶇О
+        Map<Long, MdmUnitMeasureRespDTO> unitMap = mdmUnitMeasureApi.getUnitMeasureMap(
+                convertSet(businessProducts, CrmContractProductDO::getItemUnitId));
+        contractVO.getProducts().forEach(product -> MapUtils.findAndThen(unitMap, product.getItemUnitId(),
+                unit -> product.setItemUnitName(unit.getName())));
         return contractVO;
     }
 
@@ -158,9 +177,43 @@
     public void exportContractExcel(@Valid CrmContractPageReqVO exportReqVO,
                                     HttpServletResponse response) throws IOException {
         PageResult<CrmContractDO> pageResult = contractService.getContractPage(exportReqVO, getLoginUserId());
+        // 鎷兼帴瀹㈡埛銆佸晢鏈恒�佺绾︿汉銆佸洖娆鹃噾棰濈瓑鍏宠仈淇℃伅
+        List<CrmContractRespVO> list = buildContractDetailList(pageResult.getList());
+        // 璁$畻鏈洖娆鹃噾棰濄�佽浆鎹㈠鎵圭姸鎬佷负涓枃
+        list.forEach(vo -> {
+            if (vo.getTotalPrice() != null && vo.getTotalReceivablePrice() != null) {
+                vo.setUnReceivablePrice(vo.getTotalPrice().subtract(vo.getTotalReceivablePrice()));
+            }
+            if (vo.getAuditStatus() != null) {
+                vo.setAuditStatusName(CrmAuditStatusEnum.getNameByStatus(vo.getAuditStatus()));
+            }
+        });
         // 瀵煎嚭 Excel
-        ExcelUtils.write(response, "鍚堝悓.xls", "鏁版嵁", CrmContractRespVO.class,
-                BeanUtils.toBean(pageResult.getList(), CrmContractRespVO.class));
+        ExcelUtils.write(response, "鍚堝悓.xls", "鏁版嵁", CrmContractRespVO.class, list);
+    }
+
+    @GetMapping("/get-import-template")
+    @Operation(summary = "鑾峰緱瀵煎叆鍚堝悓妯℃澘")
+    @PreAuthorize("@ss.hasPermission('crm:contract:import')")
+    public void importTemplate(HttpServletResponse response) throws IOException {
+        List<CrmContractImportExcelVO> list = Collections.singletonList(
+                CrmContractImportExcelVO.builder()
+                        .no("HT20260101000001").name("绀轰緥鍚堝悓").customerName("绀轰緥瀹㈡埛")
+                        .orderDate("2026-01-01 10:00:00").startTime("2026-01-01").endTime("2026-12-31")
+                        .discountPercent(new BigDecimal("0")).depositPrice(new BigDecimal("0"))
+                        .productCode("ITEM001").productName("绀轰緥浜у搧A")
+                        .count(new BigDecimal("100")).contractPrice(new BigDecimal("20.00")).remark("绀轰緥鏁版嵁锛屽鍏ュ墠璇锋浛鎹�")
+                        .build());
+        ExcelUtils.write(response, "鍚堝悓瀵煎叆妯℃澘.xls", "鍚堝悓", CrmContractImportExcelVO.class, list);
+    }
+
+    @PostMapping("/import")
+    @Operation(summary = "瀵煎叆鍚堝悓")
+    @PreAuthorize("@ss.hasPermission('crm:contract:import')")
+    public CommonResult<CrmContractImportRespVO> importContractExcel(@RequestParam("file") MultipartFile file) throws Exception {
+        // readFlat锛氭妸绾靛悜鍚堝苟鍗曞厓鏍硷紙鍚屼竴寮犲悎鍚岀殑澶氳鏄庣粏锛夋媺骞筹紝鍚﹀垯闄ら琛屽鐨勪富琛ㄥ瓧娈典細璇讳笉鍒�
+        List<CrmContractImportExcelVO> list = ExcelUtils.readFlat(file, CrmContractImportExcelVO.class);
+        return success(contractService.importContractList(list));
     }
 
     @PutMapping("/transfer")
@@ -174,9 +227,17 @@
     @PutMapping("/submit")
     @Operation(summary = "鎻愪氦鍚堝悓瀹℃壒")
     @PreAuthorize("@ss.hasPermission('crm:contract:update')")
-    public CommonResult<Boolean> submitContract(@RequestParam("id") Long id) {
-        contractService.submitContract(id, getLoginUserId());
+    public CommonResult<Boolean> submitContract(@RequestParam("id") Long id,
+                                                  @RequestParam("processDefinitionKey") String processDefinitionKey) {
+        contractService.submitContract(id, processDefinitionKey, getLoginUserId());
         return success(true);
+    }
+
+    @GetMapping("/approve-process-list")
+    @Operation(summary = "鑾峰彇鍚堝悓瀹℃壒娴佺▼鍒楄〃")
+    @PreAuthorize("@ss.hasPermission('crm:contract:query')")
+    public CommonResult<List<Map<String, Object>>> getContractApproveProcessList() {
+        return success(contractService.getContractApproveProcessDefinitionList());
     }
 
     private List<CrmContractRespVO> buildContractDetailList(List<CrmContractDO> contractList) {
@@ -199,6 +260,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 璁剧疆瀹㈡埛淇℃伅
@@ -216,6 +280,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()));
+            }
         });
     }
 
@@ -247,10 +317,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