feat(heartbeat): 添加版本号字段并处理亮度值-1为NULL

- 在心跳事件表中新增 version 字段,用于存储版本号信息
- 将 bright_g 字段的 -1 值映射为数据库中的 NULL,避免语义混淆
- 更新相关文档、数据库迁移脚本和测试用例
This commit is contained in:
2026-01-28 17:47:05 +08:00
parent 1644ee80bc
commit ad270bd936
6 changed files with 45 additions and 4 deletions

View File

@@ -420,6 +420,7 @@ class DatabaseManager {
'comm_seq',
'insert_card',
'bright_g',
'version',
'elec_address',
'air_address',
'voltage',
@@ -453,7 +454,8 @@ class DatabaseManager {
e.device_count,
e.comm_seq,
e.insert_card ?? null,
e.bright_g ?? null,
(e.bright_g === -1 || e.bright_g === '-1') ? null : (e.bright_g ?? null),
e.version ?? null,
Array.isArray(e.elec_address) ? e.elec_address : null,
Array.isArray(e.air_address) ? e.air_address : null,
Array.isArray(e.voltage) ? e.voltage : null,

View File

@@ -514,6 +514,7 @@ class HeartbeatProcessor {
comm_seq: pick(['comm_seq', 'commSeq', 'CommSeq']),
insert_card: pick(['insert_card', 'insertCard', 'InsertCard']),
bright_g: pick(['bright_g', 'brightG', 'BrightG']),
version: pick(['version', 'Version', 'ver', 'Ver']),
extra: pick(['extra', 'Extra']),
electricity: pick(['electricity', 'Electricity']),
air_conditioner: pick(['air_conditioner', 'airConditioner', 'AirConditioner']),
@@ -566,7 +567,9 @@ class HeartbeatProcessor {
normalized.device_count = toIntOrUndefined(normalized.device_count);
normalized.comm_seq = toIntOrUndefined(normalized.comm_seq);
normalized.insert_card = toIntOrUndefined(normalized.insert_card);
normalized.bright_g = toIntOrUndefined(normalized.bright_g);
const bg = toIntOrUndefined(normalized.bright_g);
normalized.bright_g = bg === -1 ? undefined : bg;
normalized.version = toIntOrUndefined(normalized.version);
// 其余未知字段塞进 extra避免丢信息但不覆盖显式 extra
if (!normalized.extra || typeof normalized.extra !== 'object') {
@@ -591,6 +594,7 @@ class HeartbeatProcessor {
'comm_seq','commSeq','CommSeq',
'insert_card','insertCard','InsertCard',
'bright_g','brightG','BrightG',
'version','Version','ver','Ver',
'extra','Extra',
'electricity','Electricity',
'air_conditioner','airConditioner','AirConditioner'