feat(application-form-fill): 串联填表工作流产物输出
This commit is contained in:
45
review_agent/application_form_fill/services/notifier.py
Normal file
45
review_agent/application_form_fill/services/notifier.py
Normal 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(),
|
||||
)
|
||||
Reference in New Issue
Block a user