Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
qingdaoMuseumPlatform
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
qingdaoMuseumPlatform
Commits
d7ed4a95
Commit
d7ed4a95
authored
May 22, 2026
by
PC-20251223ZVQQ\Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
一级、二级、三级页面数据展示
parent
a11cbed3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
11 deletions
+109
-11
region.ts
src/biz/region.ts
+76
-4
mysqlTableConfig.ts
src/config/mysqlTableConfig.ts
+8
-0
device.ts
src/routers/device.ts
+25
-7
No files found.
src/biz/region.ts
View file @
d7ed4a95
...
...
@@ -88,12 +88,13 @@ export async function handleDevicePush(deviceId: string, data: any, deviceTime?:
* 处理设备商推送的故障数据
* @param deviceId 设备唯一标识(必填)
* @param faultType 故障类型(必填),如“离线”“数据异常”“硬件故障”
* @param faultLevel 故障等级
* @param faultDescription 故障详细描述(可选)
* @param occurredTime 故障发生时间(可选),格式:YYYY-MM-DD HH:MM:SS,不传则使用服务器时间
* @returns {Promise<{faultId: number}>} 返回新插入故障记录的ID
* @throws 如果设备未注册,则抛出错误
*/
export
async
function
handleDeviceFaultPush
(
deviceId
:
string
,
faultType
:
string
,
faultDescription
?:
string
,
occurredTime
?:
string
)
{
export
async
function
handleDeviceFaultPush
(
deviceId
:
string
,
faultType
:
string
,
fault
Level
:
string
,
fault
Description
?:
string
,
occurredTime
?:
string
)
{
if
(
!
deviceId
||
!
faultType
)
{
throw
new
BizError
(
ERRORENUM
.
参数错误
,
"deviceId 和 faultType 不能为空"
);
}
...
...
@@ -115,6 +116,7 @@ export async function handleDeviceFaultPush( deviceId: string, faultType: string
fault_type
:
faultType
,
fault_description
:
faultDescription
||
null
,
occurred_time
:
faultTime
,
level
:
faultLevel
||
'1'
,
// 默认一级故障
status
:
0
,
// 0=未处理
resolved_time
:
null
,
created_at
:
nowStr
,
...
...
@@ -130,7 +132,7 @@ export async function handleDeviceFaultPush( deviceId: string, faultType: string
* @param regionType 区域类型(可选),如“A馆”,如果提供则返回该类型下所有区域的分析数据
* @returns 大屏所需的所有指标数据
*/
export
async
function
getRunAnalysis
(
regionKey
:
String
,
regionType
:
S
tring
)
{
export
async
function
getRunAnalysis
(
regionKey
:
number
,
regionType
:
s
tring
)
{
// 根据区域类型和名称筛选设备ID列表(如果提供了区域信息)
let
regionKeys
:
any
=
[];
...
...
@@ -486,8 +488,13 @@ export async function getRunAnalysis(regionKey: String, regionType: String) {
}
}
// 7.1 获取区域列表接口,供前端下拉选择区域类型和区域名称
let regionList: any = await getRegionList(regionType);
// 最终组装返回数据
return {
// 区域列表数据
regionList: regionList.data,
// 运行监控总数据(一年)
mainRunningManagement: {
totalCustomerNumber: 10000,
...
...
@@ -546,6 +553,33 @@ export async function getRunAnalysis(regionKey: String, regionType: String) {
}
}
/**
* 智能管控-空调设备运行弹框
* @param regionKey
* @param deviceId
*/
export async function getAcRunningPop(regionKey: number, deviceId: string) {
// 获取设备信息
let devices = await selectDataListByParam(
TABLENAME.设备表,
{ region_key: regionKey, device_id: deviceId },
["device_id", "device_type", "device_name", "control_params"]
);
if (!devices.data.length) {
throw new BizError(ERRORENUM.未找到数据, `
设备
$
{
deviceId
}
在区域
$
{
regionKey
}
中未找到
`);
}
// 获取设备最新数据
let deviceData = await selectDataListByParam(
TABLENAME.设备数据表,
{ device_id: deviceId, "%orderDesc%": "received_time", "%limit%": 1 },
["data", "received_time"]
);
return {
deviceInfo: devices.data[0].control_params,
latestData: deviceData.data.length ? deviceData.data[0].data : null
}
}
// 辅助函数:获取用电趋势(按间隔分组)
async function getEnergyTrend(deviceIds: string[], startTime: Date, endTime: Date, granularity: 'hour' | 'day' | 'month') {
if (deviceIds.length === 0) return [];
...
...
@@ -596,6 +630,38 @@ async function getEnergyTrend(deviceIds: string[], startTime: Date, endTime: Dat
return result;
}
// 基于馆内环境温度、湿度变化等,联动空调启停
async function controlAcByEnvironment(deviceId: string, data: any) {
// 获取区域内环境监测设备数据
let envDevices = await selectDataListByParam(TABLENAME.设备表, {
device_id: deviceId,
device_type: "环境监测"
}, ["id", "device_name", "region_key"]);
// 若是环境设备,则解析环境设备数据,判断是否需要联动空调设备
if (envDevices.data.length) {
// 通过设备所属区域查询当前区域中的空调设备,获取空调设备标准参数中预设的温度、湿度阈值
let regionKey = envDevices.data[0].region_key;
let acDevices = await selectDataListByParam(TABLENAME.设备表, {
region_key: regionKey,
device_type: "空调"
}, ["id", "device_name", "control_params"]);
acDevices.data.forEach((ac: any) => {
let controlParams = ac.control_params;
let maxTemp = controlParams.maxTemp;
let minTemp = controlParams.minTemp;
if (data.temperature && (data.temperature > maxTemp || data.temperature < minTemp)){
// 调用空调控制接口启停空调设备
console.log(`
联动空调
$
{
ac
.
device_name
}
(
$
{
ac
.
id
}
)启停,当前温度:
$
{
data
.
temperature
}
,阈值范围:
$
{
minTemp
}
-
$
{
maxTemp
}
`);
// 单个 TODO: 接入空调控制API,传入设备ID和控制指令(如开/关、温度设定等)
}
});
// 多个 TODO: 接入空调控制API,传入设备ID和控制指令(如开/关、温度设定等)
return { success: true, message: "成功" };
}
}
/**
* 设备类型中文到英文Key的映射
*/
...
...
@@ -620,9 +686,15 @@ let deviceTypeKeyMap: { [key: string]: string } = {
* 获取所有区域列表(供前端下拉选择)
* @returns 区域列表,按 sort_order 排序
*/
export async function getRegionList() {
export async function getRegionList( regionType: string ) {
let where: any = { "%orderAsc%": "sort_order" };
if (regionType) {
where.type = regionType;
}
let regionList = await selectDataListByParam(
TABLENAME.区域表, { }
TABLENAME.区域表,
where,
["id", "name", "type"],
);
let regionMap: any = {};
...
...
src/config/mysqlTableConfig.ts
View file @
d7ed4a95
import
{
level
}
from
"winston"
;
const
{
Sequelize
,
DataTypes
}
=
require
(
'sequelize'
);
export
const
TablesConfig
=
[
...
...
@@ -182,6 +184,12 @@ export const TablesConfig = [
allowNull
:
false
,
comment
:
'故障发生时间'
},
level
:
{
type
:
DataTypes
.
TINYINT
,
allowNull
:
false
,
defaultValue
:
0
,
comment
:
'故障等级:1=一级,2=二级,3=三级'
},
status
:
{
type
:
DataTypes
.
TINYINT
,
allowNull
:
false
,
...
...
src/routers/device.ts
View file @
d7ed4a95
...
...
@@ -21,8 +21,12 @@ export function setRouter(httpServer) {
/** 运行分析 */
httpServer
.
post
(
'/api/zc/run/analysis'
,
asyncHandler
(
getRunAnalysis
));
/** 运行分析 - 楼栋 */
httpServer
.
post
(
'/api/zc/run/analysis/building'
,
asyncHandler
(
getRunAnalysisByBuilding
));
/** 运行分析 - 楼层 */
httpServer
.
post
(
'/api/zc/run/analysis/Floor'
,
asyncHandler
(
getRunAnalysisByFloor
));
/** 空调运行弹框 */
httpServer
.
post
(
'/api/zc/run/monitor/acPop'
,
asyncHandler
(
getAcRunningPop
));
/**运行分析-弹窗 */
httpServer
.
post
(
'/api/zc/run/analysis/pop'
,
asyncHandler
(
getRunAnalysisPop
));
...
...
@@ -44,7 +48,10 @@ export function setRouter(httpServer) {
}
async
function
getRegionList
(
req
,
res
)
{
const
result
=
await
regionBiz
.
getRegionList
();
let
reqConf
=
{
regionType
:
'String'
};
const
NotMustHaveKeys
=
[];
let
{
regionType
}
=
eccReqParamater
(
reqConf
,
req
.
body
,
NotMustHaveKeys
);
const
result
=
await
regionBiz
.
getRegionList
(
regionType
);
res
.
success
(
result
);
}
...
...
@@ -66,11 +73,11 @@ async function deviceDataPush(req, res) {
* 设备商推送故障数据
*/
async
function
deviceFaultPush
(
req
,
res
)
{
let
reqConf
=
{
deviceId
:
'String'
,
faultType
:
'String'
,
faultDescription
:
'String'
,
occurredTime
:
'String'
};
let
reqConf
=
{
deviceId
:
'String'
,
faultType
:
'String'
,
fault
Level
:
'String'
,
fault
Description
:
'String'
,
occurredTime
:
'String'
};
const
NotMustHaveKeys
=
[
"faultDescription"
];
let
{
deviceId
,
faultType
,
faultDescription
,
occurredTime
}
=
eccReqParamater
(
reqConf
,
req
.
body
,
NotMustHaveKeys
);
let
{
deviceId
,
faultType
,
fault
Level
,
fault
Description
,
occurredTime
}
=
eccReqParamater
(
reqConf
,
req
.
body
,
NotMustHaveKeys
);
const
result
=
await
deviceBiz
.
handleDeviceFaultPush
(
deviceId
,
faultType
,
faultDescription
,
occurredTime
);
const
result
=
await
regionBiz
.
handleDeviceFaultPush
(
deviceId
,
faultType
,
faultLevel
,
faultDescription
,
occurredTime
);
res
.
success
(
result
);
}
...
...
@@ -80,7 +87,7 @@ async function deviceFaultPush(req, res) {
*/
async
function
getRunAnalysis
(
req
,
res
)
{
const
{
}
=
req
.
body
;
const
result
=
await
deviceBiz
.
getRunAnalysis
(
);
const
result
=
await
regionBiz
.
getRunAnalysis
(
0
,
""
);
res
.
success
(
result
);
}
...
...
@@ -91,7 +98,7 @@ async function deviceFaultPush(req, res) {
let
reqConf
=
{
regionType
:
'String'
};
const
NotMustHaveKeys
=
[];
let
{
regionType
}
=
eccReqParamater
(
reqConf
,
req
.
body
,
NotMustHaveKeys
);
const
result
=
await
regionBiz
.
getRunAnalysis
(
""
,
regionType
);
const
result
=
await
regionBiz
.
getRunAnalysis
(
0
,
regionType
);
res
.
success
(
result
);
}
...
...
@@ -99,7 +106,7 @@ async function deviceFaultPush(req, res) {
* 运行分析-楼层
*/
async
function
getRunAnalysisByFloor
(
req
,
res
)
{
let
reqConf
=
{
regionKey
:
'
String
'
};
let
reqConf
=
{
regionKey
:
'
Number
'
};
const
NotMustHaveKeys
=
[];
let
{
regionKey
}
=
eccReqParamater
(
reqConf
,
req
.
body
,
NotMustHaveKeys
);
const
result
=
await
regionBiz
.
getRunAnalysis
(
regionKey
,
""
);
...
...
@@ -107,6 +114,17 @@ async function deviceFaultPush(req, res) {
}
/**
* 空调运行弹框
*/
async
function
getAcRunningPop
(
req
,
res
)
{
let
reqConf
=
{
regionKey
:
'Number'
,
deviceId
:
'String'
};
const
NotMustHaveKeys
=
[];
let
{
regionKey
,
deviceId
}
=
eccReqParamater
(
reqConf
,
req
.
body
,
NotMustHaveKeys
);
const
result
=
await
regionBiz
.
getAcRunningPop
(
regionKey
,
deviceId
);
res
.
success
(
result
);
}
/**
* 运行分析-弹窗
*/
async
function
getRunAnalysisPop
(
req
,
res
)
{
...
...
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