From e3f4a394c1a4333db2fd3a9383be29fa9d9055e0 Mon Sep 17 00:00:00 2001 From: python Date: Thu, 11 Dec 2025 10:31:44 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E6=B7=BB=E5=8A=A0=E9=80=9A=E8=BF=87t?= =?UTF-8?q?askId=E8=8E=B7=E5=8F=96=E6=96=87=E6=A1=A3=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E6=94=AF=E6=8C=81=E6=96=87=E4=BB=B6=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=9F=A5=E8=AF=A2=E5=92=8C=E5=8F=82=E6=95=B0=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=94=99=E8=AF=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86=E8=83=BD=E5=8A=9B=E3=80=82=E5=90=8C=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E6=A1=A3=E7=94=9F=E6=88=90=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E7=A1=AE=E4=BF=9D=E7=94=9F=E6=88=90=E7=9A=84?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E5=90=8D=E7=A7=B0=E5=92=8C=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E7=9A=84=E5=87=86=E7=A1=AE=E6=80=A7=E3=80=82"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 4897c96b05f75d26249bf50d62546030b873196a. --- app.py | 3 +++ services/document_service.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/app.py b/app.py index 360c111..3557842 100644 --- a/app.py +++ b/app.py @@ -701,6 +701,7 @@ def generate_document(): return error_response(3001, f"文档生成失败: {str(e)}") +<<<<<<< HEAD @app.route('/fPolicTask/getDocument', methods=['POST']) def get_document_by_task(): """ @@ -829,6 +830,8 @@ def get_document_by_task(): return error_response(3001, f"文档生成失败: {str(e)}") +======= +>>>>>>> parent of 4897c96 (添加通过taskId获取文档的接口,支持文件列表查询和参数验证,增强错误处理能力。同时,优化文档生成逻辑,确保生成的文档名称和路径的准确性。) if __name__ == '__main__': # 确保static目录存在 os.makedirs('static', exist_ok=True) diff --git a/services/document_service.py b/services/document_service.py index 7bfdaab..0a00699 100644 --- a/services/document_service.py +++ b/services/document_service.py @@ -138,6 +138,7 @@ class DocumentService: doc = Document(template_path) print(f"[DEBUG] 文档包含 {len(doc.paragraphs)} 个段落, {len(doc.tables)} 个表格") +<<<<<<< HEAD def replace_placeholder_in_paragraph(paragraph): """在段落中替换占位符(处理跨run的情况)""" try: @@ -203,6 +204,18 @@ class DocumentService: if placeholder in before_text and placeholder not in after_text: replaced_placeholders.add(field_code) total_replacements += before_text.count(placeholder) +======= + # 替换占位符 {{field_code}} 为实际值 + for paragraph in doc.paragraphs: + # 替换段落文本中的占位符 + for field_code, field_value in field_data.items(): + placeholder = f"{{{{{field_code}}}}}" + if placeholder in paragraph.text: + # 替换占位符 + for run in paragraph.runs: + if placeholder in run.text: + run.text = run.text.replace(placeholder, field_value or '') +>>>>>>> parent of 4897c96 (添加通过taskId获取文档的接口,支持文件列表查询和参数验证,增强错误处理能力。同时,优化文档生成逻辑,确保生成的文档名称和路径的准确性。) # 替换表格中的占位符 try: @@ -251,6 +264,7 @@ class DocumentService: for table in doc.tables: for row in table.rows: for cell in row.cells: +<<<<<<< HEAD if hasattr(cell, 'paragraphs'): for paragraph in cell.paragraphs: text = paragraph.text @@ -267,6 +281,15 @@ class DocumentService: print(f" - ⚠️ 仍有未替换的占位符: {sorted(remaining_placeholders)}") else: print(f" - ✓ 所有占位符已成功替换") +======= + for paragraph in cell.paragraphs: + for field_code, field_value in field_data.items(): + placeholder = f"{{{{{field_code}}}}}" + if placeholder in paragraph.text: + for run in paragraph.runs: + if placeholder in run.text: + run.text = run.text.replace(placeholder, field_value or '') +>>>>>>> parent of 4897c96 (添加通过taskId获取文档的接口,支持文件列表查询和参数验证,增强错误处理能力。同时,优化文档生成逻辑,确保生成的文档名称和路径的准确性。) # 保存到临时文件 temp_dir = tempfile.gettempdir()