优化(直播履约): 即时选号并收敛订单快照同步
This commit is contained in:
@@ -80,6 +80,10 @@ def sync_tasks(
|
||||
current: User = Depends(require_permission("platform_fulfillment:use")),
|
||||
) -> dict[str, Any]:
|
||||
result = service.sync_pending_tasks(db, limit=limit)
|
||||
if result.get("taskIds"):
|
||||
from ..services.platform_fulfillment.auto_allocator import wake_auto_allocator
|
||||
|
||||
wake_auto_allocator(result["taskIds"])
|
||||
record_audit(
|
||||
db,
|
||||
current,
|
||||
@@ -98,7 +102,6 @@ def get_task(
|
||||
current: User = Depends(require_permission("platform_fulfillment:view")),
|
||||
) -> dict[str, Any]:
|
||||
del current
|
||||
service.refresh_binding(db, task_id=task_id)
|
||||
return service.get_task_detail(db, task_id)
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ from ..services.integration.security import (
|
||||
verify_webhook_signature,
|
||||
webhook_tolerance_seconds,
|
||||
)
|
||||
from ..services.platform_fulfillment import service
|
||||
from ..services.platform_fulfillment import auto_allocator, service
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/api/integration/platform-fulfillment",
|
||||
@@ -81,9 +81,27 @@ async def sync_order_event(
|
||||
received_at=datetime.now(UTC),
|
||||
)
|
||||
db.add(inbox)
|
||||
result = service.sync_pending_tasks(db, limit=500, commit=False)
|
||||
data = payload.get("data")
|
||||
snapshot = data if isinstance(data, dict) else payload
|
||||
has_snapshot = bool(
|
||||
str(snapshot.get("sourceOrderItemId") or "").strip()
|
||||
and str(snapshot.get("internalSkuKey") or "").strip()
|
||||
)
|
||||
if has_snapshot:
|
||||
result = service.sync_order_snapshot(db, payload, commit=False)
|
||||
else:
|
||||
item_ids = [
|
||||
str(value).strip()
|
||||
for value in (
|
||||
snapshot.get("sourceOrderItemId"),
|
||||
snapshot.get("orderItemId"),
|
||||
)
|
||||
if str(value or "").strip()
|
||||
]
|
||||
result = service.sync_order_item_ids(db, item_ids, commit=False)
|
||||
inbox.processed_at = datetime.now(UTC)
|
||||
db.commit()
|
||||
auto_allocator.wake_auto_allocator(result.get("taskIds", []))
|
||||
return {**result, "duplicate": False}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user