浏览代码

Updated schema to match new core field

master
Lorenzo Pollutri 17 小时前
父节点
当前提交
95f102987e
共有 2 个文件被更改,包括 46 次插入1 次删除
  1. +44
    -1
      routes/reslevis.py
  2. +2
    -0
      schemas/reslevis.py

+ 44
- 1
routes/reslevis.py 查看文件

@@ -3,6 +3,7 @@ import json
import os import os
import tempfile import tempfile
from urllib.parse import urlencode from urllib.parse import urlencode
from uuid import UUID


from fastapi import APIRouter, Depends, File, Form, HTTPException, Query, Request, UploadFile from fastapi import APIRouter, Depends, File, Form, HTTPException, Query, Request, UploadFile
import httpx import httpx
@@ -176,6 +177,48 @@ def _uid_from_claims(claims: dict) -> str:
return str(uid) 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: def _floor_maps_index_path() -> str:
return os.path.join(config_env.RESLEVIS_MAPS_DIR, "maps.json") return os.path.join(config_env.RESLEVIS_MAPS_DIR, "maps.json")


@@ -626,7 +669,7 @@ async def getAlarms():
if not isinstance(payload, list): if not isinstance(payload, list):
raise HTTPException(status_code=502, detail="Unexpected CORE response type") 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( @router.put(


+ 2
- 0
schemas/reslevis.py 查看文件

@@ -176,6 +176,8 @@ class AlarmCoreItem(BaseModel):
status: str status: str
timestamp: str timestamp: str
operator: Optional[UUID] = None operator: Optional[UUID] = None
operatorName: Optional[str] = None
assignment_timestamp: Optional[str] = None
resolution_timestamp: Optional[str] = None resolution_timestamp: Optional[str] = None






正在加载...
取消
保存