| | |
| | | |
| | | @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"); |