feat: 添加 G5 状态表 IP 同步功能,新增 upsert 方法并更新相关测试
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
# Change: add g5 room status ip upsert
|
||||
|
||||
## Why
|
||||
当前双写仅写入 onoffline_record_g5,未同步更新 G5 状态表 `room_status.room_status_moment_g5` 的 `ip` 字段,导致状态表与最新上报数据存在延迟。
|
||||
|
||||
## What Changes
|
||||
- 新增 G5 状态表同步机制:按 `hotel_id + room_id` 查找目标行,并使用 `ON CONFLICT DO UPDATE` 更新 `ip`。
|
||||
- 同步时仅处理查找到的第一条匹配行(`LIMIT 1`)。
|
||||
- 无论 `ip` 是否变化都执行 upsert 更新,以触发数据库更新时间相关触发器。
|
||||
|
||||
## Impact
|
||||
- Affected specs: `openspec/specs/onoffline/spec.md`
|
||||
- Affected code: `src/db/g5DatabaseManager.js`, `src/index.js`, `tests/g5DatabaseManager.test.js`
|
||||
@@ -0,0 +1,19 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: G5 状态表 IP 同步
|
||||
系统 SHALL 在处理并写入数据时,同步将对应设备的 `ip` 更新到 G5 状态表 `room_status.room_status_moment_g5`。
|
||||
|
||||
#### Scenario: 按唯一键同步 IP
|
||||
- **GIVEN** 当前处理行包含 `hotel_id` 与 `room_id`
|
||||
- **WHEN** 执行 G5 状态表同步
|
||||
- **THEN** 系统按 `hotel_id + room_id` 查找状态表记录,并仅对查找到的第一条记录执行写入
|
||||
|
||||
#### Scenario: 使用 upsert 触发更新
|
||||
- **GIVEN** 状态表已存在同键记录
|
||||
- **WHEN** 执行写入
|
||||
- **THEN** 系统使用 `ON CONFLICT (hotel_id, room_id) DO UPDATE` 更新 `ip`
|
||||
|
||||
#### Scenario: IP 不变仍触发更新
|
||||
- **GIVEN** 新 `ip` 与库内 `ip` 相同
|
||||
- **WHEN** 执行状态表同步
|
||||
- **THEN** 系统仍执行更新语句,以触发表上的更新时间相关触发器
|
||||
@@ -0,0 +1,10 @@
|
||||
## 1. Implementation
|
||||
- [x] 1.1 Add room status IP upsert method in G5 DB manager.
|
||||
- [x] 1.2 Trigger room status IP upsert in the main write path.
|
||||
- [x] 1.3 Add tests for status mapping and room status dedupe behavior.
|
||||
- [x] 1.4 Add OpenSpec delta for the new synchronization requirement.
|
||||
|
||||
## 2. Validation
|
||||
- [x] 2.1 Run `npm run test`.
|
||||
- [x] 2.2 Run `npm run build`.
|
||||
- [x] 2.3 Run `openspec validate add-g5-room-status-ip-upsert --strict`.
|
||||
Reference in New Issue
Block a user