From a82d847bbb39e2417d4c9773ebc4fc51fdb0b8fc Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 10 十一月 2026 13:31:31 +0800
Subject: [PATCH] feat(crm): 完善投标保证金与报价单关联及作废功能

---
 yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/quotation/CrmSaleQuotationController.java |  160 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 153 insertions(+), 7 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 fda9a92..dd0bb9b 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
@@ -8,16 +8,25 @@
 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.controller.admin.quotation.vo.CrmSaleQuotationOptionRespVO;
 import cn.iocoder.yudao.module.crm.controller.admin.quotation.vo.CrmSaleQuotationPageReqVO;
 import cn.iocoder.yudao.module.crm.controller.admin.quotation.vo.CrmSaleQuotationRespVO;
+import cn.iocoder.yudao.module.crm.controller.admin.quotation.vo.CrmSaleQuotationRevisionRespVO;
 import cn.iocoder.yudao.module.crm.controller.admin.quotation.vo.CrmSaleQuotationSaveReqVO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.bidbond.CrmBidBondDO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.quotation.CrmSaleQuotationDO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.quotation.CrmSaleQuotationProductDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.quotation.CrmSaleQuotationRevisionDO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
+import cn.iocoder.yudao.module.crm.dal.mysql.bidbond.CrmBidBondMapper;
 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,16 +47,23 @@
 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;
+import java.util.Set;
 
 import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.UPDATE;
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
 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
@@ -57,6 +73,9 @@
 
     @Resource
     private CrmSaleQuotationService saleQuotationService;
+
+    @Resource
+    private CrmBidBondMapper bidBondMapper;
 
     @Resource
     private AdminUserApi adminUserApi;
@@ -69,9 +88,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 = "鍒涘缓閿�鍞姤浠峰崟")
@@ -90,17 +113,30 @@
 
     @DeleteMapping("/delete")
     @Operation(summary = "鍒犻櫎閿�鍞姤浠峰崟")
-    @Parameter(name = "ids", description = "缂栧彿鏁扮粍", required = true)
+    @Parameter(name = "id", description = "鍗曚釜缂栧彿", required = false)
+    @Parameter(name = "ids", description = "缂栧彿鏁扮粍", required = false)
     @PreAuthorize("@ss.hasPermission('crm:sale-quotation:delete')")
-    public CommonResult<Boolean> deleteSaleQuotation(@RequestParam("ids") List<Long> ids) {
-        saleQuotationService.deleteSaleQuotation(ids);
+    public CommonResult<Boolean> deleteSaleQuotation(
+            @RequestParam(value = "id", required = false) Long id,
+            @RequestParam(value = "ids", required = false) List<Long> ids) {
+        // 鏀寔鍗曚釜id鎴栧涓猧ds
+        List<Long> deleteIds = new java.util.ArrayList<>();
+        if (id != null) {
+            deleteIds.add(id);
+        }
+        if (ids != null && !ids.isEmpty()) {
+            deleteIds.addAll(ids);
+        }
+        if (deleteIds.isEmpty()) {
+            throw new IllegalArgumentException("璇锋眰鍙傛暟缂哄け:id 鎴� ids");
+        }
+        saleQuotationService.deleteSaleQuotation(deleteIds);
         return success(true);
     }
 
     @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) {
@@ -112,7 +148,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));
@@ -120,7 +155,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));
@@ -128,7 +162,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));
@@ -146,12 +179,112 @@
         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)
     @PreAuthorize("@ss.hasPermission('crm:sale-quotation:convert-contract')")
     public CommonResult<Long> convertToContract(@RequestParam("id") Long id) {
         return success(saleQuotationService.convertToContract(id, getLoginUserId()));
+    }
+
+    @PutMapping("/void")
+    @Operation(summary = "浣滃簾閿�鍞姤浠峰崟")
+    @Parameter(name = "id", description = "鎶ヤ环鍗曠紪鍙�", required = true)
+    @Parameter(name = "reason", description = "浣滃簾鍘熷洜", required = true)
+    @PreAuthorize("@ss.hasPermission('crm:sale-quotation:void')")
+    @ApiAccessLog(operateType = UPDATE)
+    public CommonResult<Boolean> voidSaleQuotation(@RequestParam("id") Long id,
+                                                   @RequestParam("reason") String reason) {
+        saleQuotationService.voidSaleQuotation(id, reason);
+        return success(true);
+    }
+
+    @GetMapping("/revision/list")
+    @Operation(summary = "鑾峰緱鎶ヤ环鍗曡疆娆℃祦姘村垪琛�")
+    @Parameter(name = "quotationId", description = "鎶ヤ环鍗曠紪鍙�", required = true)
+    @PreAuthorize("@ss.hasPermission('crm:sale-quotation:query')")
+    public CommonResult<List<CrmSaleQuotationRevisionRespVO>> getRevisionList(
+            @RequestParam("quotationId") Long quotationId) {
+        List<CrmSaleQuotationRevisionDO> list = saleQuotationService.getSaleQuotationRevisionList(quotationId);
+        return success(BeanUtils.toBean(list, CrmSaleQuotationRevisionRespVO.class));
+    }
+
+    @GetMapping("/revision/export-excel")
+    @Operation(summary = "瀵煎嚭鎶ヤ环鍗曡疆娆℃祦姘� Excel")
+    @Parameter(name = "quotationId", description = "鎶ヤ环鍗曠紪鍙�", required = true)
+    @PreAuthorize("@ss.hasPermission('crm:sale-quotation:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportRevisionExcel(@RequestParam("quotationId") Long quotationId,
+                                    HttpServletResponse response) throws IOException {
+        List<CrmSaleQuotationRevisionRespVO> list = BeanUtils.toBean(
+                saleQuotationService.getSaleQuotationRevisionList(quotationId),
+                CrmSaleQuotationRevisionRespVO.class);
+        ExcelUtils.write(response, "鎶ヤ环杞娴佹按.xls", "鏁版嵁", CrmSaleQuotationRevisionRespVO.class, list);
+    }
+
+    @GetMapping("/bindable-list")
+    @Operation(summary = "鑾峰緱瀹㈡埛涓嬪彲缁戝畾鎶曟爣鐨勬姤浠峰崟鍒楄〃")
+    @Parameter(name = "customerId", description = "瀹㈡埛缂栧彿", required = true)
+    @Parameter(name = "bidBondId", description = "褰撳墠鎶曟爣淇濊瘉閲戠紪鍙凤紙缂栬緫鏃剁敤浜庝繚鐣欒嚜韬粦瀹氾級", required = false)
+    @PreAuthorize("@ss.hasPermission('crm:sale-quotation:query')")
+    public CommonResult<List<CrmSaleQuotationOptionRespVO>> getBindableList(
+            @RequestParam("customerId") Long customerId,
+            @RequestParam(value = "bidBondId", required = false) Long bidBondId) {
+        return success(BeanUtils.toBean(
+                saleQuotationService.getBindableQuotationList(customerId, bidBondId),
+                CrmSaleQuotationOptionRespVO.class));
     }
 
     // ==================== 鏋勫缓鍝嶅簲 VO ====================
