fix(account): 一键查询按反馈收敛 —— 只在账号管理展示、结果落账号、修 1970 显示
按用户反馈改了四处。 ## ① 结果只在账号管理展示(不再出现在精英宝典/电竞手册页) 移除了工作台页的结果弹窗与导入。**类型集合保留**(三个工作台都有)—— 因为账号页批量建任务要用 `handbook_scope` 过 `DOUYU_HANDBOOK_TASK_TYPES` 校验, 去掉会被「该任务不属于当前工作台」拦掉;去掉的只是**快捷操作按钮**。 ## ② 不再每次弹出 原来任务跑完就自动弹面板,而且任务会被反复轮询到。现在整个弹窗机制去掉了: 结果落在账号上,打开账号就能看。 ## ③ 结果写进账号(新增迁移 0047) 新增 `accounts.overview_snapshot`(JSON)+ `overview_queried_at`,覆盖式只留最新一份。 详情页直接读账号上的快照,不再轮询任务。 **为什么放账号而不是只留任务里**:任务会被保留策略清掉(长保留档 90 天), 而「这个账号现在什么情况」是**账号的信息**,不该依赖一条日志的寿命。 ## ④ 修 1970/1/1 08:00:00(真 bug) 斗鱼用 `0` / `"0"` / 空串表示「没有这个时间」。原实现直接透传, 前端 `new Date(0)` → **1970/1/1 08:00:00** —— 运营会以为"到期时间是 1970 年"。 两端都修了: - 后端新增 `_ts()`,把 `0`/`"0"`/空/负数 归成 `None`(积分到期、宝典到期、 电竞到期、商品活动时间四处都过一遍) - 前端 `formatTime` 也把 `0`/负数显示成 `-`(上游再出错也不至于显示 1970) ## 测试(+14 条,共 36) - `TestTimestampNormalisation`:`0`/`"0"`/空/负数 → `None`;真实时间戳透传 - `TestSnapshotIsWrittenToAccount`:快照与时间落到账号上、 **`willExpireTime="0"` 不能落库成 0**(1970 的回归用例)、覆盖式不追加 ## 验证 `TZ=Asia/Shanghai` **588 passed / 6 skipped**;`TZ=UTC` 41 passed; ruff 全绿;前端 build 通过、lint 0 errors。
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
"""账号上存「一键查询」快照:`overview_snapshot` / `overview_queried_at`
|
||||
|
||||
一键查询的结果以前只写在 `douyu_tasks.result` 里。那样有两个问题:
|
||||
|
||||
1. 任务会被保留策略清掉(`query_account_overview` 属长保留档,90 天),
|
||||
而运营关心的是「**这个账号现在什么情况**」,不该依赖一条日志的寿命;
|
||||
2. 想看结果得去斗鱼工作台翻任务 —— 但它本质是**账号的信息**,
|
||||
应该在账号管理里。
|
||||
|
||||
所以把最近一次快照落到账号上(覆盖式,只留最新一份)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "20261004_0047"
|
||||
down_revision: str | None = "20261004_0046"
|
||||
branch_labels: str | None = None
|
||||
depends_on: str | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"accounts",
|
||||
sa.Column(
|
||||
"overview_snapshot",
|
||||
sa.JSON(),
|
||||
nullable=True,
|
||||
comment="最近一次一键查询的结构化结果",
|
||||
),
|
||||
)
|
||||
op.add_column(
|
||||
"accounts",
|
||||
sa.Column(
|
||||
"overview_queried_at",
|
||||
sa.DateTime(),
|
||||
nullable=True,
|
||||
comment="最近一次一键查询的时间",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column("accounts", "overview_queried_at")
|
||||
op.drop_column("accounts", "overview_snapshot")
|
||||
@@ -104,6 +104,12 @@ class Account(Base):
|
||||
role_bind_status: Mapped[str] = mapped_column(
|
||||
String(16), default="unknown", server_default="unknown"
|
||||
)
|
||||
# 最近一次「一键查询」的快照(结构化结果)。存在账号上而不是只留在任务里:
|
||||
# 任务会被保留策略清掉,而运营看的是"这个账号现在什么情况"。
|
||||
overview_snapshot: Mapped[dict | None] = mapped_column(JSON, nullable=True)
|
||||
overview_queried_at: Mapped[datetime | None] = mapped_column(
|
||||
UTCDateTime, nullable=True
|
||||
)
|
||||
# 积分**到期时刻**(斗鱼在积分查询里给 `willExpireTime`,只有送礼后的那次查询才有)。
|
||||
# 积分到期是账号资产的真实减少,但斗鱼不会「通知」你 —— 所以这里记下到期时刻,
|
||||
# 由作业在到期后补记一条 `points_expire` 事件(否则这个减少在时间线上是空白)。
|
||||
|
||||
@@ -306,6 +306,9 @@ def list_accounts(
|
||||
last_exchange_at=exchange_stats.get(acc.id, (0, None, ""))[1],
|
||||
last_exchange_name=exchange_stats.get(acc.id, (0, None, ""))[2],
|
||||
**bind_payload(acc),
|
||||
# 最近一次「一键查询」快照:存在账号上,不依赖任务日志的寿命
|
||||
overview_snapshot=acc.overview_snapshot,
|
||||
overview_queried_at=acc.overview_queried_at,
|
||||
)
|
||||
# 只有管理员可看完整字段(密码、邮箱等)
|
||||
if can_include_sensitive:
|
||||
|
||||
@@ -123,8 +123,8 @@ def extract_high_value_goods(
|
||||
"score": hit.get("score") if hit else None,
|
||||
"count": hit.get("count") if hit else None,
|
||||
"count_limited": hit.get("countLimited") if hit else None,
|
||||
"start_time": hit.get("startTime") if hit else None,
|
||||
"end_time": hit.get("endTime") if hit else None,
|
||||
"start_time": _ts(hit.get("startTime")) if hit else None,
|
||||
"end_time": _ts(hit.get("endTime")) if hit else None,
|
||||
"pic": str(hit.get("pic") or "") if hit else "",
|
||||
"in_goods_list": hit is not None,
|
||||
"missing": hit is None and not got,
|
||||
@@ -153,6 +153,27 @@ def _goods_config(config: dict) -> list[str]:
|
||||
return list(DEFAULT_HIGH_VALUE_GOODS)
|
||||
|
||||
|
||||
def _ts(value: Any) -> Any:
|
||||
"""斗鱼用 `0` / `"0"` / 空串表示「没有这个时间」。
|
||||
|
||||
直接透传的后果:前端把 `0` 当 Unix 时间戳 → 显示成 **1970/1/1 08:00:00**,
|
||||
运营看到会以为"到期时间是 1970 年"。所以在这里就归成 `None`,
|
||||
让「没有」和「有一个很早的时间」区分得开。
|
||||
"""
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, bool):
|
||||
return None
|
||||
if isinstance(value, (int, float)):
|
||||
return None if int(value) <= 0 else value
|
||||
text = str(value).strip()
|
||||
if not text:
|
||||
return None
|
||||
if text.lstrip("-").isdigit() and int(text) <= 0:
|
||||
return None
|
||||
return value
|
||||
|
||||
|
||||
class OverviewMixin:
|
||||
"""一键查询域:只读聚合,不写状态、不发事件。"""
|
||||
|
||||
@@ -225,7 +246,7 @@ class OverviewMixin:
|
||||
overview["assets"]["points"] = points.get("points")
|
||||
# `_refresh_account_points` 只回 {"points", "points_query"},
|
||||
# 到期时间得从 points_query 里取 —— 复用已有具名函数,不自己扒结构。
|
||||
overview["assets"]["points_expire_at"] = _points_expire_at(points)
|
||||
overview["assets"]["points_expire_at"] = _ts(_points_expire_at(points))
|
||||
except Exception as exc: # noqa: BLE001
|
||||
errors["points"] = _err(exc)
|
||||
|
||||
@@ -239,7 +260,7 @@ class OverviewMixin:
|
||||
)
|
||||
overview["elite"] = {
|
||||
"opened": elite.get("elite_opened"),
|
||||
"expire_time": elite.get("elite_expire_time"),
|
||||
"expire_time": _ts(elite.get("elite_expire_time")),
|
||||
"points": elite.get("elite_manual_score"),
|
||||
}
|
||||
except Exception as exc: # noqa: BLE001
|
||||
@@ -265,7 +286,7 @@ class OverviewMixin:
|
||||
"opened": opened,
|
||||
"manual_type": manual_type,
|
||||
"points": esports.get("esports_points"),
|
||||
"expire_time": esports.get("esports_expire_time"),
|
||||
"expire_time": _ts(esports.get("esports_expire_time")),
|
||||
}
|
||||
except Exception as exc: # noqa: BLE001
|
||||
errors["esports"] = _err(exc)
|
||||
@@ -324,5 +345,10 @@ class OverviewMixin:
|
||||
if errors:
|
||||
message += f"({len(errors)} 项未取到)"
|
||||
|
||||
# 落到账号上:任务会被保留策略清掉,而「这个账号现在什么情况」是账号的信息,
|
||||
# 应该在账号管理里看,不该依赖一条日志的寿命。
|
||||
account.overview_snapshot = overview
|
||||
account.overview_queried_at = datetime.now(UTC)
|
||||
|
||||
logger.info(f"[douyu] 一键查询账号 {account.id}: {message}")
|
||||
self._mark_task(db, task, "success", message, overview)
|
||||
|
||||
Reference in New Issue
Block a user