调整筛选逻辑

This commit is contained in:
mgw
2025-03-24 17:18:19 +08:00
parent 01ac8a19b6
commit 2b2da79e33

View File

@@ -1130,7 +1130,7 @@ class Sf_Dashboard_Connect(http.Controller):
SELECT * FROM device_data SELECT * FROM device_data
WHERE device_name = %s WHERE device_name = %s
AND time::date = CURRENT_DATE AND time::date = CURRENT_DATE
AND device_state in ('离线') AND device_state in ('待机', '警告', '运行中')
ORDER BY time ASC ORDER BY time ASC
LIMIT 1; LIMIT 1;
""", (item,)) """, (item,))
@@ -1143,7 +1143,7 @@ class Sf_Dashboard_Connect(http.Controller):
SELECT * FROM device_data SELECT * FROM device_data
WHERE device_name = %s WHERE device_name = %s
AND time::date = CURRENT_DATE AND time::date = CURRENT_DATE
AND device_state in ('离线') AND device_state in ('待机', '警告', '运行中')
ORDER BY time DESC ORDER BY time DESC
LIMIT 1; LIMIT 1;
""", (item,)) """, (item,))
@@ -1161,11 +1161,11 @@ class Sf_Dashboard_Connect(http.Controller):
# 获取当月第一条记录排除device_state等于离线的记录 # 获取当月第一条记录排除device_state等于离线的记录
with conn.cursor() as cur: with conn.cursor() as cur:
cur.execute(""" cur.execute("""
SELECT * FROM device_datas SELECT * FROM device_data
WHERE device_name = %s WHERE device_name = %s
AND time >= DATE_TRUNC('MONTH', CURRENT_DATE) AND time >= DATE_TRUNC('MONTH', CURRENT_DATE)
AND time < DATE_TRUNC('MONTH', CURRENT_DATE) + INTERVAL '1 MONTH' AND time < DATE_TRUNC('MONTH', CURRENT_DATE) + INTERVAL '1 MONTH'
AND device_state in ('离线') AND device_state in ('待机', '警告', '运行中')
ORDER BY time ASC ORDER BY time ASC
LIMIT 1; LIMIT 1;
""", (item,)) """, (item,))
@@ -1179,7 +1179,7 @@ class Sf_Dashboard_Connect(http.Controller):
WHERE device_name = %s WHERE device_name = %s
AND time >= DATE_TRUNC('MONTH', CURRENT_DATE) AND time >= DATE_TRUNC('MONTH', CURRENT_DATE)
AND time < DATE_TRUNC('MONTH', CURRENT_DATE) + INTERVAL '1 MONTH' AND time < DATE_TRUNC('MONTH', CURRENT_DATE) + INTERVAL '1 MONTH'
AND device_state in ('离线') AND device_state in ('待机', '警告', '运行中')
ORDER BY time DESC ORDER BY time DESC
LIMIT 1; LIMIT 1;
""", (item,)) """, (item,))
@@ -1200,7 +1200,7 @@ class Sf_Dashboard_Connect(http.Controller):
cur.execute(""" cur.execute("""
SELECT * FROM device_data SELECT * FROM device_data
WHERE device_name = %s WHERE device_name = %s
AND device_state in ('离线') AND device_state in ('待机', '警告', '运行中')
ORDER BY time ASC ORDER BY time ASC
LIMIT 1; LIMIT 1;
""", (item,)) """, (item,))
@@ -1212,7 +1212,7 @@ class Sf_Dashboard_Connect(http.Controller):
cur.execute(""" cur.execute("""
SELECT * FROM device_data SELECT * FROM device_data
WHERE device_name = %s WHERE device_name = %s
AND device_state in ('离线') AND device_state in ('待机', '警告', '运行中')
ORDER BY time DESC ORDER BY time DESC
LIMIT 1; LIMIT 1;
""", (item,)) """, (item,))
@@ -1290,7 +1290,7 @@ class Sf_Dashboard_Connect(http.Controller):
cur.execute(""" cur.execute("""
SELECT * FROM device_data SELECT * FROM device_data
WHERE device_name = %s WHERE device_name = %s
AND device_state in ('离线') AND process_time IS NOT NULL AND device_state in ('待机', '警告', '运行中') AND process_time IS NOT NULL
ORDER BY time DESC ORDER BY time DESC
LIMIT 1; LIMIT 1;
""", (item,)) """, (item,))
@@ -1299,7 +1299,7 @@ class Sf_Dashboard_Connect(http.Controller):
cur.execute(""" cur.execute("""
SELECT * FROM device_data SELECT * FROM device_data
WHERE device_name = %s WHERE device_name = %s
AND device_state in ('离线') AND time >= %s AND process_time IS NOT NULL AND device_state in ('待机', '警告', '运行中') AND time >= %s AND process_time IS NOT NULL
ORDER BY time ASC ORDER BY time ASC
LIMIT 1; LIMIT 1;
""", (item, time_threshold)) """, (item, time_threshold))