Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniZeroHall
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
node_server
uniZeroHall
Commits
a617ca57
Commit
a617ca57
authored
Jun 04, 2026
by
PC-20251223ZVQQ\Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
企业信息和智能监控
parent
89246caf
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
192 additions
and
8 deletions
+192
-8
serverConfig.xml
serverConfig.xml
+6
-0
device.ts
src/biz/device.ts
+145
-7
serverConfig.ts
src/config/serverConfig.ts
+11
-0
systemClass.ts
src/config/systemClass.ts
+7
-1
device.ts
src/routers/device.ts
+23
-0
No files found.
serverConfig.xml
View file @
a617ca57
...
@@ -16,4 +16,10 @@
...
@@ -16,4 +16,10 @@
<mysqlPwd>qaz123456</mysqlPwd>
<mysqlPwd>qaz123456</mysqlPwd>
<dataBase>unicarbon_platform</dataBase> -->
<dataBase>unicarbon_platform</dataBase> -->
</mysqldb>
</mysqldb>
<compInfo>
<history>
22年
</history>
<employee>
200+
</employee>
<technical>
80+
</technical>
<area>
16000㎡
</area>
</compInfo>
</config>
</config>
src/biz/device.ts
View file @
a617ca57
import
{
selectOneDataByParam
,
selectDataListByParam
,
selectPaginatedDataWithOrder
}
from
"../data/findData"
;
import
{
selectOneDataByParam
,
selectDataListByParam
,
selectPaginatedDataWithOrder
}
from
"../data/findData"
;
import
{
TABLENAME
}
from
"../config/dbEnum"
;
import
{
TABLENAME
}
from
"../config/dbEnum"
;
import
{
getMySqlMs
}
from
"../tools/systemTools"
;
import
{
getMySqlMs
}
from
"../tools/systemTools"
;
import
{
systemConfig
}
from
"../config/serverConfig"
;
import
{
BizError
}
from
"../util/bizError"
;
import
{
BizError
}
from
"../util/bizError"
;
import
{
ERRORENUM
}
from
"../config/errorEnum"
;
import
{
ERRORENUM
}
from
"../config/errorEnum"
;
import
{
addData
}
from
"../data/addData"
;
import
{
addData
}
from
"../data/addData"
;
import
{
updateManyData
}
from
"../data/updateData"
;
import
{
updateManyData
}
from
"../data/updateData"
;
import
{
region
}
from
"tencentcloud-sdk-nodejs"
;
/**
/**
...
@@ -198,9 +200,9 @@ export async function getRunAnalysis() {
...
@@ -198,9 +200,9 @@ export async function getRunAnalysis() {
let
yesterdayEnergy
=
await
getTotalEnergy
(
energyDeviceIds
,
yesterdayStart
,
yesterdayEnd
);
let
yesterdayEnergy
=
await
getTotalEnergy
(
energyDeviceIds
,
yesterdayStart
,
yesterdayEnd
);
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
)
;
// 3. 用电趋势:过去24小时(按小时)、过去7天、过去30天、过去一年(按月)
// 3. 用电趋势:过去24小时(按小时)、过去7天、过去30天、过去一年(按月)
let
now
=
new
Date
();
let
now
=
new
Date
();
...
@@ -357,11 +359,11 @@ export async function getRunAnalysis() {
...
@@ -357,11 +359,11 @@ export async function getRunAnalysis() {
return {
return {
energyManagement: {
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
},
},
electricityTrend: {
electricityTrend: {
...
@@ -771,6 +773,129 @@ function isOnline(receivedTime: string | undefined): boolean {
...
@@ -771,6 +773,129 @@ function isOnline(receivedTime: string | undefined): boolean {
return diffMinutes <= 30;
return diffMinutes <= 30;
}
}
/**
* 获取智能监控数据
* @returns 设备在线状态、空气质量监测、设备监测详情
*/
export async function getSmartMonitor() {
// 设备运行基础数据
let allDevices = await selectDataListByParam(TABLENAME.设备表, {}, ["device_type", "device_id"]);
let totalDevices = allDevices.data.length;
let runningDevices = totalDevices;
let faultRecords = await selectDataListByParam(
TABLENAME.设备故障表,
{ status: { "%ne%": 2 } },
["device_id"]
);
let faultDeviceIds = new Set(faultRecords.data.map((r: any) => r.device_id));
let faultDevices = faultDeviceIds.size;
let normalRate = totalDevices === 0 ? '100%' : (((totalDevices - faultDevices) / totalDevices) * 100).toFixed(2) + '%';
// 智能监测情况、故障原因分析和运维处置状态(模拟数据,待接入真实告警表)
let monitorStatus = {
level1: 5,
level2: 10,
level3: 15,
dataList: [{
regionKey: 1,
regionName: "多功能商务包厢",
fault: 20
}, {
regionKey: 2,
regionName: "多功能商务包厢卫生间",
fault: 35
}]
};
let faultReason = [
{ reason: "设备老化", count: 20 },
{ reason: "环境因素", count: 15 },
{ reason: "操作失误", count: 10 },
{ reason: "软件问题", count: 5 }
];
let faultList = [
{ riskContent: "空调压缩机异常", alertTime: "26/02/01", regionKey: 1, regionName: "多功能商务包厢", deviceId: "ac_01", status: "已解决" },
{ riskContent: "温度传感器离线", alertTime: "26/02/01", regionKey: 1, regionName: "多功能商务包厢", deviceId: "temp_sensor_01", status: "已响应" },
{ riskContent: "湿度超标", alertTime: "26/02/02", regionKey: 2, regionName: "多功能商务包厢卫生间", deviceId: "humidity_sensor_01", status: "未处理" }
];
let processStatus = {
processing: 1, // 处理中
pending: 1, // 待处理
processed: 1, // 已处理
dataList: faultList
};
// 环境监测
let nowTime = new Date();
let airQualityDevices = await selectDataListByParam(TABLENAME.设备表, { device_type: "空气质量传感" }, ["device_id"]);
let airDeviceIds = airQualityDevices.data.map(d => d.device_id);
let qualityIndex = 300;
let co2Trend = [];
let currentCo2 = '21ppm';
let currentTemperature = '21℃';
let temperatureTrend = [];
let currentHumidity = '47%';
let humidityTrend = [];
let currentPm25 = '21μg/m³';
let pm25Trend = [];
let co2TrendDetail = [];
if (airDeviceIds.length) {
let latestAir = await selectDataListByParam(TABLENAME.设备数据表, {
device_id: { "%in%": airDeviceIds },
"%orderDesc%": "received_time",
"%limit%": 1
}, ["data"]);
if (latestAir.data.length) {
let airData = parseDeviceData(latestAir.data[0].data);
currentTemperature = `
$
{
airData
?.
temperature
??
21
}
℃
`;
currentHumidity = `
$
{
airData
?.
humidity
??
47
}
%
`;
currentPm25 = `
$
{
airData
?.
pm25
??
21
}
μ
g
/
m
³
`;
currentCo2 = `
$
{
airData
?.
co2
??
400
}
ppm
`;
qualityIndex = 500 - (airData?.pm25 ?? 0);
}
// 过去24小时趋势
let last24h = new Date(nowTime.getTime() - 24*3600000);
let airHistory = await selectDataListByParam(TABLENAME.设备数据表, {
device_id: { "%in%": airDeviceIds },
received_time: { "%gte%": last24h.toISOString().slice(0,19).replace('T',' ') }
}, ["data", "received_time"]);
let hourlyData = new Map();
for (let rec of airHistory.data) {
let d = new Date(rec.received_time);
let hourKey = `
$
{
d
.
getHours
()}
时
`;
let data = parseDeviceData(rec.data);
if (!hourlyData.has(hourKey)) {
hourlyData.set(hourKey, { temp: data?.temperature, hum: data?.humidity, pm: data?.pm25, co2: data?.co2 });
}
}
for (let i = 0; i < 24; i++) {
let key = `
$
{
i
}
时
`;
let val = hourlyData.get(key);
temperatureTrend.push({ time: `
$
{
i
}:
00
`, value: val?.temp?.toString() ?? '21' });
humidityTrend.push({ time: `
$
{
i
}:
00
`, value: val?.hum?.toString() ?? '47' });
pm25Trend.push({ time: `
$
{
i
}:
00
`, value: val?.pm?.toString() ?? '21' });
let co2Val = val?.co2 ?? 400;
co2TrendDetail.push({ time: `
$
{
i
}:
00
`, value: (co2Val / 100).toFixed(1) });
co2Trend.push({ time: `
$
{
i
}
时
`, value: co2Val.toString() });
}
}
return {
summaryData: {
runningDevices,
normalRate,
faultDevices
},
monitorStatus,
faultReason,
processStatus,
temperatureTrend,
humidityTrend,
pm25Trend,
co2Trend
};
}
/**
/**
* 获取智能监控弹窗数据
* 获取智能监控弹窗数据
...
@@ -938,6 +1063,19 @@ export async function getSmartMonitorPop(regionKey: string) {
...
@@ -938,6 +1063,19 @@ export async function getSmartMonitorPop(regionKey: string) {
};
};
}
}
/**
* 获取企业信息
* @returns
*/
export async function getCompanyInfo() {
// Implementation for fetching company information
return {
history: systemConfig.compInfo.history,
employee: systemConfig.compInfo.employee,
technical: systemConfig.compInfo.technical,
area: systemConfig.compInfo.area
};
}
/**
/**
* 获取所有区域列表(供前端下拉选择)
* 获取所有区域列表(供前端下拉选择)
...
...
src/config/serverConfig.ts
View file @
a617ca57
...
@@ -37,6 +37,17 @@ export async function initConfig() {
...
@@ -37,6 +37,17 @@ export async function initConfig() {
}
}
}
}
// 企业信息配置
if
(
configInfo
.
config
.
compInfo
)
{
let
compInfo
=
configInfo
.
config
.
compInfo
[
0
];
systemConfig
.
compInfo
=
{
employee
:
compInfo
.
employee
?
compInfo
.
employee
[
0
]
:
""
,
history
:
compInfo
.
history
?
compInfo
.
history
[
0
]
:
""
,
technical
:
compInfo
.
technical
?
compInfo
.
technical
[
0
]
:
""
,
area
:
compInfo
.
area
?
compInfo
.
area
[
0
]
:
""
};
}
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
'ERROR => 服务器配置解析错误 请检查根目录下 serverConfig.xml 文件是否正确'
);
console
.
log
(
'ERROR => 服务器配置解析错误 请检查根目录下 serverConfig.xml 文件是否正确'
);
console
.
log
(
err
);
console
.
log
(
err
);
...
...
src/config/systemClass.ts
View file @
a617ca57
...
@@ -15,5 +15,10 @@ export class ServerConfig {
...
@@ -15,5 +15,10 @@ export class ServerConfig {
pwd
:
string
,
pwd
:
string
,
dataBase
:
string
,
dataBase
:
string
,
}
}
compInfo
:{
history
:
string
,
employee
:
string
,
technical
:
string
,
area
:
string
,
}
}
}
\ No newline at end of file
src/routers/device.ts
View file @
a617ca57
...
@@ -22,8 +22,14 @@ export function setRouter(httpServer) {
...
@@ -22,8 +22,14 @@ export function setRouter(httpServer) {
/**运行分析-弹窗 */
/**运行分析-弹窗 */
httpServer
.
post
(
'/api/zc/run/analysis/pop'
,
asyncHandler
(
getRunAnalysisPop
));
httpServer
.
post
(
'/api/zc/run/analysis/pop'
,
asyncHandler
(
getRunAnalysisPop
));
/** 智能监控 */
httpServer
.
post
(
'/api/zc/smart/monitor'
,
asyncHandler
(
getSmartMonitor
));
/** 智能监控-弹窗 */
/** 智能监控-弹窗 */
httpServer
.
post
(
'/api/zc/smart/monitor/pop'
,
asyncHandler
(
getSmartMonitorPop
));
httpServer
.
post
(
'/api/zc/smart/monitor/pop'
,
asyncHandler
(
getSmartMonitorPop
));
/** 企业信息 */
httpServer
.
post
(
'/api/zc/company/info'
,
asyncHandler
(
getCompanyInfo
));
}
}
...
@@ -86,6 +92,14 @@ async function deviceFaultPush(req, res) {
...
@@ -86,6 +92,14 @@ async function deviceFaultPush(req, res) {
res
.
success
(
result
);
res
.
success
(
result
);
}
}
/**
* 智能监控
*/
async
function
getSmartMonitor
(
req
,
res
)
{
const
{
}
=
req
.
body
;
const
result
=
await
deviceBiz
.
getSmartMonitor
();
res
.
success
(
result
);
}
/**
/**
* 智能监控-弹窗
* 智能监控-弹窗
...
@@ -98,6 +112,15 @@ async function getSmartMonitorPop(req, res) {
...
@@ -98,6 +112,15 @@ async function getSmartMonitorPop(req, res) {
res
.
success
(
result
);
res
.
success
(
result
);
}
}
/**
* 企业信息
*/
async
function
getCompanyInfo
(
req
,
res
)
{
const
{
}
=
req
.
body
;
const
result
=
await
deviceBiz
.
getCompanyInfo
();
res
.
success
(
result
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment