refactor(shipping-notice): 进度信号统一为 15 阶 stage 契约码并透传阻断原因
- 后端进度写入 step_key 全量切换为 15 阶契约 stage 码 - 投影层清除 CheckPoint stepN_* 遗留别名与子串/前缀启发式,阶段信号按契约码精确匹配 - 建单前 Case 摘要透传草稿首要阻断原因 - 前端标签/归一化/处理卡片同步契约码,阻断原因按 i18n 优先展示 - 修复正式下游回看时 activeCase 刻意为空导致队列定位与接收解析上下文静默跳过 - 同步更新投影/门禁/工作台/RPA 流程测试
This commit is contained in:
1 parent
d1adbe5ec5
commit
18af972d20
34 files changed
+903
-111
No files matched your search
@@ -2,7 +2,7 @@
|
||||
services/shipping_notice/tool_common.py
|
||||
|
||||
用途:发货通知 Tool 链共享配置、payload 合并、消息拼接与任务事件写入(无阶段业务编排)。
|
||||
依赖:constants、models.ShippingTaskEvent、fulfillment_audit、stp_progress_contract。
|
||||
依赖:constants、models.ShippingTaskEvent、fulfillment_audit、stp_progress_contract、progress_audit_contract。
|
||||
逻辑:task_workflow / inventory_workflow / fulfillment_workflow / decision_workflow 共用;
|
||||
log_task_event 对 inventory_rpa_/inventory_source_/export_/notice_replace/
|
||||
freight_cancellation_/STP 事件同步投影到 ShippingAuditEvent;
|
||||
@@ -20,6 +20,10 @@ from flask import current_app
|
||||
from app import db
|
||||
from app.models import ShippingNotice, ShippingOrderTask, ShippingTaskEvent
|
||||
from app.services.shipping_notice.constants import AUTO_CHAIN_FALLBACK
|
||||
from app.services.shipping_notice.progress_audit_contract import (
|
||||
SHIPPING_PROCESSING_STAGES,
|
||||
shipping_processing_stage_index,
|
||||
)
|
||||
|
||||
|
||||
def cfg_bool(key: str, default: bool = False) -> bool:
|
||||
@@ -211,7 +215,7 @@ def prepend_tool_message(result: dict[str, Any], prefix: str) -> dict[str, Any]:
|
||||
def set_task_step_progress(
|
||||
task: ShippingNotice,
|
||||
*,
|
||||
step_key: str,
|
||||
stage: str,
|
||||
step_title: str,
|
||||
status: str,
|
||||
message: str,
|
||||
@@ -221,13 +225,38 @@ def set_task_step_progress(
|
||||
detail: str | None = None,
|
||||
extra: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
"""写入任务当前步骤与步骤内细粒度进度,统一落到 OT 的流程字段。"""
|
||||
"""写入任务当前步骤与步骤内细粒度进度,统一落到 OT 的流程字段。
|
||||
|
||||
【AI 触发时机】履约工作流(库存准备/匹配/Excel/上传/通知重解析)报告阶段内
|
||||
细粒度进度或失败等待人工时调用。
|
||||
|
||||
核心逻辑:``stage`` 必须是冻结 15 阶契约码(SHIPPING_PROCESSING_STAGES 成员),
|
||||
写入 ``current_step`` 与 ``step_payload_json.current_step_progress`` 供投影展示;
|
||||
``OT.stage`` 仅按 15 阶序列【只进不退】推进——空缺时直接写入,已有值仅当新
|
||||
stage 序号不小于旧值才覆盖,保证进度上报永远不会把订单拉回早期阶段。
|
||||
|
||||
Args:
|
||||
stage: 15 阶契约码(如 inventory_fetching / inventory_matching /
|
||||
excel_generating / freight_uploading);禁止传入 CheckPoint 时代
|
||||
stepN_* 遗留键(已全部清除)。
|
||||
step_title: 展示用步骤名。
|
||||
status: 步骤执行态(running/completed/needs_human/failed 等调用方语义)。
|
||||
message: 用户可读进度说明。
|
||||
|
||||
Raises:
|
||||
ValueError: ``stage`` 不是 15 阶契约成员时立即失败(写错阶段码属于代码缺陷)。
|
||||
"""
|
||||
code = str(stage or '').strip()
|
||||
if code not in SHIPPING_PROCESSING_STAGES:
|
||||
raise ValueError(
|
||||
f'set_task_step_progress: stage must be a SHIPPING_PROCESSING_STAGES member, got {stage!r}'
|
||||
)
|
||||
owner = task
|
||||
if isinstance(task, ShippingNotice) and getattr(task, 'order_task_id', None):
|
||||
owner = db.session.get(ShippingOrderTask, int(task.order_task_id)) or task
|
||||
payload = dict(getattr(owner, 'step_payload_json', None) or {})
|
||||
progress: dict[str, Any] = {
|
||||
"step_key": step_key,
|
||||
"stage": code,
|
||||
"step_title": step_title,
|
||||
"status": status,
|
||||
"message": str(message or "").strip(),
|
||||
@@ -244,9 +273,19 @@ def set_task_step_progress(
|
||||
progress["extra"] = extra
|
||||
payload["current_step_progress"] = progress
|
||||
if hasattr(owner, 'current_step'):
|
||||
owner.current_step = step_key
|
||||
owner.current_step = code
|
||||
if hasattr(owner, 'stage'):
|
||||
owner.stage = step_key
|
||||
current_stage = str(getattr(owner, 'stage', None) or '').strip().lower()
|
||||
current_idx = shipping_processing_stage_index(current_stage)
|
||||
target_idx = shipping_processing_stage_index(code)
|
||||
# 只进不退:进度上报只允许推进或停留在既有序列位置,禁止回退
|
||||
# (历史缺陷:进度上报曾把 order_creating 踩回早期码,工作台掉回接收解析)。
|
||||
if (
|
||||
not current_stage
|
||||
or current_idx is None
|
||||
or (target_idx is not None and target_idx >= current_idx)
|
||||
):
|
||||
owner.stage = code
|
||||
if hasattr(owner, 'step_payload_json'):
|
||||
owner.step_payload_json = payload
|
||||
|
||||
|
||||
Reference in new issue
Block a user