feat: 四份报告按用户口径重做
- 核验日报: 先报订单数量(远程vs本地, verify 修复后重数 verifyReport.post)/商品行数一致性, 再报状态不符单数; SDS 统计口径排除'售后'与本地对称 - OCR: Orders 加 ocrProcessedAt 列(写入自动盖时间戳), 日报报'今日处理 X · 识别失败 Y'(db.count_ocr_today) - 失败任务: check_prefect_failures 补 workflow 名, 日报/设备报列 run 名+状态+时间 - 设备日报: 新增 metrics-agent 侧车(每5分钟采样内存/swap/GPU+每日 du 快照), 报告改 平均/峰值/最低 + 总体/根目录/home 余量 + 增长最快目录 + GPU 温度; 采样缺失降级瞬时值 - Dockerfile 加 tzdata(TZ=Asia/Shanghai); du 用实际占块且容错 rc=1
This commit is contained in:
+35
-2
@@ -48,6 +48,14 @@ def _diff(remote_stats: list, local: dict[str, int]) -> tuple[dict[str, int], bo
|
||||
return diff, has_diff
|
||||
|
||||
|
||||
def _remote_map(remote_stats: list) -> dict[str, int]:
|
||||
"""远程状态→数量映射(排除"售后"和无名状态,与本地口径对称)。"""
|
||||
out = {getattr(s, "name", None): (getattr(s, "orderNum", 0) or 0) for s in remote_stats}
|
||||
out.pop("售后", None)
|
||||
out.pop(None, None)
|
||||
return out
|
||||
|
||||
|
||||
@flow(name="sds-verify", log_prints=True)
|
||||
def sds_verify(mode: str = "recent", recent_days: int = 1, date_range: str | None = None) -> dict:
|
||||
days = _parse_days(mode, recent_days, date_range)
|
||||
@@ -68,7 +76,8 @@ def sds_verify(mode: str = "recent", recent_days: int = 1, date_range: str | Non
|
||||
remote_stats = client.get_status(
|
||||
OrderQueryParams(pay_date_begin=format_date(day_start), pay_date_end=format_date(day_end))
|
||||
)
|
||||
remote_total = sum(getattr(s, "orderNum", 0) or 0 for s in remote_stats)
|
||||
remote_map = _remote_map(remote_stats)
|
||||
remote_total = sum(remote_map.values())
|
||||
local_counts = db.get_order_count_by_status("SDS", day_start, day_end)
|
||||
diff, has_diff = _diff(remote_stats, local_counts)
|
||||
|
||||
@@ -91,13 +100,37 @@ def sds_verify(mode: str = "recent", recent_days: int = 1, date_range: str | Non
|
||||
totals["goodsUpdated"] += stats["goodsUpdated"]
|
||||
day_reports.append({"date": day_str, "remote": remote_total, "local": sum(local_counts.values()), "diff": diff, "ok": False,
|
||||
"orders": stats["orderCount"], "goods": stats["goodsCount"]})
|
||||
|
||||
# 修复后重数:数量接口 + 本地 SQL 很便宜,给出修复后的数量一致性结论(口径与 _diff 相同,排除"售后")
|
||||
post = None
|
||||
if days_with_diff:
|
||||
post_days, post_diff_days = [], 0
|
||||
for day in days:
|
||||
day_start, day_end = start_of_day(day), start_of_day(day) + timedelta(days=1)
|
||||
remote_stats = client.get_status(
|
||||
OrderQueryParams(pay_date_begin=format_date(day_start), pay_date_end=format_date(day_end))
|
||||
)
|
||||
remote_map = _remote_map(remote_stats)
|
||||
local_counts = db.get_order_count_by_status("SDS", day_start, day_end)
|
||||
statuses = set(remote_map) | set(local_counts)
|
||||
statuses.discard("售后")
|
||||
has_diff = any(remote_map.get(st, 0) != local_counts.get(st, 0) for st in statuses)
|
||||
post_diff_days += int(has_diff)
|
||||
post_days.append({"date": format_date(day).split(" ")[0],
|
||||
"remote": sum(remote_map.values()),
|
||||
"local": sum(v for k, v in local_counts.items() if k != "售后"),
|
||||
"ok": not has_diff})
|
||||
post = {"days": post_days, "daysWithDiff": post_diff_days,
|
||||
"remote": sum(d["remote"] for d in post_days), "local": sum(d["local"] for d in post_days)}
|
||||
print(f"[核验重数] 修复后 远程 {post['remote']} 本地 {post['local']} / 有差异 {post_diff_days} 天")
|
||||
finally:
|
||||
client.close()
|
||||
|
||||
print(f"[核验汇总] 共 {len(days)} 天 / 有差异 {days_with_diff} 天 / {totals}")
|
||||
emit_verify_report("SDS 数据核验", day_reports, totals, len(days), days_with_diff)
|
||||
return {
|
||||
"verifyReport": {"days": day_reports, "summary": {"totalDays": len(days), "daysWithDiff": days_with_diff, **totals}},
|
||||
"verifyReport": {"days": day_reports, "post": post,
|
||||
"summary": {"totalDays": len(days), "daysWithDiff": days_with_diff, **totals}},
|
||||
"syncRange": {"from": format_date(start_of_day(days[0])) if days else "", "to": format_date(start_of_day(days[-1])) if days else ""},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user