Files
Web_BLS_RCUAction_Server/openspec/changes/feature-loop-name-enrichment.md
XuJiacheng 4e0f5213db feat: 添加回路名称字段并实现元数据缓存查询
在 RCU 事件处理中新增回路名称(loop_name)字段,用于标识具体设备回路。
- 在 rcu_action_events 表中添加 loop_name 字段
- 新增项目元数据缓存模块,每日从 temporary_project 表刷新房间与回路信息
- 处理消息时,根据 device_id、dev_addr 等字段查询缓存获取回路名称
- 若缓存未命中,则根据设备类型规则生成兜底名称
- 更新环境变量、文档及测试用例以适配新功能
2026-02-02 19:43:49 +08:00

1.4 KiB

Feature: Loop Name Enrichment

Status: Proposed Date: 2026-02-02

Summary

Enrich incoming RCU action events with loop_name by looking up metadata from temporary_project tables. This allows easier identification of specific device loops (e.g., "Main Chandelier") in the event log.

Requirements

  1. Cache Mechanism:
    • Load rooms and loops data from temporary_project schema into memory.
    • Refresh cache daily at 1:00 AM.
  2. Enrichment:
    • For each incoming event, look up loop_name using device_id and dev_addr.
    • device_id -> room_type_id (via rooms table).
    • room_type_id + dev_addr -> loop_name (via loops table).
  3. Storage:
    • Store loop_name in rcu_action_events table.

Ambiguity Resolution

  • The requirement mentioned matching dev_type to find the loop. However, standard RCU addressing uses dev_addr (and dev_loop). We assume loops.loop_address corresponds to the packet's dev_addr (converted to string).
  • We will attempt to match dev_addr against loop_address.

Schema Changes

  • Table: rcu_action.rcu_action_events
  • Column: loop_name (VARCHAR(255), Nullable)

Implementation Plan

  1. Database: Update init_db.sql and databaseManager.js.
  2. Cache: Create src/cache/projectMetadata.js.
  3. Processor: Integrate cache lookup in src/processor/index.js.
  4. Lifecycle: Initialize cache in src/index.js.