feat: 持久化资料包导出记录与列表摘要

This commit is contained in:
2026-06-04 02:41:49 +08:00
parent 0e49466746
commit ab3d520642
9 changed files with 250 additions and 8 deletions

View File

@@ -7,7 +7,7 @@ import types
from zipfile import ZipFile
from apps.documents.forms import DocumentUploadForm
from apps.documents.models import SubmissionBatch, UploadedDocument
from apps.documents.models import ExportedDocument, SubmissionBatch, UploadedDocument
from apps.documents.services import extract_text, import_submission_batch, index_document
from apps.chat.models import Conversation
@@ -475,3 +475,68 @@ def test_import_submission_batch_records_warnings_for_unsupported_7z_entries(db,
assert batch.file_count == 1
assert batch.exception_count == 1
assert any("CH1/忽略图片.png" in warning for warning in warnings)
def test_create_export_record_persists_batch_conversation_and_file_metadata(db):
from apps.documents.services import create_export_record
batch = SubmissionBatch.objects.create(
batch_id="SUB-20260604-010",
product_name="产品X",
workflow_type="registration",
conversation_id="conv-010",
file_count=2,
page_count=12,
import_status="completed",
)
record = create_export_record(
batch=batch,
conversation_id="conv-010",
product_name="产品X",
template_name="注册证导出模板",
template_version="V1.0",
export_mode="draft",
output_type="registration_word_export_report",
file_name="SUB-20260604-010-draft.docx",
relative_path="exports/20260604/SUB-20260604-010-draft.docx",
download_url="/media/exports/20260604/SUB-20260604-010-draft.docx",
)
assert ExportedDocument.objects.count() == 1
assert record.batch == batch
assert record.conversation_id == "conv-010"
assert record.product_name == "产品X"
assert record.template_name == "注册证导出模板"
assert record.export_mode == "draft"
def test_document_list_shows_latest_export_record_for_batch(client, db):
batch = SubmissionBatch.objects.create(
batch_id="SUB-20260604-011",
product_name="产品Y",
workflow_type="registration",
conversation_id="conv-011",
file_count=2,
page_count=12,
import_status="completed",
)
ExportedDocument.objects.create(
batch=batch,
conversation_id="conv-011",
product_name="产品Y",
template_name="注册证导出模板",
template_version="V1.0",
export_mode="draft",
output_type="registration_word_export_report",
file_name="SUB-20260604-011-draft.docx",
relative_path="exports/20260604/SUB-20260604-011-draft.docx",
download_url="/media/exports/20260604/SUB-20260604-011-draft.docx",
)
response = client.get(reverse("documents:list"))
content = response.content.decode("utf-8")
assert response.status_code == 200
assert "最近导出" in content
assert "SUB-20260604-011-draft.docx" in content