refactor(shipping-inventory): 统一库存准备事实来源与门禁状态

This commit is contained in:
hugo committed 2026-09-04 20:23:00 +08:00
1 parent 761a06e21a
commit eb55f407ae
62 files changed
+4242 -1471

No files matched your search

@@ -35,15 +35,24 @@ def run_shipping_inventory_callback_process(ctx: JobContext, payload: dict) -> N
result = process_rpa_report_inventory_batch(dict(job.payload_json or {}))
result_data = result.get('data') if isinstance(result, dict) else None
transport_status = str(
result.get('status') if isinstance(result, dict) else ''
).strip().lower()
result_status = str(
(result_data or {}).get('result_status') if isinstance(result_data, dict) else ''
).strip().lower()
if result_status in {'failed', 'partial_failed'}:
if transport_status == 'failed' or result_status in {'failed', 'partial_failed'}:
failed_items = result_data.get('failed') if isinstance(result_data, dict) else []
first_error = failed_items[0].get('error') if isinstance(failed_items, list) and failed_items and isinstance(failed_items[0], dict) else None
from app.services.shipping_notice.inventory_rpa_workflow import settle_failed_inventory_callback
settle_failed_inventory_callback(
dict(job.payload_json or {}),
error=str(first_error or (result or {}).get('message') or 'inventory_callback_processing_failed'),
)
fail_job(
job.id,
error=str(first_error or f'inventory_callback_business_{result_status}'),
error=str(first_error or (result or {}).get('message') or f'inventory_callback_business_{result_status or transport_status}'),
result={'status': 'processed', 'callback_result': result},
retryable=False,
owned_attempt=owned_attempt,
@@ -84,6 +84,18 @@ def run_shipping_process_gate(ctx: JobContext, payload: dict) -> None:
attempt_id = int(payload.get('attempt_id') or 0)
raw_job_id = payload.get('job_id')
job = db.session.get(Job, int(raw_job_id)) if raw_job_id else None
external_wait_poll_gate_id = int(payload.get('external_wait_poll_gate_id') or 0)
if external_wait_poll_gate_id and job is not None:
from app.services.shipping_notice.process_gate_job_service import run_inventory_external_wait_poll
result = run_inventory_external_wait_poll(gate_id=external_wait_poll_gate_id)
finish_job(job.id, result=result, owned_attempt=int(job.attempts or 0))
if str(result.get('gate_status') or '') == 'waiting_external':
gate = db.session.get(ShippingProcessGate, external_wait_poll_gate_id)
if gate is not None and gate.latest_attempt_id:
schedule_waiting_external_poll(attempt_id=int(gate.latest_attempt_id))
db.session.commit()
return
if attempt_id <= 0 or job is None:
raise RuntimeError('missing_attempt_id_or_job_id')