Sfoglia il codice sorgente

增加新热事件原因

xueyiming 5 giorni fa
parent
commit
558aedab56
3 ha cambiato i file con 43 aggiunte e 3 eliminazioni
  1. 1 0
      app/api/routes.py
  2. 33 2
      app/services/demand_pool_service.py
  3. 9 1
      frontend/src/App.tsx

+ 1 - 0
app/api/routes.py

@@ -49,6 +49,7 @@ DEMAND_POOL_EXPORT_COLUMNS: list[tuple[str, str]] = [
     ("权重", "weight"),
     ("视频数量", "video_count"),
     ("日期", "dt"),
+    ("原因", "reason"),
 ]
 
 ELEMENT_DEMAND_EXPORT_COLUMNS: list[tuple[str, str]] = [

+ 33 - 2
app/services/demand_pool_service.py

@@ -1,3 +1,4 @@
+import json
 import re
 
 from sqlalchemy import text
@@ -23,6 +24,35 @@ def _normalize_date(date_value: str | None) -> str | None:
 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(
     strategies: list[str] | None = None,
     start_dt: str | None = None,
@@ -149,7 +179,7 @@ def query_demand_pool_records(
         "total": total,
         "page": page,
         "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,
             `type`,
             video_count,
+            ext_info,
             dt
         FROM {table_name}
         {where_sql}
@@ -199,7 +230,7 @@ def export_demand_pool_records(
     with SessionLocal() as session:
         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(

+ 9 - 1
frontend/src/App.tsx

@@ -34,6 +34,7 @@ type DemandPoolItem = {
   weight: number | null;
   video_count: number | null;
   dt: string | null;
+  reason: string | null;
 };
 
 type QueryResponse = {
@@ -497,6 +498,13 @@ function DemandPoolPanel() {
         sorter: true,
         sortOrder: getSortOrderForColumn("dt"),
       },
+      {
+        title: "原因",
+        dataIndex: "reason",
+        width: 140,
+        ellipsis: true,
+        render: (v) => v ?? "",
+      },
       {
         title: "操作",
         key: "actions",
@@ -670,7 +678,7 @@ function DemandPoolPanel() {
               columns={columns}
               dataSource={data.items}
               pagination={false}
-              scroll={{ x: 1180 }}
+              scroll={{ x: 1320 }}
               rowClassName={(_, index) => (index % 2 === 0 ? "row-even" : "row-odd")}
               onChange={(_, __, sorter) => {
                 if (Array.isArray(sorter)) {