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

@@ -52,7 +52,7 @@ def test_rpa_attempt_status_updates_its_bound_preparation_source(app):
sync_preparation_source_from_rpa_attempt,
)
task = ShippingNotice(task_no='SN-PREP-LINEAGE-1', process_status='waiting_inventory')
task = ShippingNotice(task_no='SN-PREP-LINEAGE-1')
db.session.add(task)
db.session.flush()
preparation = create_inventory_preparation_round(
@@ -87,7 +87,7 @@ def test_preparation_trigger_identity_includes_gate_and_callback(monkeypatch, ap
from app.services.shipping_notice.process_gate_service import ensure_execution_for_workflow_version
from app.services.shipping_notice import per_source_rpa_service
task = ShippingNotice(task_no='SN-PREP-TRIGGER-IDENTITY', process_status='waiting_inventory')
task = ShippingNotice(task_no='SN-PREP-TRIGGER-IDENTITY')
db.session.add(task)
db.session.flush()
execution = ensure_execution_for_workflow_version(task_id=int(task.id), actor_type='system')
@@ -120,7 +120,7 @@ def test_missing_inventory_trigger_is_failed_not_pending(monkeypatch, app):
from app.models import ShippingNotice
from app.services.shipping_notice import per_source_rpa_service
task = ShippingNotice(task_no='SN-PREP-TRIGGER-MISSING', process_status='waiting_inventory')
task = ShippingNotice(task_no='SN-PREP-TRIGGER-MISSING')
db.session.add(task)
db.session.flush()
monkeypatch.setattr(per_source_rpa_service, 'task_frozen_inventory_source_codes', lambda task: ['DBS'])
@@ -134,7 +134,11 @@ def test_missing_inventory_trigger_is_failed_not_pending(monkeypatch, app):
result = per_source_rpa_service.ensure_all_required_sources_prepared(task, mode='retry_rpa')
assert result.pending_source_codes == []
assert result.failed_source_codes == ['DBS']
attempt = per_source_rpa_service._latest_attempt(task.task_no, 'DBS')
# 读取真实数据库记录,避免被用于构造场景的 monkeypatch 查询函数遮蔽。
from app.models import ShippingTaskInventoryRpaAttempt
attempt = ShippingTaskInventoryRpaAttempt.query.filter_by(
task_no=task.task_no, source_code='DBS', attempt_no=1,
).one()
assert attempt.status == 'failed'
assert attempt.error_code == 'trigger_not_written'
@@ -146,7 +150,7 @@ def test_formal_gate_inventory_retry_uses_operator_id_for_snapshot_freeze(monkey
from app.services.shipping_notice import process_gate_executor
task = ShippingNotice(
task_no='SN-PREP-FREEZE-OPERATOR', process_status='waiting_inventory',
task_no='SN-PREP-FREEZE-OPERATOR',
order_snapshot_id=None, order_data_version=1,
)
db.session.add(task)
@@ -195,7 +199,7 @@ def test_per_source_callback_rejects_candidate_set_identity_mismatch(app):
)
from app.services.shipping_notice.per_source_rpa_service import per_source_callback_handler
task = ShippingNotice(task_no='SN-PREP-CALLBACK-IDENTITY', process_status='waiting_inventory')
task = ShippingNotice(task_no='SN-PREP-CALLBACK-IDENTITY')
db.session.add(task)
db.session.flush()
current = ShippingInventoryCandidateSet(
@@ -254,7 +258,7 @@ def test_rpa_report_inventory_fails_closed_on_per_source_identity_mismatch(app,
from app.models import ShippingNotice, ShippingTaskEvent
from app.services.shipping_notice import inventory_rpa_workflow
task = ShippingNotice(task_no='SNCALLBACKIDENTITYENTRY', process_status='waiting_inventory')
task = ShippingNotice(task_no='SNCALLBACKIDENTITYENTRY')
db.session.add(task)
db.session.commit()
@@ -305,7 +309,7 @@ def test_rpa_report_inventory_parses_per_source_run_with_hyphenated_task_no(app,
from app.models import ShippingNotice
from app.services.shipping_notice import inventory_rpa_workflow
task = ShippingNotice(task_no='SN-2026-001', process_status='waiting_inventory')
task = ShippingNotice(task_no='SN-2026-001')
db.session.add(task)
db.session.commit()
captured = {}
@@ -341,7 +345,7 @@ def test_rpa_report_inventory_batch_fails_closed_on_per_source_identity_mismatch
from app.models import ShippingNotice, ShippingTaskEvent
from app.services.shipping_notice import inventory_rpa_workflow
task = ShippingNotice(task_no='SNCALLBACKBATCHIDENTITY', process_status='waiting_inventory')
task = ShippingNotice(task_no='SNCALLBACKBATCHIDENTITY')
db.session.add(task)
db.session.commit()
@@ -408,7 +412,7 @@ def test_inventory_rpa_failure_is_not_projected_back_to_waiting_external(app):
from app.services.shipping_notice.process_gate_service import queue_gate_attempt
task = ShippingNotice(
task_no='SN-RPA-FAILED-GATE', process_status='waiting_inventory',
task_no='SN-RPA-FAILED-GATE',
pending_human_reason='rpa_exhausted', error_message='RPA export failed',
)
db.session.add(task)
@@ -430,6 +434,7 @@ def test_inventory_rpa_failure_is_not_projected_back_to_waiting_external(app):
gate_code='inventory_preparation',
trigger_type='auto',
actor_type='system',
actor_id=None,
idempotency_key='shipping-auto-progress:rpa-failed-poll',
input_snapshot={'action_code': 'poll_inventory_preparation'},
)
@@ -448,7 +453,9 @@ def test_inventory_rpa_failure_is_not_projected_back_to_waiting_external(app):
assert gate.status == 'blocked_manual'
assert gate.blocking_reason_code == 'inventory_rpa_exhausted'
db.session.refresh(execution)
assert execution.status == 'blocked'
# Gate 已进入可人工恢复的 blocked_manual;Execution 仍保持 active,
# 由当前业务阶段/Gate 投影表达阻断,不再回写旧的 execution blocked 状态。
assert execution.status == 'active'
def test_formal_gate_attempt_creates_preparation_lineage_and_passes_gate(app, monkeypatch):
@@ -469,8 +476,9 @@ def test_formal_gate_attempt_creates_preparation_lineage_and_passes_gate(app, mo
task = ShippingNotice(
task_no='SNFORMALPREPLINEAGE',
process_status='waiting_inventory',
inventory_source_code='DBS',
# 该用例从 inventory_preparation Gate 开始,前置订单复核/冻结事实必须显式存在。
order_snapshot_id=1,
)
db.session.add(task)
db.session.flush()
@@ -544,7 +552,6 @@ def test_formal_start_gate_stops_at_customer_resolution_before_inventory(app):
task = ShippingNotice(
task_no='SNSTARTCUSTOMERPENDING',
process_status='created',
current_order_extraction_id=101,
order_snapshot_id=201,
customer_resolution_status='pending',
@@ -568,7 +575,6 @@ def test_formal_start_gate_stops_at_field_conflict_before_inventory(app):
task = ShippingNotice(
task_no='SNSTARTFIELDCONFLICT',
process_status='created',
current_order_extraction_id=101,
order_snapshot_id=201,
customer_resolution_status='confirmed',
@@ -594,7 +600,7 @@ def test_candidate_refreeze_invalidates_formal_gate_attempt_and_job(app):
from app.services.shipping_notice.auto_progress_controller import supersede_auto_progress_for_candidate_refreeze
from app.services.shipping_notice.process_gate_service import ensure_execution_for_workflow_version, queue_gate_attempt
task = ShippingNotice(task_no='SNCANDIDATEREFREEZEATTEMPT', process_status='waiting_inventory')
task = ShippingNotice(task_no='SNCANDIDATEREFREEZEATTEMPT')
db.session.add(task)
db.session.flush()
old_candidate = ShippingInventoryCandidateSet(
@@ -641,7 +647,7 @@ def test_legacy_workspace_forwarding_audit_is_structured(app):
from app.models import ShippingNotice, ShippingTaskEvent
from app.services.shipping_notice.auto_progress_controller import audit_legacy_forwarded_entrypoint
task = ShippingNotice(task_no='SNLEGACYFORWARDAUDIT', process_status='waiting_inventory')
task = ShippingNotice(task_no='SNLEGACYFORWARDAUDIT')
db.session.add(task)
db.session.flush()
@@ -670,7 +676,7 @@ def test_apx_runtime_audit_is_read_only_and_counts_active_states(app):
from app.models import Job, ShippingNotice, ShippingProcessExecution
from app.services.shipping_notice.apx_runtime_audit import audit_apx_runtime_state
task = ShippingNotice(task_no='SN-APX-AUDIT', process_status='waiting_inventory')
task = ShippingNotice(task_no='SN-APX-AUDIT')
db.session.add(task)
db.session.flush()
active = ShippingProcessExecution(
@@ -950,7 +956,7 @@ def test_inventory_preparation_retry_freezes_legacy_task_before_rpa(monkeypatch)
'freeze_mode': 'manual',
}
assert task.order_snapshot_id == 901
assert result['outcome'] == 'waiting_external'
assert result['outcome'] == 'blocked_retryable'
def test_manual_business_block_is_a_successful_attempt(app):