|
@@ -1,3 +1,4 @@
|
|
|
|
|
+import json
|
|
|
import re
|
|
import re
|
|
|
|
|
|
|
|
from sqlalchemy import text
|
|
from sqlalchemy import text
|
|
@@ -23,6 +24,35 @@ def _normalize_date(date_value: str | None) -> str | None:
|
|
|
MAX_EXPORT_ROWS = 50_000
|
|
MAX_EXPORT_ROWS = 50_000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _reason_from_ext_info(value: object) -> str | None:
|
|
|
|
|
+ """从 ext_info JSON 中解析 method 字段作为原因。"""
|
|
|
|
|
+ if value is None:
|
|
|
|
|
+ return None
|
|
|
|
|
+ if isinstance(value, dict):
|
|
|
|
|
+ parsed: object = value
|
|
|
|
|
+ else:
|
|
|
|
|
+ raw = str(value).strip()
|
|
|
|
|
+ if not raw:
|
|
|
|
|
+ return None
|
|
|
|
|
+ try:
|
|
|
|
|
+ parsed = json.loads(raw)
|
|
|
|
|
+ except json.JSONDecodeError:
|
|
|
|
|
+ return None
|
|
|
|
|
+ if not isinstance(parsed, dict):
|
|
|
|
|
+ return None
|
|
|
|
|
+ method = parsed.get("method")
|
|
|
|
|
+ if method is None:
|
|
|
|
|
+ return None
|
|
|
|
|
+ text_value = str(method).strip()
|
|
|
|
|
+ return text_value or None
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _enrich_demand_pool_item(row: dict[str, object]) -> dict[str, object]:
|
|
|
|
|
+ item = dict(row)
|
|
|
|
|
+ item["reason"] = _reason_from_ext_info(item.get("ext_info"))
|
|
|
|
|
+ return item
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _build_demand_pool_filters(
|
|
def _build_demand_pool_filters(
|
|
|
strategies: list[str] | None = None,
|
|
strategies: list[str] | None = None,
|
|
|
start_dt: str | None = None,
|
|
start_dt: str | None = None,
|
|
@@ -149,7 +179,7 @@ def query_demand_pool_records(
|
|
|
"total": total,
|
|
"total": total,
|
|
|
"page": page,
|
|
"page": page,
|
|
|
"page_size": page_size,
|
|
"page_size": page_size,
|
|
|
- "items": [dict(row) for row in rows],
|
|
|
|
|
|
|
+ "items": [_enrich_demand_pool_item(dict(row)) for row in rows],
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -188,6 +218,7 @@ def export_demand_pool_records(
|
|
|
weight,
|
|
weight,
|
|
|
`type`,
|
|
`type`,
|
|
|
video_count,
|
|
video_count,
|
|
|
|
|
+ ext_info,
|
|
|
dt
|
|
dt
|
|
|
FROM {table_name}
|
|
FROM {table_name}
|
|
|
{where_sql}
|
|
{where_sql}
|
|
@@ -199,7 +230,7 @@ def export_demand_pool_records(
|
|
|
with SessionLocal() as session:
|
|
with SessionLocal() as session:
|
|
|
rows = session.execute(query_sql, export_params).mappings().all()
|
|
rows = session.execute(query_sql, export_params).mappings().all()
|
|
|
|
|
|
|
|
- return [dict(row) for row in rows]
|
|
|
|
|
|
|
+ return [_enrich_demand_pool_item(dict(row)) for row in rows]
|
|
|
|
|
|
|
|
|
|
|
|
|
def query_strategy_options(
|
|
def query_strategy_options(
|