feat(automation): 巡检和重登优先保住高价值账号的 CK
价值按套装和积分现算,不看标签。第 1、2 档 6 小时巡检一次,并先占重登名额。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy import String, and_, cast, func, or_, select, text
|
||||
from sqlalchemy import and_, func, or_, select, text
|
||||
from sqlalchemy.orm import Session, defer, joinedload
|
||||
|
||||
from ..database import get_db
|
||||
@@ -53,6 +53,12 @@ from ..services.account_service import (
|
||||
cookie_account_ids_query,
|
||||
parse_and_build_accounts,
|
||||
)
|
||||
from ..services.account_value import (
|
||||
SUIT_BAIRIMENG,
|
||||
SUIT_MENGTU,
|
||||
is_high_value_expr,
|
||||
suit_owned_expr,
|
||||
)
|
||||
from ..services.audit_service import record_account_action, record_audit
|
||||
from ..services.douyu_service import cookie_holding_filter
|
||||
|
||||
@@ -79,17 +85,6 @@ def _query_str(value) -> str:
|
||||
return value.strip() if isinstance(value, str) else ""
|
||||
|
||||
|
||||
def _high_value_contains_expr(column, text: str):
|
||||
"""匹配 JSON 字段中是否包含特定商品名(同时兼容 MySQL 与 SQLite 字符存储)。"""
|
||||
import json
|
||||
|
||||
escaped = json.dumps(text).strip('"')
|
||||
return or_(
|
||||
cast(column, String).like(f"%{text}%"),
|
||||
cast(column, String).like(f"%{escaped}%"),
|
||||
)
|
||||
|
||||
|
||||
def _filter_accounts_query(
|
||||
db: Session,
|
||||
query,
|
||||
@@ -146,10 +141,8 @@ def _filter_accounts_query(
|
||||
# 高价值套装筛选
|
||||
hv = _query_str(high_value_filter)
|
||||
if hv:
|
||||
bairimeng_expr = _high_value_contains_expr(
|
||||
Account.high_value_owned, "兔兔白日梦"
|
||||
)
|
||||
mengtu_expr = _high_value_contains_expr(Account.high_value_owned, "狂战萌兔")
|
||||
bairimeng_expr = suit_owned_expr(Account.high_value_owned, SUIT_BAIRIMENG)
|
||||
mengtu_expr = suit_owned_expr(Account.high_value_owned, SUIT_MENGTU)
|
||||
if hv == "both_available":
|
||||
query = query.filter(
|
||||
Account.overview_queried_at.isnot(None),
|
||||
@@ -176,14 +169,7 @@ def _filter_accounts_query(
|
||||
query = query.filter(Account.overview_queried_at.is_(None))
|
||||
elif hv == "high_value_broken":
|
||||
query = query.filter(
|
||||
or_(
|
||||
and_(
|
||||
Account.overview_queried_at.isnot(None),
|
||||
~bairimeng_expr,
|
||||
~mengtu_expr,
|
||||
),
|
||||
Account.points >= 300,
|
||||
),
|
||||
is_high_value_expr(),
|
||||
Account.ck_check_status.in_(["invalid", "error"]),
|
||||
)
|
||||
|
||||
@@ -494,17 +480,10 @@ def accounts_summary(
|
||||
by_status = {str(row[0] or ""): int(row[1] or 0) for row in status_rows}
|
||||
visible_total = sum(by_status.values())
|
||||
# 高价值及核心资产分布(单次聚合,供前端快捷胶囊展示)
|
||||
bairimeng_expr = _high_value_contains_expr(Account.high_value_owned, "兔兔白日梦")
|
||||
mengtu_expr = _high_value_contains_expr(Account.high_value_owned, "狂战萌兔")
|
||||
bairimeng_expr = suit_owned_expr(Account.high_value_owned, SUIT_BAIRIMENG)
|
||||
mengtu_expr = suit_owned_expr(Account.high_value_owned, SUIT_MENGTU)
|
||||
high_value_broken_expr = and_(
|
||||
or_(
|
||||
and_(
|
||||
Account.overview_queried_at.isnot(None),
|
||||
~bairimeng_expr,
|
||||
~mengtu_expr,
|
||||
),
|
||||
Account.points >= 300,
|
||||
),
|
||||
is_high_value_expr(),
|
||||
Account.ck_check_status.in_(["invalid", "error"]),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user