feat(通知): 账号状态汇总(检测账号跑完 + 每日 09:30)

- 新事件 account.status.summary:总数/正常/异常/状态分布/异常账号清单
- 计划收尾检测 read_text(account_status) 才发,普通发布计划不刷屏
- 每日 09:30 全量汇总;ACCOUNT_STATUS_DAILY/ACCOUNT_STATUS_SUMMARY_AT 可配
- 生产企微 webhook 已订阅该事件;测试与文档同步
This commit is contained in:
2026-10-21 16:33:24 +08:00
parent e356b6b806
commit 677c3189c9
11 changed files with 178 additions and 0 deletions
+27
View File
@@ -214,6 +214,33 @@ row = Device.query.get("A11:5555"); row.cur_account_name = ""; db.session.commit
check("分不清且没有历史 → 返回空",
ap.resolve_masked_name("A11:5555", "锋哥苏***探访"), "")
print("▶ ⑧ 账号状态汇总通知(事件 account.status.summary)")
with app.app_context():
r = DeviceAccount.query.filter_by(nickname="锋哥苏州百业探访").first()
if r:
r.account_status = "正常"
r2 = DeviceAccount.query.filter_by(nickname="周周苏州吃喝玩乐").first()
if r2:
r2.account_status = "账号异常"
db.session.commit()
notes = []
from core import notifier as _notifier # noqa: E402
_orig_notify = _notifier.notify
_notifier.notify = lambda ev, **kw: notes.append((ev, kw))
try:
ok = af.notify_account_status_summary(job_name="检测账号", source="计划运行")
finally:
_notifier.notify = _orig_notify
check("汇总函数返回 True", ok, True)
check("事件名", notes[0][0] if notes else "", "account.status.summary")
kw = notes[0][1] if notes else {}
check("总数等于账号库", kw.get("total"), len(af.roster_rows()))
check("有异常账号", (kw.get("abnormal") or 0) >= 1, True)
check("有正常账号", (kw.get("normal") or 0) >= 1, True)
check("异常清单包含具体账号",
any("周周苏州吃喝玩乐" in x for x in (kw.get("abnormal_accounts") or [])), True)
print()
if fails:
print("❌ 失败 %d 项:%s" % (len(fails), "、".join(fails)))