feat(fulfillment): 支持共享账号操作并完善时间线
This commit is contained in:
@@ -40,7 +40,11 @@ from ..business_events import record_account_query, record_douyu_task_started
|
||||
from ..douyu_account_state import DouyuLiveAccountState, refresh_douyu_account_state
|
||||
from ..douyu_activity_query import activity_client, query_exchange_eligibility
|
||||
from ..douyu_batch_launcher import start_douyu_batch, stop_douyu_batches
|
||||
from ..douyu_service import douyu_config_value, ensure_douyu_config
|
||||
from ..douyu_service import (
|
||||
SUPPORTED_DOUYU_TASK_TYPES,
|
||||
douyu_config_value,
|
||||
ensure_douyu_config,
|
||||
)
|
||||
from ..external_order_source import (
|
||||
OrderLookupUnavailable,
|
||||
list_pending_manual_fulfillments,
|
||||
@@ -648,6 +652,80 @@ def _append_event(
|
||||
)
|
||||
|
||||
|
||||
def record_douyu_operation_started(
|
||||
db: Session,
|
||||
task: PlatformFulfillmentTask,
|
||||
*,
|
||||
current: User,
|
||||
batch_id: str,
|
||||
task_type: str,
|
||||
douyu_task_ids: list[int],
|
||||
payload: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
"""记录履约上下文发起的斗鱼操作,账号任务结果由执行器补写。"""
|
||||
_append_event(
|
||||
db,
|
||||
task.id,
|
||||
"douyu_operation_started",
|
||||
actor_type="user",
|
||||
actor_id=current.id,
|
||||
detail={
|
||||
"batchId": batch_id,
|
||||
"douyuTaskIds": douyu_task_ids,
|
||||
"taskType": task_type,
|
||||
"taskLabel": SUPPORTED_DOUYU_TASK_TYPES.get(task_type, task_type),
|
||||
"accountId": task.account_id,
|
||||
"payload": payload or {},
|
||||
},
|
||||
)
|
||||
db.commit()
|
||||
|
||||
|
||||
def record_douyu_operation_result(
|
||||
db: Session,
|
||||
douyu_task: DouyuTask,
|
||||
*,
|
||||
status: str,
|
||||
message: str,
|
||||
) -> None:
|
||||
"""把履约上下文的斗鱼任务终态投影到履约时间线。"""
|
||||
if not douyu_task.platform_task_id:
|
||||
return
|
||||
event_type = {
|
||||
"success": "douyu_operation_succeeded",
|
||||
"stopped": "douyu_operation_stopped",
|
||||
}.get(status, "douyu_operation_failed")
|
||||
exists = (
|
||||
db.query(PlatformFulfillmentEvent.id)
|
||||
.filter(
|
||||
PlatformFulfillmentEvent.task_id == int(douyu_task.platform_task_id),
|
||||
PlatformFulfillmentEvent.event_type == event_type,
|
||||
PlatformFulfillmentEvent.detail_json["douyuTaskId"].as_integer()
|
||||
== int(douyu_task.id),
|
||||
)
|
||||
.first()
|
||||
)
|
||||
if exists is not None:
|
||||
return
|
||||
_append_event(
|
||||
db,
|
||||
int(douyu_task.platform_task_id),
|
||||
event_type,
|
||||
detail={
|
||||
"batchId": douyu_task.batch_id,
|
||||
"douyuTaskId": int(douyu_task.id),
|
||||
"taskType": douyu_task.task_type,
|
||||
"taskLabel": SUPPORTED_DOUYU_TASK_TYPES.get(
|
||||
douyu_task.task_type,
|
||||
douyu_task.task_type,
|
||||
),
|
||||
"accountId": douyu_task.account_id,
|
||||
"status": status,
|
||||
"message": (message or "")[:1000],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def _emit_order_site_binding_state(
|
||||
db: Session,
|
||||
task_id: int,
|
||||
@@ -2500,6 +2578,8 @@ __all__ = [
|
||||
"list_tasks",
|
||||
"mark_manual_required",
|
||||
"reconcile_binding_state_outbox",
|
||||
"record_douyu_operation_result",
|
||||
"record_douyu_operation_started",
|
||||
"refresh_binding",
|
||||
"refresh_exchange_eligibility",
|
||||
"release_task_account",
|
||||
|
||||
Reference in New Issue
Block a user