style: 统一飞书通知节点状态语义

This commit is contained in:
2026-06-04 04:11:00 +08:00
parent 87f674cece
commit 47ca116937
8 changed files with 64 additions and 9 deletions

View File

@@ -259,7 +259,7 @@ def _build_registration_node_results(output_type: str, structured_output: dict)
if message_status in {"failed", "error"}:
nodes[7]["status"] = "失败"
elif message_status in {"sent", "success"}:
nodes[7]["status"] = "完成"
nodes[7]["status"] = "发送"
else:
nodes[7]["status"] = "待处理"
return nodes

View File

@@ -241,6 +241,28 @@ def build_detail_summary(log: AgentAuditLog, conversation, notifications) -> dic
}
def normalize_conversation_node_results(node_results: list[dict] | None) -> list[dict]:
"""
统一处理历史详情页的节点状态展示口径。
兼容历史上遗留的“飞书通知 / 已完成”节点状态,
页面展示时统一映射为“已发送”。
"""
normalized = []
for node in node_results or []:
item = dict(node)
if item.get("label") == "飞书通知":
status = item.get("status", "")
if status in {"已完成", "success", "sent"}:
item["status"] = "已发送"
elif status in {"failed", "error"}:
item["status"] = "失败"
elif status in {"pending", "processing"}:
item["status"] = "待处理"
normalized.append(item)
return normalized
def _get_risk_status_display_text(status: str) -> str:
return RISK_STATUS_DISPLAY.get(status, status or "-")

View File

@@ -2,7 +2,12 @@ from django.shortcuts import get_object_or_404, render
from .models import AgentAuditLog, NotificationRecord
from apps.chat.models import Conversation
from .services import build_detail_summary, build_history_metrics, build_history_rows
from .services import (
build_detail_summary,
build_history_metrics,
build_history_rows,
normalize_conversation_node_results,
)
def log_list(request):
@@ -67,6 +72,9 @@ def log_detail(request, log_id: int):
"log": audit_log,
"notifications": notifications,
"conversation": conversation,
"conversation_node_results": normalize_conversation_node_results(
conversation.node_results if conversation else []
),
"detail_summary": detail_summary,
},
)

View File

@@ -117,7 +117,8 @@ def detail(request, conversation_id: str):
)
active_node = "risk"
conversation.refresh_from_db()
workspace_summary = _build_workspace_summary(conversation, batch)
display_node_results = _normalize_node_results(conversation.node_results)
workspace_summary = _build_workspace_summary(conversation, batch, display_node_results)
conversation_context = _build_conversation_context(conversation, batch, workspace_summary)
prompt_templates = _build_prompt_templates()
analysis_card = _build_analysis_card(result, conversation)
@@ -140,7 +141,7 @@ def detail(request, conversation_id: str):
"result": result,
"audit_log": audit_log,
"task_modes": task_modes,
"node_results": conversation.node_results,
"node_results": display_node_results,
"active_node": active_node,
"workspace_summary": workspace_summary,
"conversation_context": conversation_context,
@@ -258,8 +259,13 @@ def _persist_notification_records(result: AgentResult, *, web_detail_url: str =
)
def _build_workspace_summary(conversation: Conversation, batch: SubmissionBatch | None) -> dict:
node_status_map = {node.get("label"): node.get("status", "") for node in conversation.node_results}
def _build_workspace_summary(
conversation: Conversation,
batch: SubmissionBatch | None,
display_node_results: list[dict] | None = None,
) -> dict:
normalized_nodes = display_node_results or _normalize_node_results(conversation.node_results)
node_status_map = {node.get("label"): node.get("status", "") for node in normalized_nodes}
risk_status = node_status_map.get("风险预警", "待处理")
notify_status = node_status_map.get("飞书通知", "待处理")
export_status = node_status_map.get("Word 回填导出", "待处理")
@@ -458,6 +464,23 @@ def _build_notify_card(result: AgentResult | None, conversation: Conversation) -
}
def _normalize_node_results(node_results: list[dict]) -> list[dict]:
normalized = []
for node in node_results or []:
item = dict(node)
label = item.get("label", "")
status = item.get("status", "")
if label == "飞书通知":
if status in {"已完成", "success", "sent"}:
item["status"] = "已发送"
elif status in {"failed", "error"}:
item["status"] = "失败"
elif status in {"pending", "processing"}:
item["status"] = "待处理"
normalized.append(item)
return normalized
def _get_risk_level_display_text(level: str) -> str:
return RISK_LEVEL_DISPLAY.get(level, level)

View File

@@ -37,8 +37,8 @@
<section class="panel">
<h2 class="section-title">会话节点结果</h2>
<ul class="detail-list">
{% if conversation and conversation.node_results %}
{% for node in conversation.node_results %}
{% if conversation_node_results %}
{% for node in conversation_node_results %}
<li class="detail-item">
<strong>{{ node.label }} / {{ node.status }}</strong>
{% if node.summary %}

View File

@@ -507,7 +507,7 @@ def test_feishu_notification_report_builds_notification_payload_with_receipt_and
},
)
assert result.node_results[7]["status"] == "完成"
assert result.node_results[7]["status"] == "发送"
assert result.notification_payload["message_status"] == "sent"
assert result.notification_payload["web_detail_url"] == "https://example.com/audit/3"
assert result.notification_payload["receipt"]["message_id"] == "msg-3"

View File

@@ -532,6 +532,7 @@ def test_audit_detail_page_shows_export_summary_and_notification_receipt(client,
assert "风险项未清零" in content
assert "通知回执" in content
assert "msg-9" in content
assert "飞书通知 / 已发送" in content
assert "已发送" in content

View File

@@ -738,6 +738,7 @@ def test_chat_page_shows_risk_and_notification_cards_from_conversation_summary(c
assert "张三" in content
assert "True" in content
assert "CH1.11.5 沟通记录缺失" in content
assert "飞书通知 / 已发送" in content
assert "飞书通知能力卡" in content
assert "task_completed" in content
assert "已发送" in content