feat(account-check): 增加履约账号 CK 保护目标
This commit is contained in:
@@ -48,6 +48,8 @@ from ..models import (
|
||||
from ..permissions import user_has_permission
|
||||
from ..schemas import (
|
||||
CookieReloginRequest,
|
||||
DouyuAccountProtectionTargetOut,
|
||||
DouyuAccountProtectionTargetUpdate,
|
||||
DouyuConfigOut,
|
||||
DouyuConfigUpdate,
|
||||
DouyuExchangeResultImageOut,
|
||||
@@ -63,12 +65,17 @@ from ..schemas import (
|
||||
)
|
||||
from ..services.account_binding import bind_payload
|
||||
from ..services.account_observability import account_platform_status
|
||||
from ..services.account_protection_service import (
|
||||
evaluate_protection_targets,
|
||||
update_protection_group,
|
||||
)
|
||||
from ..services.account_supply_service import (
|
||||
evaluate_supply_target,
|
||||
update_supply_target,
|
||||
upsert_supply_target,
|
||||
)
|
||||
from ..services.audit_service import record_audit
|
||||
from ..services.automation.scheduler import ensure_jobs
|
||||
from ..services.business_events import record_recharge
|
||||
from ..services.douyu_activity_query import activity_client, query_activity_goods
|
||||
from ..services.douyu_batch_launcher import (
|
||||
@@ -735,6 +742,53 @@ def get_account_platform_status(
|
||||
return account_platform_status(db)
|
||||
|
||||
|
||||
@router.put(
|
||||
"/account-protection-targets/{group_key}",
|
||||
response_model=DouyuAccountProtectionTargetOut,
|
||||
)
|
||||
def update_account_protection_target(
|
||||
group_key: str,
|
||||
req: DouyuAccountProtectionTargetUpdate,
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("douyu:config")),
|
||||
):
|
||||
"""更新履约保护组的 CK 目标与巡检/重登策略。"""
|
||||
ensure_jobs(db)
|
||||
before_rows = evaluate_protection_targets(db)
|
||||
before = next(
|
||||
(row for row in before_rows if row["group_key"] == group_key),
|
||||
None,
|
||||
)
|
||||
try:
|
||||
job, groups = update_protection_group(
|
||||
db,
|
||||
group_key=group_key,
|
||||
enabled=req.enabled,
|
||||
target_count=req.target_count,
|
||||
probe_interval_minutes=req.probe_interval_minutes,
|
||||
auto_relogin=req.auto_relogin,
|
||||
)
|
||||
except KeyError:
|
||||
raise HTTPException(status_code=404, detail="履约保护目标不存在") from None
|
||||
except LookupError as exc:
|
||||
raise HTTPException(status_code=409, detail=str(exc)) from None
|
||||
|
||||
after_config = job.config
|
||||
record_audit(
|
||||
db,
|
||||
current,
|
||||
action="douyu:account-protection-target:update",
|
||||
target=f"automation_job:{job.key}:{group_key}",
|
||||
detail={
|
||||
"before": before,
|
||||
"after": groups[group_key],
|
||||
},
|
||||
)
|
||||
db.commit()
|
||||
rows = evaluate_protection_targets(db, job_config=after_config)
|
||||
return next(row for row in rows if row["group_key"] == group_key)
|
||||
|
||||
|
||||
@router.get("/accounts")
|
||||
def list_task_accounts(
|
||||
search: str = Query(""),
|
||||
|
||||
Reference in New Issue
Block a user