feat(fulfillment): 增加工作台状态事件同步
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
@@ -20,6 +21,7 @@ from ..services.audit_service import record_audit
|
||||
from ..services.platform_fulfillment import service
|
||||
|
||||
router = APIRouter(prefix="/api/platform-fulfillment", tags=["直播账号履约"])
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@router.get("/settings")
|
||||
@@ -63,6 +65,10 @@ def list_tasks(
|
||||
current: User = Depends(require_permission("platform_fulfillment:view")),
|
||||
) -> dict[str, Any]:
|
||||
del current
|
||||
try:
|
||||
service.sync_pending_tasks_if_due(db, limit=100)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
logger.warning("自动同步待履约订单失败,继续返回本地任务: %s", exc)
|
||||
return service.list_tasks(
|
||||
db,
|
||||
status=status,
|
||||
@@ -97,6 +103,7 @@ 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)
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from sqlalchemy.orm import Session
|
||||
from ..database import get_db
|
||||
from ..schemas import (
|
||||
PlatformFulfillmentCustomerBindingAction,
|
||||
PlatformFulfillmentCustomerSessionBatchRequest,
|
||||
PlatformFulfillmentCustomerSessionRequest,
|
||||
)
|
||||
from ..services.platform_fulfillment import service
|
||||
@@ -32,6 +33,18 @@ def require_integration_key(
|
||||
raise HTTPException(status_code=401, detail="直播账号履约集成鉴权失败")
|
||||
|
||||
|
||||
@router.post(
|
||||
"/events/order-sync",
|
||||
dependencies=[Depends(require_integration_key)],
|
||||
)
|
||||
def sync_order_event(
|
||||
payload: dict[str, Any],
|
||||
db: Session = Depends(get_db),
|
||||
) -> dict[str, Any]:
|
||||
del payload
|
||||
return service.sync_pending_tasks(db, limit=500)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/customer-sessions/ensure", dependencies=[Depends(require_integration_key)]
|
||||
)
|
||||
@@ -73,6 +86,17 @@ def get_customer_binding_status(
|
||||
return service.customer_refresh_binding(db, task_id=task_id)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/customer-sessions/status/batch",
|
||||
dependencies=[Depends(require_integration_key)],
|
||||
)
|
||||
def get_customer_binding_statuses(
|
||||
req: PlatformFulfillmentCustomerSessionBatchRequest,
|
||||
db: Session = Depends(get_db),
|
||||
) -> dict[str, Any]:
|
||||
return service.customer_refresh_bindings(db, task_ids=req.task_ids)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/customer-sessions/{task_id}/binding/confirm",
|
||||
dependencies=[Depends(require_integration_key)],
|
||||
|
||||
Reference in New Issue
Block a user