|
|
@@ -3,6 +3,7 @@ package com.izouma.ticketExchange.service;
|
|
|
import com.izouma.ticketExchange.domain.Schedule;
|
|
|
import com.izouma.ticketExchange.repo.ScheduleRepo;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
@@ -21,14 +22,26 @@ import static java.time.temporal.ChronoUnit.DAYS;
|
|
|
@AllArgsConstructor
|
|
|
public class ScheduleService {
|
|
|
private ScheduleRepo scheduleRepo;
|
|
|
+ private TppService tppService;
|
|
|
|
|
|
public List cinemaSchedule(Long cinemaId, Long showId) {
|
|
|
- List<Schedule> scheduleList = scheduleRepo.findByCinemaIdAndShowIdAndShowTimeAfter(cinemaId, showId, LocalDateTime.now());
|
|
|
+ List<Schedule> scheduleList = tppService.getSchedules(cinemaId).stream()
|
|
|
+ .filter(schedule -> schedule.getShowId().equals(showId)
|
|
|
+ && schedule.getShowTime().isAfter(LocalDateTime.now()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+// List<Schedule> scheduleList = scheduleRepo.findByCinemaIdAndShowIdAndShowTimeAfter(cinemaId, showId, LocalDateTime.now());
|
|
|
return scheduleList.stream()
|
|
|
.sorted(Comparator.comparing(Schedule::getShowDate))
|
|
|
- .collect(Collectors.groupingBy(schedule -> {
|
|
|
- String date = schedule.getShowDate().format(DateTimeFormatter.ofPattern("MM-dd"));
|
|
|
- switch ((int) DAYS.between(LocalDate.now(), schedule.getShowDate())) {
|
|
|
+ .collect(Collectors.groupingBy(Schedule::getShowDate,
|
|
|
+ Collectors.mapping(location -> location, Collectors.toList())))
|
|
|
+ .entrySet()
|
|
|
+ .stream()
|
|
|
+ .sorted(Comparator.comparing(Map.Entry::getKey))
|
|
|
+ .map((Function<Map.Entry<LocalDate, List<Schedule>>, Map>) stringListEntry -> {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ stringListEntry.getValue().sort(Comparator.comparing(Schedule::getShowTime));
|
|
|
+ String date = stringListEntry.getKey().format(DateTimeFormatter.ofPattern("MM-dd"));
|
|
|
+ switch ((int) DAYS.between(LocalDate.now(), stringListEntry.getKey())) {
|
|
|
case 0:
|
|
|
date = "今天" + date;
|
|
|
break;
|
|
|
@@ -40,16 +53,9 @@ public class ScheduleService {
|
|
|
break;
|
|
|
default:
|
|
|
String[] weekDays = {"周一", "周二", "周三", "周四", "周五", "周六", "周日"};
|
|
|
- date = weekDays[schedule.getShowDate().getDayOfWeek().getValue()] + date;
|
|
|
+ date = weekDays[stringListEntry.getKey().getDayOfWeek().getValue() - 1] + date;
|
|
|
}
|
|
|
- return date;
|
|
|
- }, Collectors.mapping(location -> location, Collectors.toList())))
|
|
|
- .entrySet()
|
|
|
- .stream()
|
|
|
- .map((Function<Map.Entry<String, List<Schedule>>, Map>) stringListEntry -> {
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- stringListEntry.getValue().sort(Comparator.comparing(Schedule::getShowTime));
|
|
|
- map.put("showDate", stringListEntry.getKey());
|
|
|
+ map.put("showDate", date);
|
|
|
map.put("schedules", stringListEntry.getValue());
|
|
|
return map;
|
|
|
})
|