feat(douyu): 完善账号同步域与供给目标配置
This commit is contained in:
@@ -33,7 +33,15 @@ from sqlalchemy.orm import Session
|
||||
from core.douyu import DouyuActivityClient
|
||||
|
||||
from ..models import Account, DouyuTask
|
||||
from .account_sync_service import sync_storehome_snapshot
|
||||
from .account_sync_service import (
|
||||
DOMAIN_ELITE,
|
||||
DOMAIN_ESPORTS,
|
||||
DOMAIN_EXCHANGE_RECORDS,
|
||||
DOMAIN_GOLD,
|
||||
DOMAIN_POINTS,
|
||||
record_sync_success,
|
||||
sync_storehome_snapshot,
|
||||
)
|
||||
from .business_events import record_official_exchange
|
||||
from .douyu_account_probe import (
|
||||
ROLE_BOUND,
|
||||
@@ -301,6 +309,15 @@ class OverviewMixin:
|
||||
gold = self._refresh_account_gold_balance(client, account)
|
||||
overview["assets"]["gold_balance"] = gold.get("gold_balance")
|
||||
overview["assets"]["exchange_balance"] = gold.get("exchange_balance")
|
||||
record_sync_success(
|
||||
db,
|
||||
account_id=int(account.id),
|
||||
domain=DOMAIN_GOLD,
|
||||
source="douyu_task.query_account_overview",
|
||||
observed_at=queried_at,
|
||||
raw_payload=gold,
|
||||
task_id=task.id,
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001 外部接口边界需要宽泛兜底
|
||||
errors["gold"] = _err(exc)
|
||||
|
||||
@@ -317,6 +334,17 @@ class OverviewMixin:
|
||||
# 在账号详情里展示 —— 查询只是一次「刷新」,不是另开一份副本。
|
||||
expire_dt = _parse_expire_at(expire_raw)
|
||||
account.points_expire_at = expire_dt
|
||||
record_sync_success(
|
||||
db,
|
||||
account_id=int(account.id),
|
||||
domain=DOMAIN_POINTS,
|
||||
source="douyu_task.query_account_overview",
|
||||
observed_at=queried_at,
|
||||
raw_payload=points.get("points_query")
|
||||
if isinstance(points.get("points_query"), dict)
|
||||
else points,
|
||||
task_id=task.id,
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
errors["points"] = _err(exc)
|
||||
|
||||
@@ -333,6 +361,15 @@ class OverviewMixin:
|
||||
"expire_time": _ts(elite.get("elite_expire_time")),
|
||||
"points": elite.get("elite_manual_score"),
|
||||
}
|
||||
record_sync_success(
|
||||
db,
|
||||
account_id=int(account.id),
|
||||
domain=DOMAIN_ELITE,
|
||||
source="douyu_task.query_account_overview",
|
||||
observed_at=queried_at,
|
||||
raw_payload=elite,
|
||||
task_id=task.id,
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
errors["elite"] = _err(exc)
|
||||
|
||||
@@ -358,6 +395,15 @@ class OverviewMixin:
|
||||
"points": esports.get("esports_points"),
|
||||
"expire_time": _ts(esports.get("esports_expire_time")),
|
||||
}
|
||||
record_sync_success(
|
||||
db,
|
||||
account_id=int(account.id),
|
||||
domain=DOMAIN_ESPORTS,
|
||||
source="douyu_task.query_account_overview",
|
||||
observed_at=queried_at,
|
||||
raw_payload=esports,
|
||||
task_id=task.id,
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
errors["esports"] = _err(exc)
|
||||
|
||||
@@ -512,6 +558,17 @@ class OverviewMixin:
|
||||
overview["exchange_events_added"] = record_official_exchange_records(
|
||||
db, account, all_records
|
||||
)
|
||||
record_sync_success(
|
||||
db,
|
||||
account_id=int(account.id),
|
||||
domain=DOMAIN_EXCHANGE_RECORDS,
|
||||
source="douyu_task.query_account_overview",
|
||||
observed_at=queried_at,
|
||||
item_count=len(all_records),
|
||||
changed_count=int(overview["exchange_events_added"] or 0),
|
||||
raw_payload=_group_by_scope(all_records),
|
||||
task_id=task.id,
|
||||
)
|
||||
overview["exchange_records"] = {
|
||||
scope: rows[:EXCHANGE_RECORD_DISPLAY_LIMIT]
|
||||
for scope, rows in _group_by_scope(all_records).items()
|
||||
|
||||
Reference in New Issue
Block a user