feat(shipping-process-gates): 落地全门禁中断恢复并消除双真相
纳入 Execution/Gate/Attempt 模型与迁移、Worker/API/前端恢复卡片与 Admin 诊断, Gate 阻断时清零旧 action_buttons,异常摘要统一脱敏,并为运维筛选与 Attempt Diff 补齐入口。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
b352c281d5
commit
323928626b
92 files changed
+11930
-458
No files matched your search
@@ -2,9 +2,12 @@
|
||||
services/shipping_notice/ui_state.py
|
||||
|
||||
用途:发货通知任务/批次 UI 状态读模型,作为通知摘要、人工复核与任务工作台的统一状态来源。
|
||||
依赖:models.ShippingTask/ShippingBatch、state_machine、query_service、constants、stp_progress_contract。
|
||||
依赖:models.ShippingTask/ShippingBatch、state_machine、query_service、constants、stp_progress_contract、
|
||||
process_gate_projection(统一 Gate 用户摘要)。
|
||||
逻辑:从 ShippingTask DB 字段经状态机解析 checkpoint/checkpoint_kind/action_buttons,
|
||||
再补充七步流程与可解释 summary(当前待办、暂停原因、下一自动步骤、操作入口、stp_facts);
|
||||
若存在 ProcessExecution 且当前有 blocking Gate,则清空 action_buttons,
|
||||
恢复动作仅由 process_gate 驱动(Gate 为唯一业务真相);
|
||||
批次 UI 仅作会话上传集合摘要,不作为履约写操作面。
|
||||
"""
|
||||
|
||||
@@ -546,13 +549,35 @@ def build_task_ui_state(task: ShippingTask) -> dict[str, Any]:
|
||||
构建单票任务 UI State。
|
||||
|
||||
核心逻辑:所有 UI 入口只消费这里输出的 checkpoint/checkpoint_kind/action_buttons/summary,
|
||||
禁止 Chat、通知卡与任务中心分别推导状态。
|
||||
禁止 Chat、通知卡与任务中心分别推导状态;有 Execution 时附带统一 Gate 用户摘要;
|
||||
存在 current_blocking_gate 时清空 STP action_buttons,恢复仅走 process_gate。
|
||||
"""
|
||||
ui = resolve_task_ui_state(task)
|
||||
action_buttons = _action_buttons_for_task(task)
|
||||
process_gate = _process_gate_user_summary_for_task(task)
|
||||
# [STEP] Gate 阻断时旧 action_buttons 不再作为业务恢复真相,避免双卡片/双动作。
|
||||
if isinstance(process_gate, dict) and process_gate.get('current_blocking_gate'):
|
||||
action_buttons = []
|
||||
steps = build_shipping_workflow_steps(task, ui.checkpoint)
|
||||
current_index = _derive_current_step_index(task)
|
||||
current_step = steps[current_index] if 0 <= current_index < len(steps) else None
|
||||
summary = _build_task_summary(
|
||||
task,
|
||||
ui.checkpoint,
|
||||
checkpoint_kind=ui.checkpoint_kind,
|
||||
action_buttons=action_buttons,
|
||||
)
|
||||
if process_gate is not None:
|
||||
summary['process_gate'] = process_gate
|
||||
# 仅输出当前 Gate;删除旧门禁重复摘要键(若历史调用方写入)。
|
||||
summary.pop('auto_build_gates', None)
|
||||
summary.pop('failed_gates', None)
|
||||
if process_gate.get('blocking_message'):
|
||||
summary['current_blocking_message'] = process_gate['blocking_message']
|
||||
if process_gate.get('diagnostic_hint'):
|
||||
summary['diagnostic_hint'] = process_gate['diagnostic_hint']
|
||||
if process_gate.get('current_blocking_gate'):
|
||||
summary['allowed_actions'] = []
|
||||
return {
|
||||
"task_no": task.task_no,
|
||||
"batch_no": task.batch.batch_no if task.batch is not None else None,
|
||||
@@ -564,17 +589,34 @@ def build_task_ui_state(task: ShippingTask) -> dict[str, Any]:
|
||||
"match_status": task.match_status,
|
||||
"current_step": current_step,
|
||||
"steps": steps,
|
||||
"summary": _build_task_summary(
|
||||
task,
|
||||
ui.checkpoint,
|
||||
checkpoint_kind=ui.checkpoint_kind,
|
||||
action_buttons=action_buttons,
|
||||
),
|
||||
"summary": summary,
|
||||
"action_buttons": action_buttons,
|
||||
"process_gate": process_gate,
|
||||
"updated_at": task.updated_at.isoformat() if task.updated_at else None,
|
||||
}
|
||||
|
||||
|
||||
def _process_gate_user_summary_for_task(task: ShippingTask) -> dict[str, Any] | None:
|
||||
"""
|
||||
按 Task 查找活动 Execution 的用户 Gate 摘要。
|
||||
|
||||
Returns:
|
||||
project_user_gate_summary;无 Execution 时 None。
|
||||
"""
|
||||
from app.models import ShippingProcessExecution
|
||||
from app.services.shipping_notice.process_gate_projection import project_user_gate_summary
|
||||
|
||||
execution = (
|
||||
ShippingProcessExecution.query
|
||||
.filter_by(task_id=int(task.id))
|
||||
.order_by(ShippingProcessExecution.id.desc())
|
||||
.first()
|
||||
)
|
||||
if execution is None:
|
||||
return None
|
||||
return project_user_gate_summary(execution)
|
||||
|
||||
|
||||
def build_batch_ui_state(batch: ShippingBatch) -> dict[str, Any]:
|
||||
"""
|
||||
构建批次级会话上传集合摘要(非履约写操作面)。
|
||||
|
||||
Reference in new issue
Block a user