refactor(shipping-notice): 重构货代发货通知状态管理,移除废弃的process_status字段

统一货代发货通知的业务阶段为四个标准阶段:接收解析、订单复核、发货准备、上传完成
设置 ui_state 为前端唯一状态数据源,不再依赖 process_status 驱动业务流程
删除 shipping_notices 表的废弃 process_status 列及对应复合索引,新增数据库迁移脚本
替换全栈代码中所有对 process_status 的引用为生命周期、上传状态等领域字段
更新相关文档、测试用例与前端展示逻辑适配新的状态管理规则
This commit is contained in:
hugo committed 2026-08-15 10:19:10 +08:00
1 parent 6684e7181a
commit 5ef8329bd8
178 files changed
+5091 -1734

No files matched your search

@@ -32,41 +32,22 @@ from app.services.shipping_notice.business_fingerprint import (
)
from app.services.shipping_notice.reservation_id import validated_reservation_id
# 与 state_machine 主路径对齐的活跃/完成/关闭态(禁止 needs_review/matching/export_ready 等非主状态)
_ACTIVE_PROCESS_STATUSES = frozenset(
{
'created',
'parsed',
'pending_review',
'inventory_ready',
'waiting_inventory',
'matched',
'waiting_upload',
'upload_failed',
}
)
_COMPLETED_PROCESS_STATUSES = frozenset({'uploaded', 'completed'})
_CLOSED_PROCESS_STATUSES = frozenset({'closed', 'rejected'})
_IRREVERSIBLE_PROCESS_STATUSES = frozenset({'uploaded', 'completed', 'closed', 'rejected'})
def classify_task_lifecycle(process_status: str | None) -> str:
"""将 process_status 归类为 active / completed / closed / unknown。"""
status = str(process_status or '').strip().lower()
if status in _ACTIVE_PROCESS_STATUSES:
return 'active'
if status in _COMPLETED_PROCESS_STATUSES:
return 'completed'
if status in _CLOSED_PROCESS_STATUSES:
def classify_task_lifecycle(task: ShippingNotice | dict[str, Any] | None) -> str:
"""根据生命周期/上传结果事实归类 active / completed / closed。"""
if task is None:
return 'unknown'
get = task.get if isinstance(task, dict) else lambda key, default=None: getattr(task, key, default)
lifecycle = str(get('lifecycle_status', '') or '').strip().lower()
if lifecycle in {'voided', 'archived', 'deleted', 'cancelled', 'canceled'}:
return 'closed'
return 'unknown'
upload = str(get('upload_status', '') or '').strip().lower()
if upload in {'uploaded', 'succeeded', 'success'} or get('freight_ref_no') or get('upload_receipt_json'):
return 'completed'
return 'active'
def is_irreversible_task(task: ShippingNotice) -> bool:
"""已 uploaded 或终态任务不可原地覆盖源文件。"""
status = str(task.process_status or '').strip().lower()
if status in _IRREVERSIBLE_PROCESS_STATUSES:
return True
upload_status = str(task.upload_status or '').strip().lower()
return upload_status in {'uploaded', 'succeeded', 'success'}
@@ -74,11 +55,10 @@ def is_irreversible_task(task: ShippingNotice) -> bool:
def _match_payload(task: ShippingNotice, *, match_type: str, matched_fields: list[str]) -> dict[str, Any]:
return {
'task_no': task.task_no,
'process_status': task.process_status,
'document_version': int(task.document_version or 1),
'match_type': match_type,
'matched_fields': list(matched_fields),
'lifecycle': classify_task_lifecycle(task.process_status),
'lifecycle': classify_task_lifecycle(task),
'created_at': utc_iso(task.created_at),
'content_fingerprint': task.content_fingerprint,
'content_fingerprint_version': task.content_fingerprint_version,
@@ -181,7 +161,7 @@ def detect_duplicates_for_intake(
.filter(
ShippingNotice.user_id == int(intake.user_id),
ShippingNotice.source_content_hash == content_hash,
ShippingNotice.process_status.notin_(list(_CLOSED_PROCESS_STATUSES)),
ShippingNotice.lifecycle_status == 'active',
)
.order_by(ShippingNotice.id.desc())
.limit(10)
@@ -235,7 +215,7 @@ def detect_duplicates_for_intake(
else 'possible_revision'
)
else:
primary_life = classify_task_lifecycle(matches[0].get('process_status'))
primary_life = str(matches[0].get('lifecycle') or 'unknown')
if primary_life == 'active':
status = 'same_active_task'
elif primary_life == 'completed':
@@ -253,7 +233,7 @@ def detect_duplicates_for_intake(
ShippingNotice.user_id == int(intake.user_id),
ShippingNotice.business_fingerprint == fingerprint,
ShippingNotice.fingerprint_version == version,
ShippingNotice.process_status.notin_(list(_CLOSED_PROCESS_STATUSES)),
ShippingNotice.lifecycle_status == 'active',
)
.order_by(ShippingNotice.id.desc())
.limit(5)
@@ -521,7 +501,7 @@ def detect_duplicates_for_candidate(
.filter(
ShippingNotice.user_id == int(intake.user_id),
ShippingNotice.source_content_hash == content_hash,
ShippingNotice.process_status.notin_(list(_CLOSED_PROCESS_STATUSES)),
ShippingNotice.lifecycle_status == 'active',
)
)
if skipped_ids:
@@ -574,7 +554,7 @@ def detect_duplicates_for_candidate(
else 'possible_revision'
)
else:
primary_life = classify_task_lifecycle(matches[0].get('process_status'))
primary_life = str(matches[0].get('lifecycle') or 'unknown')
if primary_life == 'active':
status = 'same_active_task'
elif primary_life == 'completed':
@@ -588,7 +568,7 @@ def detect_duplicates_for_candidate(
ShippingNotice.user_id == int(intake.user_id),
ShippingNotice.business_fingerprint == fingerprint,
ShippingNotice.fingerprint_version == version,
ShippingNotice.process_status.notin_(list(_CLOSED_PROCESS_STATUSES)),
ShippingNotice.lifecycle_status == 'active',
)
)
if skipped_ids: