fix(regulatory-info-package): 完成后追加下载摘要

This commit is contained in:
2026-06-10 19:56:50 +08:00
parent 6d4b519f83
commit b728703e67
2 changed files with 68 additions and 1 deletions

View File

@@ -128,6 +128,7 @@ class RegulatoryInfoPackageWorkflowExecutor:
self.batch.status = RegulatoryInfoPackageBatch.Status.SUCCESS
self.batch.finished_at = timezone.now()
self.batch.save(update_fields=["status", "finished_at"])
self._append_completion_message()
record_event(self.batch, "workflow_completed", {"batch_id": self.batch.pk})
def _nodes(self):
@@ -309,6 +310,42 @@ class RegulatoryInfoPackageWorkflowExecutor:
)
return
def _append_completion_message(self) -> None:
if (
Message.objects.filter(
conversation=self.batch.conversation,
role=Message.Role.ASSISTANT,
content__contains=self.batch.batch_no,
)
.filter(content__contains=self.batch.output_zip_name)
.exists()
):
return
exports = list(
ExportedSummaryFile.objects.filter(
workflow_type=WORKFLOW_TYPE,
workflow_batch_id=self.batch.pk,
)
)
exports = sorted(exports, key=lambda export: 0 if export.export_type == ExportedSummaryFile.ExportType.ZIP else 1)
content = build_assistant_summary(
batch_no=self.batch.batch_no,
exports=[
{
"file_name": export.file_name,
"download_url": f"/api/review-agent/file-summary/exports/{export.pk}/download/",
"export_type": export.export_type,
}
for export in exports
],
failed_files=[item for item in self.batch.generated_files if item.get("status") == "failed"],
)
Message.objects.create(
conversation=self.batch.conversation,
role=Message.Role.ASSISTANT,
content=content,
)
def _create_export(self, *, path: str, export_type: str, export_category: str) -> ExportedSummaryFile:
from pathlib import Path