Commit 3d2c5503 by sunqi02

fix: 更新企业微信群机器人 webhook URL 配置

1 parent d457ba85
......@@ -15,7 +15,7 @@ COURSE_BASE_URL=http://lessonjump.test.glsx.com.cn/
QUERY_URL=http://192.168.1.71:8104/wiki/query/json
# 企业微信群机器人 webhook(周报推送)
WECOM_WEBHOOK_URL=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=your_webhook_key_here
WECOM_WEBHOOK_URL=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=6a4a519c-db14-41c9-8ef7-8ab780c4ec0b
# 数据库
DB_HOST=192.168.3.92
......
from __future__ import annotations
import logging
from datetime import timedelta
from typing import Optional
from sqlalchemy import func, text
......@@ -86,7 +87,8 @@ class CustomerInfoService:
"""获取需要推送的记录。
mode='sync': 同步触发推送, 仅 last_pushed_at IS NULL 的新记录。
mode='daily': 每日推送, 包含从未推送或上次推送日期非今日的记录。
mode='daily': 每日推送, 仅推送创建时间在近 3 天内的记录(t, t+1, t+2),
且从未推送或上次推送日期非今日。
"""
now = china_now()
today = now.date()
......@@ -99,9 +101,13 @@ class CustomerInfoService:
if mode == "sync":
candidates = base_query.filter(CustomerGroupPhone.last_pushed_at.is_(None)).all()
elif mode == "daily":
window_start = today - timedelta(days=2)
candidates = base_query.filter(
(CustomerGroupPhone.last_pushed_at.is_(None))
| (func.date(CustomerGroupPhone.last_pushed_at) < today)
(
(CustomerGroupPhone.last_pushed_at.is_(None))
| (func.date(CustomerGroupPhone.last_pushed_at) < today)
),
func.date(CustomerGroupPhone.create_time).between(window_start, today),
).all()
else:
raise ValueError(f"Unknown push mode: {mode}")
......
......@@ -15,7 +15,7 @@ logger = logging.getLogger(__name__)
WECOM_WEBHOOK_URL = os.getenv(
"WECOM_WEBHOOK_URL",
"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=6a4a519c-db14-41c9-8ef7-8ab780c4ec0b",
"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=c1357c4b-c802-4b93-93d9-e871301a4015",
)
......@@ -33,25 +33,29 @@ class WeeklyReportService:
new_groups: 过去7天新增的群数
bound_groups: 已绑定手机号的群数
pass_rate: 认证通过率(已绑定 / 总群数 * 100)
overdue_unbound_groups: 创建超过3天仍未绑定手机号的群数
"""
now = china_now()
seven_days_ago = now - timedelta(days=7)
three_days_ago = now - timedelta(days=3)
row = self.db.execute(
text("""
SELECT
COUNT(*) AS total_groups,
SUM(CASE WHEN create_time >= :seven_days_ago THEN 1 ELSE 0 END) AS new_groups,
SUM(CASE WHEN phone IS NOT NULL THEN 1 ELSE 0 END) AS bound_groups
SUM(CASE WHEN phone IS NOT NULL THEN 1 ELSE 0 END) AS bound_groups,
SUM(CASE WHEN phone IS NULL AND create_time < :three_days_ago THEN 1 ELSE 0 END) AS overdue_unbound_groups
FROM customer_group_phones
WHERE group_status != 'deleted'
"""),
{"seven_days_ago": seven_days_ago},
{"seven_days_ago": seven_days_ago, "three_days_ago": three_days_ago},
).fetchone()
total_groups = int(row.total_groups or 0)
new_groups = int(row.new_groups or 0)
bound_groups = int(row.bound_groups or 0)
overdue_unbound_groups = int(row.overdue_unbound_groups or 0)
pass_rate = (bound_groups / total_groups * 100) if total_groups > 0 else 0.0
return {
......@@ -59,6 +63,7 @@ class WeeklyReportService:
"new_groups": new_groups,
"bound_groups": bound_groups,
"pass_rate": round(pass_rate, 2),
"overdue_unbound_groups": overdue_unbound_groups,
}
def build_markdown_content(self, stats: Dict[str, int | float]) -> str:
......@@ -71,6 +76,7 @@ class WeeklyReportService:
f"**绑定手机号的群数:** {stats['bound_groups']} 个\n"
f"**认证通过率:** {stats['pass_rate']}%\n"
f"**当前总群数:** {stats['total_groups']} 个\n"
f"**超过3天未认证群数:** {stats['overdue_unbound_groups']} 个\n"
)
def send_report(self, content: str) -> Dict[str, Any]:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!