feat(regulatory): 增加整改复核闭环
This commit is contained in:
@@ -7,9 +7,10 @@ from django.http import Http404, JsonResponse
|
||||
from django.views.decorators.http import require_http_methods
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from review_agent.models import RegulatoryReviewBatch, WorkflowNodeRun
|
||||
from review_agent.models import FileSummaryBatch, RegulatoryReviewBatch, WorkflowNodeRun
|
||||
from review_agent.regulatory_review.events import record_event
|
||||
from review_agent.regulatory_review.workflow import start_regulatory_review_workflow
|
||||
from review_agent.regulatory_review.services.rectification_review import review_missing_issues
|
||||
from review_agent.regulatory_review.workflow import create_regulatory_review_batch, start_regulatory_review_workflow
|
||||
|
||||
|
||||
@require_http_methods(["GET"])
|
||||
@@ -78,6 +79,87 @@ def confirm_conditions(request, batch_id: int):
|
||||
progress=100,
|
||||
message="适用条件已确认",
|
||||
)
|
||||
|
||||
|
||||
@require_http_methods(["POST"])
|
||||
@login_required
|
||||
def start_full_review(request, batch_id: int):
|
||||
source_batch = RegulatoryReviewBatch.objects.filter(pk=batch_id, user=request.user).first()
|
||||
if not source_batch:
|
||||
raise Http404("批次不存在。")
|
||||
payload, error_response = _json_payload(request)
|
||||
if error_response:
|
||||
return error_response
|
||||
summary_batch = FileSummaryBatch.objects.filter(
|
||||
pk=payload.get("file_summary_batch_id"),
|
||||
conversation=source_batch.conversation,
|
||||
user=request.user,
|
||||
status=FileSummaryBatch.Status.SUCCESS,
|
||||
).first()
|
||||
if not summary_batch:
|
||||
return JsonResponse({"error": "file_summary_batch_id 不存在或未成功。"}, status=400)
|
||||
new_batch = create_regulatory_review_batch(
|
||||
conversation=source_batch.conversation,
|
||||
user=request.user,
|
||||
source_summary_batch=summary_batch,
|
||||
)
|
||||
new_batch.condition_json = {
|
||||
"source_review_batch_id": source_batch.pk,
|
||||
"regenerated_from": {
|
||||
"batch_id": source_batch.pk,
|
||||
"batch_no": source_batch.batch_no,
|
||||
"file_summary_batch_id": source_batch.source_summary_batch_id,
|
||||
"file_summary_batch_no": source_batch.source_summary_batch.batch_no,
|
||||
},
|
||||
"confirmed": True,
|
||||
"confirmed_conditions": source_batch.condition_json.get("confirmed_conditions", {}),
|
||||
}
|
||||
new_batch.save(update_fields=["condition_json"])
|
||||
record_event(
|
||||
new_batch,
|
||||
"full_package_review_started",
|
||||
{"source_review_batch_id": source_batch.pk, "source_review_batch_no": source_batch.batch_no},
|
||||
)
|
||||
start_regulatory_review_workflow(
|
||||
new_batch,
|
||||
async_run=getattr(settings, "REGULATORY_REVIEW_ASYNC", True),
|
||||
)
|
||||
new_batch.refresh_from_db()
|
||||
return JsonResponse(
|
||||
{
|
||||
"batch": {
|
||||
"id": new_batch.pk,
|
||||
"workflow_type": "regulatory_review",
|
||||
"batch_no": new_batch.batch_no,
|
||||
"status": new_batch.status,
|
||||
"source_review_batch_id": source_batch.pk,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@require_http_methods(["POST"])
|
||||
@login_required
|
||||
def review_issues(request, batch_id: int):
|
||||
batch = RegulatoryReviewBatch.objects.filter(pk=batch_id, user=request.user).first()
|
||||
if not batch:
|
||||
raise Http404("批次不存在。")
|
||||
payload, error_response = _json_payload(request)
|
||||
if error_response:
|
||||
return error_response
|
||||
issue_ids = payload.get("issue_ids")
|
||||
if not isinstance(issue_ids, list):
|
||||
return JsonResponse({"error": "issue_ids 必须是列表。"}, status=400)
|
||||
summary_batch = FileSummaryBatch.objects.filter(
|
||||
pk=payload.get("file_summary_batch_id"),
|
||||
conversation=batch.conversation,
|
||||
user=request.user,
|
||||
status=FileSummaryBatch.Status.SUCCESS,
|
||||
).first()
|
||||
if not summary_batch:
|
||||
return JsonResponse({"error": "file_summary_batch_id 不存在或未成功。"}, status=400)
|
||||
record = review_missing_issues(batch=batch, issue_ids=[int(item) for item in issue_ids], file_summary_batch=summary_batch)
|
||||
return JsonResponse({"review_record": record})
|
||||
record_event(
|
||||
batch,
|
||||
"condition_confirmed",
|
||||
@@ -126,3 +208,10 @@ def _normalize_conditions(conditions: dict) -> dict[str, str]:
|
||||
"intended_use",
|
||||
]
|
||||
return {key: str(conditions.get(key) or "").strip() for key in allowed}
|
||||
|
||||
|
||||
def _json_payload(request):
|
||||
try:
|
||||
return json.loads(request.body.decode("utf-8") or "{}"), None
|
||||
except json.JSONDecodeError:
|
||||
return {}, JsonResponse({"error": "请求体不是有效 JSON。"}, status=400)
|
||||
|
||||
Reference in New Issue
Block a user