From f02d0df2f1dfc7a8b775cf50d45375e57628a5ef Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 10 十一月 2026 11:26:22 +0800
Subject: [PATCH] feat(ncr): 完善NCR处置联动逻辑与关闭校验

---
 yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/quotation/CrmSaleQuotationController.java |   69 ++++++++++++++++++++++++++++++++--
 1 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/quotation/CrmSaleQuotationController.java b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/quotation/CrmSaleQuotationController.java
index af0912e..870fe71 100644
--- a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/quotation/CrmSaleQuotationController.java
+++ b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/quotation/CrmSaleQuotationController.java
@@ -17,7 +17,11 @@
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
 import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
 import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
+import cn.iocoder.yudao.module.crm.enums.quotation.CrmSaleQuotationStatusEnum;
+import cn.iocoder.yudao.module.crm.service.quotation.CrmSaleQuotationExcelRenderer;
+import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
 import cn.iocoder.yudao.module.crm.service.quotation.CrmSaleQuotationService;
+import cn.iocoder.yudao.module.system.service.companyconfig.SystemCompanyConfigService;
 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;
@@ -38,6 +42,8 @@
 import org.springframework.web.bind.annotation.*;
 
 import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Map;
 
@@ -47,7 +53,10 @@
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
+import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.SALE_QUOTATION_EXPORT_FAIL_NOT_APPROVE;
+import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.SALE_QUOTATION_NOT_EXISTS;
 
 @Tag(name = "绠$悊鍚庡彴 - CRM 閿�鍞姤浠峰崟")
 @RestController
@@ -69,9 +78,13 @@
     @Resource
     private CrmCustomerService customerService;
     @Resource
+    private CrmContactService contactService;
+    @Resource
     private CrmBusinessService businessService;
     @Resource
     private StorageAttachmentApi storageAttachmentApi;
+    @Resource
+    private SystemCompanyConfigService companyConfigService;
 
     @PostMapping("/create")
     @Operation(summary = "鍒涘缓閿�鍞姤浠峰崟")
@@ -114,7 +127,6 @@
     @GetMapping("/get")
     @Operation(summary = "鑾峰緱閿�鍞姤浠峰崟")
     @Parameter(name = "id", description = "缂栧彿", required = true, example = "1024")
-    @PreAuthorize("@ss.hasPermission('crm:sale-quotation:query')")
     public CommonResult<CrmSaleQuotationRespVO> getSaleQuotation(@RequestParam("id") Long id) {
         CrmSaleQuotationDO saleQuotation = saleQuotationService.getSaleQuotation(id);
         if (saleQuotation == null) {
@@ -126,7 +138,6 @@
 
     @GetMapping("/page")
     @Operation(summary = "鑾峰緱閿�鍞姤浠峰崟鍒嗛〉")
-    @PreAuthorize("@ss.hasPermission('crm:sale-quotation:query')")
     public CommonResult<PageResult<CrmSaleQuotationRespVO>> getSaleQuotationPage(@Valid CrmSaleQuotationPageReqVO pageReqVO) {
         PageResult<CrmSaleQuotationDO> pageResult = saleQuotationService.getSaleQuotationPage(pageReqVO, getLoginUserId());
         return success(buildSaleQuotationRespVOPageResult(pageResult));
@@ -134,7 +145,6 @@
 
     @GetMapping("/page-by-customer")
     @Operation(summary = "鑾峰緱閿�鍞姤浠峰崟鍒嗛〉锛堝熀浜庡鎴凤級")
-    @PreAuthorize("@ss.hasPermission('crm:sale-quotation:query')")
     public CommonResult<PageResult<CrmSaleQuotationRespVO>> getSaleQuotationPageByCustomerId(@Valid CrmSaleQuotationPageReqVO pageReqVO) {
         PageResult<CrmSaleQuotationDO> pageResult = saleQuotationService.getSaleQuotationPageByCustomerId(pageReqVO);
         return success(buildSaleQuotationRespVOPageResult(pageResult));
@@ -142,7 +152,6 @@
 
     @GetMapping("/page-by-business")
     @Operation(summary = "鑾峰緱閿�鍞姤浠峰崟鍒嗛〉锛堝熀浜庡晢鏈猴級")
-    @PreAuthorize("@ss.hasPermission('crm:sale-quotation:query')")
     public CommonResult<PageResult<CrmSaleQuotationRespVO>> getSaleQuotationPageByBusinessId(@Valid CrmSaleQuotationPageReqVO pageReqVO) {
         PageResult<CrmSaleQuotationDO> pageResult = saleQuotationService.getSaleQuotationPageByBusinessId(pageReqVO);
         return success(buildSaleQuotationRespVOPageResult(pageResult));
@@ -160,6 +169,58 @@
         ExcelUtils.write(response, "閿�鍞姤浠峰崟.xls", "鏁版嵁", CrmSaleQuotationRespVO.class, list);
     }
 
+    @GetMapping({"/export-word", "/export-quotation-excel"})
+    @Operation(summary = "瀵煎嚭閿�鍞姤浠峰崟 Excel锛堝甫鐢靛瓙绔狅級")
+    @Parameter(name = "id", description = "鎶ヤ环鍗曠紪鍙�", required = true)
+    @PreAuthorize("@ss.hasPermission('crm:sale-quotation:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportSaleQuotationWord(@RequestParam("id") Long id,
+                                        HttpServletResponse response) throws IOException {
+        CrmSaleQuotationDO saleQuotation = saleQuotationService.getSaleQuotation(id);
+        if (saleQuotation == null) {
+            throw exception(SALE_QUOTATION_NOT_EXISTS);
+        }
+        if (!CrmSaleQuotationStatusEnum.APPROVE.getStatus().equals(saleQuotation.getStatus())
+                && !CrmSaleQuotationStatusEnum.CONVERTED.getStatus().equals(saleQuotation.getStatus())) {
+            CrmSaleQuotationStatusEnum current = CrmSaleQuotationStatusEnum.getByStatus(saleQuotation.getStatus());
+            throw exception(SALE_QUOTATION_EXPORT_FAIL_NOT_APPROVE, saleQuotation.getNo(),
+                    current != null ? current.getName() : String.valueOf(saleQuotation.getStatus()));
+        }
+        CrmSaleQuotationRespVO respVO = buildSaleQuotationRespVO(saleQuotation,
+                saleQuotationService.getSaleQuotationProductListByQuotationId(id));
+        var companyConfig = companyConfigService.getCompanyConfig();
+        String companyName = companyConfig != null ? companyConfig.getCompanyName() : null;
+        var customer = saleQuotation.getCustomerId() == null ? null : customerService.getCustomer(saleQuotation.getCustomerId());
+        var contact = saleQuotation.getContactId() == null ? null : contactService.getContact(saleQuotation.getContactId());
+        String phone = contact == null ? null : (contact.getMobile() != null && !contact.getMobile().isBlank()
+                ? contact.getMobile() : contact.getTelephone());
+        byte[] content = CrmSaleQuotationExcelRenderer.render(respVO, companyName,
+                customer == null ? null : customer.getDetailAddress(), contact == null ? null : contact.getName(), phone);
+
+        String filename = "鎶ヤ环鍗�-" + saleQuotation.getNo()
+                + (respVO.getCustomerName() != null ? "-" + respVO.getCustomerName() : "") + ".xlsx";
+        String encoded = URLEncoder.encode(filename, StandardCharsets.UTF_8).replace("+", "%20");
+        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+        response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + encoded);
+        response.getOutputStream().write(content);
+    }
+
+    @PutMapping("/submit")
+    @Operation(summary = "鎻愪氦閿�鍞姤浠峰鎵�")
+    @Parameter(name = "id", description = "鎶ヤ环鍗曠紪鍙�", required = true)
+    @PreAuthorize("@ss.hasPermission('crm:sale-quotation:update')")
+    public CommonResult<Boolean> submitSaleQuotation(@RequestParam("id") Long id,
+                                                     @RequestParam(value = "processDefinitionKey", required = false) String processDefinitionKey) {
+        saleQuotationService.submitSaleQuotation(id, processDefinitionKey, getLoginUserId());
+        return success(true);
+    }
+
+    @GetMapping("/approve-process-list")
+    @Operation(summary = "鑾峰彇閿�鍞姤浠峰鎵规祦绋嬪垪琛�")
+    public CommonResult<List<Map<String, Object>>> getSaleQuotationApproveProcessList() {
+        return success(saleQuotationService.getSaleQuotationApproveProcessDefinitionList());
+    }
+
     @PostMapping("/convert-contract")
     @Operation(summary = "杞负鍚堝悓")
     @Parameter(name = "id", description = "鎶ヤ环鍗曠紪鍙�", required = true)

--
Gitblit v1.9.3