通过环境监测控制空调并存日志

parent 37602267
...@@ -390,6 +390,9 @@ async function integrateAcDevices() { ...@@ -390,6 +390,9 @@ async function integrateAcDevices() {
continue; continue;
} }
let deviceType = '空调';
let deviceName = '空调内机';
// 查找对应的 region_key // 查找对应的 region_key
let regionKey = 0; let regionKey = 0;
if (item.roomId) { if (item.roomId) {
...@@ -398,6 +401,11 @@ async function integrateAcDevices() { ...@@ -398,6 +401,11 @@ async function integrateAcDevices() {
const region = await regionModel.findOne({ where: { room_id: item.roomId } }); const region = await regionModel.findOne({ where: { room_id: item.roomId } });
if (region) { if (region) {
regionKey = region.id; regionKey = region.id;
// 如果区域地址包含新风,则空调视为新风机
if (region.name && region.name.includes('新风')) {
deviceType = '新风';
deviceName = '新风机';
}
} }
} }
} }
...@@ -407,8 +415,8 @@ async function integrateAcDevices() { ...@@ -407,8 +415,8 @@ async function integrateAcDevices() {
device_id: deviceId, device_id: deviceId,
device_ad: item.indoorUnitId || '', device_ad: item.indoorUnitId || '',
region_key: regionKey, region_key: regionKey,
device_type: '空调', device_type: deviceType,
device_name: `空调内机-${deviceId}`, device_name: `${deviceName}-${deviceId}`,
control_params: AC_CONTROL_PARAMS, control_params: AC_CONTROL_PARAMS,
}); });
insertCount++; insertCount++;
...@@ -715,14 +723,14 @@ async function integrateMeterDeviceData() { ...@@ -715,14 +723,14 @@ async function integrateMeterDeviceData() {
* 数据集成-九合一环境设备数据集成 * 数据集成-九合一环境设备数据集成
*/ */
export async function airDeviceData() { export async function airDeviceData() {
// TODO: 暂无对应接口 // 暂无对应接口 -> MQTT
} }
/** /**
* 数据集成-客流监测设备数据集成 * 数据集成-客流监测设备数据集成
*/ */
export async function customerDeviceData() { export async function customerDeviceData() {
// TODO: 暂无对应接口 // 暂无对应接口 -> MQTT
} }
/** /**
......
import { TABLENAME } from "../config/dbEnum"; import { TABLENAME } from "../config/dbEnum";
import { addData } from "../data/addData"; import { addData } from "../data/addData";
import { selectOneDataByParam } from "../data/findData"; import { selectOneDataByParam } from "../data/findData";
import { controlAcByEnvironment } from "./running";
/** /**
* 处理接收到的单条设备数据,并存入数据库 * 处理接收到的环境设备数据,并存入数据库
* *
* 消息示例: * 消息示例:
* { * {
...@@ -87,6 +88,9 @@ export async function processDeviceData(message) { ...@@ -87,6 +88,9 @@ export async function processDeviceData(message) {
); );
console.log(`数据入库成功: 设备 ${devEUI}`); console.log(`数据入库成功: 设备 ${devEUI}`);
// 调用空调控制
await controlAcByEnvironment(devEUI, data);
} catch (error) { } catch (error) {
console.error('数据处理失败:', error); console.error('数据处理失败:', error);
......
...@@ -7,7 +7,8 @@ export enum TABLENAME { ...@@ -7,7 +7,8 @@ export enum TABLENAME {
设备数据表 = 'device_data', 设备数据表 = 'device_data',
区域表 = 'region', 区域表 = 'region',
设备故障表 = 'device_fault', 设备故障表 = 'device_fault',
用户信息表 = 'user_info' 用户信息表 = 'user_info',
设备日志表 = 'device_logs'
}; };
/** /**
......
...@@ -278,5 +278,53 @@ export const TablesConfig = [ ...@@ -278,5 +278,53 @@ export const TablesConfig = [
{ type: "hasMany", target: "device", foreignKey: "region_key" } { type: "hasMany", target: "device", foreignKey: "region_key" }
] ]
}, },
// 设备日志表
{
tableNameCn: '设备日志表',
tableName: 'device_logs',
schema: {
id: {
type: DataTypes.BIGINT,
allowNull: false,
primaryKey: true,
autoIncrement: true,
comment: '自增主键'
},
device_id: {
type: DataTypes.STRING(50),
allowNull: false,
comment: '设备标识'
},
device_type: {
type: DataTypes.STRING(50),
allowNull: false,
comment: '设备类型,如“空调”“出风口”'
},
operation_content: {
type: DataTypes.JSON,
allowNull: true,
comment: '操作内容{"option":"on","time":"2026-06-26 12:00:00"}'
},
status: {
type: DataTypes.INTEGER,
allowNull: false,
comment: '操作状态,0否1是'
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
comment: '创建时间'
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
comment: '更新时间'
}
},
association: [
]
},
]; ];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment