feat(shipping-notice): 升级货代发货流程为五阶段,完善业务校验
将货代发货流程从四阶段扩展为五阶段,拆分上传相关逻辑至独立的货代上传阶段; 统一多语言文案修正客户状态语义,将"客户尚未识别"调整为符合业务的"客户尚未确认"; 新增严格的上传成功验证谓词,需同时满足任务状态、全部预约单上传成功、存在有效成功上传尝试三个条件方可标记为完成; 新增坐标取值模型配置,支持Legacy冻结绝对坐标和锚点框架受限平移两种模式; 更新全链路相关文档、前端组件、后端服务与测试用例,确保业务逻辑对齐新业务规则。
This commit is contained in:
1 parent
1b6483a4ea
commit
935bf26fa6
86 files changed
+2743
-311
No files matched your search
@@ -6,7 +6,7 @@ services/shipping_notice/ui_state.py
|
||||
process_gate_projection(统一 Gate 用户摘要)、
|
||||
order_review_workbench_projection.apply_post_ot_gate_rules。
|
||||
逻辑:从 ShippingNotice DB 字段经状态机解析 checkpoint/checkpoint_kind,再统一投影 actions,
|
||||
再补充四阶段流程与可解释 summary(当前待办、暂停原因、下一自动步骤、操作入口、
|
||||
再补充五阶段流程与可解释 summary(当前待办、暂停原因、下一自动步骤、操作入口、
|
||||
stp_facts、progress_nodes);
|
||||
若存在 ProcessExecution,所有用户动作统一由 process_gate/actions 投影;
|
||||
Task 即正式 OT,Gate 摘要必须套用 OT 后规则(系统等待不冒充人工待办);
|
||||
@@ -71,7 +71,8 @@ WORKFLOW_STEPS: tuple[dict[str, str], ...] = (
|
||||
{"id": "shipping-stage-1", "code": "intake_parse", "label": "接收解析"},
|
||||
{"id": "shipping-stage-2", "code": "order_review", "label": "订单复核"},
|
||||
{"id": "shipping-stage-3", "code": "fulfillment_prep", "label": "通知准备"},
|
||||
{"id": "shipping-stage-4", "code": "upload_complete", "label": "通知完成"},
|
||||
{"id": "shipping-stage-4", "code": "freight_upload", "label": "货代上传"},
|
||||
{"id": "shipping-stage-5", "code": "upload_complete", "label": "通知完成"},
|
||||
)
|
||||
|
||||
_CURRENT_STEP_INDEX_MAP: dict[str, int] = {
|
||||
@@ -135,7 +136,7 @@ _PAUSE_REASON_BY_CHECKPOINT: dict[str, tuple[str, str]] = {
|
||||
CP_EXPORT_GENERATED: ("wait_manual_upload", "Excel 已生成,请下载后在货代平台上传,并在本系统登记凭据"),
|
||||
}
|
||||
|
||||
# 业务人员可见的四阶段;Gate/checkpoint 仍保留内部精度,但不得成为主进度条。
|
||||
# 业务人员可见的五阶段;Gate/checkpoint 仍保留内部精度,但不得成为主进度条。
|
||||
_STAGE_CHECKPOINT_CODES: dict[str, str] = {
|
||||
CP_PARSE_REVIEW: "order_review",
|
||||
CP_RSV_REQ: "order_review",
|
||||
@@ -148,12 +149,12 @@ _STAGE_CHECKPOINT_CODES: dict[str, str] = {
|
||||
CP_READY_EXPORT: "fulfillment_prep",
|
||||
CP_EXPORT_READY: "fulfillment_prep",
|
||||
CP_EXPORT_GENERATED: "fulfillment_prep",
|
||||
CP_WAITING_UPLOAD: "upload_complete",
|
||||
CP_WAITING_UPLOAD: "freight_upload",
|
||||
CP_UPLOAD_REQ: "fulfillment_prep",
|
||||
CP_UPLOAD_FAILED: "upload_complete",
|
||||
CP_UPLOAD_RESULT_UNKNOWN: "upload_complete",
|
||||
CP_UPLOADED: "upload_complete",
|
||||
CP_COMPLETED: "upload_complete",
|
||||
CP_UPLOAD_FAILED: "freight_upload",
|
||||
CP_UPLOAD_RESULT_UNKNOWN: "freight_upload",
|
||||
CP_UPLOADED: "freight_upload",
|
||||
CP_COMPLETED: "freight_upload",
|
||||
CP_REJECTED: "order_review",
|
||||
}
|
||||
|
||||
@@ -165,11 +166,13 @@ def _task_lifecycle(
|
||||
gate = (process_gate or {}).get('current_blocking_gate') or (process_gate or {}).get('current_gate')
|
||||
legacy_stage = _STAGE_CHECKPOINT_CODES.get(str(checkpoint or ''))
|
||||
if legacy_stage is None:
|
||||
legacy_stage = 'upload_complete' if str(checkpoint or '') in {CP_UPLOADED, CP_COMPLETED} else None
|
||||
legacy_stage = 'freight_upload' if str(checkpoint or '') in {CP_UPLOADED, CP_COMPLETED} else None
|
||||
if legacy_stage is None:
|
||||
# 仅没有 Gate 时,沿用旧任务领域事实映射;不能覆盖正式 Gate。
|
||||
legacy_index = _derive_current_step_index(task)
|
||||
legacy_stage = ('intake_parse', 'order_review', 'fulfillment_prep', 'upload_complete')[legacy_index]
|
||||
legacy_stage = ('intake_parse', 'order_review', 'fulfillment_prep', 'freight_upload')[legacy_index]
|
||||
from app.services.shipping_notice.upload_attempt_service import has_verified_upload_success
|
||||
|
||||
return project_lifecycle(
|
||||
current_gate=gate if isinstance(gate, dict) else None,
|
||||
blocking_reason=(
|
||||
@@ -180,6 +183,7 @@ def _task_lifecycle(
|
||||
legacy_stage=legacy_stage,
|
||||
# ShippingNotice 是已确认的正式 OT;生命周期入口可回看,写动作仍由 Gate 授权。
|
||||
has_candidate_context=True,
|
||||
verified_upload_success=has_verified_upload_success(task),
|
||||
)
|
||||
|
||||
|
||||
@@ -249,7 +253,7 @@ def _unified_actions(*, process_gate: dict[str, Any] | None) -> dict[str, Any]:
|
||||
|
||||
def _derive_current_step_index(task: ShippingNotice) -> int:
|
||||
"""
|
||||
根据任务领域事实推导四阶段流程当前索引。
|
||||
根据任务领域事实推导五阶段流程当前索引。
|
||||
|
||||
核心逻辑:优先使用 current_step 精准定位;缺失时按复核、库存、导出、上传事实兜底。
|
||||
"""
|
||||
@@ -295,7 +299,7 @@ def build_shipping_workflow_steps(
|
||||
lifecycle_stage: str | None = None,
|
||||
) -> list[dict[str, str]]:
|
||||
"""
|
||||
构造四阶段流程状态。
|
||||
构造五阶段流程状态。
|
||||
|
||||
Returns:
|
||||
list[dict]: 每步包含 id/code/label/status,status 为 completed/current/pending/blocked。
|
||||
@@ -304,13 +308,15 @@ def build_shipping_workflow_steps(
|
||||
(index for index, item in enumerate(LIFECYCLE_STAGES) if item['code'] == lifecycle_stage),
|
||||
None,
|
||||
)
|
||||
# 正式 Gate 已存在时,四阶段流程条必须使用同一裁决结果;旧字段只服务于历史兼容。
|
||||
# 正式 Gate 已存在时,五阶段流程条必须使用同一裁决结果;旧字段只服务于历史兼容。
|
||||
current_index = lifecycle_index if lifecycle_index is not None else _derive_current_step_index(task)
|
||||
pending_reason = str(task.pending_human_reason or "").strip()
|
||||
checkpoint_value = str(checkpoint or "").strip()
|
||||
steps: list[dict[str, str]] = []
|
||||
for index, step in enumerate(WORKFLOW_STEPS):
|
||||
if str(getattr(task, "upload_status", None) or "").strip().lower() in {"uploaded", "succeeded", "success"}:
|
||||
# ``upload_complete`` 已由唯一成功谓词裁决。历史 Task.upload_status 不能让
|
||||
# 流程条伪装为完成,否则会与 lifecycle_entries 和批次完成率分叉。
|
||||
if lifecycle_stage == "upload_complete":
|
||||
status = "completed"
|
||||
elif index < current_index:
|
||||
status = "completed"
|
||||
@@ -664,7 +670,7 @@ def _build_stage_context(
|
||||
stp_facts: dict[str, Any] | None,
|
||||
process_gate: dict[str, Any] | None,
|
||||
) -> dict[str, Any]:
|
||||
"""构造四阶段工作台的只读事实摘要,禁止把它作为新的业务状态机。
|
||||
"""构造五阶段工作台的只读事实摘要,禁止把它作为新的业务状态机。
|
||||
|
||||
通知准备只消费已经冻结的订单行、库存匹配结果和 Excel Artifact;通知完成
|
||||
只以真实上传 Attempt 判定成功,不能因进入 ``upload_complete`` 工作面而假装完成。
|
||||
@@ -834,13 +840,17 @@ def _build_stage_context(
|
||||
ShippingExportArtifact.task_id == task.id,
|
||||
).order_by(ShippingUploadAttempt.created_at.desc(), ShippingUploadAttempt.id.desc()).all()
|
||||
latest_attempt = attempts[0] if attempts else None
|
||||
succeeded_attempt = next(
|
||||
(item for item in attempts if str(getattr(item, 'status', '') or '').lower() == 'succeeded'),
|
||||
None,
|
||||
)
|
||||
latest_status = str(getattr(latest_attempt, 'status', '') or '').lower()
|
||||
upload_outcome = (
|
||||
'succeeded' if latest_status == 'succeeded' else
|
||||
'failed' if latest_status in {'failed', 'timed_out'} else
|
||||
'unknown' if latest_status == 'unknown' else
|
||||
'running' if latest_status in {'pending', 'running'} else
|
||||
'awaiting_manual' if lifecycle_stage == 'upload_complete' else
|
||||
'awaiting_manual' if lifecycle_stage == 'freight_upload' else
|
||||
'not_started'
|
||||
)
|
||||
return {
|
||||
@@ -869,6 +879,15 @@ def _build_stage_context(
|
||||
},
|
||||
'upload': {
|
||||
'outcome': upload_outcome,
|
||||
# 成功工作面只能消费该不可变成功事实,而非“最近一条 Attempt”。后者可能
|
||||
# 是迟到失败或人工核对记录,不能反向定义完成证据。
|
||||
'succeeded_attempt': ({
|
||||
'id': succeeded_attempt.id,
|
||||
'status': succeeded_attempt.status,
|
||||
'mode': succeeded_attempt.mode,
|
||||
'freight_ref_no': succeeded_attempt.freight_ref_no,
|
||||
'finished_at': succeeded_attempt.finished_at.isoformat() if succeeded_attempt.finished_at else None,
|
||||
} if succeeded_attempt is not None else None),
|
||||
'latest_attempt': ({
|
||||
'id': latest_attempt.id,
|
||||
'status': latest_attempt.status,
|
||||
@@ -930,7 +949,7 @@ def build_task_ui_state(
|
||||
'enabled': True,
|
||||
# Artifact 已验证是下载授权的唯一来源;它直接声明展示位置,
|
||||
# 不依赖旧 checkpoint 或 action code 位置映射。
|
||||
'target_surface': 'upload_complete',
|
||||
'target_surface': 'freight_upload',
|
||||
'target_anchor': 'excel_artifact',
|
||||
}, default_kind='view')
|
||||
action_codes = {
|
||||
|
||||
Reference in new issue
Block a user