refactor(douyu): 完成阶段5旧链路清理
This commit is contained in:
@@ -13,18 +13,13 @@ from core.douyu import DouyuActivityClient, DouyuActivityError
|
||||
|
||||
from ..models import Account, DouyuEsportsGoodsSnapshot, DouyuGoodsSnapshot, DouyuTask
|
||||
from .account_exchange_sync_service import sync_exchange_records
|
||||
from .account_sync_service import sync_storehome_snapshot
|
||||
from .business_events import record_exchange
|
||||
from .douyu_activity_query import (
|
||||
query_activity_goods,
|
||||
query_activity_goods_result,
|
||||
query_csrf,
|
||||
query_elite_user_info,
|
||||
query_esports_goods_result,
|
||||
query_limited_goods_result,
|
||||
)
|
||||
from .douyu_goods_service import upsert_goods_snapshot
|
||||
from .douyu_read_gateway import storehome_snapshot_from_result
|
||||
from .high_value_service import (
|
||||
DEFAULT_HIGH_VALUE_GOODS,
|
||||
HIGH_VALUE_STATUS_OWNED,
|
||||
@@ -78,48 +73,6 @@ class GoodsMixin:
|
||||
def _push_log(self, level: str, message: str) -> None: ...
|
||||
def _mark_task(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
|
||||
def _execute_refresh_goods(
|
||||
self, db: Session, task: DouyuTask, account: Account, cookie: str, config: dict
|
||||
):
|
||||
client = self._client(cookie)
|
||||
result = query_activity_goods_result(
|
||||
client,
|
||||
manual_id=str(config["manual_id"]),
|
||||
rid=str(config["rid"]),
|
||||
)
|
||||
goods = [
|
||||
dict(item)
|
||||
for item in result.get("goods") or []
|
||||
if isinstance(item, dict)
|
||||
]
|
||||
snapshot = storehome_snapshot_from_result(
|
||||
result,
|
||||
manual_id=str(config["manual_id"]),
|
||||
rid=str(config["rid"]),
|
||||
)
|
||||
upsert_goods_snapshot(db, goods, commit=False)
|
||||
sync_storehome_snapshot(
|
||||
db,
|
||||
account,
|
||||
snapshot,
|
||||
source="douyu_task.refresh_goods",
|
||||
task_id=task.id,
|
||||
)
|
||||
high_value_goods = extract_high_value_goods(goods, DEFAULT_HIGH_VALUE_GOODS, [])
|
||||
apply_high_value_goods(account, high_value_goods)
|
||||
account.updated_at = datetime.now(UTC)
|
||||
self._mark_task(
|
||||
db,
|
||||
task,
|
||||
"success",
|
||||
f"已刷新商品 {len(goods)} 个",
|
||||
{
|
||||
"goods_count": len(goods),
|
||||
"goods": goods,
|
||||
"high_value_goods": high_value_goods,
|
||||
},
|
||||
)
|
||||
|
||||
def _refresh_high_value_after_exchange(
|
||||
self,
|
||||
client: DouyuActivityClient,
|
||||
@@ -736,52 +689,6 @@ class GoodsMixin:
|
||||
)
|
||||
self._mark_task(db, task, "success", message, result)
|
||||
|
||||
def _execute_query_limited_goods(
|
||||
self, db: Session, task: DouyuTask, account: Account, cookie: str, config: dict
|
||||
):
|
||||
client = self._client(cookie)
|
||||
result = query_limited_goods_result(
|
||||
client, manual_id=str(config["manual_id"]), rid=str(config["rid"])
|
||||
)
|
||||
limited = result["limited_goods"]
|
||||
snapshot = storehome_snapshot_from_result(
|
||||
result,
|
||||
manual_id=str(config["manual_id"]),
|
||||
rid=str(config["rid"]),
|
||||
)
|
||||
goods = list(snapshot.items)
|
||||
sync_storehome_snapshot(
|
||||
db,
|
||||
account,
|
||||
snapshot,
|
||||
source="douyu_task.query_limited_goods",
|
||||
task_id=task.id,
|
||||
)
|
||||
high_value_goods = extract_high_value_goods(goods, DEFAULT_HIGH_VALUE_GOODS, [])
|
||||
apply_high_value_goods(account, high_value_goods)
|
||||
names = [
|
||||
str(item.get("commodityName") or "")
|
||||
for item in limited
|
||||
if item.get("commodityName")
|
||||
]
|
||||
message = (
|
||||
"无受限商品(均可兑换)"
|
||||
if not names
|
||||
else f"已达上限 {len(names)} 个: {', '.join(names[:5])}"
|
||||
)
|
||||
account.updated_at = datetime.now(UTC)
|
||||
self._mark_task(
|
||||
db,
|
||||
task,
|
||||
"success",
|
||||
message,
|
||||
{
|
||||
"limited_count": len(limited),
|
||||
"limited_goods": limited,
|
||||
"high_value_goods": high_value_goods,
|
||||
},
|
||||
)
|
||||
|
||||
def _execute_query_exchange_records(
|
||||
self, db: Session, task: DouyuTask, account: Account, cookie: str, config: dict
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user