Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
dj
/
rop-dj-supervisor-mini
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit dda5bd0a
authored
Mar 20, 2026
by
范富荣
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化生成最近 3年所有周一到周日方法
1 parent
ba8df690
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
15 deletions
src/main/java/cn/com/glsx/dj/supervisor/controller/SupervisorTaskInfoController.java
src/main/java/cn/com/glsx/dj/supervisor/controller/SupervisorTaskInfoController.java
View file @
dda5bd0
...
...
@@ -234,30 +234,27 @@ public class SupervisorTaskInfoController {
}
/**
* 生成最近
一
年所有周一到周日
* 生成最近
3
年所有周一到周日
*
* @return
*/
@ApiOperation
(
value
=
"生成最近
一
年所有周一到周日"
)
@ApiOperation
(
value
=
"生成最近
3
年所有周一到周日"
)
@ServiceMethod
(
method
=
"dj.api.supervisor.mini.get.generateWeeklyRanges"
,
needInSession
=
NeedInSessionType
.
NO
)
public
RopResponse
<
List
<
Map
>>
generateWeeklyRanges
(
AbstractRopRequest
request
)
{
public
RopResponse
<
List
<
Map
<
String
,
String
>>>
generateWeeklyRanges
(
AbstractRopRequest
request
)
{
int
yearCount
=
Integer
.
parseInt
(
environment
.
getProperty
(
"supervisor.weekly.range.years"
,
"3"
));
LocalDate
now
=
LocalDate
.
now
();
LocalDate
thisMonday
=
now
.
with
(
TemporalAdjusters
.
previousOrSame
(
DayOfWeek
.
MONDAY
));
LocalDate
oneYearAgo
=
now
.
minusYears
(
3
);
LocalDate
oneYearAgoMonday
=
oneYearAgo
.
with
(
TemporalAdjusters
.
previousOrSame
(
DayOfWeek
.
MONDAY
));
LocalDate
currentMonday
=
now
.
with
(
TemporalAdjusters
.
previousOrSame
(
DayOfWeek
.
MONDAY
));
LocalDate
endMonday
=
now
.
minusYears
(
yearCount
).
with
(
TemporalAdjusters
.
previousOrSame
(
DayOfWeek
.
MONDAY
));
List
<
Map
>
result
=
new
ArrayList
<>();
// 预估容量:每年约 53 周,避免底层数组频繁扩容
List
<
Map
<
String
,
String
>>
result
=
new
ArrayList
<>(
yearCount
*
53
+
1
);
LocalDate
currentMonday
=
thisMonday
;
while
(!
currentMonday
.
isBefore
(
oneYearAgoMonday
))
{
LocalDate
sunday
=
currentMonday
.
plusDays
(
6
);
Map
<
String
,
String
>
weekRange
=
new
HashMap
<>();
while
(!
currentMonday
.
isBefore
(
endMonday
))
{
Map
<
String
,
String
>
weekRange
=
new
HashMap
<>(
4
);
// 初始化容量为 4
weekRange
.
put
(
"startDate"
,
currentMonday
.
toString
());
// 周一
weekRange
.
put
(
"endDate"
,
sunday
.
toString
());
// 周日
result
.
add
(
weekRange
);
// Map 是 Object 的子类
weekRange
.
put
(
"endDate"
,
currentMonday
.
plusDays
(
6
).
toString
());
// 周日
result
.
add
(
weekRange
);
currentMonday
=
currentMonday
.
minusWeeks
(
1
);
// 上一周
}
return
RopResponse
.
success
(
result
);
...
...
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