docs: 更新字段
- 更新数据库schema和文档,增加insert_card和bright_g字段支持 - 同步更新heartbeatProcessor.js和databaseManager.js以支持新字段
This commit is contained in:
@@ -33,6 +33,8 @@
|
||||
| carbon_state | int2 | 是 | 碳控状态(枚举待定) |
|
||||
| device_count | int2 | 是 | 设备数量/上报设备数量(语义待确认) |
|
||||
| comm_seq | int4 | 是 | 通讯序号(语义待确认) |
|
||||
| insert_card | int2 | 否 | 是否插卡(整数;可为空;不建索引) |
|
||||
| bright_g | int2 | 否 | 全局亮度值(整数;可为空;不建索引) |
|
||||
| elec_address | text[] | 否 | 电力设备地址数组(与 voltage[] 等按下标对齐) |
|
||||
| voltage | double precision[] | 否 | 电压数组 |
|
||||
| ampere | double precision[] | 否 | 电流数组 |
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
| extra | object | {"source":"gw","ver":"1.2.3"} | 扩展字段:原文、版本等其他自定义字段 |
|
||||
| electricity | array<object> | [{"address":"add11","voltage":3.2,...}] | 电力设备数组(按原始顺序拆列落库为数组列) |
|
||||
| air_conditioner | array<object> | [{"address":"ac1","state":1,...}] | 空调设备数组(按原始顺序拆列落库为数组列) |
|
||||
| insert_card | number/int | 1 | 是否插卡(整数,可为空) |
|
||||
| bright_g | number/int | 80 | 全局亮度值(整数,可为空) |
|
||||
|
||||
## 4. JSON 示例
|
||||
```json
|
||||
@@ -56,6 +58,8 @@
|
||||
"carbon_state": 0,
|
||||
"device_count": 1,
|
||||
"comm_seq": 7,
|
||||
"insert_card": 1,
|
||||
"bright_g": 80,
|
||||
"electricity": [
|
||||
{
|
||||
"address": "add11",
|
||||
|
||||
@@ -28,6 +28,9 @@ CREATE TABLE IF NOT EXISTS heartbeat.heartbeat_events (
|
||||
device_count int2 NOT NULL,
|
||||
comm_seq int4 NOT NULL,
|
||||
|
||||
insert_card int2,
|
||||
bright_g int2,
|
||||
|
||||
elec_address text[],
|
||||
air_address text[],
|
||||
voltage double precision[],
|
||||
@@ -80,6 +83,8 @@ ALTER TABLE heartbeat.heartbeat_events ADD COLUMN IF NOT EXISTS speed int2[];
|
||||
ALTER TABLE heartbeat.heartbeat_events ADD COLUMN IF NOT EXISTS set_temp int2[];
|
||||
ALTER TABLE heartbeat.heartbeat_events ADD COLUMN IF NOT EXISTS now_temp int2[];
|
||||
ALTER TABLE heartbeat.heartbeat_events ADD COLUMN IF NOT EXISTS solenoid_valve int2[];
|
||||
ALTER TABLE heartbeat.heartbeat_events ADD COLUMN IF NOT EXISTS insert_card int2;
|
||||
ALTER TABLE heartbeat.heartbeat_events ADD COLUMN IF NOT EXISTS bright_g int2;
|
||||
|
||||
-- 指定索引
|
||||
CREATE INDEX IF NOT EXISTS idx_heartbeat_events_hotel_id ON heartbeat.heartbeat_events (hotel_id);
|
||||
|
||||
@@ -98,6 +98,9 @@ class DatabaseManager {
|
||||
device_count int2 NOT NULL,
|
||||
comm_seq int4 NOT NULL,
|
||||
|
||||
insert_card int2,
|
||||
bright_g int2,
|
||||
|
||||
elec_address text[],
|
||||
air_address text[],
|
||||
voltage double precision[],
|
||||
@@ -148,6 +151,8 @@ class DatabaseManager {
|
||||
ALTER TABLE heartbeat.heartbeat_events ADD COLUMN IF NOT EXISTS set_temp int2[];
|
||||
ALTER TABLE heartbeat.heartbeat_events ADD COLUMN IF NOT EXISTS now_temp int2[];
|
||||
ALTER TABLE heartbeat.heartbeat_events ADD COLUMN IF NOT EXISTS solenoid_valve int2[];
|
||||
ALTER TABLE heartbeat.heartbeat_events ADD COLUMN IF NOT EXISTS insert_card int2;
|
||||
ALTER TABLE heartbeat.heartbeat_events ADD COLUMN IF NOT EXISTS bright_g int2;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_heartbeat_events_hotel_id ON heartbeat.heartbeat_events (hotel_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_heartbeat_events_power_state ON heartbeat.heartbeat_events (power_state);
|
||||
@@ -413,6 +418,8 @@ class DatabaseManager {
|
||||
'carbon_state',
|
||||
'device_count',
|
||||
'comm_seq',
|
||||
'insert_card',
|
||||
'bright_g',
|
||||
'elec_address',
|
||||
'air_address',
|
||||
'voltage',
|
||||
@@ -445,6 +452,8 @@ class DatabaseManager {
|
||||
e.carbon_state,
|
||||
e.device_count,
|
||||
e.comm_seq,
|
||||
e.insert_card ?? null,
|
||||
e.bright_g ?? null,
|
||||
Array.isArray(e.elec_address) ? e.elec_address : null,
|
||||
Array.isArray(e.air_address) ? e.air_address : null,
|
||||
Array.isArray(e.voltage) ? e.voltage : null,
|
||||
|
||||
@@ -512,6 +512,8 @@ class HeartbeatProcessor {
|
||||
carbon_state: pick(['carbon_state', 'carbonState', 'CarbonState']),
|
||||
device_count: pick(['device_count', 'deviceCount', 'DeviceCount']),
|
||||
comm_seq: pick(['comm_seq', 'commSeq', 'CommSeq']),
|
||||
insert_card: pick(['insert_card', 'insertCard', 'InsertCard']),
|
||||
bright_g: pick(['bright_g', 'brightG', 'BrightG']),
|
||||
extra: pick(['extra', 'Extra']),
|
||||
electricity: pick(['electricity', 'Electricity']),
|
||||
air_conditioner: pick(['air_conditioner', 'airConditioner', 'AirConditioner']),
|
||||
@@ -563,6 +565,8 @@ class HeartbeatProcessor {
|
||||
normalized.carbon_state = toIntOrUndefined(normalized.carbon_state);
|
||||
normalized.device_count = toIntOrUndefined(normalized.device_count);
|
||||
normalized.comm_seq = toIntOrUndefined(normalized.comm_seq);
|
||||
normalized.insert_card = toIntOrUndefined(normalized.insert_card);
|
||||
normalized.bright_g = toIntOrUndefined(normalized.bright_g);
|
||||
|
||||
// 其余未知字段塞进 extra(避免丢信息),但不覆盖显式 extra
|
||||
if (!normalized.extra || typeof normalized.extra !== 'object') {
|
||||
@@ -585,6 +589,8 @@ class HeartbeatProcessor {
|
||||
'carbon_state','carbonState','CarbonState',
|
||||
'device_count','deviceCount','DeviceCount',
|
||||
'comm_seq','commSeq','CommSeq',
|
||||
'insert_card','insertCard','InsertCard',
|
||||
'bright_g','brightG','BrightG',
|
||||
'extra','Extra',
|
||||
'electricity','Electricity',
|
||||
'air_conditioner','airConditioner','AirConditioner'
|
||||
|
||||
Reference in New Issue
Block a user