模拟数据

parent 4b0f675a
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
<dataBase>dst_technology_platform</dataBase> <dataBase>dst_technology_platform</dataBase>
<!-- 服务器mysql配置 --> <!-- 服务器mysql配置 -->
<!-- <mysqlHost>127.0.0.1</mysqlHost> <!-- <mysqlHost>127.0.0.1</mysqlHost>
<mysqlPort>3306</mysqlPort> <mysqlPort>13306</mysqlPort>
<mysqlUser>root</mysqlUser> <mysqlUser>root</mysqlUser>
<mysqlPwd>qaz123456</mysqlPwd> <mysqlPwd>root</mysqlPwd>
<dataBase>dst_technology_platform</dataBase> --> <dataBase>dst_technology_platform</dataBase> -->
</mysqldb> </mysqldb>
</config> </config>
...@@ -3,13 +3,114 @@ ...@@ -3,13 +3,114 @@
*/ */
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import * as path from 'path';
import { post } from '../util/request'; import { post } from '../util/request';
import { analysisXml } from '../util/myXML';
import { planaryArrayBecomeOfBlockData } from '../util/analysisExcel';
import { selectDataListByParam } from '../data/findData';
import { TABLENAME } from '../config/dbEnum';
const xlsx = require('node-xlsx');
/** /**
* 区域位置 * 区域位置
* @returns 区域位置数据 * @returns 区域位置数据
*/ */
export async function getRegionLocation(gatewayPage: number) { export async function getRegionLocation(gatewayPage: number) {
const result = [{"regionKey":"32","regionName":"三十二位","xz":1587,"yz":487,"qualityIndex":"优","gatewayPage":gatewayPage}]; // const result = [{"regionKey":"32","regionName":"三十二位","xz":1587,"yz":487,"qualityIndex":"优","gatewayPage":gatewayPage}];
// 读取区域坐标分布.xlsx文件中的表格数据,更新区域表中的区域参数字段
const result = await readRegionAxis(gatewayPage);
return result;
}
/**
* 读取区域坐标
*/
export async function readRegionAxis(gatewayPage: number) {
let result = [];
const filePath = path.join(__dirname.substring(0, __dirname.indexOf("out")), "res", "区域坐标分布.xlsx");
const workSheets = xlsx.parse(filePath);
const sheetMap:any = {};
for (const sheetInfo of workSheets) {
sheetMap[sheetInfo.name] = sheetInfo.data;
}
if (gatewayPage === 1) {
let analysisSheet = sheetMap["运行分析"];
result = await readSheet(analysisSheet, gatewayPage);
} else if (gatewayPage === 2) {
let monitorSheet = sheetMap["智能监控"];
result = await readSheet(monitorSheet, gatewayPage);
}
return result;
}
async function readSheet(sheet: any[][], gatewayPage: number) {
// 取出所有区域名称,查询区域表获取区域数据
let regionList = await selectDataListByParam(TABLENAME.区域表, {});
// let regionMap = {
// "会议室": "1001",
// "公共办公区": "1002",
// "办公室": "2001",
// "仓库": "2002",
// "CEO办公室": "2003",
// "传感器生产间": "3001",
// "前台": "0001",
// "卫生间": "3000"
// }
let regionMap = regionList.data.map((bean)=>{
regionMap[bean.regionName] = bean.regionKey
});
// 根据区域信息查询所有环境设备,通过环境设备查询最新环境指标
let deviceMap = {
"会议室": [
{ "deviceId": "AC1", "deviceType": "空调", "power": "off" },
{ "deviceId": "Z1", "deviceType": "照明", "power": "on" }
],
"公共办公区": [
{ "deviceId": "AC2", "deviceType": "空调", "power": "on" },
{ "deviceId": "Z12", "deviceType": "照明", "power": "on" },
{ "deviceId": "F1", "deviceType": "排风", "power": "on" },
{ "deviceId": "E1", "deviceType": "IEQ传感器", "power": "on" },
{ "deviceId": "Y1", "deviceType": "烟感器", "power": "on" }
],
"办公室": [
{ "deviceId": "AC3", "deviceType": "空调", "power": "on" },
{ "deviceId": "Z2", "deviceType": "照明", "power": "on" },
{ "deviceId": "F2", "deviceType": "排风", "power": "on" }
],
"仓库": [{ "deviceId": "AC11", "deviceType": "空调", "power": "off" }],
"CEO办公室": [{ "deviceId": "AC12", "deviceType": "空调", "power": "off" }],
"传感器生产间": [{ "deviceId": "AC13", "deviceType": "空调", "power": "off" }],
"卫生间": [
{ "deviceId": "S1", "deviceType": "摄像头", "power": "on" },
{ "deviceId": "E100", "deviceType": "IEQ传感器", "power": "on" },
{ "deviceId": "X1", "deviceType": "音响", "power": "on" }
],
"前台": [
{ "deviceId": "S0", "deviceType": "摄像头", "power": "on" },
{ "deviceId": "T1", "deviceType": "人流监测", "power": "on" }
]
}
// 循环区域,根据各区域环境指标计算各区域的环境质量得出优良中差四个值
let sheetData = await planaryArrayBecomeOfBlockData(sheet);
let result = [];
if (sheetData && sheetData[0].blockData) {
let block = sheetData[0];
const headerRow = block.blockData[0];
const index = headerRow.indexOf("区域名称");
const xindex = headerRow.indexOf("X轴坐标");
const yindex = headerRow.indexOf("Y轴坐标");
result = block.blockData.slice(1).map((row: any) => ({
regionKey: regionMap[row[0]],
regionName: String(row[index] ?? ""),
xz: row[xindex],
yz: row[yindex],
qualityIndex: row[index] ? row[xindex]<500?"优":row[xindex]<1000?"良":row[xindex]<1200?"中":"差" : "优",
gatewayPage: gatewayPage,
devices: deviceMap[row[0]]
}))?? [];
}
return result; return result;
} }
\ No newline at end of file
...@@ -8,6 +8,9 @@ import { BizError } from '../util/bizError'; ...@@ -8,6 +8,9 @@ import { BizError } from '../util/bizError';
import { ERRORENUM } from '../config/errorEnum'; import { ERRORENUM } from '../config/errorEnum';
import { max } from 'moment'; import { max } from 'moment';
import { title } from 'process'; import { title } from 'process';
import { TABLENAME } from '../config/dbEnum';
import { selectDataListByParam, selectOneDataByParam } from '../data/findData';
import { controlIndoorUnit } from './feiyiClient';
/** /**
* 运行分析 * 运行分析
...@@ -277,6 +280,220 @@ export async function getAnalysisPopup() { ...@@ -277,6 +280,220 @@ export async function getAnalysisPopup() {
} }
/** /**
* 环境态势感知
* @returns 今日环境监测数据
*/
export async function getRunEnvironmental() {
// 一、环境数据总览
let hjsjzl = {
"temperature": {
"current": 24.5,
"environmental": "良",
"zrtb": "+1.2%",
"max": 32,
"min": 12
},
"humidity": {
"current": 55,
"environmental": "中",
"zrtb": "+1.2%",
"max": 80,
"min": 10
},
"pm25": {
"current": 0,
"environmental": "优",
"zrtb": "+1.2%",
"max": 0.22
},
"co2": {
"current": 800,
"environmental": "优",
"zrtb": "+1.2%",
"max": 0.22,
"min": 10
},
"hcho": {
"current": 0,
"environmental": "优",
"zrtb": "+1.2%",
"max": 0.08
},
"lightLevel": {
"current": 0,
"environmental": "差",
"zrtb": "+1.2%",
"max": 1,
"min": 0
},
"tvoc": {
"current": 2,
"environmental": "优",
"zrtb": "+1.2%",
"max": 10,
"min": 0
},
};
// 二、环境参数趋势对比分析
let hjqsdbfx = {
"wd": {
"jr": [{
"key": "06:00",
"value": 16
}, {
"key": "12:00",
"value": 26
}, {
"key": "18:00",
"value": 18
}],
"zr": [{
"key": "06:00",
"value": 18
}, {
"key": "12:00",
"value": 24
}, {
"key": "18:00",
"value": 20
}],
"bz": [{
"key": "2026-07-06",
"value": 25
}, {
"key": "2026-07-07",
"value": 22
}, {
"key": "2026-07-08",
"value": 24
}, {
"key": "2026-07-09",
"value": 23
}],
"by": [{
"key": "2026-07-06",
"value": 25
}, {
"key": "2026-07-07",
"value": 22
}, {
"key": "2026-07-08",
"value": 24
}, {
"key": "2026-07-09",
"value": 23
}],
},
"sd": {},
"pm25": {},
"co2": {},
"tvoc": {},
"hcho": {},
"hyl": {},
"gz": {
"jr": [{
"key": "06:00",
"value": 0
}, {
"key": "12:00",
"value": 1
}, {
"key": "18:00",
"value": 0
}],
"zr": [{
"key": "06:00",
"value": 0
}, {
"key": "12:00",
"value": 1
}, {
"key": "18:00",
"value": 1
}],
"bz": [{
"key": "2026-07-06",
"value": 0.2
}, {
"key": "2026-07-07",
"value": 0.8
}, {
"key": "2026-07-08",
"value": 0.5
}, {
"key": "2026-07-09",
"value": 0.6
}],
"by": [{
"key": "2026-07-06",
"value": 0.2
}, {
"key": "2026-07-07",
"value": 0.8
}, {
"key": "2026-07-08",
"value": 0.5
}, {
"key": "2026-07-09",
"value": 0.6
}],
},
"zy": {},
};
// 三、场景设备监测明细
let cjsbjcmx = {
"titleList": ["场景点位","状态","更新时间","温度","湿度","pm2.5","co2","tvoc","甲醛","含氧量","光照","噪音"],
"dataList": [{
"regionName": "卫生间",
"deviceStatus": "部分在线",
"updateTime": "2026-07-09 06:00:00",
"wd": 17,
"sd": 0,
"pm25": 1000,
"co2": 800,
"tvoc": 8,
"hcho": 0.8,
"hyl": 0,
"gz": 1,
"zy": 0
},{
"regionKey": "2002",
"regionName": "仓库",
"deviceStatus": "离线",
"updateTime": "2026-07-09 12:00:00",
"wd": 16,
"sd": 0,
"pm25": 1000,
"co2": 800,
"tvoc": 8,
"hcho": 0.8,
"hyl": 0,
"gz": 0,
"zy": 0
},{
"regionName": "前台",
"deviceStatus": "在线",
"updateTime": "2026-07-09 18:00:00",
"wd": 18,
"sd": 0,
"pm25": 1000,
"co2": 800,
"tvoc": 8,
"hcho": 0.8,
"hyl": 0,
"gz": 1,
"zy": 0
}],
};
let ret = {
hjsjzl: hjsjzl,
hjqsdbfx: hjqsdbfx,
cjsbjcmx: cjsbjcmx
};
return ret;
}
/**
* 智能监控 * 智能监控
* @returns 大屏所需的所有指标数据 * @returns 大屏所需的所有指标数据
*/ */
...@@ -401,12 +618,14 @@ export async function getMonitorPopup() { ...@@ -401,12 +618,14 @@ export async function getMonitorPopup() {
{ {
"deviceId": "8-1-0-2", "deviceId": "8-1-0-2",
"deviceName": "空调内机8-1-0-2", "deviceName": "空调内机8-1-0-2",
"deviceType": "空调",
"status": 0, "status": 0,
"parameter": "8-1-0-2", "parameter": "8-1-0-2",
"monitoringData": "" "monitoringData": ""
},{ },{
"deviceId": "24E124710E466083", "deviceId": "24E124710E466083",
"deviceName": "环境监测cgq6", "deviceName": "环境监测cgq6",
"deviceType": "IEQ传感器",
"status": 0, "status": 0,
"parameter": "‌o3,co2,hpa,pir,hcho,pm10,pm25,tvoc,humidity,lighting,pressure,temperature", "parameter": "‌o3,co2,hpa,pir,hcho,pm10,pm25,tvoc,humidity,lighting,pressure,temperature",
"monitoringData": "10、2000、1260、5、1.25、1000、1000、500、100、L5、5000、60" "monitoringData": "10、2000、1260、5、1.25、1000、1000、500、100、L5、5000、60"
...@@ -433,6 +652,74 @@ export async function controlDeviceRunning(params: { ...@@ -433,6 +652,74 @@ export async function controlDeviceRunning(params: {
return { isSuccess: false }; return { isSuccess: false };
} }
/**
* 智能管控-空调设备运行弹窗
* @param regionKey
* @param deviceId
*/
export async function getAcRunningPop(regionKey: string, deviceId: string) {
// 获取设备信息
let devices = await selectDataListByParam(
TABLENAME.设备表,
{ region_key: regionKey, device_id: deviceId },
["device_id", "device_type", "device_name", "device_param"]
);
if (!devices.data.length) {
throw new BizError(ERRORENUM.未找到数据, `设备 ${deviceId} 在区域 ${regionKey} 中未找到`);
}
// 获取设备最新数据
let deviceData = await selectDataListByParam(
TABLENAME.设备数据表,
{ device_id: deviceId, "%orderDesc%": "device_time", "%limit%": 1 },
["device_data", "device_time"]
);
return {
deviceInfo: devices.data[0].device_param,
latestData: deviceData.data.length ? deviceData.data[0].device_data : null
}
}
/**
* 设备运行弹框 - 空调启停
* @param deviceId
*/
export async function controlAcRunning(params: {}) {
let deviceId = params["deviceId"];
let mode = params["mode"];
let power = params["power"] || "on";
let setTemp = params["setTemp"];
let maxTemp = params["maxTemp"] || 30; // 默认锁定温度上限
let minTemp = params["minTemp"] || 16; // 默认锁定温度下限
let autoControl = params["autoControl"] || "生效";
let fanSpeed = params["fanSpeed"];
// 1. 通过设备信息,获取内机地址
let device = await selectOneDataByParam(
TABLENAME.设备表,
{ device_id: deviceId },
["id", "device_id", "region_key", "device_name", "device_param"]
);
if (!device.data || !device.data.id) {
throw new BizError(ERRORENUM.未找到数据, `设备 ${deviceId} 未注册`);
}
// 2. 接入空调控制API,更新空调设备信息
let acPrarms = {
"indoorUnitAddressFull": [deviceId],
"workMode": acDeviceKeyMap[mode],
"onOff": acDeviceKeyMap[power],
"tempSet": Number(setTemp),
"fanSpeed": acDeviceKeyMap[fanSpeed],
"onOffLock": acDeviceKeyMap[autoControl],
"workModeLock": acDeviceKeyMap[autoControl],
"tempSetLock": acDeviceKeyMap[autoControl],
"tempSetLo": Number(minTemp),
"tempSetHi": Number(maxTemp),
"openApiAction": autoControl === "生效" ? "control" : "lock"
};
// return await controlIndoorUnit(acPrarms);
return { isSuccess: false };
}
let deviceTypeList: string[] = [ let deviceTypeList: string[] = [
"IEQ传感器", "IEQ传感器",
"烟感器", "烟感器",
...@@ -444,4 +731,25 @@ let deviceTypeList: string[] = [ ...@@ -444,4 +731,25 @@ let deviceTypeList: string[] = [
"人流监测", "人流监测",
"电表", "电表",
"排风" "排风"
] ]
\ No newline at end of file
/**
* 空调中文到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,
"解除": 1,
"生效": 0
}
\ No newline at end of file
...@@ -271,7 +271,7 @@ export const TablesConfig = [ ...@@ -271,7 +271,7 @@ export const TablesConfig = [
allowNull: true, allowNull: true,
comment: '设备数据(JSON格式存储,数据在设备参数定义范围内)' comment: '设备数据(JSON格式存储,数据在设备参数定义范围内)'
}, },
push_time: { device_time: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false, allowNull: false,
comment: '推送时间' comment: '推送时间'
...@@ -321,16 +321,41 @@ export const TablesConfig = [ ...@@ -321,16 +321,41 @@ export const TablesConfig = [
allowNull: false, allowNull: false,
comment: '日期' comment: '日期'
}, },
ac_controls: {
type: Sequelize.STRING(50),
allowNull: false,
comment: '操作状态:off关on开'
},
todo_item: { todo_item: {
type: DataTypes.JSON, type: DataTypes.JSON,
allowNull: true, allowNull: true,
comment: '待办事项(JSON格式存储)' comment: '待办事项,除了开关以外可以设定模式、温度等。例:{"温度":"24.5","模式":"制冷","风速":"低风"}'
}, },
schedule_time: { schedule_time: {
type: DataTypes.DATE, type: Sequelize.STRING(50),
allowNull: true, allowNull: true,
comment: '定时时间' comment: '定时时间'
}, },
set_conditions: {
type: DataTypes.JSON,
allowNull: true,
comment: '设定条件,除了定时以外可以通过条件开启或关闭设备。例:{"温度":"≤26&≥22"}'
},
begin_validity: {
type: DataTypes.DATE,
allowNull: true,
comment: '有效时间起,不设置则为空'
},
end_validity: {
type: DataTypes.DATE,
allowNull: true,
comment: '有效时间止,不设置则为空'
},
outward_time: {
type: Sequelize.STRING(200),
allowNull: true,
comment: '有效除外时间,多个通过逗号分隔'
},
created_at: { created_at: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false, allowNull: false,
......
...@@ -11,12 +11,18 @@ export function setRouter(httpServer) { ...@@ -11,12 +11,18 @@ export function setRouter(httpServer) {
httpServer.post('/api/dq/run/analysis', asyncHandler(getRunAnalysis)); httpServer.post('/api/dq/run/analysis', asyncHandler(getRunAnalysis));
/** 运行分析弹窗 */ /** 运行分析弹窗 */
httpServer.post('/api/dq/run/analysis/popup', asyncHandler(getAnalysisPopup)); httpServer.post('/api/dq/run/analysis/popup', asyncHandler(getAnalysisPopup));
/** 环境态势感知 */
httpServer.post('/api/dq/run/analysis/environmental', asyncHandler(getRunEnvironmental));
/** 智能监控 */ /** 智能监控 */
httpServer.post('/api/dq/run/monitoring', asyncHandler(getRunMonitoring)); httpServer.post('/api/dq/run/monitoring', asyncHandler(getRunMonitoring));
/** 智能监控弹窗 */ /** 智能监控弹窗 */
httpServer.post('/api/dq/run/monitor/popup', asyncHandler(getMonitorPopup)); httpServer.post('/api/dq/run/monitor/popup', asyncHandler(getMonitorPopup));
/** 控制设备运行 */ /** 控制设备运行 */
httpServer.post('/api/dq/run/device/running', asyncHandler(controlDeviceRunning)); httpServer.post('/api/dq/run/device/running', asyncHandler(controlDeviceRunning));
/** 空调运行弹窗 */
httpServer.post('/api/dq/run/monitor/acPop', asyncHandler(getAcRunningPop));
/** 空调运行控制 */
httpServer.post('/api/dq/run/monitor/acRun', asyncHandler(controlAcRunning));
} }
/** /**
...@@ -38,6 +44,15 @@ async function getAnalysisPopup(req, res) { ...@@ -38,6 +44,15 @@ async function getAnalysisPopup(req, res) {
} }
/** /**
* 环境态势感知
*/
async function getRunEnvironmental(req, res) {
const { } = req.body;
const result = await runningBiz.getRunEnvironmental();
res.success(result);
}
/**
* 智能监控 * 智能监控
*/ */
async function getRunMonitoring(req, res) { async function getRunMonitoring(req, res) {
...@@ -62,9 +77,32 @@ async function getMonitorPopup(req, res) { ...@@ -62,9 +77,32 @@ async function getMonitorPopup(req, res) {
* @param res * @param res
*/ */
async function controlDeviceRunning(req, res) { async function controlDeviceRunning(req, res) {
let reqConf = {deviceId:'String', deviceType:'String', status:'Number'}; let reqConf = { deviceId:'String', deviceType:'String', status:'Number' };
const NotMustHaveKeys = [ "deviceType" ]; const NotMustHaveKeys = [ "deviceType" ];
let params = eccReqParamater(reqConf, req.body, NotMustHaveKeys); let params = eccReqParamater(reqConf, req.body, NotMustHaveKeys);
const result = await runningBiz.controlDeviceRunning(params); const result = await runningBiz.controlDeviceRunning(params);
res.success(result); res.success(result);
}
/**
* 空调运行弹框
*/
async function getAcRunningPop(req, res) {
let reqConf = {regionKey:'String', deviceId:'String'};
const NotMustHaveKeys = [];
let { regionKey, deviceId } = eccReqParamater(reqConf, req.body, NotMustHaveKeys);
const result = await runningBiz.getAcRunningPop(regionKey, deviceId);
res.success(result);
}
/**
* 控制空调运行
*/
async function controlAcRunning(req, res) {
let reqConf = {deviceId:'String', mode:'String', power:'String', setTemp:'String', maxTemp:'String', minTemp:'String', autoControl:'String', fanSpeed:'String', regionKey:"String"};
const NotMustHaveKeys = [ 'power', 'maxTemp', 'minTemp', 'autoControl', 'regionKey' ];
let { deviceId, mode, power, setTemp, maxTemp, minTemp, autoControl, fanSpeed, regionKey } = eccReqParamater(reqConf, req.body, NotMustHaveKeys);
let params = { deviceId, mode, power, setTemp, maxTemp, minTemp, autoControl, fanSpeed, regionKey };
const result = await runningBiz.controlAcRunning(params);
res.success(result);
} }
\ No newline at end of file
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