| 12345678910111213141516171819202122232425262728293031323334 |
- """陕西局 JSON 适配入口;真实接口路径由同事提供,不猜测路径。"""
- import asyncio
- import config
- from algorithms.main_fan.models import Device, MonitorPoint, OperatingSeries, SwitchRecord, FanStateRecord
- def items_of(value):
- """显式支持 items 或 data.items/list;其他响应要求补充接口适配。"""
- if isinstance(value, dict) and "data" in value:
- value = value["data"]
- if isinstance(value, dict):
- value = value.get("items")
- if not isinstance(value, list):
- raise ValueError("业务接口未返回 items 数组,请按对方实际响应补充字段适配")
- return value
- async def fetch(gateway, agent_code, mine_code):
- paths = {kind: config.get_str(key) for kind, key in {
- "devices": "MAIN_FAN_DEVICES_PATH", "points": "MAIN_FAN_POINTS_PATH", "files": "MAIN_FAN_REPORTS_PATH",
- "operating_series":"MAIN_FAN_SERIES_PATH", "switch_records":"MAIN_FAN_SWITCHES_PATH",
- "fan_state_records":"MAIN_FAN_OPERATION_LOG_PATH"}.items()}
- selected = [(kind, path) for kind, path in paths.items() if path]
- if not selected:
- raise ValueError("尚未配置主通风机设备、测点或报告目录接口路径")
- values = await asyncio.gather(*(gateway.proxy(agent_code, path, params={"mineCode": mine_code}) for _, path in selected))
- result = {kind: [] for kind in paths}
- for (kind, _), value in zip(selected, values):
- rows = items_of(value)
- schema = {"devices": Device, "points": MonitorPoint,"operating_series":OperatingSeries,
- "switch_records":SwitchRecord,"fan_state_records":FanStateRecord}.get(kind)
- result[kind] = [schema.model_validate(r).model_dump(mode="json") for r in rows] if schema else rows
- return result
|