refactor: 下沉资料包列表上下文到 documents 服务层
This commit is contained in:
@@ -247,6 +247,50 @@ def build_batch_rows(batches) -> list[dict]:
|
||||
return rows
|
||||
|
||||
|
||||
def build_document_list_context(*, keyword: str = "") -> dict:
|
||||
"""
|
||||
组装资料包列表页所需的筛选结果与展示上下文。
|
||||
|
||||
View 只负责读取 query params,批次搜索、统计和异常聚合统一放到服务层。
|
||||
"""
|
||||
batches = SubmissionBatch.objects.all()
|
||||
if keyword:
|
||||
batches = batches.filter(product_name__icontains=keyword) | batches.filter(
|
||||
batch_id__icontains=keyword
|
||||
)
|
||||
batches = list(batches)
|
||||
documents = list(UploadedDocument.objects.all())
|
||||
status_counts = {
|
||||
"pending": sum(
|
||||
1 for batch in batches if batch.import_status == SubmissionBatch.STATUS_PENDING
|
||||
),
|
||||
"completed": sum(
|
||||
1 for batch in batches if batch.import_status == SubmissionBatch.STATUS_COMPLETED
|
||||
),
|
||||
"review_required": sum(
|
||||
1
|
||||
for batch in batches
|
||||
if batch.import_status == SubmissionBatch.STATUS_REVIEW_REQUIRED
|
||||
),
|
||||
"total": len(batches),
|
||||
}
|
||||
return {
|
||||
"documents": documents,
|
||||
"batches": batches,
|
||||
"batch_rows": build_batch_rows(batches),
|
||||
"keyword": keyword,
|
||||
"status_counts": status_counts,
|
||||
"processing_pipeline": [
|
||||
{"title": "原始文件接收", "detail": "校验格式、大小和场景归属后保存原件。"},
|
||||
{"title": "文本与表格抽取", "detail": "按 PDF / DOCX / MD / TXT 使用不同解析策略。"},
|
||||
{"title": "页数统计与可信度评估", "detail": "对 Word 页数采用估算与可信度标记。"},
|
||||
{"title": "章节点归类", "detail": "基于文件名、标题和正文线索识别 CH 节点。"},
|
||||
{"title": "切片与索引入库", "detail": "生成知识切片,供 RAG、规则定位和审计引用使用。"},
|
||||
],
|
||||
"exception_items": build_exception_items(batches, documents),
|
||||
}
|
||||
|
||||
|
||||
def build_exception_items(batches, documents) -> list[dict]:
|
||||
"""
|
||||
聚合资料包页需要关注的异常提示。
|
||||
|
||||
Reference in New Issue
Block a user