添加 羽心堂只筛选指定仓库

This commit is contained in:
2026-04-23 16:40:45 +08:00
parent 110b8a960c
commit 3e1d479643
5 changed files with 103 additions and 42 deletions
+18 -14
View File
@@ -58,8 +58,8 @@ def sync_brand_target(
access_token: str,
app_token: str,
tables: list[dict[str, Any]],
postgres_rows: list[dict[str, Any]],
target: BrandSyncTarget,
postgres_rows: list[dict[str, Any]] | None = None,
) -> dict[str, Any]:
target_table = next(
(table for table in tables if table.get("name") == target.table_name),
@@ -71,7 +71,7 @@ def sync_brand_target(
if not table_id:
raise FeishuApiError(f"目标飞书表缺少 table_id: {target.table_name}")
filtered_rows = [row for row in (postgres_rows or []) if row.get("品牌名称") == target.brand_name]
target_rows = postgres_rows or []
available_fields = client.ensure_target_fields(access_token, app_token, table_id)
existing_records = client.list_records(access_token, app_token, table_id)
existing_record_ids = [record.get("record_id") for record in existing_records if record.get("record_id")]
@@ -80,38 +80,42 @@ def sync_brand_target(
access_token,
app_token,
table_id,
[build_feishu_record(row) for row in filtered_rows],
) if filtered_rows else 0
[build_feishu_record(row) for row in target_rows],
) if target_rows else 0
return {
"brand_name": target.brand_name,
"warehouse_keys": target.warehouse_keys,
"target_table_name": target.table_name,
"target_table_id": table_id,
"available_fields": available_fields,
"source_row_count": len(postgres_rows or []),
"filtered_row_count": len(filtered_rows),
"source_row_count": len(target_rows),
"filtered_row_count": len(target_rows),
"deleted_record_count": deleted_count,
"created_record_count": created_count,
}
def run_sync_brand(config: AppConfig, client: FeishuClient, postgres_result: dict[str, Any] | None = None) -> dict[str, Any]:
postgres_payload = postgres_result or query_postgres(config)
postgres_rows = postgres_payload["rows"]
access_token = client.get_tenant_access_token()
base_info = client.parse_base_info(client.build_base_url(), access_token)
app_token = base_info["app_token"] or ""
client.enable_advanced_permission(access_token, app_token)
tables = client.list_tables(access_token, app_token)
results = [
sync_brand_target(client, access_token, app_token, tables, postgres_rows, target)
for target in BRAND_SYNC_TARGETS
]
results = []
source_row_count = 0
for index, target in enumerate(BRAND_SYNC_TARGETS):
if postgres_result is not None and index == 0:
postgres_payload = postgres_result
else:
postgres_payload = query_postgres(config, target=target)
postgres_rows = postgres_payload["rows"]
source_row_count += len(postgres_rows or [])
results.append(sync_brand_target(client, access_token, app_token, tables, target, postgres_rows))
return {
"target_count": len(BRAND_SYNC_TARGETS),
"source_row_count": len(postgres_rows or []),
"source_row_count": source_row_count,
"targets": results,
}