|
|
|
@@ -3,6 +3,7 @@ import json |
|
|
|
import os |
|
|
|
import tempfile |
|
|
|
from urllib.parse import urlencode |
|
|
|
from uuid import UUID |
|
|
|
|
|
|
|
from fastapi import APIRouter, Depends, File, Form, HTTPException, Query, Request, UploadFile |
|
|
|
import httpx |
|
|
|
@@ -176,6 +177,48 @@ def _uid_from_claims(claims: dict) -> str: |
|
|
|
return str(uid) |
|
|
|
|
|
|
|
|
|
|
|
def _uuid_or_none(value): |
|
|
|
if value in ("", None, 0, "0"): |
|
|
|
return None |
|
|
|
try: |
|
|
|
return str(UUID(str(value))) |
|
|
|
except (TypeError, ValueError, AttributeError): |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
def _operator_uuid_by_name(value): |
|
|
|
name = str(value).strip() |
|
|
|
if not name: |
|
|
|
return None |
|
|
|
|
|
|
|
try: |
|
|
|
rows = operator_repo.list() |
|
|
|
except Exception: |
|
|
|
return None |
|
|
|
|
|
|
|
target = name.lower() |
|
|
|
for row in rows: |
|
|
|
if not isinstance(row, dict): |
|
|
|
continue |
|
|
|
if str(row.get("name") or "").strip().lower() == target: |
|
|
|
return _uuid_or_none(row.get("id")) |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
def _normalize_alarm_core(row: dict) -> dict: |
|
|
|
row = dict(row) |
|
|
|
operator_raw = row.get("operator") |
|
|
|
operator_uuid = _uuid_or_none(operator_raw) |
|
|
|
|
|
|
|
if operator_uuid is None and operator_raw not in ("", None, 0, "0"): |
|
|
|
operator_uuid = _operator_uuid_by_name(operator_raw) |
|
|
|
if operator_uuid is None and not row.get("operatorName"): |
|
|
|
row["operatorName"] = str(operator_raw) |
|
|
|
|
|
|
|
row["operator"] = operator_uuid |
|
|
|
return row |
|
|
|
|
|
|
|
|
|
|
|
def _floor_maps_index_path() -> str: |
|
|
|
return os.path.join(config_env.RESLEVIS_MAPS_DIR, "maps.json") |
|
|
|
|
|
|
|
@@ -626,7 +669,7 @@ async def getAlarms(): |
|
|
|
if not isinstance(payload, list): |
|
|
|
raise HTTPException(status_code=502, detail="Unexpected CORE response type") |
|
|
|
|
|
|
|
return payload |
|
|
|
return [_normalize_alarm_core(row) for row in payload if isinstance(row, dict)] |
|
|
|
|
|
|
|
|
|
|
|
@router.put( |
|
|
|
|