fix(计划): 定时触发补 app context;账号状态加检测时间与历史记录

- _fire 内调用 run_plan(修复 18:00 Working outside application context,无运行记录)
- device_account 新增 status_checked_at;新表 account_status_log(schema v23)
- 每次检测/手改留痕;资产表显示检测时间 + 「记录」弹窗
- API /api/af/account_status_logs;备份标签/文档/测试同步
This commit is contained in:
2026-10-22 07:59:18 +08:00
parent 7bc19e9eaa
commit 122e239e45
13 changed files with 222 additions and 18 deletions
+32 -2
View File
@@ -360,8 +360,18 @@ def api_af_roster_update(row_id):
row.douyin_id = (data.get("douyin_id") or "").strip()[:64]
if "account_status" in data:
# 账号状态:手改(正常/账号异常/限流…);任务里「读取文字」写
# 变量 account_status 时也会走同一列(见 af.set_account_status)
row.account_status = (data.get("account_status") or "").strip()[:80]
# 变量 account_status 时也会走同一列(见 af.set_account_status)。
# 手改也进历史表(source=手动修改),但**不刷新检测时间**(那列只表示真检测)。
from core.models import AccountStatusLog
new_st = (data.get("account_status") or "").strip()[:80]
if new_st != (row.account_status or ""):
db.session.add(AccountStatusLog(
id=uuid.uuid4().hex[:8], account_id=row.id,
nickname=row.nickname, device_name=row.device_name or "",
serial=row.serial or "", status=new_st, source="手动修改",
run_id="", detected_at=time.strftime("%Y-%m-%d %H:%M:%S"),
created_at=time.strftime("%Y-%m-%d %H:%M:%S")))
row.account_status = new_st
row.updated_at = time.strftime("%Y-%m-%d %H:%M:%S")
db.session.commit()
_log.info("账号库编辑:%s → 昵称 %s / 设备 %s", row_id, row.nickname, row.device_name)
@@ -405,6 +415,26 @@ def api_af_roster():
return jsonify({"ok": True, "rows": rows, "groups": groups, "total": len(rows)})
@bp.route("/api/af/account_status_logs")
@perm_required(PERM_DEVICES)
def api_af_account_status_logs():
"""账号状态检测记录(资产管理 → 账号状态 → 记录)。"""
from core.models import AccountStatusLog
name = (request.args.get("name") or "").strip()
try:
limit = max(1, min(200, int(request.args.get("limit", 50) or 50)))
except (TypeError, ValueError):
limit = 50
q = AccountStatusLog.query
if name:
q = q.filter(AccountStatusLog.nickname == name)
rows = (q.order_by(AccountStatusLog.detected_at.desc(),
AccountStatusLog.id.desc())
.limit(limit).all())
return jsonify({"ok": True, "rows": [r.to_dict() for r in rows],
"total": len(rows)})
# ==================== 账号池对外只读 API ====================
# 其他应用用 `X-Account-Token`(或 Bearer)访问,不需要登录会话。
@bp.route("/api/account_pool/accounts", methods=["GET", "OPTIONS"])