feat(regulatory): 增加适用条件确认暂停恢复

This commit is contained in:
2026-06-07 09:19:31 +08:00
parent bd805203f1
commit bbd2d3532a
12 changed files with 535 additions and 1 deletions

View File

@@ -1,10 +1,15 @@
from __future__ import annotations
import json
from django.conf import settings
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.regulatory_review.events import record_event
from review_agent.regulatory_review.workflow import start_regulatory_review_workflow
@require_http_methods(["GET"])
@@ -43,6 +48,59 @@ def batch_status(request, batch_id: int):
)
@require_http_methods(["POST"])
@login_required
def confirm_conditions(request, batch_id: int):
batch = RegulatoryReviewBatch.objects.filter(pk=batch_id, user=request.user).first()
if not batch:
raise Http404("批次不存在。")
try:
payload = json.loads(request.body.decode("utf-8") or "{}")
except json.JSONDecodeError:
return JsonResponse({"error": "请求体不是有效 JSON。"}, status=400)
conditions = payload.get("conditions")
if not isinstance(conditions, dict):
return JsonResponse({"error": "conditions 必须是对象。"}, status=400)
batch.condition_json = {
**(batch.condition_json or {}),
"confirmed": True,
"confirmed_conditions": _normalize_conditions(conditions),
}
batch.status = RegulatoryReviewBatch.Status.RUNNING
batch.save(update_fields=["condition_json", "status"])
WorkflowNodeRun.objects.filter(
workflow_type="regulatory_review",
workflow_batch_id=batch.pk,
node_code="condition_confirm",
).update(
status=WorkflowNodeRun.Status.SUCCESS,
progress=100,
message="适用条件已确认",
)
record_event(
batch,
"condition_confirmed",
{"conditions": batch.condition_json["confirmed_conditions"], "resume_from": "rule_scope"},
)
start_regulatory_review_workflow(
batch,
async_run=getattr(settings, "REGULATORY_REVIEW_ASYNC", True),
)
batch.refresh_from_db()
return JsonResponse(
{
"batch": {
"id": batch.pk,
"workflow_type": "regulatory_review",
"batch_no": batch.batch_no,
"status": batch.status,
"condition_json": batch.condition_json,
}
}
)
def _format_risk_summary(risk_summary: dict) -> str:
labels = [
("blocking", "阻断项"),
@@ -56,3 +114,15 @@ def _format_risk_summary(risk_summary: dict) -> str:
for key, label in labels
if int(risk_summary.get(key) or 0)
)
def _normalize_conditions(conditions: dict) -> dict[str, str]:
allowed = [
"product_category",
"registration_type",
"clinical_evaluation_path",
"product_name",
"model_spec",
"intended_use",
]
return {key: str(conditions.get(key) or "").strip() for key in allowed}