From dbce7bc302b82133fdb35c8195a5efb19f7cdcbe Mon Sep 17 00:00:00 2001 From: I-migi Date: Wed, 27 Nov 2024 16:59:37 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B2=BD=EA=B8=B0=20=EC=83=81=ED=83=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20=EB=B0=B0=EC=B9=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../processor/LeagueStatusProcessor.java | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/batch/src/main/java/springproject/badmintonbatch/batch/processor/LeagueStatusProcessor.java b/batch/src/main/java/springproject/badmintonbatch/batch/processor/LeagueStatusProcessor.java index d8bc11c1..23f311bc 100644 --- a/batch/src/main/java/springproject/badmintonbatch/batch/processor/LeagueStatusProcessor.java +++ b/batch/src/main/java/springproject/badmintonbatch/batch/processor/LeagueStatusProcessor.java @@ -19,29 +19,47 @@ public class LeagueStatusProcessor implements ItemProcessor { private final SinglesMatchReader singlesMatchReader; private final DoublesMatchReader doublesMatchReader; + @Override public League process(League item) { LocalDateTime now = LocalDateTime.now(); + switch (item.getLeagueStatus()) { + case RECRUITING: + handleRecruiting(item); + break; + case RECRUITING_COMPLETED: + handleRecruitingCompleted(item, now); + break; + case PLAYING: + handlePlaying(item, now); + break; + } + + return item; + } + + private void handleRecruiting(League item) { if (!isParticipantCountValid(item)) { item.cancelLeague(); - return item; + } else { + item.completeLeagueRecruiting(); } + } - item.completeLeagueRecruiting(); - + private void handleRecruitingCompleted(League item, LocalDateTime now) { if (isLeagueInProgress(item, now)) { item.startLeague(); } + } + private void handlePlaying(League item, LocalDateTime now) { if (isLeagueOverdue(item, now)) { if (!areAllMatchesFinished(item)) { item.cancelLeague(); - return item; + } else { + item.finishLeague(); } - item.finishLeague(); } - - return item; } private boolean isParticipantCountValid(League item) { @@ -49,7 +67,7 @@ private boolean isParticipantCountValid(League item) { } private boolean isLeagueInProgress(League item, LocalDateTime now) { - return item.getLeagueAt().isBefore(now) && item.getLeagueAt().plusHours(12).isAfter(now); + return item.getLeagueAt().isBefore(now); } private boolean isLeagueOverdue(League item, LocalDateTime now) { @@ -61,3 +79,4 @@ private boolean areAllMatchesFinished(League item) { && doublesMatchReader.allMatchesFinishedForLeague(item.getLeagueId()); } } +