feat(application-form-fill): 串联填表工作流产物输出

This commit is contained in:
2026-06-07 18:40:04 +08:00
parent f35a3ba9b4
commit 9be10ef990
5 changed files with 396 additions and 1 deletions

View File

@@ -0,0 +1,45 @@
from __future__ import annotations
from django.utils import timezone
from review_agent.models import (
ApplicationFormFillBatch,
ApplicationFormFillNotificationRecord,
ExportedSummaryFile,
)
def notify_completion(
batch: ApplicationFormFillBatch,
exports: list[ExportedSummaryFile],
*,
fail: bool = False,
) -> ApplicationFormFillNotificationRecord:
export_ids = [export.pk for export in exports]
message_summary = (
f"自动填表批次 {batch.batch_no} 已完成,"
f"模板 {', '.join(batch.selected_templates or []) or '未识别'}"
f"冲突字段 {len(batch.conflict_summary or [])} 个。"
)
if fail:
return ApplicationFormFillNotificationRecord.objects.create(
batch=batch,
recipient=batch.user,
channel=ApplicationFormFillNotificationRecord.Channel.MOCK,
template_codes=batch.selected_templates,
export_ids=export_ids,
message_summary=message_summary,
send_status=ApplicationFormFillNotificationRecord.SendStatus.FAILED,
retry_count=1,
error_message="mock notification failed",
)
return ApplicationFormFillNotificationRecord.objects.create(
batch=batch,
recipient=batch.user,
channel=ApplicationFormFillNotificationRecord.Channel.MOCK,
template_codes=batch.selected_templates,
export_ids=export_ids,
message_summary=message_summary,
send_status=ApplicationFormFillNotificationRecord.SendStatus.SUCCESS,
sent_at=timezone.now(),
)

View File

@@ -0,0 +1,35 @@
from __future__ import annotations
from review_agent.models import ApplicationFormFillBatch, ExportedSummaryFile
def build_assistant_summary(batch: ApplicationFormFillBatch, exports: list[ExportedSummaryFile]) -> str:
word_exports = [export for export in exports if export.export_type == ExportedSummaryFile.ExportType.WORD]
trace_exports = [
export
for export in exports
if export.export_type in {ExportedSummaryFile.ExportType.EXCEL, ExportedSummaryFile.ExportType.JSON}
]
lines = ["已生成申报模板自动填表文件。", "", "| 文件 | Word | PDF |", "| --- | --- | --- |"]
if word_exports:
for export in word_exports:
lines.append(f"| {export.file_name} | [下载](/api/review-agent/file-summary/exports/{export.pk}/download/) | 待增强 |")
else:
lines.append("| 自动填表结果 | 未生成 | 待增强 |")
conflicts = batch.conflict_summary or []
if conflicts:
lines.extend(["", "| 冲突字段 | 采用值 | 冲突来源 | 处理 |", "| --- | --- | --- | --- |"])
for item in conflicts:
conflict_sources = "".join(
f"{value.get('source_file', '')}{value.get('value', '')}" for value in item.get("conflict_values", [])
)
lines.append(
f"| {item.get('field_label', item.get('field_key', ''))} | {item.get('selected_value', '')} | {conflict_sources or '-'} | {item.get('handling', '')} |"
)
if trace_exports:
lines.append("")
for export in trace_exports:
lines.append(f"[下载{export.file_name}](/api/review-agent/file-summary/exports/{export.pk}/download/)")
return "\n".join(lines).strip()