feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码
This commit is contained in:
1 parent
935bf26fa6
commit
7cfd5d167e
230 files changed
+9337
-10989
No files matched your search
@@ -2,8 +2,8 @@
|
||||
services/shipping_notice/lifecycle_projection.py
|
||||
|
||||
用途:为批次进度、任务详情与订单生命周期工作台裁决同一份五阶段业务生命周期。
|
||||
依赖:process_gate_contract 的阻断原因归属;调用方提供正式 Gate、Case/Candidate 或历史兜底事实。
|
||||
逻辑:正式 Process Gate 优先,其次是可解释阻断原因;仅无正式事实时才使用旧阶段兜底。
|
||||
依赖:process_gate_contract 的阻断原因归属;调用方提供正式 Gate、Case/Candidate 或已核验成功事实。
|
||||
逻辑:正式 Process Gate 优先,其次是可解释阻断原因;无正式事实时保持未分类。
|
||||
本模块只做只读业务投影,不授权任何写操作;阶段入口与实际动作权限必须分开。
|
||||
"""
|
||||
|
||||
@@ -48,24 +48,29 @@ LIFECYCLE_STAGE_BY_GATE: dict[str, str] = {
|
||||
'manual_upload_handoff': 'freight_upload',
|
||||
}
|
||||
|
||||
# 没有正式 Gate 的历史项才能使用此映射。它必须保持在共享裁决器内,避免各入口漂移。
|
||||
LIFECYCLE_STAGE_RANGES: tuple[tuple[str, set[str]], ...] = (
|
||||
('intake_parse', {'upload_received', 'email_parsing', 'email_adjudicating', 'document_parsing', 'candidate_creating'}),
|
||||
('order_review', {
|
||||
'customer_resolving', 'duplicate_checking', 'order_creating', 'review_required',
|
||||
'waiting_review', 'waiting_human_review', 'waiting_human', 'pre_ot_stp', 'order_review',
|
||||
}),
|
||||
('fulfillment_prep', {
|
||||
'inventory_source_resolving', 'inventory_fetching', 'inventory_fetch', 'inventory_preparation',
|
||||
'inventory_candidates_calculated', 'inventory_candidates_frozen', 'inventory_snapshots_ready',
|
||||
'inventory_matching', 'inventory_match', 'inventory_matched', 'excel_generating',
|
||||
'excel_generate', 'excel_generated',
|
||||
}),
|
||||
('freight_upload', {
|
||||
'freight_uploading', 'freight_upload', 'upload_receipt_recorded', 'upload_complete', 'completed',
|
||||
}),
|
||||
)
|
||||
|
||||
# 已持久化的 Processing 技术阶段到五阶段业务工作面的唯一映射。它只用于
|
||||
# 读模型展示,不推进订单、不创建任务,也不授予任何动作。正式 Gate 仍在
|
||||
# 技术阶段缺失时提供兜底,避免历史数据被无条件覆盖。
|
||||
LIFECYCLE_STAGE_BY_PROCESSING_STAGE: dict[str, str] = {
|
||||
'upload_received': 'intake_parse',
|
||||
'email_parsing': 'intake_parse',
|
||||
'document_parsing': 'intake_parse',
|
||||
'email_adjudicating': 'intake_parse',
|
||||
'candidate_creating': 'intake_parse',
|
||||
'waiting_review': 'order_review',
|
||||
'customer_resolving': 'order_review',
|
||||
'duplicate_checking': 'order_review',
|
||||
'inventory_source_resolving': 'order_review',
|
||||
'order_creating': 'fulfillment_prep',
|
||||
'inventory_fetching': 'fulfillment_prep',
|
||||
'inventory_preparation': 'fulfillment_prep',
|
||||
'inventory_matching': 'fulfillment_prep',
|
||||
'inventory_sufficiency': 'fulfillment_prep',
|
||||
'excel_generating': 'fulfillment_prep',
|
||||
'freight_uploading': 'freight_upload',
|
||||
'manual_upload_handoff': 'freight_upload',
|
||||
'completed': 'upload_complete',
|
||||
}
|
||||
|
||||
def lifecycle_entries(
|
||||
*,
|
||||
@@ -104,14 +109,16 @@ def project_lifecycle(
|
||||
*,
|
||||
current_gate: dict[str, Any] | None,
|
||||
blocking_reason: dict[str, Any] | None,
|
||||
legacy_stage: str | None,
|
||||
has_candidate_context: bool,
|
||||
has_intake_parse_context: bool = False,
|
||||
verified_upload_success: bool = False,
|
||||
processing_stage: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""按 Gate → 阻断归属 → 历史阶段的固定优先级裁决生命周期和入口。
|
||||
"""按成功事实 → Gate → 已持久化阶段 → 阻断归属的固定优先级裁决生命周期。
|
||||
|
||||
``authority`` 仅用于诊断/迁移观测;前端不得据此再计算阶段或放开按钮。
|
||||
``processing_stage`` 是订单处理流程已写入的事实,仅映射展示工作面;它不能
|
||||
授权动作或推进流程。``authority`` 仅用于诊断/迁移观测;前端不得据此再计算
|
||||
阶段或放开按钮。
|
||||
"""
|
||||
gate = current_gate if isinstance(current_gate, dict) else {}
|
||||
gate_code = str(gate.get('gate_code') or gate.get('code') or '').strip().lower()
|
||||
@@ -123,6 +130,11 @@ def project_lifecycle(
|
||||
elif gate_code in LIFECYCLE_STAGE_BY_GATE:
|
||||
lifecycle_stage = LIFECYCLE_STAGE_BY_GATE[gate_code]
|
||||
authority = 'process_gate'
|
||||
elif str(processing_stage or '').strip().lower() in LIFECYCLE_STAGE_BY_PROCESSING_STAGE:
|
||||
lifecycle_stage = LIFECYCLE_STAGE_BY_PROCESSING_STAGE[
|
||||
str(processing_stage or '').strip().lower()
|
||||
]
|
||||
authority = 'processing_stage'
|
||||
else:
|
||||
reason = blocking_reason if isinstance(blocking_reason, dict) else {}
|
||||
reason_code = str(reason.get('code') or reason.get('blocking_reason_code') or '').strip()
|
||||
@@ -131,12 +143,8 @@ def project_lifecycle(
|
||||
lifecycle_stage = LIFECYCLE_STAGE_BY_GATE[owning_gate]
|
||||
authority = 'blocking_reason'
|
||||
else:
|
||||
normalized_legacy = str(legacy_stage or '').strip().lower()
|
||||
lifecycle_stage = next(
|
||||
(code for code, aliases in LIFECYCLE_STAGE_RANGES if normalized_legacy in aliases),
|
||||
normalized_legacy if normalized_legacy in LIFECYCLE_STAGE_CODES else None,
|
||||
)
|
||||
authority = 'legacy_fallback' if lifecycle_stage else 'unclassified'
|
||||
lifecycle_stage = None
|
||||
authority = 'unclassified'
|
||||
return {
|
||||
'lifecycle_stage': lifecycle_stage,
|
||||
'lifecycle_entries': lifecycle_entries(
|
||||
|
||||
Reference in new issue
Block a user