From 60e5ff404eb78e158c9d64fba4aaa66dbe6055ca Mon Sep 17 00:00:00 2001
From: yeuimu <2197651308@qq.com>
Date: Fri, 28 Aug 2026 02:02:18 +0000
Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8E=BB=E6=8E=89=20aibot=20=E4=B8=8D?=
=?UTF-8?q?=E6=94=AF=E6=8C=81=E7=9A=84=20font=20=E6=A0=87=E7=AD=BE,?=
=?UTF-8?q?=E6=94=B9=E5=8A=A0=E7=B2=97+emoji;=E8=A1=A5=E6=8B=89=E9=87=8F?=
=?UTF-8?q?=E5=90=88=E8=AE=A1=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=B8=AD=E6=96=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
flows/monitor/alert_failure.py | 2 +-
flows/monitor/daily_report.py | 29 +++++++++++++++++++++--------
flows/monitor/device_check.py | 9 ++++-----
scripts/wecom_capture_chatid.py | 2 +-
4 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/flows/monitor/alert_failure.py b/flows/monitor/alert_failure.py
index 0b3612d..870a08b 100644
--- a/flows/monitor/alert_failure.py
+++ b/flows/monitor/alert_failure.py
@@ -103,7 +103,7 @@ def wecom_alert_failure(event: dict | str | None = None) -> dict:
occurred = occurred or ended
lines = [
- f'🔴 **流程失败** {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}")
diff --git a/flows/monitor/daily_report.py b/flows/monitor/daily_report.py
index df4cfa1..f3bc9bd 100644
--- a/flows/monitor/daily_report.py
+++ b/flows/monitor/daily_report.py
@@ -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'**{n_diff} 天有差异(已补拉)**')
+ 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'**{g["zeroGoodsOrders"]}**' 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 += ["", ('⚠️ **存在需关注项,见上**' if attention
- else '✅ **数据全部一致,无异常**')]
+ lines += ["", ("⚠️ **存在需关注项,见上**" if attention else "✅ **数据全部一致,无异常**")]
return "\n".join(lines), attention
diff --git a/flows/monitor/device_check.py b/flows/monitor/device_check.py
index e81e0a7..f4afd21 100644
--- a/flows/monitor/device_check.py
+++ b/flows/monitor/device_check.py
@@ -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'**{pct:.0f}%**'
+ 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" · 异常 **{len(issues)}**"
+ 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 += ["", ('🔴 **有项目需要处理,见上**' if alarms
- else '✅ **一切正常**')]
+ lines += ["", ("🔴 **有项目需要处理,见上**" if alarms else "✅ **一切正常**")]
content = "\n".join(lines)
sent = send_markdown(content)
diff --git a/scripts/wecom_capture_chatid.py b/scripts/wecom_capture_chatid.py
index bbbbca3..65a508d 100644
--- a/scripts/wecom_capture_chatid.py
+++ b/scripts/wecom_capture_chatid.py
@@ -63,7 +63,7 @@ def do_save_chatid(chatid: str) -> None:
def do_test(message: str) -> None:
from flows.shared.wecom import send_markdown
- ok = send_markdown(f'✅ **机器人通知链路正常**\n\n> {message}')
+ ok = send_markdown(f"✅ **机器人通知链路正常**\n\n> {message}")
sys.exit(0 if ok else 1)