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
44f637ff
Commit
44f637ff
authored
Sep 03, 2026
by
PC-20251223ZVQQ\Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
耗电同比
parent
1be0dee2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
4 deletions
+43
-4
running.ts
src/biz/running.ts
+10
-4
dateUtils.ts
src/util/dateUtils.ts
+33
-0
No files found.
src/biz/running.ts
View file @
44f637ff
...
@@ -18,6 +18,7 @@ import {
...
@@ -18,6 +18,7 @@ import {
getMonthStart
,
getMonthStart
,
getLastMonthStart
,
getLastMonthStart
,
getLastMonthEnd
,
getLastMonthEnd
,
getLastMonthSameTimeEnd
,
getHoursAgo
,
getHoursAgo
,
getDaysAgoStart
,
getDaysAgoStart
,
getMonthsAgoStart
,
getMonthsAgoStart
,
...
@@ -397,15 +398,20 @@ export async function getRunAnalysis() {
...
@@ -397,15 +398,20 @@ export async function getRunAnalysis() {
const
todayStart
=
getTodayStart
();
const
todayStart
=
getTodayStart
();
const
todayEnd
=
getTodayEnd
();
const
todayEnd
=
getTodayEnd
();
const
yesterdayStart
=
getYesterdayStart
();
const
yesterdayStart
=
getYesterdayStart
();
const
yesterdayEnd
=
getYesterdayEnd
();
//
const yesterdayEnd = getYesterdayEnd();
const
monthStart
=
getMonthStart
();
const
monthStart
=
getMonthStart
();
const
lastMonthStart
=
getLastMonthStart
();
const
lastMonthStart
=
getLastMonthStart
();
const
lastMonthEnd
=
getLastMonthEnd
();
// const lastMonthEnd = getLastMonthEnd();
// ---- energyManagement 对称口径专用(不动 dateUtils 中原有边界函数,别处仍共用) ----
// 昨日同刻:昨天 0 点 → 昨天当前同一时刻(秒级对称,与今日「0点→现在」等长)
const
yesterdaySameTimeEnd
=
getHoursAgo
(
24
);
// 上月同期:上月 1 号 → 对标日(短月/本月月底自动兜底到上月最后一天)
const
lastMonthSameTimeEnd
=
getLastMonthSameTimeEnd
();
const
jrnh
=
await
getElectricitySumInRange
(
todayStart
,
todayEnd
);
const
jrnh
=
await
getElectricitySumInRange
(
todayStart
,
todayEnd
);
const
zrnh
=
await
getElectricitySumInRange
(
yesterdayStart
,
yesterdayEnd
);
const
zrnh
=
await
getElectricitySumInRange
(
yesterdayStart
,
yesterday
SameTime
End
);
const
bynh
=
await
getElectricitySumInRange
(
monthStart
,
todayEnd
);
const
bynh
=
await
getElectricitySumInRange
(
monthStart
,
todayEnd
);
const
synh
=
await
getElectricitySumInRange
(
lastMonthStart
,
lastMonthEnd
);
const
synh
=
await
getElectricitySumInRange
(
lastMonthStart
,
lastMonth
SameTime
End
);
const
zrtb
=
calcCompareRate
(
jrnh
,
zrnh
);
const
zrtb
=
calcCompareRate
(
jrnh
,
zrnh
);
const
sytb
=
calcCompareRate
(
bynh
,
synh
);
const
sytb
=
calcCompareRate
(
bynh
,
synh
);
...
...
src/util/dateUtils.ts
View file @
44f637ff
...
@@ -71,6 +71,39 @@ export function getLastMonthEnd(): string {
...
@@ -71,6 +71,39 @@ export function getLastMonthEnd(): string {
return
formatTime
(
now
);
return
formatTime
(
now
);
}
}
/**
* 获取上月同期结束时间(用于「本月至今 vs 上月同期」的对称对比)
* 对标规则:
* - 普通日(今天不是本月最后一天):对标上月同号日,截止到与当前一致的时分秒(秒级对称);
* - 短月截断:上月没有今天这个号数(如 3/31 → 2 月),取上月最后一天 23:59:59;
* - 本月月底:今天已是本月最后一天,直接对标上月最后一天 23:59:59(整月对比)。
* @param now 基准时刻,默认当前时间
*/
export
function
getLastMonthSameTimeEnd
(
now
:
Date
=
new
Date
()):
string
{
const
y
=
now
.
getFullYear
();
const
m
=
now
.
getMonth
();
// 0-11,本月
const
day
=
now
.
getDate
();
// 本月最后一天号数(判断“今天是否本月最后一天”)
const
daysThisMonth
=
new
Date
(
y
,
m
+
1
,
0
).
getDate
();
// 上月最后一天 23:59:59(月底对标 / 短月兜底)
const
lastMonthLastDay
=
new
Date
(
y
,
m
,
0
);
lastMonthLastDay
.
setHours
(
23
,
59
,
59
,
999
);
const
fallback
=
formatTime
(
lastMonthLastDay
);
// 今天已是本月最后一天 → 对标上月整月
if
(
day
===
daysThisMonth
)
return
fallback
;
// 短月:上月没有今天这个号数(如 3/31 → 2 月)→ 对标上月整月
const
daysLastMonth
=
lastMonthLastDay
.
getDate
();
if
(
day
>
daysLastMonth
)
return
fallback
;
// 普通日:上月同号日,截止到与当前一致的时分秒
const
sameDay
=
new
Date
(
y
,
m
-
1
,
day
,
now
.
getHours
(),
now
.
getMinutes
(),
now
.
getSeconds
(),
0
);
return
formatTime
(
sameDay
);
}
/** 获取 N 小时前的时间字符串 */
/** 获取 N 小时前的时间字符串 */
export
function
getHoursAgo
(
n
:
number
):
string
{
export
function
getHoursAgo
(
n
:
number
):
string
{
const
now
=
new
Date
();
const
now
=
new
Date
();
...
...
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