Compare commits
1 Commits
6e13990386
...
ff9482780d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff9482780d |
@@ -100,6 +100,7 @@ async def _create_tables(pool: aiomysql.Pool):
|
|||||||
CREATE TABLE IF NOT EXISTS `tb_state_tst` (
|
CREATE TABLE IF NOT EXISTS `tb_state_tst` (
|
||||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
`dnt_id` INT NOT NULL COMMENT 'FK → dnt_info.id',
|
`dnt_id` INT NOT NULL COMMENT 'FK → dnt_info.id',
|
||||||
|
`detector_serial` VARCHAR(45) DEFAULT '' COMMENT '车检器序列号',
|
||||||
`dpg430_addr` TINYINT DEFAULT 0,
|
`dpg430_addr` TINYINT DEFAULT 0,
|
||||||
`pcnum` VARCHAR(10) DEFAULT '' COMMENT '批次号',
|
`pcnum` VARCHAR(10) DEFAULT '' COMMENT '批次号',
|
||||||
`serialnum` INT DEFAULT 0 COMMENT '流水号',
|
`serialnum` INT DEFAULT 0 COMMENT '流水号',
|
||||||
@@ -320,6 +321,26 @@ async def _create_tables(pool: aiomysql.Pool):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# V2.4.0 迁移:tb_state_tst 增加车检器序列号
|
||||||
|
for col, col_def in [
|
||||||
|
("detector_serial", "VARCHAR(45) DEFAULT '' COMMENT '车检器序列号'"),
|
||||||
|
]:
|
||||||
|
try:
|
||||||
|
await cur.execute(
|
||||||
|
f"ALTER TABLE `tb_state_tst` ADD COLUMN `{col}` {col_def}"
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 13. 待插入的车检器序列号表 (V2.4.0)
|
||||||
|
await cur.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS `tb_pending_detector` (
|
||||||
|
`dnt_id` INT PRIMARY KEY COMMENT 'FK → dnt_info.id',
|
||||||
|
`detector_serial` VARCHAR(45) DEFAULT '' COMMENT '待插入的车检器序列号',
|
||||||
|
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
||||||
|
""")
|
||||||
|
|
||||||
# 11. 设备事件日志表
|
# 11. 设备事件日志表
|
||||||
await cur.execute("""
|
await cur.execute("""
|
||||||
CREATE TABLE IF NOT EXISTS `tb_device_log` (
|
CREATE TABLE IF NOT EXISTS `tb_device_log` (
|
||||||
@@ -544,18 +565,19 @@ async def insert_test_result(dnt_id: int, dpg430_addr: int, pcnum: str,
|
|||||||
relay_code: int = 0):
|
relay_code: int = 0):
|
||||||
"""插入测试结果到 tb_state_tst"""
|
"""插入测试结果到 tb_state_tst"""
|
||||||
coil_id, simulate_car_id = await get_fixture_coil_car_ids(dnt_id)
|
coil_id, simulate_car_id = await get_fixture_coil_car_ids(dnt_id)
|
||||||
|
detector_serial = await get_pending_detector_serial(dnt_id)
|
||||||
pool = await get_pool()
|
pool = await get_pool()
|
||||||
async with pool.acquire() as conn:
|
async with pool.acquire() as conn:
|
||||||
async with conn.cursor() as cur:
|
async with conn.cursor() as cur:
|
||||||
await cur.execute(
|
await cur.execute(
|
||||||
"""INSERT INTO tb_state_tst
|
"""INSERT INTO tb_state_tst
|
||||||
(dnt_id, dpg430_addr, pcnum, serialnum, sub_type, str_type,
|
(dnt_id, detector_serial, dpg430_addr, pcnum, serialnum, sub_type, str_type,
|
||||||
test_mode, data_source,
|
test_mode, data_source,
|
||||||
iffinish, fault_info, relay_out, ppvalue, idle_freq,
|
iffinish, fault_info, relay_out, ppvalue, idle_freq,
|
||||||
enter_freq, exit_freq, enter_dist, exit_dist, enter_speed, exit_speed,
|
enter_freq, exit_freq, enter_dist, exit_dist, enter_speed, exit_speed,
|
||||||
relay_code, coil_id, simulate_car_id)
|
relay_code, coil_id, simulate_car_id)
|
||||||
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
|
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
|
||||||
(dnt_id, dpg430_addr, pcnum, serialnum, sub_type, str_type,
|
(dnt_id, detector_serial, dpg430_addr, pcnum, serialnum, sub_type, str_type,
|
||||||
test_mode, data_source,
|
test_mode, data_source,
|
||||||
iffinish, fault_info, relay_out, ppvalue, idle_freq,
|
iffinish, fault_info, relay_out, ppvalue, idle_freq,
|
||||||
enter_freq, exit_freq, enter_dist, exit_dist, enter_speed, exit_speed,
|
enter_freq, exit_freq, enter_dist, exit_dist, enter_speed, exit_speed,
|
||||||
@@ -573,19 +595,20 @@ async def insert_wave_data(dnt_id: int, dpg430_addr: int,
|
|||||||
coil_id, simulate_car_id = await get_fixture_coil_car_ids(dnt_id)
|
coil_id, simulate_car_id = await get_fixture_coil_car_ids(dnt_id)
|
||||||
dev_type = await get_fixture_dev_type(dnt_id)
|
dev_type = await get_fixture_dev_type(dnt_id)
|
||||||
str_type = await get_dev_type_name(dev_type) if dev_type else ""
|
str_type = await get_dev_type_name(dev_type) if dev_type else ""
|
||||||
|
detector_serial = await get_pending_detector_serial(dnt_id)
|
||||||
pool = await get_pool()
|
pool = await get_pool()
|
||||||
async with pool.acquire() as conn:
|
async with pool.acquire() as conn:
|
||||||
async with conn.cursor() as cur:
|
async with conn.cursor() as cur:
|
||||||
await cur.execute(
|
await cur.execute(
|
||||||
"""INSERT INTO tb_state_tst
|
"""INSERT INTO tb_state_tst
|
||||||
(dnt_id, dpg430_addr, sub_type, str_type,
|
(dnt_id, detector_serial, dpg430_addr, sub_type, str_type,
|
||||||
test_mode, data_source,
|
test_mode, data_source,
|
||||||
relay_out, relay_code,
|
relay_out, relay_code,
|
||||||
remain_count, work_freq, curr_dist, speed,
|
remain_count, work_freq, curr_dist, speed,
|
||||||
near_dist, far_dist, b4_enter_dist, b4_leave_dist,
|
near_dist, far_dist, b4_enter_dist, b4_leave_dist,
|
||||||
coil_id, simulate_car_id)
|
coil_id, simulate_car_id)
|
||||||
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
|
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
|
||||||
(dnt_id, dpg430_addr, dev_type, str_type,
|
(dnt_id, detector_serial, dpg430_addr, dev_type, str_type,
|
||||||
1, "B4",
|
1, "B4",
|
||||||
relay_out, relay_code,
|
relay_out, relay_code,
|
||||||
remain_count, work_freq, curr_dist, speed,
|
remain_count, work_freq, curr_dist, speed,
|
||||||
@@ -838,3 +861,25 @@ async def get_vehicle_base_test_by_type(type_num: int) -> dict | None:
|
|||||||
(type_num,),
|
(type_num,),
|
||||||
)
|
)
|
||||||
return await cur.fetchone()
|
return await cur.fetchone()
|
||||||
|
|
||||||
|
|
||||||
|
# ─── tb_pending_detector ───────────────────────────────────────────
|
||||||
|
|
||||||
|
async def get_pending_detector_serial(dnt_id: int) -> str:
|
||||||
|
"""获取并清除待插入的车检器序列号(一次性消费)"""
|
||||||
|
pool = await get_pool()
|
||||||
|
async with pool.acquire() as conn:
|
||||||
|
async with conn.cursor(aiomysql.DictCursor) as cur:
|
||||||
|
await cur.execute(
|
||||||
|
"SELECT detector_serial FROM tb_pending_detector WHERE dnt_id=%s",
|
||||||
|
(dnt_id,),
|
||||||
|
)
|
||||||
|
row = await cur.fetchone()
|
||||||
|
if row:
|
||||||
|
# 清除已消费的记录
|
||||||
|
await cur.execute(
|
||||||
|
"DELETE FROM tb_pending_detector WHERE dnt_id=%s",
|
||||||
|
(dnt_id,),
|
||||||
|
)
|
||||||
|
return row["detector_serial"] or ""
|
||||||
|
return ""
|
||||||
|
|||||||
Reference in New Issue
Block a user