测试信息页面优化: 限制6000条、字段调整、车检器序列号搜索

- 查询/导出/图表统一 LIMIT 6000 条
- 列顺序: 时间→第一列, 测试模式→最后一列, 隐藏ID
- 设备编码只显示后6位, 默认每页100条
- 新增车检器序列号搜索 (detector_serial LIKE)
- 四个文件同步修改: models.py, test_data.py, test_data.js, test_data.html
This commit is contained in:
wangfq
2026-06-18 09:44:18 +08:00
parent f0ec79ca2f
commit 8a6b5c6d07
4 changed files with 57 additions and 31 deletions

View File

@@ -149,11 +149,12 @@ def get_latest_test_state(dnt_id: int) -> dict | None:
conn.close()
def get_test_data(page: int = 1, per_page: int = 20,
def get_test_data(page: int = 1, per_page: int = 100,
serial: str = "", date_from: str = "",
date_to: str = "", test_mode: str = "",
data_source: str = "") -> tuple[list[dict], int]:
"""分页查询测试数据JOIN dnt_info返回 (records, total)
data_source: str = "",
detector_serial: str = "") -> tuple[list[dict], int]:
"""分页查询测试数据JOIN dnt_info最多返回最近 6000 条,返回 (records, total)
test_mode: ''=全部, '0'=灵敏度, '1'=波动
data_source: ''=全部, 'B2', 'B4'
@@ -166,6 +167,9 @@ def get_test_data(page: int = 1, per_page: int = 20,
if serial:
where.append("d.serial LIKE %s")
params.append(f"%{serial}%")
if detector_serial:
where.append("t.detector_serial LIKE %s")
params.append(f"%{detector_serial}%")
if date_from:
where.append("t.create_time >= %s")
params.append(date_from if len(date_from) > 10 else date_from)
@@ -181,17 +185,21 @@ def get_test_data(page: int = 1, per_page: int = 20,
where_clause = " AND ".join(where) if where else "1=1"
# count
# count — 最多 6000 条
cur.execute(
f"SELECT COUNT(*) as total FROM tb_state_tst t "
f"JOIN dnt_info d ON t.dnt_id = d.id WHERE {where_clause}",
f"SELECT COUNT(*) as total FROM ("
f"SELECT 1 FROM tb_state_tst t "
f"JOIN dnt_info d ON t.dnt_id = d.id "
f"WHERE {where_clause} ORDER BY t.id DESC LIMIT 6000"
f") sub",
params,
)
total = cur.fetchone()["total"]
# data
# data — 子查询限 6000 后再分页
offset = (page - 1) * per_page
cur.execute(
f"SELECT * FROM ("
f"SELECT t.*, d.serial, "
f"c.coil_num, c.name as coil_name, "
f"sc.simulate_num, sc.name as car_name "
@@ -200,7 +208,8 @@ def get_test_data(page: int = 1, per_page: int = 20,
f"LEFT JOIN tb_coil_info c ON t.coil_id = c.id "
f"LEFT JOIN tb_simulate_car sc ON t.simulate_car_id = sc.id "
f"WHERE {where_clause} "
f"ORDER BY t.id DESC LIMIT %s OFFSET %s",
f"ORDER BY t.id DESC LIMIT 6000"
f") sub ORDER BY id DESC LIMIT %s OFFSET %s",
params + [per_page, offset],
)
records = cur.fetchall()
@@ -212,8 +221,9 @@ def get_test_data(page: int = 1, per_page: int = 20,
def get_all_test_data_for_export(serial: str = "", date_from: str = "",
date_to: str = "", test_mode: str = "",
data_source: str = "") -> list[dict]:
"""导出全部数据
data_source: str = "",
detector_serial: str = "") -> list[dict]:
"""导出全部数据(最多最近 6000 条)
test_mode: ''=全部, '0'=灵敏度, '1'=波动
data_source: ''=全部, 'B2', 'B4'
@@ -226,6 +236,9 @@ def get_all_test_data_for_export(serial: str = "", date_from: str = "",
if serial:
where.append("d.serial LIKE %s")
params.append(f"%{serial}%")
if detector_serial:
where.append("t.detector_serial LIKE %s")
params.append(f"%{detector_serial}%")
if date_from:
where.append("t.create_time >= %s")
params.append(date_from if len(date_from) > 10 else date_from)
@@ -248,7 +261,7 @@ def get_all_test_data_for_export(serial: str = "", date_from: str = "",
f"JOIN dnt_info d ON t.dnt_id = d.id "
f"LEFT JOIN tb_coil_info c ON t.coil_id = c.id "
f"LEFT JOIN tb_simulate_car sc ON t.simulate_car_id = sc.id "
f"WHERE {where_clause} ORDER BY t.id DESC",
f"WHERE {where_clause} ORDER BY t.id DESC LIMIT 6000",
params,
)
return cur.fetchall()