feat: 详细日志(分页/映射/批次进度)+ Artifacts 摘要(sync-summary/verify-report)

This commit is contained in:
yeuimu
2026-07-23 09:01:39 +00:00
parent 367168bcdc
commit 4ec7cf2dd6
18 changed files with 154 additions and 22 deletions
+1
View File
@@ -51,6 +51,7 @@ def sync_sds_records(
order_inputs, goods_inputs, skipped = map_sds_records(
raw_orders, channel_map, channel_refresh, skip_unpaid
)
print(f"[SDS] 映射完成: 订单 {len(order_inputs)} / 商品 {len(goods_inputs)} / 跳过待付款 {skipped} (共 {len(raw_orders)})")
stats = db.sync_orders_and_goods(order_inputs, goods_inputs)
stats["orderCount"] = len(order_inputs)
stats["goodsCount"] = len(goods_inputs)
+3 -2
View File
@@ -11,8 +11,8 @@ from prefect import flow, task
from flows.sds._pipeline import sync_sds_records
from flows.shared import (
SyncDB, create_sds_client, fetch_sds_all_pages, floor_to_hour, format_date,
get_channel_type_map, refresh_channel_type_map,
SyncDB, build_stats_rows, create_sds_client, emit_sync_summary, fetch_sds_all_pages,
floor_to_hour, format_date, get_channel_type_map, refresh_channel_type_map,
)
@@ -52,6 +52,7 @@ def sds_incremental_sync() -> dict:
raw = extract_orders(params)
stats = upsert_records(raw)
print(f"完成: 订单 {stats['orderCount']} / 商品 {stats['goodsCount']}")
emit_sync_summary("SDS 增量同步", build_stats_rows("SDS", stats, [("时间范围", f"{params['pay_date_begin']} ~ {params['pay_date_end']}")]))
return {"syncRange": {"from": params["pay_date_begin"], "to": params["pay_date_end"]}, **stats}
+3 -1
View File
@@ -11,7 +11,8 @@ from prefect import flow, task
from flows.sds._pipeline import sync_sds_records
from flows.shared import (
SyncDB, create_sds_client, fetch_sds_all_pages, get_channel_type_map, refresh_channel_type_map,
SyncDB, build_stats_rows, create_sds_client, emit_sync_summary,
fetch_sds_all_pages, get_channel_type_map, refresh_channel_type_map,
)
@@ -69,6 +70,7 @@ def sds_order_sync(
raw = extract_orders(params)
stats = upsert_records(raw)
print(f"完成: 订单 {stats['orderCount']} / 商品 {stats['goodsCount']} / 跳过待付款 {stats.get('skippedUnpaid',0)}")
emit_sync_summary("SDS 订单同步", build_stats_rows("SDS", stats, [("时间范围", f"{pay_date_begin} ~ {pay_date_end}")]))
return {"syncRange": {"from": pay_date_begin, "to": pay_date_end}, **stats}
+3 -2
View File
@@ -11,8 +11,8 @@ from prefect import flow, task
from flows.sds._pipeline import sync_sds_records
from flows.shared import (
SyncDB, create_sds_client, fetch_sds_all_pages, format_date, get_channel_type_map,
refresh_channel_type_map, start_of_day,
SyncDB, build_stats_rows, create_sds_client, emit_sync_summary, fetch_sds_all_pages,
format_date, get_channel_type_map, refresh_channel_type_map, start_of_day,
)
@@ -48,6 +48,7 @@ def sds_recent_sync(recent_days: int = 7) -> dict:
raw = extract_orders(params)
stats = upsert_records(raw)
print(f"完成: 订单 {stats['orderCount']} / 商品 {stats['goodsCount']}")
emit_sync_summary("SDS 近期同步", build_stats_rows("SDS", stats, [("近N天", days), ("时间范围", f"{params['created_date_begin']} ~ {params['created_date_end']}")]))
return {"syncRange": {"from": params["created_date_begin"], "to": format_date(now)},
"recentDays": days, **stats}
+3 -2
View File
@@ -9,8 +9,8 @@ from prefect import flow, task
from api.sds.models import OrderPageRequest
from flows.shared import (
SyncDB, create_sds_client, get_channel_type_map,
refresh_channel_type_map, resolve_courier_source,
SyncDB, build_stats_rows, create_sds_client, emit_sync_summary,
get_channel_type_map, refresh_channel_type_map, resolve_courier_source,
)
from flows.shared.mappers import map_sds_goods, map_sds_order
@@ -99,6 +99,7 @@ def sds_refresh_100_prefix() -> dict:
remote = fetch_remote(order_nos)
stats = upsert_records(remote, order_nos)
print(f"完成: 刷新 {stats['orderCount']} / 仍待分配 {stats.get('skippedStillPending',0)} / 待付款 {stats.get('skippedUnpaid',0)}")
emit_sync_summary("SDS 100前缀刷新", build_stats_rows("SDS", stats, [("目标订单", len(order_nos))]))
return {"targetCount": len(order_nos), **stats}
+3 -1
View File
@@ -10,7 +10,8 @@ from prefect import flow, task
from api.sds.models import OrderPageRequest
from flows.sds._pipeline import sync_sds_records
from flows.shared import (
SyncDB, create_sds_client, get_channel_type_map, refresh_channel_type_map,
SyncDB, build_stats_rows, create_sds_client, emit_sync_summary,
get_channel_type_map, refresh_channel_type_map,
)
SDS_FINISHED_STATUSES = ["已完成", "已取消"]
@@ -54,6 +55,7 @@ def sds_refresh_pending() -> dict:
raw = fetch_pending(order_nos)
stats = upsert_records(raw)
print(f"完成: 匹配 {len(raw)} | {stats}")
emit_sync_summary("SDS 刷新未完结", build_stats_rows("SDS", stats, [("未完结订单", len(order_nos)), ("匹配", len(raw))]))
return {"pendingCount": len(order_nos), "matchedCount": len(raw), **stats}
+6 -4
View File
@@ -12,8 +12,8 @@ from prefect import flow, task
from api.sds.models import OrderQueryParams
from flows.sds._pipeline import sync_sds_records
from flows.shared import (
SyncDB, create_sds_client, fetch_sds_all_pages, format_date, get_channel_type_map,
refresh_channel_type_map, start_of_day,
SyncDB, create_sds_client, emit_verify_report, fetch_sds_all_pages, format_date,
get_channel_type_map, refresh_channel_type_map, start_of_day,
)
@@ -75,7 +75,7 @@ def sds_verify(mode: str = "recent", recent_days: int = 1, date_range: str | Non
print(f"[核验 {day_str}] 远程 {remote_total} 本地 {sum(local_counts.values())}"
+ (f" 差异 {diff}" if has_diff else " 一致,跳过"))
if not has_diff:
day_reports.append({"date": day_str, "diff": diff, "ok": True})
day_reports.append({"date": day_str, "remote": remote_total, "local": sum(local_counts.values()), "diff": diff, "ok": True})
continue
days_with_diff += 1
@@ -89,11 +89,13 @@ def sds_verify(mode: str = "recent", recent_days: int = 1, date_range: str | Non
totals["ordersUpdated"] += stats["ordersUpdated"]
totals["goodsAdded"] += stats["goodsCreated"]
totals["goodsUpdated"] += stats["goodsUpdated"]
day_reports.append({"date": day_str, "diff": diff, "ok": False,
day_reports.append({"date": day_str, "remote": remote_total, "local": sum(local_counts.values()), "diff": diff, "ok": False,
"orders": stats["orderCount"], "goods": stats["goodsCount"]})
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}},
"syncRange": {"from": format_date(start_of_day(days[0])) if days else "", "to": format_date(start_of_day(days[-1])) if days else ""},