优化(账号分配): 增加换绑与CK分类及测试操作
This commit is contained in:
@@ -226,6 +226,83 @@ class TestAssignablePool(_Base):
|
||||
|
||||
|
||||
class TestAssignmentPools(_Base):
|
||||
def test_default_rebind_ready_pool_requires_available_rebind_and_unexpired_ck(
|
||||
self,
|
||||
):
|
||||
ready = self.make_account(
|
||||
"pool-rebind-ready",
|
||||
role_bind_status="bound",
|
||||
role_change_available_at=self.now - timedelta(hours=1),
|
||||
ck_expected_expires_at=self.now + timedelta(days=3),
|
||||
)
|
||||
expiring = self.make_account(
|
||||
"pool-rebind-expiring-ck",
|
||||
role_bind_status="bound",
|
||||
role_change_available_at=self.now - timedelta(hours=1),
|
||||
ck_expected_expires_at=self.now + timedelta(hours=8),
|
||||
)
|
||||
self.make_account(
|
||||
"pool-rebind-cooldown",
|
||||
role_bind_status="bound",
|
||||
role_change_available_at=self.now + timedelta(days=2),
|
||||
ck_expected_expires_at=self.now + timedelta(days=3),
|
||||
)
|
||||
self.make_account(
|
||||
"pool-rebind-unbound",
|
||||
role_bind_status="unbound",
|
||||
ck_expected_expires_at=self.now + timedelta(days=3),
|
||||
)
|
||||
self.make_account(
|
||||
"pool-rebind-expired-ck",
|
||||
role_bind_status="bound",
|
||||
role_change_available_at=self.now - timedelta(hours=1),
|
||||
ck_expected_expires_at=self.now - timedelta(hours=1),
|
||||
)
|
||||
|
||||
result = list_accounts(
|
||||
assign_status="unassigned",
|
||||
assignable_only=True,
|
||||
occupancy="free",
|
||||
bind_change_status="available",
|
||||
ck_expiry_status="not_expired",
|
||||
page=1,
|
||||
page_size=50,
|
||||
include_sensitive=False,
|
||||
db=self.session,
|
||||
current=self.admin,
|
||||
)
|
||||
|
||||
items = {item.username: item for item in result["items"]}
|
||||
assert set(items) == {ready.username, expiring.username}
|
||||
assert items[ready.username].bind_change_status == "available"
|
||||
assert items[ready.username].bind_change_label == "可换绑"
|
||||
assert items[ready.username].ck_expiry_status == "valid"
|
||||
assert items[expiring.username].ck_expiry_status == "expiring"
|
||||
assert items[expiring.username].ck_expiry_label == "24 小时内到期"
|
||||
|
||||
def test_rebind_and_ck_category_filters_can_be_used_independently(self):
|
||||
cooling = self.make_account(
|
||||
"pool-only-cooling",
|
||||
role_bind_status="bound",
|
||||
role_change_available_at=self.now + timedelta(days=2),
|
||||
ck_expected_expires_at=self.now + timedelta(days=3),
|
||||
)
|
||||
expired = self.make_account(
|
||||
"pool-only-expired",
|
||||
role_bind_status="bound",
|
||||
role_change_available_at=self.now - timedelta(hours=1),
|
||||
ck_expected_expires_at=self.now - timedelta(hours=1),
|
||||
)
|
||||
invalid = self.make_account(
|
||||
"pool-only-invalid",
|
||||
ck_check_status="invalid",
|
||||
ck_expected_expires_at=self.now - timedelta(days=1),
|
||||
)
|
||||
|
||||
assert self.names(bind_change_status="cooldown") == [cooling.username]
|
||||
assert self.names(ck_expiry_status="expired") == [expired.username]
|
||||
assert self.names(ck_expiry_status="invalid") == [invalid.username]
|
||||
|
||||
def test_occupancy_filter_excludes_lease_and_collab(self):
|
||||
free = self.make_account("pool-free")
|
||||
leased = self.make_account("pool-leased")
|
||||
|
||||
@@ -2,7 +2,7 @@ import csv
|
||||
import io
|
||||
import threading
|
||||
import time
|
||||
from datetime import UTC, datetime
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Response
|
||||
@@ -61,6 +61,7 @@ from ..services.account_events_service import (
|
||||
emit_bulk,
|
||||
)
|
||||
from ..services.account_lifecycle import (
|
||||
DEFAULT_CK_LIFETIME,
|
||||
STATUS_ACTIVE,
|
||||
STATUS_ARCHIVED,
|
||||
STATUS_DISABLED,
|
||||
@@ -91,9 +92,84 @@ from ..services.login_failure import classify_failure, failure_kind_label
|
||||
router = APIRouter(prefix="/api/accounts", tags=["账号管理"])
|
||||
|
||||
_ASSIGNMENT_SKIN_CACHE_SECONDS = 60.0
|
||||
_CK_EXPIRING_HOURS = 24
|
||||
_assignment_skin_cache_lock = threading.Lock()
|
||||
_assignment_skin_cache: tuple[float, int, list[dict[str, Any]]] | None = None
|
||||
|
||||
CK_EXPIRY_LABELS = {
|
||||
"valid": "有效",
|
||||
"expiring": "24 小时内到期",
|
||||
"expired": "已过期",
|
||||
"invalid": "已失效",
|
||||
"error": "检测异常",
|
||||
"untested": "未检测",
|
||||
"missing": "无 CK",
|
||||
"unknown": "未预测到期",
|
||||
}
|
||||
BIND_CHANGE_LABELS = {
|
||||
"available": "可换绑",
|
||||
"cooldown": "换绑冷却",
|
||||
"unbound": "未绑定",
|
||||
"pending": "待确认",
|
||||
"unknown": "未知",
|
||||
}
|
||||
|
||||
|
||||
def _as_utc(value: datetime | None) -> datetime | None:
|
||||
if value is None:
|
||||
return None
|
||||
return value.replace(tzinfo=UTC) if value.tzinfo is None else value.astimezone(UTC)
|
||||
|
||||
|
||||
def _account_ck_expiry(
|
||||
account: Account,
|
||||
*,
|
||||
now: datetime,
|
||||
) -> tuple[str, datetime | None, int | None]:
|
||||
"""账号列表的 CK 到期分类;未明确检测过的 CK 不和有效 CK 混在一起。"""
|
||||
if not account.cookie:
|
||||
return "missing", None, None
|
||||
status = str(account.ck_check_status or "")
|
||||
if status in {"invalid", "error"}:
|
||||
return status, _as_utc(account.ck_expected_expires_at), None
|
||||
if status != "valid":
|
||||
return "untested", _as_utc(account.ck_expected_expires_at), None
|
||||
expires_at = _as_utc(account.ck_expected_expires_at)
|
||||
if expires_at is None:
|
||||
# 有有效检测但从未形成到期预测时,只给“有效/未预测”,不能猜成过期。
|
||||
fallback_at = _as_utc(
|
||||
account.cookie_updated_at or account.ck_checked_at
|
||||
)
|
||||
if fallback_at is None:
|
||||
return "unknown", None, None
|
||||
expires_at = fallback_at + DEFAULT_CK_LIFETIME
|
||||
remaining_seconds = (expires_at - now).total_seconds()
|
||||
remaining_hours = max(0, int(remaining_seconds // 3600))
|
||||
if remaining_seconds <= 0:
|
||||
return "expired", expires_at, 0
|
||||
if remaining_seconds <= _CK_EXPIRING_HOURS * 3600:
|
||||
return "expiring", expires_at, remaining_hours
|
||||
return "valid", expires_at, remaining_hours
|
||||
|
||||
|
||||
def _account_bind_change(
|
||||
account: Account,
|
||||
*,
|
||||
now: datetime,
|
||||
) -> tuple[bool, str, datetime | None]:
|
||||
"""能否换绑:只看精英角色,并沿用账号上已合并本地 7 天锁的可用时间。"""
|
||||
role_status = str(account.role_bind_status or "")
|
||||
if role_status == "unbound":
|
||||
return False, "unbound", None
|
||||
if role_status == "pending":
|
||||
return False, "pending", _as_utc(account.role_change_available_at)
|
||||
if role_status != "bound":
|
||||
return False, "unknown", _as_utc(account.role_change_available_at)
|
||||
available_at = _as_utc(account.role_change_available_at)
|
||||
if available_at is not None and available_at > now:
|
||||
return False, "cooldown", available_at
|
||||
return True, "available", available_at
|
||||
|
||||
|
||||
def _visible_accounts_query(db: Session, current: User):
|
||||
"""返回当前用户可见的斗鱼账号查询。"""
|
||||
@@ -250,6 +326,8 @@ def _filter_accounts_query(
|
||||
account_names: str = "",
|
||||
status: str = "",
|
||||
ck_status: str = "",
|
||||
ck_expiry_status: str = "",
|
||||
bind_change_status: str = "",
|
||||
failure_kind: str = "",
|
||||
bind_status: str = "",
|
||||
high_value_filter: str = "",
|
||||
@@ -301,6 +379,71 @@ def _filter_accounts_query(
|
||||
ck_value = _query_str(ck_status)
|
||||
if ck_value:
|
||||
query = query.filter(Account.ck_check_status == ck_value)
|
||||
ck_expiry_value = _query_str(ck_expiry_status)
|
||||
if ck_expiry_value:
|
||||
now = datetime.now(UTC)
|
||||
expiring_cutoff = now + timedelta(hours=_CK_EXPIRING_HOURS)
|
||||
if ck_expiry_value == "missing":
|
||||
query = query.filter(or_(Account.cookie.is_(None), Account.cookie == ""))
|
||||
elif ck_expiry_value in {"invalid", "error"}:
|
||||
query = query.filter(Account.ck_check_status == ck_expiry_value)
|
||||
elif ck_expiry_value == "untested":
|
||||
query = query.filter(
|
||||
Account.cookie.isnot(None),
|
||||
Account.cookie != "",
|
||||
Account.ck_check_status.notin_(["valid", "invalid", "error"]),
|
||||
)
|
||||
elif ck_expiry_value in {
|
||||
"not_expired",
|
||||
"valid",
|
||||
"expiring",
|
||||
"expired",
|
||||
"unknown",
|
||||
}:
|
||||
query = query.filter(Account.ck_check_status == "valid")
|
||||
if ck_expiry_value == "not_expired":
|
||||
query = query.filter(
|
||||
or_(
|
||||
Account.ck_expected_expires_at.is_(None),
|
||||
Account.ck_expected_expires_at > now,
|
||||
)
|
||||
)
|
||||
elif ck_expiry_value == "unknown":
|
||||
query = query.filter(Account.ck_expected_expires_at.is_(None))
|
||||
elif ck_expiry_value == "expired":
|
||||
query = query.filter(
|
||||
Account.ck_expected_expires_at.isnot(None),
|
||||
Account.ck_expected_expires_at <= now,
|
||||
)
|
||||
elif ck_expiry_value == "expiring":
|
||||
query = query.filter(
|
||||
Account.ck_expected_expires_at > now,
|
||||
Account.ck_expected_expires_at <= expiring_cutoff,
|
||||
)
|
||||
else:
|
||||
query = query.filter(
|
||||
Account.ck_expected_expires_at > expiring_cutoff
|
||||
)
|
||||
bind_change_value = _query_str(bind_change_status)
|
||||
if bind_change_value:
|
||||
now = datetime.now(UTC)
|
||||
if bind_change_value == "available":
|
||||
query = query.filter(
|
||||
Account.role_bind_status == "bound",
|
||||
or_(
|
||||
Account.role_change_available_at.is_(None),
|
||||
Account.role_change_available_at <= now,
|
||||
),
|
||||
)
|
||||
elif bind_change_value == "cooldown":
|
||||
query = query.filter(
|
||||
Account.role_bind_status == "bound",
|
||||
Account.role_change_available_at > now,
|
||||
)
|
||||
elif bind_change_value == "unbound":
|
||||
query = query.filter(Account.role_bind_status == "unbound")
|
||||
elif bind_change_value == "pending":
|
||||
query = query.filter(Account.role_bind_status == "pending")
|
||||
fk_value = _query_str(failure_kind)
|
||||
if fk_value:
|
||||
query = query.filter(Account.relogin_failure_kind == fk_value)
|
||||
@@ -439,6 +582,8 @@ def _selection_query(db: Session, current: User, req: AccountBulkSelection):
|
||||
account_names=req.account_names,
|
||||
status=req.status,
|
||||
ck_status=req.ck_status,
|
||||
ck_expiry_status=req.ck_expiry_status,
|
||||
bind_change_status=req.bind_change_status,
|
||||
failure_kind=req.failure_kind,
|
||||
bind_status=req.bind_status,
|
||||
high_value_filter=req.high_value_filter,
|
||||
@@ -612,6 +757,17 @@ def list_accounts(
|
||||
ck_status: str = Query(
|
||||
"", description="按 CK 健康结论筛选:valid / invalid / error"
|
||||
),
|
||||
ck_expiry_status: str = Query(
|
||||
"",
|
||||
description=(
|
||||
"按 CK 到期分类筛选:valid/expiring/expired/invalid/error/"
|
||||
"untested/missing/unknown/not_expired"
|
||||
),
|
||||
),
|
||||
bind_change_status: str = Query(
|
||||
"",
|
||||
description="按换绑分类筛选:available/cooldown/unbound/pending",
|
||||
),
|
||||
failure_kind: str = Query(
|
||||
"",
|
||||
description="按最近登录失败分型筛选:must_bind_mobile/captcha/credential/email_code/email_quota/network",
|
||||
@@ -664,6 +820,8 @@ def list_accounts(
|
||||
account_names=account_names,
|
||||
status=status,
|
||||
ck_status=ck_status,
|
||||
ck_expiry_status=ck_expiry_status,
|
||||
bind_change_status=bind_change_status,
|
||||
failure_kind=failure_kind,
|
||||
bind_status=bind_status,
|
||||
high_value_filter=high_value_filter,
|
||||
@@ -828,6 +986,7 @@ def list_accounts(
|
||||
if ids
|
||||
else {}
|
||||
)
|
||||
output_now = datetime.now(UTC)
|
||||
result = []
|
||||
for acc in accounts:
|
||||
eff_kind = acc.relogin_failure_kind or ""
|
||||
@@ -835,6 +994,13 @@ def list_accounts(
|
||||
refined = classify_failure(acc.relogin_last_error)
|
||||
if not eff_kind or (eff_kind == "network" and refined != "network"):
|
||||
eff_kind = refined
|
||||
ck_expiry_status, ck_expires_at, ck_remaining_hours = _account_ck_expiry(
|
||||
acc,
|
||||
now=output_now,
|
||||
)
|
||||
can_change_bind, bind_change_status, bind_change_available_at = (
|
||||
_account_bind_change(acc, now=output_now)
|
||||
)
|
||||
|
||||
item = AccountOut(
|
||||
id=acc.id,
|
||||
@@ -855,6 +1021,13 @@ def list_accounts(
|
||||
has_cookie=bool(acc.cookie),
|
||||
ck_check_status=acc.ck_check_status or "",
|
||||
ck_checked_at=acc.ck_checked_at,
|
||||
ck_expires_at=ck_expires_at,
|
||||
ck_expiry_status=ck_expiry_status,
|
||||
ck_expiry_label=CK_EXPIRY_LABELS.get(
|
||||
ck_expiry_status,
|
||||
ck_expiry_status,
|
||||
),
|
||||
ck_remaining_hours=ck_remaining_hours,
|
||||
points=acc.points,
|
||||
gold_balance=acc.gold_balance,
|
||||
elite_opened=acc.elite_opened,
|
||||
@@ -863,6 +1036,13 @@ 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),
|
||||
can_change_bind=can_change_bind,
|
||||
bind_change_status=bind_change_status,
|
||||
bind_change_label=BIND_CHANGE_LABELS.get(
|
||||
bind_change_status,
|
||||
bind_change_status,
|
||||
),
|
||||
bind_change_available_at=bind_change_available_at,
|
||||
# 只返回官方 storehome 的紧凑三态,不把整份快照带进列表。
|
||||
high_value=high_value_payload(acc),
|
||||
overview_queried_at=acc.overview_queried_at,
|
||||
@@ -875,9 +1055,6 @@ def list_accounts(
|
||||
redundancy_class=(
|
||||
profile_map[acc.id].redundancy_class if acc.id in profile_map else ""
|
||||
),
|
||||
ck_remaining_hours=(
|
||||
profile_map[acc.id].ck_remaining_hours if acc.id in profile_map else None
|
||||
),
|
||||
active_lease_purpose=(
|
||||
str(lease_map[acc.id].purpose or "") if acc.id in lease_map else ""
|
||||
),
|
||||
@@ -915,6 +1092,8 @@ def list_account_ids(
|
||||
),
|
||||
status: str = Query(""),
|
||||
ck_status: str = Query(""),
|
||||
ck_expiry_status: str = Query(""),
|
||||
bind_change_status: str = Query(""),
|
||||
failure_kind: str = Query(""),
|
||||
bind_status: str = Query(""),
|
||||
high_value_filter: str = Query(""),
|
||||
@@ -949,6 +1128,8 @@ def list_account_ids(
|
||||
account_names=account_names,
|
||||
status=status,
|
||||
ck_status=ck_status,
|
||||
ck_expiry_status=ck_expiry_status,
|
||||
bind_change_status=bind_change_status,
|
||||
failure_kind=failure_kind,
|
||||
bind_status=bind_status,
|
||||
high_value_filter=high_value_filter,
|
||||
|
||||
+20
-2
@@ -217,6 +217,10 @@ class AccountBulkSelection(BaseModel):
|
||||
has_cookie: bool = False
|
||||
status: str = ""
|
||||
ck_status: str = ""
|
||||
#: CK 到期分类:valid/expiring/expired/invalid/error/untested/missing/unknown
|
||||
ck_expiry_status: str = ""
|
||||
#: 换绑分类:available/cooldown/unbound/pending/unknown
|
||||
bind_change_status: str = ""
|
||||
failure_kind: str = ""
|
||||
bind_status: str = ""
|
||||
high_value_filter: str = ""
|
||||
@@ -322,12 +326,20 @@ class AccountOut(BaseModel):
|
||||
has_cookie: bool = False
|
||||
ck_check_status: str = ""
|
||||
ck_checked_at: datetime | None = None
|
||||
ck_expires_at: datetime | None = None
|
||||
ck_expiry_status: str = ""
|
||||
ck_expiry_label: str = ""
|
||||
ck_remaining_hours: int | None = None
|
||||
points: int | None = None
|
||||
gold_balance: int | None = None
|
||||
elite_opened: bool | None = None
|
||||
esports_opened: bool | None = None
|
||||
role_bind_status: str = "unknown"
|
||||
role_bind_label: str = ""
|
||||
can_change_bind: bool = False
|
||||
bind_change_status: str = ""
|
||||
bind_change_label: str = ""
|
||||
bind_change_available_at: datetime | None = None
|
||||
esports_bind_status: str = "unknown"
|
||||
esports_bind_label: str = ""
|
||||
xpd_bind_status: str = "unknown"
|
||||
@@ -343,7 +355,6 @@ class AccountOut(BaseModel):
|
||||
supply_role: str = ""
|
||||
quality_score: int | None = None
|
||||
redundancy_class: str = ""
|
||||
ck_remaining_hours: int | None = None
|
||||
active_lease_purpose: str = ""
|
||||
active_lease_expires_at: datetime | None = None
|
||||
in_active_collab: bool = False
|
||||
@@ -373,12 +384,20 @@ class AccountOut(BaseModel):
|
||||
"has_cookie": self.has_cookie,
|
||||
"ck_check_status": self.ck_check_status,
|
||||
"ck_checked_at": _isoformat(self.ck_checked_at),
|
||||
"ck_expires_at": _isoformat(self.ck_expires_at),
|
||||
"ck_expiry_status": self.ck_expiry_status,
|
||||
"ck_expiry_label": self.ck_expiry_label,
|
||||
"ck_remaining_hours": self.ck_remaining_hours,
|
||||
"points": self.points,
|
||||
"gold_balance": self.gold_balance,
|
||||
"elite_opened": self.elite_opened,
|
||||
"esports_opened": self.esports_opened,
|
||||
"role_bind_status": self.role_bind_status,
|
||||
"role_bind_label": self.role_bind_label,
|
||||
"can_change_bind": self.can_change_bind,
|
||||
"bind_change_status": self.bind_change_status,
|
||||
"bind_change_label": self.bind_change_label,
|
||||
"bind_change_available_at": _isoformat(self.bind_change_available_at),
|
||||
"esports_bind_status": self.esports_bind_status,
|
||||
"esports_bind_label": self.esports_bind_label,
|
||||
"xpd_bind_status": self.xpd_bind_status,
|
||||
@@ -394,7 +413,6 @@ class AccountOut(BaseModel):
|
||||
"supply_role": self.supply_role,
|
||||
"quality_score": self.quality_score,
|
||||
"redundancy_class": self.redundancy_class,
|
||||
"ck_remaining_hours": self.ck_remaining_hours,
|
||||
"active_lease_purpose": self.active_lease_purpose,
|
||||
"active_lease_expires_at": _isoformat(self.active_lease_expires_at),
|
||||
"in_active_collab": self.in_active_collab,
|
||||
|
||||
@@ -34,6 +34,8 @@ export const accountApi = {
|
||||
include_sensitive?: boolean;
|
||||
status?: string;
|
||||
ck_status?: string;
|
||||
ck_expiry_status?: string;
|
||||
bind_change_status?: string;
|
||||
failure_kind?: string;
|
||||
bind_status?: string;
|
||||
high_value_filter?: string;
|
||||
@@ -63,6 +65,8 @@ export const accountApi = {
|
||||
has_cookie?: boolean;
|
||||
status?: string;
|
||||
ck_status?: string;
|
||||
ck_expiry_status?: string;
|
||||
bind_change_status?: string;
|
||||
failure_kind?: string;
|
||||
bind_status?: string;
|
||||
high_value_filter?: string;
|
||||
|
||||
@@ -43,6 +43,8 @@ export interface AccountBulkSelection {
|
||||
has_cookie?: boolean;
|
||||
status?: string;
|
||||
ck_status?: string;
|
||||
ck_expiry_status?: string;
|
||||
bind_change_status?: string;
|
||||
failure_kind?: string;
|
||||
bind_status?: string;
|
||||
high_value_filter?: string;
|
||||
@@ -448,12 +450,20 @@ export interface AccountItem {
|
||||
has_cookie: boolean;
|
||||
ck_check_status: string;
|
||||
ck_checked_at: string | null;
|
||||
ck_expires_at: string | null;
|
||||
ck_expiry_status: string;
|
||||
ck_expiry_label: string;
|
||||
ck_remaining_hours?: number | null;
|
||||
points: number | null;
|
||||
gold_balance: number | null;
|
||||
elite_opened: boolean | null;
|
||||
esports_opened: boolean | null;
|
||||
role_bind_status: BindStatus;
|
||||
role_bind_label: string;
|
||||
can_change_bind: boolean;
|
||||
bind_change_status: string;
|
||||
bind_change_label: string;
|
||||
bind_change_available_at: string | null;
|
||||
esports_bind_status: BindStatus;
|
||||
esports_bind_label: string;
|
||||
xpd_bind_status: BindStatus;
|
||||
@@ -469,7 +479,6 @@ export interface AccountItem {
|
||||
supply_role?: string;
|
||||
quality_score?: number | null;
|
||||
redundancy_class?: string;
|
||||
ck_remaining_hours?: number | null;
|
||||
active_lease_purpose: string;
|
||||
active_lease_expires_at: string | null;
|
||||
in_active_collab: boolean;
|
||||
|
||||
@@ -21,7 +21,9 @@ import {
|
||||
import {
|
||||
CheckCircleOutlined,
|
||||
ClearOutlined,
|
||||
FieldTimeOutlined,
|
||||
ReloadOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
SearchOutlined,
|
||||
SendOutlined,
|
||||
SwapOutlined,
|
||||
@@ -32,6 +34,7 @@ import {
|
||||
|
||||
import {
|
||||
accountApi,
|
||||
douyuApi,
|
||||
type AccountItem,
|
||||
type AssignmentOptions,
|
||||
type AssignmentsSummary,
|
||||
@@ -39,15 +42,23 @@ import {
|
||||
} from '../api/modules';
|
||||
import { getErrorMessage } from '../utils/error';
|
||||
import { message } from '../utils/antdMessage';
|
||||
import { formatTime } from '../utils/time';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
const STORAGE_KEY_SELECTED_USER = 'assignments_selected_user_id';
|
||||
|
||||
type PoolPreset = 'free' | 'zero_points' | 'elite_points' | 'high_value' | 'custom';
|
||||
type PoolPreset =
|
||||
| 'rebind_ready'
|
||||
| 'free'
|
||||
| 'zero_points'
|
||||
| 'elite_points'
|
||||
| 'high_value'
|
||||
| 'custom';
|
||||
type AssignmentTab = 'candidate' | 'assigned';
|
||||
|
||||
const POOL_PRESETS: Array<{ value: PoolPreset; label: string }> = [
|
||||
{ value: 'rebind_ready', label: '可换绑 + 有效CK' },
|
||||
{ value: 'free', label: '空闲号' },
|
||||
{ value: 'zero_points', label: '无积分' },
|
||||
{ value: 'elite_points', label: '精英令 + 积分' },
|
||||
@@ -84,6 +95,20 @@ function occupancyLabel(record: AccountItem): string {
|
||||
return '空闲';
|
||||
}
|
||||
|
||||
function bindChangeTone(status: string) {
|
||||
if (status === 'available') return 'green';
|
||||
if (status === 'cooldown') return 'orange';
|
||||
if (status === 'pending') return 'gold';
|
||||
return 'default';
|
||||
}
|
||||
|
||||
function ckExpiryTone(status: string) {
|
||||
if (status === 'valid') return 'green';
|
||||
if (status === 'expiring') return 'gold';
|
||||
if (status === 'expired' || status === 'invalid' || status === 'error') return 'red';
|
||||
return 'default';
|
||||
}
|
||||
|
||||
function highValueTags(record: AccountItem) {
|
||||
const items = [
|
||||
record.high_value?.bairimeng === 'available' ? '白日梦可换' : '',
|
||||
@@ -112,7 +137,7 @@ export default function AssignmentsPage() {
|
||||
const [allTags, setAllTags] = useState<string[]>([]);
|
||||
|
||||
const [activeTab, setActiveTab] = useState<AssignmentTab>('candidate');
|
||||
const [poolPreset, setPoolPreset] = useState<PoolPreset>('free');
|
||||
const [poolPreset, setPoolPreset] = useState<PoolPreset>('rebind_ready');
|
||||
const [occupancy, setOccupancy] = useState('free');
|
||||
const [searchText, setSearchText] = useState('');
|
||||
const [filterTag, setFilterTag] = useState<string | undefined>();
|
||||
@@ -121,6 +146,8 @@ export default function AssignmentsPage() {
|
||||
const [eliteOpened, setEliteOpened] = useState<boolean | undefined>();
|
||||
const [minPoints, setMinPoints] = useState<number | null>(null);
|
||||
const [maxPoints, setMaxPoints] = useState<number | null>(null);
|
||||
const [ckExpiryStatus, setCkExpiryStatus] = useState<string | undefined>('not_expired');
|
||||
const [bindChangeStatus, setBindChangeStatus] = useState<string | undefined>('available');
|
||||
const [dispatchQuantity, setDispatchQuantity] = useState(10);
|
||||
|
||||
const [pagedAccounts, setPagedAccounts] = useState<AccountItem[]>([]);
|
||||
@@ -130,6 +157,8 @@ export default function AssignmentsPage() {
|
||||
const [assigning, setAssigning] = useState(false);
|
||||
const [dispatching, setDispatching] = useState(false);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [checkingCk, setCheckingCk] = useState(false);
|
||||
const [checkingRebind, setCheckingRebind] = useState(false);
|
||||
const summaryRequestRef = useRef(0);
|
||||
const pagedRequestRef = useRef(0);
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
@@ -151,8 +180,12 @@ export default function AssignmentsPage() {
|
||||
elite_opened: eliteOpened,
|
||||
min_points: minPoints ?? undefined,
|
||||
max_points: maxPoints ?? undefined,
|
||||
ck_expiry_status: ckExpiryStatus,
|
||||
bind_change_status: bindChangeStatus,
|
||||
}),
|
||||
[
|
||||
bindChangeStatus,
|
||||
ckExpiryStatus,
|
||||
commodityId,
|
||||
eliteOpened,
|
||||
filterTag,
|
||||
@@ -278,13 +311,24 @@ export default function AssignmentsPage() {
|
||||
const applyPreset = (preset: PoolPreset) => {
|
||||
setPoolPreset(preset);
|
||||
resetPaging();
|
||||
if (preset === 'free') {
|
||||
if (preset === 'rebind_ready') {
|
||||
setOccupancy('free');
|
||||
setCommodityId(undefined);
|
||||
setHighValueFilter(undefined);
|
||||
setEliteOpened(undefined);
|
||||
setMinPoints(null);
|
||||
setMaxPoints(null);
|
||||
setCkExpiryStatus('not_expired');
|
||||
setBindChangeStatus('available');
|
||||
} else if (preset === 'free') {
|
||||
setOccupancy('free');
|
||||
setCommodityId(undefined);
|
||||
setHighValueFilter(undefined);
|
||||
setEliteOpened(undefined);
|
||||
setMinPoints(null);
|
||||
setMaxPoints(null);
|
||||
setCkExpiryStatus(undefined);
|
||||
setBindChangeStatus(undefined);
|
||||
} else if (preset === 'zero_points') {
|
||||
setOccupancy('free');
|
||||
setCommodityId(undefined);
|
||||
@@ -292,6 +336,8 @@ export default function AssignmentsPage() {
|
||||
setEliteOpened(undefined);
|
||||
setMinPoints(0);
|
||||
setMaxPoints(0);
|
||||
setCkExpiryStatus(undefined);
|
||||
setBindChangeStatus(undefined);
|
||||
} else if (preset === 'elite_points') {
|
||||
setOccupancy('free');
|
||||
setCommodityId(undefined);
|
||||
@@ -299,6 +345,8 @@ export default function AssignmentsPage() {
|
||||
setEliteOpened(true);
|
||||
setMinPoints(1);
|
||||
setMaxPoints(null);
|
||||
setCkExpiryStatus(undefined);
|
||||
setBindChangeStatus(undefined);
|
||||
} else if (preset === 'high_value') {
|
||||
setOccupancy('free');
|
||||
setCommodityId(undefined);
|
||||
@@ -306,6 +354,8 @@ export default function AssignmentsPage() {
|
||||
setEliteOpened(undefined);
|
||||
setMinPoints(null);
|
||||
setMaxPoints(null);
|
||||
setCkExpiryStatus(undefined);
|
||||
setBindChangeStatus(undefined);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -402,6 +452,51 @@ export default function AssignmentsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const testSelectedCk = async () => {
|
||||
if (selectedRowKeys.length === 0) {
|
||||
message.warning('请先勾选账号');
|
||||
return;
|
||||
}
|
||||
setCheckingCk(true);
|
||||
try {
|
||||
const result = await douyuApi.checkAccountsCk(selectedRowKeys);
|
||||
const invalid = result.results.filter((item) => !item.valid).length;
|
||||
if (invalid > 0) {
|
||||
message.warning(`CK 检测完成:${invalid} 个账号失效`);
|
||||
} else {
|
||||
message.success(`CK 检测完成:${result.results.length} 个账号全部有效`);
|
||||
}
|
||||
await loadPagedAccounts(true);
|
||||
} catch (error) {
|
||||
message.error(getErrorMessage(error));
|
||||
} finally {
|
||||
setCheckingCk(false);
|
||||
}
|
||||
};
|
||||
|
||||
const testSelectedRebind = async () => {
|
||||
if (selectedRowKeys.length === 0) {
|
||||
message.warning('请先勾选账号');
|
||||
return;
|
||||
}
|
||||
setCheckingRebind(true);
|
||||
try {
|
||||
const result = await douyuApi.createTasks({
|
||||
account_ids: selectedRowKeys,
|
||||
task_type: 'query_change_bind_time',
|
||||
handbook_scope: 'elite',
|
||||
concurrency: 3,
|
||||
payload: {},
|
||||
});
|
||||
message.success(`换绑时间查询已提交:${result.count} 个账号`);
|
||||
window.setTimeout(() => void loadPagedAccounts(true), 1800);
|
||||
} catch (error) {
|
||||
message.error(getErrorMessage(error));
|
||||
} finally {
|
||||
setCheckingRebind(false);
|
||||
}
|
||||
};
|
||||
|
||||
const selectedUserAssignedCount =
|
||||
supportUsers.find((user) => user.id === selectedUser?.id)?.assigned_count
|
||||
?? selectedUser?.assigned_count
|
||||
@@ -435,6 +530,42 @@ export default function AssignmentsPage() {
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '能否换绑',
|
||||
width: 145,
|
||||
render: (_: unknown, record: AccountItem) => (
|
||||
<Space direction="vertical" size={1}>
|
||||
<Tag color={bindChangeTone(record.bind_change_status)}>
|
||||
{record.bind_change_label || '未知'}
|
||||
</Tag>
|
||||
{record.bind_change_status === 'cooldown' && record.bind_change_available_at ? (
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{formatTime(record.bind_change_available_at)} 后可换
|
||||
</Text>
|
||||
) : null}
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'CK 分类',
|
||||
width: 150,
|
||||
render: (_: unknown, record: AccountItem) => (
|
||||
<Space direction="vertical" size={1}>
|
||||
<Tag color={ckExpiryTone(record.ck_expiry_status)}>
|
||||
{record.ck_expiry_label || '未知'}
|
||||
</Tag>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{record.ck_remaining_hours != null
|
||||
? `剩余 ${record.ck_remaining_hours}h`
|
||||
: record.ck_expires_at
|
||||
? `预计 ${formatTime(record.ck_expires_at)}`
|
||||
: record.ck_check_status
|
||||
? `检测 ${record.ck_check_status}`
|
||||
: '尚未检测'}
|
||||
</Text>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '积分 / 鱼翅',
|
||||
width: 150,
|
||||
@@ -735,6 +866,43 @@ export default function AssignmentsPage() {
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<Select
|
||||
allowClear
|
||||
placeholder="换绑分类"
|
||||
value={bindChangeStatus}
|
||||
onChange={(value) => {
|
||||
setBindChangeStatus(value);
|
||||
markCustom();
|
||||
}}
|
||||
style={{ width: 135 }}
|
||||
options={[
|
||||
{ value: 'available', label: '可换绑' },
|
||||
{ value: 'cooldown', label: '换绑冷却' },
|
||||
{ value: 'unbound', label: '未绑定' },
|
||||
{ value: 'pending', label: '待确认' },
|
||||
]}
|
||||
/>
|
||||
<Select
|
||||
allowClear
|
||||
placeholder="CK 分类"
|
||||
value={ckExpiryStatus}
|
||||
onChange={(value) => {
|
||||
setCkExpiryStatus(value);
|
||||
markCustom();
|
||||
}}
|
||||
style={{ width: 150 }}
|
||||
options={[
|
||||
{ value: 'not_expired', label: 'CK 有效(含临期)' },
|
||||
{ value: 'valid', label: 'CK 有效' },
|
||||
{ value: 'expiring', label: '24 小时内到期' },
|
||||
{ value: 'expired', label: 'CK 已过期' },
|
||||
{ value: 'invalid', label: 'CK 已失效' },
|
||||
{ value: 'error', label: 'CK 检测异常' },
|
||||
{ value: 'untested', label: 'CK 未检测' },
|
||||
{ value: 'missing', label: '无 CK' },
|
||||
{ value: 'unknown', label: '未预测到期' },
|
||||
]}
|
||||
/>
|
||||
<Select
|
||||
allowClear
|
||||
showSearch
|
||||
@@ -851,6 +1019,22 @@ export default function AssignmentsPage() {
|
||||
取消分配选中 {selectedRowKeys.length}
|
||||
</Button>
|
||||
) : null}
|
||||
<Button
|
||||
icon={<SafetyCertificateOutlined />}
|
||||
loading={checkingCk}
|
||||
disabled={selectedRowKeys.length === 0}
|
||||
onClick={() => void testSelectedCk()}
|
||||
>
|
||||
检测 CK{selectedRowKeys.length > 0 ? `(${selectedRowKeys.length})` : ''}
|
||||
</Button>
|
||||
<Button
|
||||
icon={<FieldTimeOutlined />}
|
||||
loading={checkingRebind}
|
||||
disabled={selectedRowKeys.length === 0}
|
||||
onClick={() => void testSelectedRebind()}
|
||||
>
|
||||
查询换绑{selectedRowKeys.length > 0 ? `(${selectedRowKeys.length})` : ''}
|
||||
</Button>
|
||||
<Text type="secondary">
|
||||
当前筛选共 {totalCount} 个 · 已选 {selectedRowKeys.length} 个
|
||||
</Text>
|
||||
@@ -883,7 +1067,7 @@ export default function AssignmentsPage() {
|
||||
}
|
||||
},
|
||||
}}
|
||||
scroll={{ x: 1180, y: 'calc(100vh - 475px)' }}
|
||||
scroll={{ x: 1490, y: 'calc(100vh - 475px)' }}
|
||||
locale={{ emptyText: '当前候选池没有账号' }}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user