fix: 自动化开始前清除旧透传记录,重置所有计数和显示

This commit is contained in:
wangfq
2026-05-28 12:00:59 +08:00
parent 3f78638c2c
commit d7255297f0
4 changed files with 21 additions and 3 deletions

View File

@@ -108,6 +108,17 @@ def get_serialnet_records(dnt_id: int, limit: int = 50) -> list[dict]:
conn.close() conn.close()
def clear_serialnet_records(dnt_id: int):
"""清除指定设备的所有透传记录"""
conn = get_conn()
try:
with conn.cursor() as cur:
cur.execute("DELETE FROM tb_serialnet WHERE dnt_id=%s", (dnt_id,))
conn.commit()
finally:
conn.close()
# ─── tb_state_tst ────────────────────────────────────────────────── # ─── tb_state_tst ──────────────────────────────────────────────────
def get_latest_test_state(dnt_id: int) -> dict | None: def get_latest_test_state(dnt_id: int) -> dict | None:

View File

@@ -8,6 +8,7 @@ from app.models import (
get_serialnet_stats, get_serialnet_stats,
get_latest_test_state, get_latest_test_state,
get_automation_averages, get_automation_averages,
clear_serialnet_records,
) )
bp = Blueprint("test_op", __name__) bp = Blueprint("test_op", __name__)
@@ -54,7 +55,8 @@ def api_automation_start():
dnt_id = data.get("dnt_id") dnt_id = data.get("dnt_id")
count = int(data.get("count", 1)) count = int(data.get("count", 1))
# 插入第一条 0xB0 指令 # 清除旧记录,然后插入第一条 0xB0
clear_serialnet_records(dnt_id)
record_id = insert_serialnet(dnt_id, COMMANDS["B0"]) record_id = insert_serialnet(dnt_id, COMMANDS["B0"])
return jsonify({ return jsonify({
"ok": True, "ok": True,

View File

@@ -48,9 +48,14 @@ async function startAuto() {
autoFailed = 0; autoFailed = 0;
autoRemaining = count; autoRemaining = count;
// 清空平均值显示 // 清空显示
resetAverages(); resetAverages();
updateUI(); document.getElementById("latest-result").innerHTML = '<p class="placeholder">等待测试...</p>';
document.getElementById("progress-bar").style.width = "0%";
document.getElementById("progress-text").textContent = "0/" + count + " (0 失败)";
document.getElementById("stat-done").textContent = "0";
document.getElementById("stat-failed").textContent = "0";
document.getElementById("stat-remaining").textContent = count;
const btn = document.getElementById("btn-auto"); const btn = document.getElementById("btn-auto");
btn.textContent = "结束"; btn.textContent = "结束";