feat: 增强处理历史资料规模与会话状态展示
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
from agent_core.results import AgentResult
|
from agent_core.results import AgentResult
|
||||||
|
from apps.chat.models import Conversation
|
||||||
|
from apps.documents.models import SubmissionBatch
|
||||||
|
|
||||||
from .models import AgentAuditLog, NotificationRecord
|
from .models import AgentAuditLog, NotificationRecord
|
||||||
|
|
||||||
@@ -106,13 +108,32 @@ def build_history_rows(logs) -> list[dict]:
|
|||||||
(item.batch_id, item.conversation_id): item
|
(item.batch_id, item.conversation_id): item
|
||||||
for item in NotificationRecord.objects.order_by("-created_at")
|
for item in NotificationRecord.objects.order_by("-created_at")
|
||||||
}
|
}
|
||||||
|
batch_map = {
|
||||||
|
item.batch_id: item
|
||||||
|
for item in SubmissionBatch.objects.filter(
|
||||||
|
batch_id__in=[log.batch_id for log in logs if log.batch_id]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
conversation_map = {
|
||||||
|
item.conversation_id: item
|
||||||
|
for item in Conversation.objects.filter(
|
||||||
|
conversation_id__in=[log.conversation_id for log in logs if log.conversation_id]
|
||||||
|
)
|
||||||
|
}
|
||||||
rows = []
|
rows = []
|
||||||
for log in logs:
|
for log in logs:
|
||||||
notification = notification_map.get((log.batch_id, log.conversation_id))
|
notification = notification_map.get((log.batch_id, log.conversation_id))
|
||||||
|
batch = batch_map.get(log.batch_id)
|
||||||
|
conversation = conversation_map.get(log.conversation_id)
|
||||||
structured_output = log.structured_output or {}
|
structured_output = log.structured_output or {}
|
||||||
rows.append(
|
rows.append(
|
||||||
{
|
{
|
||||||
"log": log,
|
"log": log,
|
||||||
|
"batch": batch,
|
||||||
|
"conversation": conversation,
|
||||||
|
"batch_scale": f"{batch.file_count} 份 / {batch.page_count} 页" if batch else "-",
|
||||||
|
"batch_status": batch.get_import_status_display_text() if batch else "-",
|
||||||
|
"conversation_status": conversation.task_status if conversation else "-",
|
||||||
"risk_status": structured_output.get("highest_risk_level")
|
"risk_status": structured_output.get("highest_risk_level")
|
||||||
or structured_output.get("risk_level")
|
or structured_output.get("risk_level")
|
||||||
or "-",
|
or "-",
|
||||||
|
|||||||
@@ -61,6 +61,9 @@
|
|||||||
<th>产品名称</th>
|
<th>产品名称</th>
|
||||||
<th>批次号</th>
|
<th>批次号</th>
|
||||||
<th>会话</th>
|
<th>会话</th>
|
||||||
|
<th>资料规模</th>
|
||||||
|
<th>资料包状态</th>
|
||||||
|
<th>会话状态</th>
|
||||||
<th>输入摘要</th>
|
<th>输入摘要</th>
|
||||||
<th>状态</th>
|
<th>状态</th>
|
||||||
<th>风险状态</th>
|
<th>风险状态</th>
|
||||||
@@ -79,6 +82,9 @@
|
|||||||
<td>{{ row.log.product_name|default:"-" }}</td>
|
<td>{{ row.log.product_name|default:"-" }}</td>
|
||||||
<td>{{ row.log.batch_id|default:"-" }}</td>
|
<td>{{ row.log.batch_id|default:"-" }}</td>
|
||||||
<td>{{ row.log.conversation_id|default:"-" }}</td>
|
<td>{{ row.log.conversation_id|default:"-" }}</td>
|
||||||
|
<td>{{ row.batch_scale }}</td>
|
||||||
|
<td>{{ row.batch_status }}</td>
|
||||||
|
<td>{{ row.conversation_status }}</td>
|
||||||
<td>{{ row.log.get_user_input_summary }}</td>
|
<td>{{ row.log.get_user_input_summary }}</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="pill {% if row.log.status == 'success' %}pill-success{% else %}pill-danger{% endif %}">{{ row.log.get_status_display_text }}</span>
|
<span class="pill {% if row.log.status == 'success' %}pill-success{% else %}pill-danger{% endif %}">{{ row.log.get_status_display_text }}</span>
|
||||||
@@ -91,7 +97,7 @@
|
|||||||
<td><a class="button" href="{% url 'audit:detail' row.log.id %}">查看详情</a></td>
|
<td><a class="button" href="{% url 'audit:detail' row.log.id %}">查看详情</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<tr><td colspan="13">暂无处理历史,先去执行一次审核任务。</td></tr>
|
<tr><td colspan="16">暂无处理历史,先去执行一次审核任务。</td></tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from agent_core.results import AgentResult
|
|||||||
from apps.audit.models import AgentAuditLog, DemoBusinessRecord, NotificationRecord
|
from apps.audit.models import AgentAuditLog, DemoBusinessRecord, NotificationRecord
|
||||||
from apps.audit.services import create_audit_log, create_notification_record
|
from apps.audit.services import create_audit_log, create_notification_record
|
||||||
from apps.chat.models import Conversation
|
from apps.chat.models import Conversation
|
||||||
|
from apps.documents.models import SubmissionBatch
|
||||||
from agent_core.tools.builtin_tools import query_demo_records
|
from agent_core.tools.builtin_tools import query_demo_records
|
||||||
|
|
||||||
|
|
||||||
@@ -354,3 +355,45 @@ def test_audit_detail_page_shows_conversation_node_results(client, db):
|
|||||||
assert "会话节点结果" in content
|
assert "会话节点结果" in content
|
||||||
assert "风险预警 / 已阻断" in content
|
assert "风险预警 / 已阻断" in content
|
||||||
assert "飞书通知 / 失败" in content
|
assert "飞书通知 / 失败" in content
|
||||||
|
|
||||||
|
|
||||||
|
def test_audit_list_shows_batch_scale_and_conversation_status(client, db):
|
||||||
|
SubmissionBatch.objects.create(
|
||||||
|
batch_id="SUB-20260604-001",
|
||||||
|
product_name="产品A",
|
||||||
|
workflow_type="registration",
|
||||||
|
conversation_id="conv-001",
|
||||||
|
file_count=4,
|
||||||
|
page_count=26,
|
||||||
|
import_status="review_required",
|
||||||
|
)
|
||||||
|
Conversation.objects.create(
|
||||||
|
conversation_id="conv-001",
|
||||||
|
title="产品A",
|
||||||
|
product_name="产品A",
|
||||||
|
batch_id="SUB-20260604-001",
|
||||||
|
task_status="failed",
|
||||||
|
node_results=[
|
||||||
|
{"label": "风险预警", "status": "已阻断"},
|
||||||
|
{"label": "飞书通知", "status": "失败"},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
create_audit_log(
|
||||||
|
"document_review",
|
||||||
|
"注册审核智能体",
|
||||||
|
"问题一",
|
||||||
|
AgentResult(answer="回答一", status="failed"),
|
||||||
|
batch_id="SUB-20260604-001",
|
||||||
|
conversation_id="conv-001",
|
||||||
|
product_name="产品A",
|
||||||
|
)
|
||||||
|
|
||||||
|
response = client.get(reverse("audit:list"))
|
||||||
|
|
||||||
|
content = response.content.decode("utf-8")
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert "资料规模" in content
|
||||||
|
assert "4 份 / 26 页" in content
|
||||||
|
assert "会话状态" in content
|
||||||
|
assert "failed" in content
|
||||||
|
assert "待复核" in content
|
||||||
|
|||||||
Reference in New Issue
Block a user