fix: 去掉 aibot 不支持的 font 标签,改加粗+emoji;补拉量合计格式化中文

This commit is contained in:
yeuimu
2026-08-28 02:02:18 +00:00
parent 14321faa91
commit 60e5ff404e
4 changed files with 27 additions and 15 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ def wecom_alert_failure(event: dict | str | None = None) -> dict:
occurred = occurred or ended
lines = [
f'🔴 <font color="warning">**流程失败**</font> {flow_name or resource_name or "未知"}',
f"🔴 **流程失败** {flow_name or resource_name or '未知'}",
]
if run_name and run_name != flow_name:
lines.append(f"> Run:{run_name}")
+21 -8
View File
@@ -25,6 +25,22 @@ def _fmt_diff(diff: dict) -> str:
return " ".join(f"{k}{v:+d}" for k, v in (diff or {}).items()) or "—"
_TOTALS_LABELS = {
"ordersAdded": "订单新增", "ordersUpdated": "订单更新", "ordersRemoved": "订单移除",
"goodsAdded": "商品新增", "goodsUpdated": "商品更新", "goodsRemoved": "商品移除",
}
def _fmt_totals(summary: dict) -> str:
parts = [f"{_TOTALS_LABELS.get(k, k)} {v:,}" for k, v in summary.items()
if k not in ("totalDays", "daysWithDiff") and v]
return " · ".join(parts)
def _short_date(date_str: str) -> str:
return date_str[5:] if len(date_str) == 10 and date_str[:4].isdigit() else date_str
def build_daily_message(
days: int, window: str, riin: dict, sds: dict,
goods: dict, ocr: dict, failures: list[dict],
@@ -41,14 +57,12 @@ def build_daily_message(
diff_days = [d for d in days_r if not d.get("ok")]
total, n_diff = summary.get("totalDays", len(days_r)), summary.get("daysWithDiff", len(diff_days))
if diff_days:
lines.append(f"**{name}** {total - n_diff}/{total} 天一致,"
f'<font color="warning">**{n_diff} 天有差异(已补拉)**</font>')
lines.append(f"**{name}** {total - n_diff}/{total} 天一致,**{n_diff} 天有差异(已补拉)**⚠️")
for d in diff_days[:8]:
lines.append(f"> {d['date']} {_fmt_diff(d.get('diff'))}(补拉 {d.get('orders', 0)} 单)")
lines.append(f"> {_short_date(d['date'])} {_fmt_diff(d.get('diff'))}(补拉 {d.get('orders', 0):,} 单)")
if len(diff_days) > 8:
lines.append(f"> …共 {len(diff_days)} 天")
totals = {k: v for k, v in summary.items()
if k not in ("totalDays", "daysWithDiff") and v}
totals = _fmt_totals(summary)
if totals:
lines.append(f"> 补拉量合计 {totals}")
lines.append("> 注:同一差异长期存在多为统计口径/状态映射问题(如发货后退款未同步)")
@@ -63,7 +77,7 @@ def build_daily_message(
lines.append("**商品完整性**")
for sys in ("RIIN", "SDS"):
g = goods[sys]
zero = f'<font color="warning">**{g["zeroGoodsOrders"]}**</font>' if g["zeroGoodsOrders"] else "0"
zero = f"**{g['zeroGoodsOrders']}**⚠️" if g["zeroGoodsOrders"] else "0"
lines.append(f"> {sys} 订单 {g['orders']:,} · 商品 {g['goods']:,} · 零商品订单 {zero} · 无名称 {g['goodsNoName']:,}")
attention = attention or g["zeroGoodsOrders"] > 0
lines.append(f"> 全库孤儿商品 {goods['RIIN']['orphanGoods']:,}")
@@ -77,8 +91,7 @@ def build_daily_message(
if failures:
attention = True
lines += ["", ('<font color="warning">⚠️ **存在需关注项,见上**</font>' if attention
else '<font color="info">✅ **数据全部一致,无异常**</font>')]
lines += ["", ("⚠️ **存在需关注项,见上**" if attention else "✅ **数据全部一致,无异常**")]
return "\n".join(lines), attention
+4 -5
View File
@@ -168,11 +168,11 @@ def _check_services() -> dict:
def _mark(pct: float | None, threshold: int) -> str:
"""百分比展示:WeCom markdown 不支持表格,超阈值用红色字体高亮。"""
"""百分比展示:超阈值加粗+🔴(WeCom aibot markdown 不支持 font 标签和表格)。"""
if pct is None:
return "—"
if pct >= threshold:
return f'<font color="warning">**{pct:.0f}%**</font>'
return f"**{pct:.0f}%**🔴"
return f"{pct:.0f}%"
@@ -227,7 +227,7 @@ def device_check(alarm_threshold: int = 80) -> dict:
if docker.get("stopped"):
docker_line += f" · 已停用 {docker['stopped']}"
if issues:
docker_line += f" · 异常 <font color=\"warning\">**{len(issues)}**</font>"
docker_line += f" · 异常 **{len(issues)}**🔴"
else:
docker_line += " · 异常 0"
lines.append(docker_line)
@@ -249,8 +249,7 @@ def device_check(alarm_threshold: int = 80) -> dict:
or (isinstance(gpus, list) and any(g["utilPct"] >= threshold or g["memPct"] >= threshold for g in gpus))
or bool(issues) or bool(failures) or not svc.get("ocr") or not svc.get("pg")
)
lines += ["", ('<font color="warning">🔴 **有项目需要处理,见上**</font>' if alarms
else '<font color="info">✅ **一切正常**</font>')]
lines += ["", ("🔴 **有项目需要处理,见上**" if alarms else "✅ **一切正常**")]
content = "\n".join(lines)
sent = send_markdown(content)