feat(douyu): 支持账号批量撤回并刷新未分配状态

新增按勾选或标签批量撤回账号归属,撤回只处理确实已分配的账号。账号管理和分配管理增加可见时自动刷新、窗口聚焦刷新及手动刷新,解决批量登录完成后未分配账号延迟出现。
This commit is contained in:
yml2213
2026-11-06 13:25:32 +08:00
parent 4c1aff47da
commit c9fbbdb828
6 changed files with 431 additions and 35 deletions
+15 -7
View File
@@ -227,8 +227,8 @@ def _filter_accounts_query(
# 只是商城接口对它稳定失败 —— 那是下面 high_value_never 那一档。
query = query.filter(Account.overview_queried_at.is_(None))
elif hv == "high_value_never":
# 从没成功读到官方 storehome:商城接口失败 / 没配 manualID。
# 高价值三态里的「unknown」要求 checked_at 非空(查过但没结论),
# 从未形成高价值结论:商城接口失败 / 没配 manualID / 新账号尚未查询。
# 高价值三态里的「unknown」要求 checked_at 非空(形成过 unknown 结论),
# 所以这一档必须单独筛,否则这批账号在界面上**无处可寻**。
query = query.filter(Account.high_value_checked_at.is_(None))
elif hv == "high_value_unknown":
@@ -819,7 +819,7 @@ def accounts_summary(
"can_bairimeng": int(hv_row[1] or 0) if hv_row else 0,
"can_mengtu": int(hv_row[2] or 0) if hv_row else 0,
"unqueried": int(hv_row[3] or 0) if hv_row else 0,
# 从没成功读到官方商城结果的账号数(与「查过但没结论」分开)。
# 从未形成高价值结论的账号数(与「形成过 unknown/过期结论」分开)。
"high_value_never": int(hv_row[4] or 0) if hv_row else 0,
"high_value_unknown": int(hv_row[5] or 0) if hv_row else 0,
"high_points": int(hv_row[6] or 0) if hv_row else 0,
@@ -1082,14 +1082,22 @@ def batch_assign_accounts(
detail=f"以下账号尚未成功登录,无法分配:{name_list}{suffix}",
)
# 先取出账号对象(批量时间线要逐个写事件,光有 count 不够)
target_accounts = db.query(Account).filter(Account.id.in_(ids)).all()
# 先取出账号对象(批量时间线要逐个写事件,光有 count 不够)。
# 「撤回」只处理当前确实有归属的账号;显式勾选里混入未分配账号时,
# 不应把它们算进撤回数量,也不该写一条假的「取消分配」时间线。
target_query = db.query(Account).filter(Account.id.in_(ids))
if req.assigned_to is None:
target_query = target_query.filter(Account.assigned_to.isnot(None))
target_accounts = target_query.all()
target_ids = [account.id for account in target_accounts]
if not target_ids:
raise HTTPException(status_code=400, detail="所选账号均未分配,无需撤回")
count = (
db.query(Account)
.filter(Account.id.in_(ids))
.filter(Account.id.in_(target_ids))
.update({Account.assigned_to: req.assigned_to}, synchronize_session=False)
)
db.query(DouyuTask).filter(DouyuTask.account_id.in_(ids)).update(
db.query(DouyuTask).filter(DouyuTask.account_id.in_(target_ids)).update(
{DouyuTask.account_assigned_to: req.assigned_to}, synchronize_session=False
)
target_user = (