Revert "添加通过taskId获取文档的接口,支持文件列表查询和参数验证,增强错误处理能力。同时,优化文档生成逻辑,确保生成的文档名称和路径的准确性。"
This reverts commit 4897c96b05f75d26249bf50d62546030b873196a.
This commit is contained in:
parent
4084cb1819
commit
e3f4a394c1
3
app.py
3
app.py
@ -701,6 +701,7 @@ def generate_document():
|
|||||||
return error_response(3001, f"文档生成失败: {str(e)}")
|
return error_response(3001, f"文档生成失败: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
@app.route('/fPolicTask/getDocument', methods=['POST'])
|
@app.route('/fPolicTask/getDocument', methods=['POST'])
|
||||||
def get_document_by_task():
|
def get_document_by_task():
|
||||||
"""
|
"""
|
||||||
@ -829,6 +830,8 @@ def get_document_by_task():
|
|||||||
return error_response(3001, f"文档生成失败: {str(e)}")
|
return error_response(3001, f"文档生成失败: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
=======
|
||||||
|
>>>>>>> parent of 4897c96 (添加通过taskId获取文档的接口,支持文件列表查询和参数验证,增强错误处理能力。同时,优化文档生成逻辑,确保生成的文档名称和路径的准确性。)
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# 确保static目录存在
|
# 确保static目录存在
|
||||||
os.makedirs('static', exist_ok=True)
|
os.makedirs('static', exist_ok=True)
|
||||||
|
|||||||
@ -138,6 +138,7 @@ class DocumentService:
|
|||||||
doc = Document(template_path)
|
doc = Document(template_path)
|
||||||
print(f"[DEBUG] 文档包含 {len(doc.paragraphs)} 个段落, {len(doc.tables)} 个表格")
|
print(f"[DEBUG] 文档包含 {len(doc.paragraphs)} 个段落, {len(doc.tables)} 个表格")
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
def replace_placeholder_in_paragraph(paragraph):
|
def replace_placeholder_in_paragraph(paragraph):
|
||||||
"""在段落中替换占位符(处理跨run的情况)"""
|
"""在段落中替换占位符(处理跨run的情况)"""
|
||||||
try:
|
try:
|
||||||
@ -203,6 +204,18 @@ class DocumentService:
|
|||||||
if placeholder in before_text and placeholder not in after_text:
|
if placeholder in before_text and placeholder not in after_text:
|
||||||
replaced_placeholders.add(field_code)
|
replaced_placeholders.add(field_code)
|
||||||
total_replacements += before_text.count(placeholder)
|
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:
|
try:
|
||||||
@ -251,6 +264,7 @@ class DocumentService:
|
|||||||
for table in doc.tables:
|
for table in doc.tables:
|
||||||
for row in table.rows:
|
for row in table.rows:
|
||||||
for cell in row.cells:
|
for cell in row.cells:
|
||||||
|
<<<<<<< HEAD
|
||||||
if hasattr(cell, 'paragraphs'):
|
if hasattr(cell, 'paragraphs'):
|
||||||
for paragraph in cell.paragraphs:
|
for paragraph in cell.paragraphs:
|
||||||
text = paragraph.text
|
text = paragraph.text
|
||||||
@ -267,6 +281,15 @@ class DocumentService:
|
|||||||
print(f" - ⚠️ 仍有未替换的占位符: {sorted(remaining_placeholders)}")
|
print(f" - ⚠️ 仍有未替换的占位符: {sorted(remaining_placeholders)}")
|
||||||
else:
|
else:
|
||||||
print(f" - ✓ 所有占位符已成功替换")
|
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()
|
temp_dir = tempfile.gettempdir()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user