{"record":{"id":"a57d4657590d726e","repo":"jeecgboot/JeecgBoot","slug":"word-message-a57d46","errorCode":null,"errorMessage":"生成word文档失败: {message}","messagePattern":"生成word文档失败: (.+?)","errorType":"exception","errorClass":"JeecgBootException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/wordtpl/controller/AigcWordTemplateController.java","lineNumber":240,"sourceCode":"            template = eoaWordTemplateService.getOne(Wrappers.lambdaQuery(AigcWordTemplate.class)\n                    .eq(AigcWordTemplate::getCode, wordTplGenDTO.getTemplateCode()));\n        }\n        AssertUtils.assertNotEmpty(\"未找到对应的模版\", template);\n\n        try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();\n             BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());) {\n            eoaWordTemplateService.generateWordFromTpl(wordTplGenDTO, outputStream);\n            String fileName = template.getName();\n            String encodedFileName = URLEncoder.encode(fileName, \"UTF-8\");\n            response.setContentType(\"application/vnd.openxmlformats-officedocument.wordprocessingml.document\");\n            response.addHeader(\"Content-Disposition\", \"attachment;filename=\" + encodedFileName + \".docx\");\n            response.addHeader(\"filename\", encodedFileName + \".docx\");\n            byte[] bytes = outputStream.toByteArray();\n            response.setHeader(\"Content-Length\", String.valueOf(bytes.length));\n            bos.write(bytes);\n        } catch (Exception e) {\n            log.error(e.getMessage(), e);\n            throw new JeecgBootException(\"生成word文档失败: \" + e.getMessage(), e);\n        }\n    }\n\n}\n","sourceCodeStart":222,"sourceCodeEnd":245,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/wordtpl/controller/AigcWordTemplateController.java#L222-L245","documentation":"generateWord() generates a document from a template + data map and streams the .docx to the response. Any exception (template not found by id/code, generateWordFromTpl failure, client-disconnect IOException) is wrapped as JeecgBootException with the cause message.","triggerScenarios":"template lookup returns null (assertNotEmpty fires first, but a stale id can still slip through); eoaWordTemplateService.generateWordFromTpl throws (see error 127); response.getOutputStream() fails on client abort.","commonSituations":"Invalid templateId or templateCode; data map keys don't match template placeholders; client cancels the download; template references an inaccessible image.","solutions":["Read the cause stacktrace in the log.","Confirm the template exists (by id, or by code via the lambdaQuery).","Reproduce generateWordFromTpl with the same DTO to isolate poi-tl vs streaming.","For ClientAbortException, treat as client disconnect."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// confirm template resolves before generating\nAigcWordTemplate template;\nif (oConvertUtils.isNotEmpty(wordTplGenDTO.getTemplateId())) {\n    template = eoaWordTemplateService.getById(wordTplGenDTO.getTemplateId());\n} else {\n    template = eoaWordTemplateService.getOne(Wrappers.lambdaQuery(AigcWordTemplate.class)\n        .eq(AigcWordTemplate::getCode, wordTplGenDTO.getTemplateCode()));\n}\nif (template == null) { response.sendError(404, \"未找到对应的模版\"); return; }","typeGuard":null,"tryCatchPattern":"try { ... } catch (java.io.IOException clientEx) {\n    log.warn(\"客户端断开，生成word下载中止\", clientEx);\n} catch (Exception e) {\n    throw new JeecgBootException(\"生成word文档失败: \" + e.getMessage(), e);\n}","preventionTips":["Validate data keys against template placeholders before generating.","Handle client disconnects separately from generation errors."],"tags":["word","generate","template","poi","controller"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}