feat(M06-E): 接入智慧插座业务控制

This commit is contained in:
Codex
2026-06-24 15:12:12 +08:00
parent 48638606fe
commit 9144fa8102
5 changed files with 198 additions and 3 deletions
+22
View File
@@ -91,6 +91,12 @@ const service = new IotMessageService({
async execute(sql, params) {
calls.push({ sql, params });
if (sql.includes('FROM qipai_devices')) {
if (params[0] === 'SOCKET_001') {
return [[{
id: 52, tenantId: 7, storeId: 11, roomId: 31,
deviceId: 'SOCKET_001', deviceType: 'SMART_SOCKET'
}], []];
}
return [[{
id: 51, tenantId: 7, storeId: 11, roomId: 31,
deviceId: 'BOX_001', deviceType: 'CONTROL_BOX'
@@ -150,6 +156,22 @@ assert.equal(calls.some((item) =>
item.sql.includes('INSERT INTO qipai_device_alerts')
&& item.params.includes('DEVICE_UNCONFIRM')
), true);
await service.handle('/devicesend/SOCKET_001', Buffer.from(JSON.stringify({
DeviceID: 'SOCKET_001', event: 'workInfo', switch: 'on',
powerW: 3601, temperature: 82, overLoad: true
})));
assert.equal(calls.some((item) =>
item.sql.includes('INSERT INTO qipai_device_alerts')
&& item.params.includes('SOCKET_OVERLOAD')
), true);
assert.equal(calls.some((item) =>
item.sql.includes('INSERT INTO qipai_device_alerts')
&& item.params.includes('SOCKET_POWER_LIMIT')
), true);
assert.equal(calls.some((item) =>
item.sql.includes('INSERT INTO qipai_device_alerts')
&& item.params.includes('SOCKET_TEMPERATURE_LIMIT')
), true);
await assert.rejects(
() => service.createCommand({