diff --git a/xumu.py b/xumu.py index 43e84ab..128d206 100644 --- a/xumu.py +++ b/xumu.py @@ -354,17 +354,24 @@ async def warning_statistics(deviceId): try: if deviceId is None or deviceId == "" or len(deviceId) != 4: return BaseResponse(code=500, msg="参数错误") - sql_for_count = f"select count(iccid) from root.warning.{deviceId}" - send_json = { - "sql": sql_for_count - } - r = requests.post(baseHost + queryUri, headers=headers, json=send_json) + # 获取设备总报警数 + r = requests.post(baseHost + queryUri, headers=headers, + json={"sql": f"select count(iccid) from root.warning.{deviceId}"}) data = r.json() values = data["values"] total_count = 0 + if len(values) != 0: + total_count = values[0][0] + # 获取设备当天报警数 + now = datetime.now().date() + r = requests.post(baseHost + queryUri, headers=headers, + json={ + "sql": f"select count(iccid) from root.warning.{deviceId} where time >= {now}T00:00:00"}) + data = r.json() + values = data["values"] today_count = 0 if len(values) != 0: - total_count = len(values[0]) + today_count = values[0][0] return_data = {"totoal_count": total_count, "today_count": today_count} return BaseResponse(data=return_data) except Exception as e: