From dbf7ba2d6495f8116bedbba3fe82c25941c4fa20 Mon Sep 17 00:00:00 2001 From: kx_guo Date: Wed, 9 Sep 2026 17:36:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=AF=BC=E5=87=BA=E7=AB=A0?= =?UTF-8?q?=E8=8A=82=E5=BD=92=E5=B9=B6=E5=B9=B6=E4=BF=9D=E7=95=99=E5=8D=A1?= =?UTF-8?q?=E7=89=87=E4=B8=8A=E4=B8=8B=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/reports.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/app/services/reports.py b/app/services/reports.py index 0f36d62..804344f 100644 --- a/app/services/reports.py +++ b/app/services/reports.py @@ -481,6 +481,9 @@ def build_risk_report_docx(result: RiskAssessmentResult) -> bytes: standards = report_data["standards"] similar_cases = report_data["similar_cases"] suggestions = report_data["suggestions"] + material_cards = report_data["material_cards"] + standard_cards = report_data["standard_cards"] + section_shift = 1 if material_cards else 0 def heading(text: str) -> None: p = document.add_paragraph() @@ -585,7 +588,6 @@ def build_risk_report_docx(result: RiskAssessmentResult) -> bytes: if label not in {"卡片类型", "分析对象", "对象类型"}: rows.append([label, value, "追加供应商画像数据"]) add_table(rows) - material_cards = report_data["material_cards"] if material_cards: heading("四、物料风险分析") rows = [["物料/字段", "分析结果"]] @@ -601,7 +603,7 @@ def build_risk_report_docx(result: RiskAssessmentResult) -> bytes: ] ) add_table(rows) - heading(f"五、相似案例匹配({len(similar_cases)} 条)") + heading(f"{'五' if section_shift else '四'}、相似案例匹配({len(similar_cases)} 条)") if similar_cases: add_table( [["日期", "产品", "问题", "处理方案"]] @@ -612,10 +614,10 @@ def build_risk_report_docx(result: RiskAssessmentResult) -> bytes: ) else: document.add_paragraph("暂无相关案例,RAG 相似案例检索未返回匹配结果。") - heading("六、预防建议") + heading(f"{'六' if section_shift else '五'}、预防建议") for index, suggestion in enumerate(suggestions or ["优先针对低分维度安排专项验证,并明确责任人与完成节点。"], 1): document.add_paragraph(f"{index}. {suggestion}") - heading("七、AI 推理方案(无历史案例场景)") + heading(f"{'七' if section_shift else '六'}、AI 推理方案(无历史案例场景)") document.add_paragraph( "本次评估已采用历史案例与标准库双引擎结论;若后续未匹配到足够历史案例,将基于相似品类、相似物料生成类比方案,并由标准库进行规则兜底。" ) @@ -630,14 +632,29 @@ def build_risk_report_docx(result: RiskAssessmentResult) -> bytes: document.add_paragraph(f"方案建议 {index}:{suggestion}") if card.warning: document.add_paragraph(f"风险提示:{card.warning}") - heading("八、标准判定结果") - if standards: + heading(f"{'八' if section_shift else '七'}、标准判定结果") + standard_rows = [ + [f"{item.category} · {item.risk_point}", item.rule, item.source or "标准文件.xlsx", item.status] + for item in standards + ] + for card in standard_cards: + if card.detected_values: + standard_rows.append( + [ + "检测值", + "、".join(f"{item.get('name', '')}:{item.get('value', '')}" for item in card.detected_values), + card.title, + "待确认", + ] + ) + if card.note: + standard_rows.append(["补充说明", card.note, card.title, "待确认"]) + for suggestion in card.suggestions: + standard_rows.append(["执行建议", suggestion, card.title, "待确认"]) + if standard_rows: add_table( [["判定维度", "判定标准", "标准来源", "当前状态"]] - + [ - [f"{item.category} · {item.risk_point}", item.rule, item.source or "标准文件.xlsx", item.status] - for item in standards - ] + + standard_rows ) else: document.add_paragraph("暂无相关标准。")