feat(processor): 同步心跳数据到 room_status 表

- 在 HeartbeatProcessor 中新增异步同步逻辑,在历史表写入成功后尝试更新 room_status 表
- 实现 DatabaseManager.upsertRoomStatus 方法,支持批量更新和自动分区创建
- 添加批次内去重逻辑,避免 PostgreSQL ON CONFLICT 冲突
- 新增相关文档:同步方案、测试报告和提案说明
This commit is contained in:
2026-02-06 15:15:03 +08:00
parent b72cdde8bf
commit e44cf10a82
5 changed files with 372 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
# Proposal: Synchronize Heartbeat Data to Room Status Table
## Background
The `room_status.room_status_moment` table is a shared table for real-time device status. The heartbeat service needs to synchronize relevant fields from Kafka messages to this table.
## Changes
1. **Database Schema**:
* Add `bright_g` (INT2) and `agreement_ver` (TEXT) columns to `room_status.room_status_moment`.
* Add a UNIQUE INDEX on `(hotel_id, room_id, device_id)` to support efficient UPSERT operations.
2. **Application Logic**:
* Implement `upsertRoomStatus` in `DatabaseManager`.
* Call this method in `HeartbeatProcessor` after successful insertion into the history table.
* Map `version` to `agreement_ver` and `bright_g` to `bright_g`.
## Tasks
- [ ] Update `docs/room_status_moment.sql` with new columns and index.
- [ ] Update `docs/plan-room-status-sync.md` with new fields and finalized plan.
- [ ] Implement `upsertRoomStatus` in `DatabaseManager`.
- [ ] Integrate into `HeartbeatProcessor`.