feat(file-summary): 接入文件汇总工作流触发
This commit is contained in:
@@ -3,6 +3,8 @@ from django.http import Http404, JsonResponse
|
||||
from django.views.decorators.http import require_http_methods
|
||||
|
||||
from review_agent.models import Conversation, FileAttachment
|
||||
from review_agent.models import FileSummaryBatch, WorkflowEvent
|
||||
from .events import serialize_event
|
||||
|
||||
from .storage import save_uploaded_attachment, serialize_attachment
|
||||
|
||||
@@ -56,3 +58,50 @@ def attachment_detail(request, conversation_id: int, attachment_id: int):
|
||||
attachment.is_active = False
|
||||
attachment.save(update_fields=["upload_status", "is_active"])
|
||||
return JsonResponse({"ok": True, "attachment": serialize_attachment(attachment)})
|
||||
|
||||
|
||||
@require_http_methods(["GET"])
|
||||
@login_required
|
||||
def batch_status(request, batch_id: int):
|
||||
batch = FileSummaryBatch.objects.filter(pk=batch_id, user=request.user).first()
|
||||
if not batch:
|
||||
raise Http404("批次不存在。")
|
||||
return JsonResponse(
|
||||
{
|
||||
"batch": {
|
||||
"id": batch.pk,
|
||||
"batch_no": batch.batch_no,
|
||||
"status": batch.status,
|
||||
"product_name": batch.product_name,
|
||||
"total_files": batch.total_files,
|
||||
"success_files": batch.success_files,
|
||||
"failed_files": batch.failed_files,
|
||||
"total_pages": batch.total_pages,
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"node_code": node.node_code,
|
||||
"node_name": node.node_name,
|
||||
"status": node.status,
|
||||
"progress": node.progress,
|
||||
"message": node.message,
|
||||
}
|
||||
for node in batch.node_runs.order_by("id")
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@require_http_methods(["GET"])
|
||||
@login_required
|
||||
def batch_events(request, batch_id: int):
|
||||
batch = FileSummaryBatch.objects.filter(pk=batch_id, user=request.user).first()
|
||||
if not batch:
|
||||
raise Http404("批次不存在。")
|
||||
after = request.GET.get("after") or "0"
|
||||
try:
|
||||
after_id = int(after)
|
||||
except ValueError:
|
||||
after_id = 0
|
||||
events = WorkflowEvent.objects.filter(batch=batch, pk__gt=after_id).order_by("id")
|
||||
return JsonResponse({"events": [serialize_event(event) for event in events]})
|
||||
|
||||
Reference in New Issue
Block a user