优化代码

This commit is contained in:
none 2023-04-19 10:56:51 +08:00
parent 54a15b59a5
commit 51db585796

View File

@ -398,7 +398,7 @@ public class UserController {
.map(UserCourseHourRecord::getHourId) .map(UserCourseHourRecord::getHourId)
.toList()) .toList())
.stream() .stream()
.collect(Collectors.groupingBy(CourseHour::getId))); .collect(Collectors.toMap(CourseHour::getId, e -> e)));
return JsonResponse.data(data); return JsonResponse.data(data);
} }
@ -450,11 +450,11 @@ public class UserController {
List<UserLearnDurationStats> monthRecords = List<UserLearnDurationStats> monthRecords =
userLearnDurationStatsService.dateBetween(id, startDateStr, todayStr); userLearnDurationStatsService.dateBetween(id, startDateStr, todayStr);
Map<Date, Long> date2duration = Map<String, Long> date2duration =
monthRecords.stream() monthRecords.stream()
.collect( .collect(
Collectors.toMap( Collectors.toMap(
UserLearnDurationStats::getCreatedDate, e -> DateTime.of(e.getCreatedDate()).toDateStr(),
UserLearnDurationStats::getDuration)); UserLearnDurationStats::getDuration));
@Data @Data
@ -467,11 +467,10 @@ public class UserController {
while (startTime <= endTime) { while (startTime <= endTime) {
String dateKey = DateTime.of(startTime).toDateStr(); String dateKey = DateTime.of(startTime).toDateStr();
Date tmpDate = new Date(startTime);
Long duration = 0L; Long duration = 0L;
if (date2duration.get(tmpDate) != null) { if (date2duration.get(dateKey) != null) {
duration = date2duration.get(tmpDate); duration = date2duration.get(dateKey);
} }
StatsItem tmpItem = new StatsItem(); StatsItem tmpItem = new StatsItem();