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

@@ -19,6 +19,7 @@ from review_agent.models import (
from review_agent.regulatory_review.services.completeness_check import run_completeness_check
from review_agent.regulatory_review.services.consistency_check import run_consistency_check
from review_agent.regulatory_review.services.export import build_assistant_summary, export_review_results
from review_agent.regulatory_review.services.info_extract import detect_regulatory_condition_candidates
from review_agent.regulatory_review.services.risk_assess import persist_findings
from review_agent.regulatory_review.services.rule_loader import load_rule_file
from review_agent.regulatory_review.services.structure_check import run_structure_check
@@ -29,6 +30,7 @@ from .events import record_event
NODE_DEFINITIONS = [
("prepare", "准备", "prepare"),
("condition_confirm", "适用条件确认", "condition_confirm"),
("rule_scope", "规则范围", "rule_scope"),
("completeness_check", "完整性核查", "completeness_check"),
("text_extract", "文本抽取", "text_extract"),
@@ -43,6 +45,10 @@ NODE_DEFINITIONS = [
logger = logging.getLogger("review_agent.regulatory_review.workflow")
class WorkflowPausedForUser(Exception):
pass
def build_batch_no() -> str:
return f"RR-{timezone.localtime().strftime('%Y%m%d%H%M%S')}-{uuid4().hex[:6]}"
@@ -108,7 +114,11 @@ class RegulatoryWorkflowExecutor:
try:
for node in self._nodes():
if node.status == WorkflowNodeRun.Status.SUCCESS:
continue
self._run_node(node)
except WorkflowPausedForUser:
return
except Exception as exc:
logger.exception("Regulatory workflow failed", extra={"batch_id": self.batch.pk})
self.batch.status = RegulatoryReviewBatch.Status.FAILED
@@ -155,6 +165,9 @@ class RegulatoryWorkflowExecutor:
)
def _execute_node(self, node_code: str) -> None:
if node_code == "condition_confirm":
self._pause_for_condition_confirmation()
return
if node_code == "rule_scope":
self.rule_set = load_rule_file()
return
@@ -181,6 +194,34 @@ class RegulatoryWorkflowExecutor:
content=build_assistant_summary(self.batch, exports),
)
def _pause_for_condition_confirmation(self) -> None:
if self.batch.condition_json.get("confirmed"):
return
candidates = detect_regulatory_condition_candidates(self.batch.source_summary_batch)
self.batch.condition_json = {
**(self.batch.condition_json or {}),
"confirmed": False,
"resume_from": "rule_scope",
"candidates": candidates,
}
self.batch.status = RegulatoryReviewBatch.Status.WAITING_USER
self.batch.save(update_fields=["status", "condition_json"])
node = WorkflowNodeRun.objects.get(
workflow_type="regulatory_review",
workflow_batch_id=self.batch.pk,
node_code="condition_confirm",
)
node.status = WorkflowNodeRun.Status.WAITING_USER
node.progress = 50
node.message = "请确认产品类别、注册类型、临床评价路径等适用条件"
node.save(update_fields=["status", "progress", "message"])
record_event(
self.batch,
"waiting_user",
{"node_code": "condition_confirm", "candidates": candidates, "resume_from": "rule_scope"},
)
raise WorkflowPausedForUser()
def _rules(self) -> dict:
if self.rule_set is None:
self.rule_set = load_rule_file()