-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/com/cmc/suppin/fcm/service/PushNotificationScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.cmc.suppin.fcm.service; | ||
|
||
import com.cmc.suppin.event.events.domain.Event; | ||
import com.cmc.suppin.event.events.domain.repository.EventRepository; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Service | ||
public class PushNotificationScheduler { | ||
|
||
private final EventRepository eventRepository; | ||
private final PushNotificationService pushNotificationService; | ||
|
||
public PushNotificationScheduler(EventRepository eventRepository, PushNotificationService pushNotificationService) { | ||
this.eventRepository = eventRepository; | ||
this.pushNotificationService = pushNotificationService; | ||
} | ||
|
||
@Scheduled(cron = "0 0 * * * *") // 매 정시에 실행 | ||
public void checkEventEndDates() { | ||
List<Event> events = eventRepository.findAll(); // 모든 이벤트 조회 | ||
|
||
LocalDateTime now = LocalDateTime.now(); | ||
|
||
for (Event event : events) { | ||
if (event.getEndDate() != null && event.getEndDate().isBefore(now)) { | ||
// 이벤트 종료일이 지났을 때 | ||
pushNotificationService.sendEventEndNotification(event); | ||
} | ||
|
||
if (event.getAnnouncementDate() != null && event.getAnnouncementDate().isBefore(now)) { | ||
// 당첨자 발표일이 지났을 때 | ||
pushNotificationService.sendAnnouncementNotification(event); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|