Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dstTechnologyPlatform
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
dstTechnologyPlatform
Commits
af021737
Commit
af021737
authored
Jul 22, 2026
by
PC-20251223ZVQQ\Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口开发2
parent
8eb38c38
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
259 additions
and
17 deletions
+259
-17
serverConfig.ts
src/config/serverConfig.ts
+20
-2
systemClass.ts
src/config/systemClass.ts
+13
-0
diqinClient.ts
src/routers/diqinClient.ts
+94
-9
running.ts
src/routers/running.ts
+6
-4
dateUtils.ts
src/util/dateUtils.ts
+124
-0
request.ts
src/util/request.ts
+2
-2
No files found.
src/config/serverConfig.ts
View file @
af021737
const
path
=
require
(
'path'
)
;
import
path
from
"path"
;
import
*
as
fs
from
"fs"
;
import
*
as
fs
from
"fs"
;
import
{
BizError
}
from
"../util/bizError"
;
import
{
BizError
}
from
"../util/bizError"
;
import
{
analysisXml
}
from
"../util/myXML"
;
import
{
analysisXml
}
from
"../util/myXML"
;
...
@@ -16,7 +16,7 @@ export async function initConfig() {
...
@@ -16,7 +16,7 @@ export async function initConfig() {
if
(
!
configInfo
||
!
configInfo
.
config
)
throw
new
BizError
(
'xml中无配置'
);
if
(
!
configInfo
||
!
configInfo
.
config
)
throw
new
BizError
(
'xml中无配置'
);
let
{
port
,
sign
,
img
,
mysqldb
}
=
configInfo
.
config
;
let
{
port
,
sign
,
img
,
mysqldb
,
feiyi
,
diqin
}
=
configInfo
.
config
;
// 基本配置
// 基本配置
systemConfig
.
port
=
parseInt
(
port
[
0
]);
systemConfig
.
port
=
parseInt
(
port
[
0
]);
...
@@ -37,6 +37,24 @@ export async function initConfig() {
...
@@ -37,6 +37,24 @@ export async function initConfig() {
}
}
}
}
// 飞奕云平台配置
if
(
feiyi
)
{
let
feiyiConfig
=
feiyi
[
0
];
systemConfig
.
feiyi
=
{
appKey
:
''
,
secretKey
:
''
,
baseUrl
:
''
};
if
(
feiyiConfig
.
feiyiAppKey
)
systemConfig
.
feiyi
.
appKey
=
feiyiConfig
.
feiyiAppKey
[
0
];
if
(
feiyiConfig
.
feiyiSecretKey
)
systemConfig
.
feiyi
.
secretKey
=
feiyiConfig
.
feiyiSecretKey
[
0
];
if
(
feiyiConfig
.
feiyiBaseUrl
)
systemConfig
.
feiyi
.
baseUrl
=
feiyiConfig
.
feiyiBaseUrl
[
0
];
}
// 迪勤云平台配置
if
(
diqin
)
{
let
diqinConfig
=
diqin
[
0
];
systemConfig
.
diqin
=
{
appKey
:
''
,
secretKey
:
''
,
baseUrl
:
''
};
if
(
diqinConfig
.
diqinAppKey
)
systemConfig
.
diqin
.
appKey
=
diqinConfig
.
diqinAppKey
[
0
];
if
(
diqinConfig
.
diqinSecretKey
)
systemConfig
.
diqin
.
secretKey
=
diqinConfig
.
diqinSecretKey
[
0
];
if
(
diqinConfig
.
diqinBaseUrl
)
systemConfig
.
diqin
.
baseUrl
=
diqinConfig
.
diqinBaseUrl
[
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 @
af021737
...
@@ -15,4 +15,16 @@ export class ServerConfig {
...
@@ -15,4 +15,16 @@ export class ServerConfig {
pwd
:
string
,
pwd
:
string
,
dataBase
:
string
,
dataBase
:
string
,
}
}
/** 飞奕云平台配置 */
feiyi
:
{
appKey
:
string
;
secretKey
:
string
;
baseUrl
:
string
;
}
/** 迪勤云平台配置 */
diqin
:
{
appKey
:
string
;
secretKey
:
string
;
baseUrl
:
string
;
}
}
}
\ No newline at end of file
src/routers/diqinClient.ts
View file @
af021737
...
@@ -6,20 +6,106 @@ import * as diqinClientBiz from '../biz/diqinClient';
...
@@ -6,20 +6,106 @@ import * as diqinClientBiz from '../biz/diqinClient';
import
{
eccReqParamater
}
from
'../util/verificationParam'
;
import
{
eccReqParamater
}
from
'../util/verificationParam'
;
export
function
setRouter
(
httpServer
)
{
export
function
setRouter
(
httpServer
)
{
/** 获取环境设备数据(调试入口,综合接口) */
/** 获取环境监测数据 */
httpServer
.
post
(
'/api/dq/diqin/getProcessDevices'
,
asyncHandler
(
getProcessDevices
));
httpServer
.
post
(
'/api/dq/diqin/getProcessDevices'
,
asyncHandler
(
getProcessDevices
));
/** 场所列表 */
httpServer
.
post
(
'/api/dq/diqin/location/list'
,
asyncHandler
(
getLocationList
));
/** 场所明细 */
httpServer
.
post
(
'/api/dq/diqin/location/detail'
,
asyncHandler
(
getLocationDetail
));
/** 监测点明细 */
httpServer
.
post
(
'/api/dq/diqin/station/detail'
,
asyncHandler
(
getStationDetail
));
/** 设备列表 */
httpServer
.
post
(
'/api/dq/diqin/dataSource/list'
,
asyncHandler
(
getDataSourceList
));
/** 设备明细 */
httpServer
.
post
(
'/api/dq/diqin/dataSource/detail'
,
asyncHandler
(
getDataSourceDetail
));
/** 历史数据 */
httpServer
.
post
(
'/api/dq/diqin/reading/list'
,
asyncHandler
(
getReadingList
));
/** 图表数据 */
httpServer
.
post
(
'/api/dq/diqin/graph/data'
,
asyncHandler
(
getGraphData
));
}
}
/**
/**
* 获取环境
监测数据
* 获取环境
设备数据(调试入口,综合接口)
* @param page 当前页码,默认 1
* @param page 当前页码,默认 1
* @param limit 每页条数,默认 10
* @param limit 每页条数,默认 10
*/
*/
async
function
getProcessDevices
(
req
,
res
)
{
async
function
getProcessDevices
(
req
,
res
)
{
let
reqConf
=
{
page
:
'Number'
,
limit
:
'Number'
,
roomId
:
'String'
,
indoorUnitAddressFull
:
'String'
};
let
reqConf
=
{
page
:
'Number'
,
limit
:
'Number'
};
const
NotMustHaveKeys
=
[
"page"
,
"limit"
,
"roomId"
,
"indoorUnitAddressFull"
];
const
NotMustHaveKeys
=
[
"page"
,
"limit"
];
let
{
page
,
limit
}
=
eccReqParamater
(
reqConf
,
req
.
body
,
NotMustHaveKeys
);
const
result
=
await
diqinClientBiz
.
processDeviceData
(
page
,
limit
);
res
.
success
(
result
);
}
/**
* 场所列表
*/
async
function
getLocationList
(
req
,
res
)
{
const
result
=
await
diqinClientBiz
.
getLocations
();
res
.
success
(
result
);
}
/**
* 场所明细
* @param locationId 场所 ID
*/
async
function
getLocationDetail
(
req
,
res
)
{
let
reqConf
=
{
locationId
:
'String'
};
let
{
locationId
}
=
eccReqParamater
(
reqConf
,
req
.
body
,
[]);
const
result
=
await
diqinClientBiz
.
getLocationDetail
(
locationId
);
res
.
success
(
result
);
}
/**
* 监测点明细
* @param stationId 监测点 ID
*/
async
function
getStationDetail
(
req
,
res
)
{
let
reqConf
=
{
stationId
:
'String'
};
let
{
stationId
}
=
eccReqParamater
(
reqConf
,
req
.
body
,
[]);
const
result
=
await
diqinClientBiz
.
getStationDetail
(
stationId
);
res
.
success
(
result
);
}
/**
* 设备列表
*/
async
function
getDataSourceList
(
req
,
res
)
{
const
result
=
await
diqinClientBiz
.
getDataSources
();
res
.
success
(
result
);
}
/**
* 设备明细
* @param dataSourceId 设备 ID
*/
async
function
getDataSourceDetail
(
req
,
res
)
{
let
reqConf
=
{
dataSourceId
:
'String'
};
let
{
dataSourceId
}
=
eccReqParamater
(
reqConf
,
req
.
body
,
[]);
const
result
=
await
diqinClientBiz
.
getDataSourceDetail
(
dataSourceId
);
res
.
success
(
result
);
}
/**
* 历史数据
* @param params 查询参数(m, id, type, start, end 等)
*/
async
function
getReadingList
(
req
,
res
)
{
let
reqConf
=
{
m
:
'String'
,
id
:
'String'
};
const
NotMustHaveKeys
=
[
"m"
,
"id"
,
"type"
,
"start"
,
"end"
];
let
params
=
eccReqParamater
(
reqConf
,
req
.
body
,
NotMustHaveKeys
);
let
params
=
eccReqParamater
(
reqConf
,
req
.
body
,
NotMustHaveKeys
);
const
result
=
await
diqinClientBiz
.
processDeviceData
(
params
);
const
result
=
await
diqinClientBiz
.
getReadings
(
params
);
res
.
success
(
result
);
res
.
success
(
result
);
}
}
\ No newline at end of file
/**
* 图表数据
* @param params 查询参数(m, id, indicator, start, end 等)
*/
async
function
getGraphData
(
req
,
res
)
{
let
reqConf
=
{
m
:
'String'
,
id
:
'String'
};
const
NotMustHaveKeys
=
[
"m"
,
"id"
,
"indicator"
,
"start"
,
"end"
];
let
params
=
eccReqParamater
(
reqConf
,
req
.
body
,
NotMustHaveKeys
);
const
result
=
await
diqinClientBiz
.
getGraphs
(
params
);
res
.
success
(
result
);
}
src/routers/running.ts
View file @
af021737
...
@@ -38,8 +38,9 @@ export function setRouter(httpServer) {
...
@@ -38,8 +38,9 @@ export function setRouter(httpServer) {
* 运行分析弹窗
* 运行分析弹窗
*/
*/
async
function
getAnalysisPopup
(
req
,
res
)
{
async
function
getAnalysisPopup
(
req
,
res
)
{
const
{
}
=
req
.
body
;
let
reqConf
=
{
regionKey
:
'String'
};
const
result
=
await
runningBiz
.
getAnalysisPopup
();
let
{
regionKey
}
=
eccReqParamater
(
reqConf
,
req
.
body
);
const
result
=
await
runningBiz
.
getAnalysisPopup
(
regionKey
);
res
.
success
(
result
);
res
.
success
(
result
);
}
}
...
@@ -65,8 +66,9 @@ async function getRunMonitoring(req, res) {
...
@@ -65,8 +66,9 @@ async function getRunMonitoring(req, res) {
* 智能监控弹窗
* 智能监控弹窗
*/
*/
async
function
getMonitorPopup
(
req
,
res
)
{
async
function
getMonitorPopup
(
req
,
res
)
{
const
{
}
=
req
.
body
;
let
reqConf
=
{
regionKey
:
'String'
};
const
result
=
await
runningBiz
.
getMonitorPopup
();
let
{
regionKey
}
=
eccReqParamater
(
reqConf
,
req
.
body
);
const
result
=
await
runningBiz
.
getMonitorPopup
(
regionKey
);
res
.
success
(
result
);
res
.
success
(
result
);
}
}
...
...
src/util/dateUtils.ts
0 → 100644
View file @
af021737
/**
* 日期时间工具函数
* 统一项目中所有日期格式化、时间范围计算逻辑
*/
/** 格式化为本地时间:yyyy-MM-dd HH:mm:ss */
export
function
formatTime
(
date
:
Date
|
string
):
string
{
if
(
!
date
)
return
''
;
const
d
=
new
Date
(
date
);
const
y
=
d
.
getFullYear
();
const
mo
=
String
(
d
.
getMonth
()
+
1
).
padStart
(
2
,
'0'
);
const
day
=
String
(
d
.
getDate
()).
padStart
(
2
,
'0'
);
const
h
=
String
(
d
.
getHours
()).
padStart
(
2
,
'0'
);
const
mi
=
String
(
d
.
getMinutes
()).
padStart
(
2
,
'0'
);
const
s
=
String
(
d
.
getSeconds
()).
padStart
(
2
,
'0'
);
return
`
${
y
}
-
${
mo
}
-
${
day
}
${
h
}
:
${
mi
}
:
${
s
}
`
;
}
/** 获取今天 00:00:00 */
export
function
getTodayStart
():
string
{
const
now
=
new
Date
();
now
.
setHours
(
0
,
0
,
0
,
0
);
return
formatTime
(
now
);
}
/** 获取今天 23:59:59 */
export
function
getTodayEnd
():
string
{
const
now
=
new
Date
();
now
.
setHours
(
23
,
59
,
59
,
999
);
return
formatTime
(
now
);
}
/** 获取昨天 00:00:00 */
export
function
getYesterdayStart
():
string
{
const
now
=
new
Date
();
now
.
setDate
(
now
.
getDate
()
-
1
);
now
.
setHours
(
0
,
0
,
0
,
0
);
return
formatTime
(
now
);
}
/** 获取昨天 23:59:59 */
export
function
getYesterdayEnd
():
string
{
const
now
=
new
Date
();
now
.
setDate
(
now
.
getDate
()
-
1
);
now
.
setHours
(
23
,
59
,
59
,
999
);
return
formatTime
(
now
);
}
/** 获取本月 1 号 00:00:00 */
export
function
getMonthStart
():
string
{
const
now
=
new
Date
();
now
.
setDate
(
1
);
now
.
setHours
(
0
,
0
,
0
,
0
);
return
formatTime
(
now
);
}
/** 获取上月 1 号 00:00:00 */
export
function
getLastMonthStart
():
string
{
const
now
=
new
Date
();
now
.
setMonth
(
now
.
getMonth
()
-
1
,
1
);
now
.
setHours
(
0
,
0
,
0
,
0
);
return
formatTime
(
now
);
}
/** 获取上月最后一天 23:59:59 */
export
function
getLastMonthEnd
():
string
{
const
now
=
new
Date
();
now
.
setDate
(
1
);
now
.
setHours
(
0
,
0
,
0
,
0
);
now
.
setMilliseconds
(
now
.
getMilliseconds
()
-
1
);
return
formatTime
(
now
);
}
/** 获取 N 小时前的时间字符串 */
export
function
getHoursAgo
(
n
:
number
):
string
{
const
now
=
new
Date
();
now
.
setHours
(
now
.
getHours
()
-
n
);
return
formatTime
(
now
);
}
/** 获取 N 天前的 start-of-day */
export
function
getDaysAgoStart
(
n
:
number
):
string
{
const
now
=
new
Date
();
now
.
setDate
(
now
.
getDate
()
-
n
);
now
.
setHours
(
0
,
0
,
0
,
0
);
return
formatTime
(
now
);
}
/** 获取 N 个月前的首日 00:00:00 */
export
function
getMonthsAgoStart
(
n
:
number
):
string
{
const
now
=
new
Date
();
now
.
setMonth
(
now
.
getMonth
()
-
n
,
1
);
now
.
setHours
(
0
,
0
,
0
,
0
);
return
formatTime
(
now
);
}
/** 计算百分比同比/环比 */
export
function
calcCompareRate
(
current
:
number
,
previous
:
number
):
string
{
if
(
previous
===
0
)
return
current
>
0
?
'100'
:
'0'
;
return
((
current
-
previous
)
/
previous
*
100
).
toFixed
(
2
);
}
// ==================== 时间分组 key 格式化 ====================
export
function
formatHourKey
(
date
:
Date
):
string
{
const
y
=
date
.
getFullYear
();
const
mo
=
String
(
date
.
getMonth
()
+
1
).
padStart
(
2
,
'0'
);
const
d
=
String
(
date
.
getDate
()).
padStart
(
2
,
'0'
);
const
h
=
String
(
date
.
getHours
()).
padStart
(
2
,
'0'
);
return
`
${
y
}
-
${
mo
}
-
${
d
}
${
h
}
时`
;
}
export
function
formatDayKey
(
date
:
Date
):
string
{
const
y
=
date
.
getFullYear
();
const
mo
=
String
(
date
.
getMonth
()
+
1
).
padStart
(
2
,
'0'
);
const
d
=
String
(
date
.
getDate
()).
padStart
(
2
,
'0'
);
return
`
${
y
}
-
${
mo
}
-
${
d
}
`
;
}
export
function
formatMonthKey
(
date
:
Date
):
string
{
const
y
=
date
.
getFullYear
();
const
mo
=
String
(
date
.
getMonth
()
+
1
).
padStart
(
2
,
'0'
);
return
`
${
y
}
-
${
mo
}
`
;
}
src/util/request.ts
View file @
af021737
...
@@ -13,7 +13,7 @@ import { BizError } from './bizError';
...
@@ -13,7 +13,7 @@ import { BizError } from './bizError';
* @returns
* @returns
*/
*/
export
function
get
(
url
:
string
,
query
?,
headers
?)
{
export
function
get
(
url
:
string
,
query
?,
headers
?)
{
if
(
!
url
||
(
url
.
search
(
/http:/
)
&&
url
.
search
(
/https:/
))
)
throw
new
BizError
(
!
url
?
"请求地址为空"
:
"请求地址错误"
);
if
(
!
url
||
!
(
url
.
startsWith
(
'http://'
)
||
url
.
startsWith
(
'https://'
))
)
throw
new
BizError
(
!
url
?
"请求地址为空"
:
"请求地址错误"
);
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
paramater
:
any
=
{
url
,
json
:
true
};
let
paramater
:
any
=
{
url
,
json
:
true
};
if
(
query
)
paramater
.
qs
=
query
;
if
(
query
)
paramater
.
qs
=
query
;
...
@@ -42,7 +42,7 @@ export function post(url, body, headers) {
...
@@ -42,7 +42,7 @@ export function post(url, body, headers) {
resolve
(
body
);
resolve
(
body
);
}
}
else
{
else
{
// reject(error)
reject
(
error
||
new
Error
(
`HTTP
${
response
?.
statusCode
||
'error'
}
`));
}
}
});
});
})
})
...
...
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