空调弹窗-控制空调运行

parent c8dee5c3
import { fail } from "assert";
import { TABLENAME } from "../config/dbEnum"; import { TABLENAME } from "../config/dbEnum";
import { ERRORENUM } from "../config/errorEnum"; import { ERRORENUM } from "../config/errorEnum";
import { selectDataListByParam } from "../data/findData"; import { selectOneDataByParam, selectDataListByParam } from "../data/findData";
import { BizError } from "../util/bizError"; import { BizError } from "../util/bizError";
import { controlIndoorUnit } from "./feiyiClient"; import { controlIndoorUnit } from "./feiyiClient";
import { getRegionList } from "./region"; import { getRegionList } from "./region";
...@@ -75,8 +76,8 @@ export async function getRunAnalysis(regionGroup: string, regionType: string) { ...@@ -75,8 +76,8 @@ export async function getRunAnalysis(regionGroup: string, regionType: string) {
let currentMonthEnergy = await getTotalEnergy(energyDeviceIds, currentMonthStart, new Date()); let currentMonthEnergy = await getTotalEnergy(energyDeviceIds, currentMonthStart, new Date());
let previousMonthEnergy = await getTotalEnergy(energyDeviceIds, lastMonthStart, lastMonthEnd); let previousMonthEnergy = await getTotalEnergy(energyDeviceIds, lastMonthStart, lastMonthEnd);
let dailyYearOnYear = yesterdayEnergy === 0 ? '0%' : `${(((todayEnergy - yesterdayEnergy) / yesterdayEnergy) * 100).toFixed(2)}%`; let dailyYearOnYear = yesterdayEnergy === 0 ? 0 : (((todayEnergy - yesterdayEnergy) / yesterdayEnergy) * 100).toFixed(2);
let monthlyYearOnYear = previousMonthEnergy === 0 ? '0%' : `${(((currentMonthEnergy - previousMonthEnergy) / previousMonthEnergy) * 100).toFixed(2)}%`; let monthlyYearOnYear = previousMonthEnergy === 0 ? 0 : (((currentMonthEnergy - previousMonthEnergy) / previousMonthEnergy) * 100).toFixed(2);
// 1.3 用电趋势:过去24小时(按小时)、过去7天、过去30天、过去一年(按月) // 1.3 用电趋势:过去24小时(按小时)、过去7天、过去30天、过去一年(按月)
let nowTime = new Date(); let nowTime = new Date();
...@@ -91,11 +92,11 @@ export async function getRunAnalysis(regionGroup: string, regionType: string) { ...@@ -91,11 +92,11 @@ export async function getRunAnalysis(regionGroup: string, regionType: string) {
// 1.4. 能耗监控数据和能耗监控趋势图数据 // 1.4. 能耗监控数据和能耗监控趋势图数据
resultAny.energyManagement = { resultAny.energyManagement = {
todayElectricity: `${todayEnergy.toFixed(0)}kwh`, todayElectricity: todayEnergy.toFixed(0),
yesterdayElectricity: `${yesterdayEnergy.toFixed(0)}kwh`, yesterdayElectricity: yesterdayEnergy.toFixed(0),
dailyYearOnYear, dailyYearOnYear,
currentMonthElectricity: `${currentMonthEnergy.toFixed(0)}kwh`, currentMonthElectricity: currentMonthEnergy.toFixed(0),
previousMonthElectricity: `${previousMonthEnergy.toFixed(0)}kwh`, previousMonthElectricity: previousMonthEnergy.toFixed(0),
monthlyYearOnYear monthlyYearOnYear
}; };
resultAny.electricityTrend = { resultAny.electricityTrend = {
...@@ -194,11 +195,9 @@ export async function getRunAnalysis(regionGroup: string, regionType: string) { ...@@ -194,11 +195,9 @@ export async function getRunAnalysis(regionGroup: string, regionType: string) {
"二级预警": 20, "二级预警": 20,
"三级预警": 18 "三级预警": 18
}; };
let alertWorkType = { let alertWorkType = [{ count: 25, name: "设备故障", proportion: '52%' },
"设备故障": { count: 25, proportion: '52%' }, { count: 15, name: "环境异常", proportion: '30%' },
"环境异常": { count: 15, proportion: '30%' }, { count: 8, name: "安全事件", proportion: '18%' }];
"安全事件": { count: 8, proportion: '18%' }
};
// 5.2. 预警监控数据 // 5.2. 预警监控数据
resultAny.alertManagement = { resultAny.alertManagement = {
alertWorkLevel: alertWorkLevel, alertWorkLevel: alertWorkLevel,
...@@ -449,8 +448,8 @@ export async function getRunAnalysis(regionGroup: string, regionType: string) { ...@@ -449,8 +448,8 @@ export async function getRunAnalysis(regionGroup: string, regionType: string) {
// 运行监控总数据(一天) // 运行监控总数据(一天)
resultAny.mainRunningManagement = { resultAny.mainRunningManagement = {
totalCustomerNumber: 10000, totalCustomerNumber: 10000,
totalDeviceOnlineRate: '99.8%', totalDeviceOnlineRate: 99.8,
totalElectricity: `360kwh`, totalElectricity: 360,
}; };
} else { } else {
// 设备监控总数据 // 设备监控总数据
...@@ -579,15 +578,40 @@ export async function getAcRunningPop(regionKey: number, deviceId: string) { ...@@ -579,15 +578,40 @@ export async function getAcRunningPop(regionKey: number, deviceId: string) {
* 设备运行弹框 - 空调启停 * 设备运行弹框 - 空调启停
* @param deviceId * @param deviceId
*/ */
export async function controlAcRunning(deviceIds?: string[], workerMode?: string) { export async function controlAcRunning(params: {}) {
let deviceId = params["deviceId"];
let mode = params["mode"];
let power = params["power"];
let setTemp = params["setTemp"];
let maxTemp = params["maxTemp"];
let minTemp = params["minTemp"];
let autoControl = params["autoControl"];
let fanSpeed = params["fanSpeed"];
// 1. 通过设备信息,获取内机地址 // 1. 通过设备信息,获取内机地址
let devices = await selectDataListByParam( let device = await selectOneDataByParam(
TABLENAME.设备表, TABLENAME.设备表,
{ device_id: { "%in%": deviceIds } }, { device_id: deviceId },
["device_id", "region_key", "device_name", "device_ad", "control_params"] ["device_id", "region_key", "device_name", "device_ad", "control_params"]
); );
// 2. 通过内机地址调用空调控制接口启停空调设备,无需校验环境温度 if (!device.data || !device.data.id) {
return await controlAcRunningApi(devices, 0, workerMode); throw new BizError(ERRORENUM.未找到数据, `设备 ${deviceId} 未注册`);
}
// 2. 接入空调控制API,更新空调设备信息
let acPrarms = {
"indoorUnitAddressFull": [deviceId],
"workMode": acDeviceKeyMap[mode],
"onOff": acDeviceKeyMap[power],
"tempSet": setTemp,
"fanSpeed": acDeviceKeyMap[fanSpeed],
"onOffLock": acDeviceKeyMap[autoControl],
"workModeLock": acDeviceKeyMap[autoControl],
"tempSetLock": acDeviceKeyMap[autoControl],
"tempSetLo": minTemp,
"tempSetHi": maxTemp,
"openApiAction": autoControl === "解除" ? "control" : "lock"
};
return await controlIndoorUnit(acPrarms);
} }
// 辅助函数:获取用电趋势(按间隔分组) // 辅助函数:获取用电趋势(按间隔分组)
...@@ -682,11 +706,6 @@ async function controlAcRunningApi(acDevices?: any, temperature?: number, worker ...@@ -682,11 +706,6 @@ async function controlAcRunningApi(acDevices?: any, temperature?: number, worker
deviceMinList.push(ac.device_ad); deviceMinList.push(ac.device_ad);
workModeMap[2] = deviceMinList; workModeMap[2] = deviceMinList;
openApiAction = "control"; openApiAction = "control";
} else if (!temperature && workerMode) {
// 根据workerMode控制空调设备
console.log(`根据工作模式控制空调 ${ac.device_name}${workerMode}`);
workModeMap[workerMode] = workModeMap[workerMode] ? [...workModeMap[workerMode], ac.device_ad] : [ac.device_ad];
openApiAction = "lock";
} }
}); });
// 多个设备: 接入空调控制API,传入设备ID和控制指令(如开/关、温度设定等) // 多个设备: 接入空调控制API,传入设备ID和控制指令(如开/关、温度设定等)
...@@ -710,4 +729,25 @@ async function controlAcRunningApi(acDevices?: any, temperature?: number, worker ...@@ -710,4 +729,25 @@ async function controlAcRunningApi(acDevices?: any, temperature?: number, worker
} }
} }
return controlResults; return controlResults;
}
/**
* 空调中文到Key的映射
* 1 制冷 2 制热 3 送风 4 除湿
* 0 关-off 1 开-on
* 1 高风-超强 2 中风-强 4 低风-弱
* 0 不锁定-解除 1 锁定-生效
*/
let acDeviceKeyMap: { [key: string]: number } = {
"制冷": 1,
"制热": 2,
"送风": 3,
"除湿": 4,
"on": 1,
"off": 0,
"超强": 1,
"强": 2,
"弱": 4,
"解除": 0,
"生效": 1
} }
\ No newline at end of file
...@@ -129,10 +129,11 @@ async function getRegionList(req, res) { ...@@ -129,10 +129,11 @@ async function getRegionList(req, res) {
* 控制空调开关 * 控制空调开关
*/ */
async function controlAcRunning(req, res) { async function controlAcRunning(req, res) {
let reqConf = {deviceId:'String', workerMode:'String'}; let reqConf = {deviceId:'String', mode:'String', power:'String', setTemp:'Number', maxTemp:'Number', minTemp:'Number', autoControl:'String', fanSpeed:'String'};
const NotMustHaveKeys = []; const NotMustHaveKeys = [];
let { deviceId, workerMode } = eccReqParamater(reqConf, req.body, NotMustHaveKeys); let { deviceId, mode, power, setTemp, maxTemp, minTemp, autoControl, fanSpeed } = eccReqParamater(reqConf, req.body, NotMustHaveKeys);
const result = await runningBiz.controlAcRunning(deviceId, workerMode); let params = { deviceId, mode, power, setTemp, maxTemp, minTemp, autoControl, fanSpeed };
const result = await runningBiz.controlAcRunning(params);
res.success(result); res.success(result);
} }
......
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