@@ -201,6 +334,13 @@
         }
         // 3. 濉厖鍏宠仈淇℃伅
         fillSaleQuotationRelatedFields(respVO);
+        // 3.1 濉厖鍏宠仈鎶曟爣鐨勪腑鏍囩粨鏋�
+        if (saleQuotation.getBidBondId() != null) {
+            CrmBidBondDO bidBond = bidBondMapper.selectById(saleQuotation.getBidBondId());
+            if (bidBond != null) {
+                respVO.setBidResult(bidBond.getBidResult());
+            }
+        }
         // 4. 濉厖闄勪欢鍒楄〃
         respVO.setAttachmentList(storageAttachmentApi.listAttachments("crm_sale_quotation", saleQuotation.getId()));
         return respVO;
@@ -237,6 +377,11 @@
         // 1.6 鍟嗘満淇℃伅锛堣繃婊� null锛宐usinessId 涓哄彲閫夊瓧娈碉級
         Map<Long, CrmBusinessDO> businessMap = businessService.getBusinessMap(
                 convertSet(pageResult.getList(), CrmSaleQuotationDO::getBusinessId, vo -> vo.getBusinessId() != null));
+        // 1.7 鎶曟爣淇℃伅锛堣繃婊� null锛宐idBondId 涓哄彲閫夊瓧娈碉級
+        Set<Long> bidBondIds = convertSet(pageResult.getList(), CrmSaleQuotationDO::getBidBondId,
+                vo -> vo.getBidBondId() != null);
+        Map<Long, CrmBidBondDO> bidBondMap = bidBondIds.isEmpty() ? Map.of()
+                : convertMap(bidBondMapper.selectByIds(bidBondIds), CrmBidBondDO::getId);
 
         // 2. 寮�濮嬫嫾鎺�
         return BeanUtils.toBean(pageResult, CrmSaleQuotationRespVO.class, vo -> {
@@ -257,6 +402,7 @@
             MapUtils.findAndThen(userMap, vo.getOwnerUserId(), user -> vo.setOwnerUserName(user.getNickname()));
             MapUtils.findAndThen(deptMap, vo.getOwnerUserId(), dept -> vo.setOwnerUserDeptName(dept.getName()));
             MapUtils.findAndThen(businessMap, vo.getBusinessId(), business -> vo.setBusinessName(business.getName()));
+            MapUtils.findAndThen(bidBondMap, vo.getBidBondId(), bidBond -> vo.setBidResult(bidBond.getBidResult()));
         });
     }
 

--
Gitblit v1.9.3