feat(application-form-fill): 新增自动填表批次模型

This commit is contained in:
2026-06-07 18:20:14 +08:00
parent f48277aea7
commit 74cbe349a8
5 changed files with 716 additions and 5 deletions

View File

@@ -7,7 +7,7 @@ from pathlib import Path
from django.http import FileResponse, Http404, JsonResponse
from django.views.decorators.http import require_http_methods
from review_agent.models import Conversation, ExportedSummaryFile, FileAttachment, Message
from review_agent.models import ApplicationFormFillBatch, Conversation, ExportedSummaryFile, FileAttachment, Message
from review_agent.models import FileSummaryBatch, WorkflowEvent
from .events import serialize_event
from .paths import resolve_storage_path
@@ -271,10 +271,7 @@ def batch_events(request, batch_id: int):
@require_http_methods(["GET"])
@login_required
def export_download(request, export_id: int):
exported = ExportedSummaryFile.objects.filter(
pk=export_id,
batch__user=request.user,
).first()
exported = _export_for_user(request.user, export_id)
if not exported:
raise Http404("导出文件不存在。")
path = Path(exported.storage_path)
@@ -288,6 +285,8 @@ def export_download(request, export_id: int):
ExportedSummaryFile.ExportType.MARKDOWN: "text/markdown; charset=utf-8",
ExportedSummaryFile.ExportType.EXCEL: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
ExportedSummaryFile.ExportType.JSON: "application/json; charset=utf-8",
ExportedSummaryFile.ExportType.WORD: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
ExportedSummaryFile.ExportType.PDF: "application/pdf",
}
content_type = content_types.get(exported.export_type, "application/octet-stream")
logger.info(
@@ -305,3 +304,21 @@ def export_download(request, export_id: int):
filename=exported.file_name,
content_type=content_type,
)
def _export_for_user(user, export_id: int) -> ExportedSummaryFile | None:
exported = ExportedSummaryFile.objects.filter(pk=export_id).first()
if not exported:
return None
if exported.workflow_type == "application_form_fill":
if not exported.workflow_batch_id:
return None
allowed = ApplicationFormFillBatch.objects.filter(
pk=exported.workflow_batch_id,
conversation__user=user,
is_deleted=False,
).exists()
return exported if allowed else None
if exported.batch.user_id != user.pk:
return None
return exported