feat: 添加回路名称字段并实现元数据缓存查询

在 RCU 事件处理中新增回路名称(loop_name)字段,用于标识具体设备回路。
- 在 rcu_action_events 表中添加 loop_name 字段
- 新增项目元数据缓存模块,每日从 temporary_project 表刷新房间与回路信息
- 处理消息时,根据 device_id、dev_addr 等字段查询缓存获取回路名称
- 若缓存未命中,则根据设备类型规则生成兜底名称
- 更新环境变量、文档及测试用例以适配新功能
This commit is contained in:
2026-02-02 19:43:49 +08:00
parent 0e6c5c3cc3
commit 4e0f5213db
12 changed files with 660 additions and 117 deletions

View File

@@ -1,5 +1,6 @@
import { describe, it, expect } from 'vitest';
import { buildRowsFromPayload } from '../src/processor/index.js';
import projectMetadata from '../src/cache/projectMetadata.js';
describe('Processor Logic', () => {
const basePayload = {
@@ -95,12 +96,15 @@ describe('Processor Logic', () => {
const payload = {
...basePayload,
direction: '上报',
cmd_word: '0x0F'
cmd_word: '0x0F',
control_list: [
{ dev_type: 1, dev_addr: 1, dev_loop: 1, dev_data: 1, type_h: 0 }
]
};
const rows = buildRowsFromPayload(payload);
expect(rows).toHaveLength(1);
expect(rows[0].action_type).toBe('ACK');
expect(rows[0].action_type).toBe('设备回路状态');
});
it('should fallback when lists are empty for 0x36', () => {
@@ -199,4 +203,27 @@ describe('Processor Logic', () => {
trace_id: 'trace-123'
});
});
it('should enrich rows with loop_name from metadata', () => {
// Mock metadata
projectMetadata.roomMap.set('dev_001', 101);
// Key format: roomTypeId:00Type00Addr00Loop
// type=1, addr=10, loop=1 -> 001010001
projectMetadata.loopMap.set('101:001010001', 'Main Chandelier');
const payload = {
...basePayload,
direction: '上报',
cmd_word: '0x36',
device_list: [
{ dev_type: 1, dev_addr: 10, dev_loop: 1, dev_data: 100 }, // Should match 001010001
{ dev_type: 1, dev_addr: 10, dev_loop: 2, dev_data: 0 } // Should not match (001010002) -> Fallback
]
};
const rows = buildRowsFromPayload(payload);
expect(rows[0].loop_name).toBe('Main Chandelier');
// dev_type 1 is 'Dev_Host_HVout'
expect(rows[1].loop_name).toBe('[1Dev_Host_HVout-10-2]');
});
});