Skip to content

Commit

Permalink
Merge pull request #197 from Team-MindWay/fix/196-event-schedule-time…
Browse files Browse the repository at this point in the history
…-inconsistency-problem-resolve

🔀 :: 이벤트 시간 불일치 문제 해결
  • Loading branch information
Umjiseung authored Jul 17, 2024
2 parents 85223cd + 727322f commit 1e438f7
Showing 1 changed file with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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("===================이벤트 스케줄러 시작===================");
Expand All @@ -34,8 +32,10 @@ public void execute() {
}

private void saveChangePast(List<Event> 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());
Expand All @@ -45,21 +45,17 @@ private void saveChangePast(List<Event> nowEvents) {
}

private void saveChangeNow(List<Event> 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===================");
}
}

0 comments on commit 1e438f7

Please sign in to comment.