Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
dj
/
rpc-mindworkplate
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 01b225a9
authored
Jan 28, 2026
by
zhouhaibao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]新增参数
1 parent
a88a4061
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
18 deletions
rpc-dj-mindworkplate/src/main/java/cn/com/glsx/dj/mindworkplate/service/monitoring/NextPeriodCalculator.java
rpc-dj-mindworkplate/src/main/java/cn/com/glsx/dj/mindworkplate/service/monitoring/NextPeriodCalculator.java
View file @
01b225a
...
@@ -9,6 +9,10 @@ public class NextPeriodCalculator {
...
@@ -9,6 +9,10 @@ public class NextPeriodCalculator {
private
static
final
DateTimeFormatter
FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
private
static
final
DateTimeFormatter
FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
calculateNextPeriod
(
2
,
"2025-01-31"
));
}
/**
/**
* 计算下一周期的开始和结束时间
* 计算下一周期的开始和结束时间
*
*
...
@@ -19,35 +23,25 @@ public class NextPeriodCalculator {
...
@@ -19,35 +23,25 @@ public class NextPeriodCalculator {
public
static
NextPeriodRange
calculateNextPeriod
(
Integer
periodType
,
String
endDateStr
)
{
public
static
NextPeriodRange
calculateNextPeriod
(
Integer
periodType
,
String
endDateStr
)
{
LocalDate
referenceDate
;
LocalDate
referenceDate
;
if
(
periodType
==
3
)
{
// 自定义:以下单结束时间为基准
if
(
endDateStr
==
null
||
endDateStr
.
trim
().
isEmpty
())
{
if
(
endDateStr
==
null
||
endDateStr
.
trim
().
isEmpty
())
{
throw
new
IllegalArgumentException
(
"自定义周期必须提供 endDate"
);
referenceDate
=
LocalDate
.
now
();
// 默认用当前时间
}
referenceDate
=
LocalDate
.
parse
(
endDateStr
,
FORMATTER
);
}
else
{
}
else
{
// 周/月:以当前日期为基准
referenceDate
=
LocalDate
.
parse
(
endDateStr
,
FORMATTER
);
referenceDate
=
LocalDate
.
now
();
}
}
LocalDate
nextStart
;
LocalDate
nextStart
;
LocalDate
nextEnd
;
LocalDate
nextEnd
;
switch
(
periodType
)
{
switch
(
periodType
)
{
case
1
:
// 周
case
1
:
// 周:以下一周期周一到周日
// 当前周的周一
LocalDate
nextMonday
=
referenceDate
.
with
(
DayOfWeek
.
MONDAY
).
plusWeeks
(
1
);
LocalDate
currentMonday
=
referenceDate
.
with
(
DayOfWeek
.
MONDAY
);
nextStart
=
nextMonday
;
// 下周一
nextEnd
=
nextMonday
.
plusDays
(
6
);
nextStart
=
currentMonday
.
plusWeeks
(
1
);
// 下周日
nextEnd
=
nextStart
.
plusDays
(
6
);
break
;
break
;
case
2
:
// 月
case
2
:
// 月:下一个月的完整月
// 下个月的第一天
nextStart
=
referenceDate
.
plusMonths
(
1
).
withDayOfMonth
(
1
);
nextStart
=
referenceDate
.
plusMonths
(
1
).
withDayOfMonth
(
1
);
// 下个月的最后一天
nextEnd
=
nextStart
.
with
(
TemporalAdjusters
.
lastDayOfMonth
());
nextEnd
=
nextStart
.
plusMonths
(
1
).
minusDays
(
1
);
break
;
break
;
case
4
:
// 自定义:结束后的一周(7天)
case
4
:
// 自定义:结束后的一周(7天)
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment