|
|
@@ -245,6 +245,43 @@ async def evaluate(inp: EvaluateInput):
|
|
|
}
|
|
|
|
|
|
|
|
|
+def _attach_names(rows: List[Dict[str, Any]]) -> None:
|
|
|
+ """补充风场名称、机组名称,取不到时前端回退编码。"""
|
|
|
+ if not rows:
|
|
|
+ return
|
|
|
+ wind_codes = sorted({r.get("wind_code") for r in rows if r.get("wind_code")})
|
|
|
+ turbine_codes = sorted({r.get("turbine_code") for r in rows if r.get("turbine_code")})
|
|
|
+ wind_names: Dict[str, str] = {}
|
|
|
+ turbine_names: Dict[str, str] = {}
|
|
|
+ try:
|
|
|
+ conn = platform_conn()
|
|
|
+ try:
|
|
|
+ with conn.cursor() as cur:
|
|
|
+ if wind_codes:
|
|
|
+ ph = ",".join(["%s"] * len(wind_codes))
|
|
|
+ cur.execute(
|
|
|
+ f"SELECT field_code, field_name FROM wind_field WHERE field_code IN ({ph})",
|
|
|
+ wind_codes,
|
|
|
+ )
|
|
|
+ for item in cur.fetchall():
|
|
|
+ wind_names[item["field_code"]] = item["field_name"]
|
|
|
+ if turbine_codes:
|
|
|
+ ph = ",".join(["%s"] * len(turbine_codes))
|
|
|
+ cur.execute(
|
|
|
+ f"SELECT engine_code, engine_name FROM wind_engine_group WHERE engine_code IN ({ph})",
|
|
|
+ turbine_codes,
|
|
|
+ )
|
|
|
+ for item in cur.fetchall():
|
|
|
+ turbine_names[item["engine_code"]] = item["engine_name"]
|
|
|
+ finally:
|
|
|
+ conn.close()
|
|
|
+ except Exception as exc:
|
|
|
+ logger.warning("补充风场/机组名称失败: %s", exc)
|
|
|
+ for row in rows:
|
|
|
+ row["wind_name"] = wind_names.get(row.get("wind_code")) or row.get("wind_code")
|
|
|
+ row["turbine_name"] = turbine_names.get(row.get("turbine_code")) or row.get("turbine_code")
|
|
|
+
|
|
|
+
|
|
|
@router.get("/list")
|
|
|
async def list_alarms(
|
|
|
windCode: Optional[str] = None,
|
|
|
@@ -279,6 +316,7 @@ async def list_alarms(
|
|
|
for key in ("data_time", "alarm_time", "ack_time", "clear_time"):
|
|
|
if row.get(key):
|
|
|
row[key] = row[key].strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ _attach_names(rows)
|
|
|
return {"code": 200, "datas": rows, "totalCount": len(rows)}
|
|
|
|
|
|
|