feat: Auto-Verify闭环 — verify API+定时验证+OKR联动+周报

This commit is contained in:
Hermes CI Fix
2026-08-10 23:15:19 +08:00
parent 7fed66d58c
commit e1ea5cd14d
9 changed files with 601 additions and 6 deletions
+52
View File
@@ -122,6 +122,58 @@ def send_mail(smtp_config: dict, to_addrs: list, title: str, content: str) -> di
# 主推送函数
# ============================================================
def send_wecom_message(content: str, title: str = "管理会计OS通知", alert_level: str = "green") -> dict:
"""发送企业微信消息到所有已启用的通知渠道(验证结果/行动报告推送用)
- 读取 notification_channels 表中启用的 wecom_app / wecom 渠道
- 无渠道时记日志并返回失败(不抛异常,保证主流程不中断)
"""
try:
from app.database import get_session_local
from app.models import NotificationChannel
except Exception as e:
logger.warning(f"send_wecom_message: 加载依赖失败: {e}")
return {"success": False, "message": f"依赖加载失败: {e}"}
db = get_session_local()()
try:
channels = db.query(NotificationChannel).filter(
NotificationChannel.enabled == True,
NotificationChannel.channel_type.in_(["wecom_app", "wecom"]),
).all()
if not channels:
logger.info(f"send_wecom_message: 无已启用的企微渠道,跳过推送: {title}")
return {"success": False, "message": "无已启用的企微通知渠道"}
results = []
for ch in channels:
config = ch.config or {}
if ch.channel_type == "wecom_app":
r = send_wecom_app(
corp_id=config.get("corp_id", ""),
corp_secret=config.get("corp_secret", ""),
agent_id=config.get("agent_id", ""),
touser=config.get("touser", "@all"),
title=title, content=content, alert_level=alert_level,
)
else:
r = send_wecom_robot(
webhook_url=config.get("webhook_url", ""),
title=title, content=content, alert_level=alert_level,
)
r["channel"] = ch.channel_type
results.append(r)
return {
"success": any(r.get("success") for r in results),
"results": results,
}
except Exception as e:
logger.error(f"send_wecom_message 异常: {e}")
return {"success": False, "message": f"推送异常: {e}"}
finally:
db.close()
def push_alert(alert: dict, channels: list[dict]) -> list[dict]:
"""向所有已启用渠道推送一条预警"""
results = []