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

@@ -24,6 +24,36 @@ describe('HeartbeatProcessor smoke', () => {
const payload = { tsMs: 1700000000123, hotelId: 1, roomId: 2, deviceId: 'd', ip: '127.0.0.1', powerState: 1, guestType: 0, cardlessState: 0, serviceMask: 1, pmsState: 1, carbonState: 0, deviceCount: 1, commSeq: 1 };
assert.equal(processor.validateData(payload), true);
});
it('parses version field', () => {
const processor = new HeartbeatProcessor(
{ batchSize: 100, batchTimeout: 1000 },
{ insertHeartbeatEvents: async () => {} }
);
const payload = { version: 10203 };
const normalized = processor.normalizeHeartbeat(payload);
assert.equal(normalized.version, 10203);
});
it('treats bright_g -1 as undefined', () => {
const processor = new HeartbeatProcessor(
{ batchSize: 100, batchTimeout: 1000 },
{ insertHeartbeatEvents: async () => {} }
);
const payload = { bright_g: -1 };
const normalized = processor.normalizeHeartbeat(payload);
assert.equal(normalized.bright_g, undefined);
});
it('treats bright_g normal value as number', () => {
const processor = new HeartbeatProcessor(
{ batchSize: 100, batchTimeout: 1000 },
{ insertHeartbeatEvents: async () => {} }
);
const payload = { bright_g: 50 };
const normalized = processor.normalizeHeartbeat(payload);
assert.equal(normalized.bright_g, 50);
});
});
describe('RedisIntegration protocol', () => {