模拟数据

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
...@@ -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