gaoluyang
3 天以前 d39e4f7d839167c16425086dfa2f8747bccfdff9
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java
@@ -118,7 +118,6 @@
    @GetMapping("/get")
    @Operation(summary = "获得合同")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('crm:contract:query')")
    public CommonResult<CrmContractRespVO> getContract(@RequestParam("id") Long id) {
        CrmContractDO contract = contractService.getContract(id);
        return success(buildContractDetail(contract));
@@ -146,9 +145,31 @@
        return contractVO;
    }
    @GetMapping("/download-document")
    @Operation(summary = "按购销合同模板下载合同 Word 文件")
    @PreAuthorize("@ss.hasPermission('crm:contract:query')")
    public void downloadDocument(@RequestParam("id") Long id, HttpServletResponse response) throws IOException {
        // getContract 包含合同数据权限校验;沿用详情页的产品、单位和客户信息。
        CrmContractRespVO contract = buildContractDetail(contractService.getContract(id));
        Assert.notNull(contract, "合同不存在");
        if (contract.getProducts() == null || contract.getProducts().isEmpty()) {
            throw new cn.iocoder.yudao.framework.common.exception.ServiceException(400, "合同没有产品明细,请先维护产品后导出");
        }
        if (contract.getTotalPrice() == null || contract.getProducts().stream()
                .anyMatch(product -> product.getContractPrice() == null || product.getCount() == null)) {
            throw new cn.iocoder.yudao.framework.common.exception.ServiceException(400, "合同金额、产品数量和单价不能为空,请先补全后导出");
        }
        byte[] content = cn.iocoder.yudao.module.crm.service.contract.CrmContractDocumentRenderer.render(contract);
        String filename = "购销合同-" + contract.getNo() + ".docx";
        response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
        response.setHeader("Cache-Control", "no-store");
        response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + java.net.URLEncoder.encode(filename, java.nio.charset.StandardCharsets.UTF_8).replace("+", "%20"));
        response.setContentLength(content.length);
        response.getOutputStream().write(content);
    }
    @GetMapping("/page")
    @Operation(summary = "获得合同分页")
    @PreAuthorize("@ss.hasPermission('crm:contract:query')")
    public CommonResult<PageResult<CrmContractRespVO>> getContractPage(@Valid CrmContractPageReqVO pageVO) {
        PageResult<CrmContractDO> pageResult = contractService.getContractPage(pageVO, getLoginUserId());
        return success(BeanUtils.toBean(pageResult, CrmContractRespVO.class).setList(buildContractDetailList(pageResult.getList())));
@@ -236,7 +257,6 @@
    @GetMapping("/approve-process-list")
    @Operation(summary = "获取合同审批流程列表")
    @PreAuthorize("@ss.hasPermission('crm:contract:query')")
    public CommonResult<List<Map<String, Object>>> getContractApproveProcessList() {
        return success(contractService.getContractApproveProcessDefinitionList());
    }
@@ -292,14 +312,12 @@
    @GetMapping("/audit-count")
    @Operation(summary = "获得待审核合同数量")
    @PreAuthorize("@ss.hasPermission('crm:contract:query')")
    public CommonResult<Long> getAuditContractCount() {
        return success(contractService.getAuditContractCount(getLoginUserId()));
    }
    @GetMapping("/remind-count")
    @Operation(summary = "获得即将到期(提醒)的合同数量")
    @PreAuthorize("@ss.hasPermission('crm:contract:query')")
    public CommonResult<Long> getRemindContractCount() {
        return success(contractService.getRemindContractCount(getLoginUserId()));
    }
@@ -307,7 +325,6 @@
    @GetMapping("/simple-list")
    @Operation(summary = "获得合同精简列表", description = "只包含的合同,主要用于前端的下拉选项")
    @Parameter(name = "customerId", description = "客户编号", required = true)
    @PreAuthorize("@ss.hasPermission('crm:contract:query')")
    public CommonResult<List<CrmContractRespVO>> getContractSimpleList(@RequestParam("customerId") Long customerId) {
        CrmContractPageReqVO pageReqVO = new CrmContractPageReqVO().setCustomerId(customerId);
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); // 不分页