From 0f8330a1cff6c46ef0936957d0e985b54b7abfe7 Mon Sep 17 00:00:00 2001 From: yxhwxn Date: Mon, 19 Aug 2024 18:39:47 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=ED=91=B8=EC=8B=9C=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EC=8A=A4=EC=BC=80=EC=A5=B4=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/PushNotificationScheduler.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/com/cmc/suppin/fcm/service/PushNotificationScheduler.java diff --git a/src/main/java/com/cmc/suppin/fcm/service/PushNotificationScheduler.java b/src/main/java/com/cmc/suppin/fcm/service/PushNotificationScheduler.java new file mode 100644 index 0000000..a931c91 --- /dev/null +++ b/src/main/java/com/cmc/suppin/fcm/service/PushNotificationScheduler.java @@ -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 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); + } + } + } +} + +