统一导出章节归并并保留卡片上下文
This commit is contained in:
parent
58ffe7b90b
commit
dbf7ba2d64
@ -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("暂无相关标准。")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user