From 727322f87a8be0331c4ca88e1a62a092ff967406 Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Wed, 17 Jul 2024 10:04:04 +0900 Subject: [PATCH] =?UTF-8?q?update=20::=20=EC=8B=9C=EA=B0=84=20=EB=82=98?= =?UTF-8?q?=EB=9D=BC=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ChangeEventStatusServiceImpl.java | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/mindway/server/v2/domain/event/service/impl/ChangeEventStatusServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/event/service/impl/ChangeEventStatusServiceImpl.java index 6d7807c..8da0f73 100644 --- a/src/main/java/com/mindway/server/v2/domain/event/service/impl/ChangeEventStatusServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/event/service/impl/ChangeEventStatusServiceImpl.java @@ -8,20 +8,18 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.time.LocalDate; -import java.util.Date; +import java.time.ZoneId; import java.util.List; import java.util.Objects; - @ServiceWithTransaction @RequiredArgsConstructor @Slf4j public class ChangeEventStatusServiceImpl implements ChangeEventStatusService { private final EventRepository eventRepository; + private final ZoneId zoneId = ZoneId.of("Asia/Seoul"); public void execute() { log.info("===================이벤트 스케줄러 시작==================="); @@ -34,8 +32,10 @@ public void execute() { } private void saveChangePast(List nowEvents) { - for (Event event: nowEvents) { - if (Objects.equals(event.getStarted_at(), LocalDate.now())) { + LocalDate now = LocalDate.now(zoneId); + + for (Event event : nowEvents) { + if (Objects.equals(event.getStarted_at(), now)) { event.changeStatus(Status.PAST); eventRepository.save(event); log.info("EventId: {}, status: NOW -> PAST", event.getId()); @@ -45,21 +45,17 @@ private void saveChangePast(List nowEvents) { } private void saveChangeNow(List pendingEvents) { - try { - - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); - Date now = formatter.parse(String.valueOf(LocalDate.now())); + LocalDate now = LocalDate.now(zoneId); - for (Event event: pendingEvents) { - Date endDate = formatter.parse(String.valueOf(event.getEnded_at())); + for (Event event : pendingEvents) { + LocalDate endDate = event.getEnded_at(); - if (now.after(endDate)) { - event.changeStatus(Status.NOW); - eventRepository.save(event); - log.info("EventId: {}, status: PENDING -> NOW", event.getId()); - } + if (now.isAfter(endDate)) { + event.changeStatus(Status.NOW); + eventRepository.save(event); + log.info("EventId: {}, status: PENDING -> NOW", event.getId()); } - log.info("===================EventPendingToNow End==================="); - } catch (ParseException e) {} + } + log.info("===================EventPendingToNow End==================="); } }