feat(regulatory): 展示法规核查工作流卡片

This commit is contained in:
2026-06-07 00:43:18 +08:00
parent 4c28466fe4
commit bd805203f1
6 changed files with 187 additions and 21 deletions

View File

@@ -11,7 +11,7 @@ from .services import (
send_message,
stream_message,
)
from .models import Conversation, FileAttachment, FileSummaryBatch
from .models import Conversation, FileAttachment, FileSummaryBatch, RegulatoryReviewBatch, WorkflowNodeRun
@login_required
@@ -42,6 +42,8 @@ def workspace(request: HttpRequest) -> HttpResponse:
if current is None and conversations.exists():
current = conversations.first()
workflow_cards = build_workflow_cards(current) if current else []
return render(
request,
"home.html",
@@ -52,7 +54,7 @@ def workspace(request: HttpRequest) -> HttpResponse:
"current_conversation": current,
"messages": current.messages.all() if current else [],
"attachments": FileAttachment.objects.filter(conversation=current).order_by("original_name", "-version_no") if current else [],
"summary_batches": FileSummaryBatch.objects.filter(conversation=current).prefetch_related("node_runs").order_by("-created_at")[:5] if current else [],
"workflow_cards": workflow_cards,
},
)
@@ -109,3 +111,56 @@ def stream_chat(request: HttpRequest) -> HttpResponse:
response["Cache-Control"] = "no-cache"
response["X-Accel-Buffering"] = "no"
return response
def build_workflow_cards(conversation: Conversation) -> list[dict[str, object]]:
cards: list[dict[str, object]] = []
for batch in FileSummaryBatch.objects.filter(conversation=conversation).prefetch_related("node_runs"):
cards.append(
{
"id": batch.pk,
"workflow_type": "file_summary",
"batch_no": batch.batch_no,
"status": batch.status,
"error_message": batch.error_message,
"risk_label": "",
"created_at": batch.created_at,
"nodes": list(batch.node_runs.order_by("id")),
}
)
regulatory_batches = RegulatoryReviewBatch.objects.filter(conversation=conversation)
for batch in regulatory_batches:
cards.append(
{
"id": batch.pk,
"workflow_type": "regulatory_review",
"batch_no": batch.batch_no,
"status": batch.status,
"error_message": batch.error_message,
"risk_label": _format_risk_label(batch.risk_summary or {}),
"created_at": batch.created_at,
"nodes": list(
WorkflowNodeRun.objects.filter(
workflow_type="regulatory_review",
workflow_batch_id=batch.pk,
).order_by("id")
),
}
)
return sorted(cards, key=lambda item: item["created_at"], reverse=True)[:5]
def _format_risk_label(risk_summary: dict) -> str:
parts = []
labels = [
("blocking", "阻断项"),
("high", "高风险"),
("medium", "中风险"),
("low", "低风险"),
("info", "提示"),
]
for key, label in labels:
count = int(risk_summary.get(key) or 0)
if count:
parts.append(f"{label} {count}")
return " · ".join(parts)