feat: 增强处理历史页指标与上下文跳转
This commit is contained in:
@@ -144,6 +144,28 @@ def build_history_rows(logs) -> list[dict]:
|
||||
return rows
|
||||
|
||||
|
||||
def build_history_metrics(history_rows: list[dict]) -> list[dict]:
|
||||
"""
|
||||
为处理历史页生成顶部指标卡。
|
||||
|
||||
口径保持前台可讲解:
|
||||
- 处理任务数:当前筛选结果中的执行记录数
|
||||
- 成功执行:状态为 success 的记录数
|
||||
- 通知已发送:通知状态为 sent 的记录数
|
||||
- 高风险阻断:风险等级为 high 的记录数
|
||||
"""
|
||||
total_count = len(history_rows)
|
||||
success_count = sum(1 for row in history_rows if row["log"].status == "success")
|
||||
notify_sent_count = sum(1 for row in history_rows if row.get("notify_status") == "sent")
|
||||
blocked_count = sum(1 for row in history_rows if row.get("risk_status") == "high")
|
||||
return [
|
||||
{"label": "处理任务数", "value": total_count, "note": "按当前筛选条件回看执行留痕。"},
|
||||
{"label": "成功执行", "value": success_count, "note": "执行完成并写入审计快照。"},
|
||||
{"label": "通知已发送", "value": notify_sent_count, "note": "已生成 sent 状态的通知留痕。"},
|
||||
{"label": "高风险阻断", "value": blocked_count, "note": "风险等级为 high 的处理记录。"},
|
||||
]
|
||||
|
||||
|
||||
def build_detail_summary(log: AgentAuditLog, conversation, notifications) -> dict:
|
||||
"""
|
||||
组装处理历史详情页的导出摘要与通知回执信息。
|
||||
|
||||
@@ -2,7 +2,7 @@ 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_rows
|
||||
from .services import build_detail_summary, build_history_metrics, build_history_rows
|
||||
|
||||
|
||||
def log_list(request):
|
||||
@@ -35,11 +35,13 @@ def log_list(request):
|
||||
if (log.structured_output or {}).get("highest_risk_level") == risk_status
|
||||
or (log.structured_output or {}).get("risk_level") == risk_status
|
||||
]
|
||||
history_rows = build_history_rows(logs)
|
||||
return render(
|
||||
request,
|
||||
"audit/log_list.html",
|
||||
{
|
||||
"history_rows": build_history_rows(logs),
|
||||
"history_rows": history_rows,
|
||||
"history_metrics": build_history_metrics(history_rows),
|
||||
"selected_scenario_id": scenario_id,
|
||||
"keyword": keyword,
|
||||
"notify_status": notify_status,
|
||||
|
||||
Reference in New Issue
Block a user