From 8e269f0e2faf6e293d7c4aeb4c4889b8c404af8d Mon Sep 17 00:00:00 2001 From: yang Date: Mon, 20 Nov 2023 22:35:10 +0900 Subject: [PATCH 1/2] =?UTF-8?q?RAC-158=20feat=20:=20=EB=A7=A4=EC=9D=BC=20?= =?UTF-8?q?=EB=B0=A4=2011=EC=8B=9C=2059=EB=B6=84=20=EC=9E=90=EB=8F=99=20?= =?UTF-8?q?=EC=B7=A8=EC=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../postgraduate/PostgraduateApplication.java | 2 ++ .../usecase/MentoringManageUseCase.java | 17 ++++++++++++++++- .../domain/repository/MentoringRepository.java | 3 ++- .../domain/service/MentoringGetService.java | 7 ++++--- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/postgraduate/PostgraduateApplication.java b/src/main/java/com/postgraduate/PostgraduateApplication.java index 7f616aee..6f830f34 100644 --- a/src/main/java/com/postgraduate/PostgraduateApplication.java +++ b/src/main/java/com/postgraduate/PostgraduateApplication.java @@ -2,7 +2,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; +@EnableScheduling @SpringBootApplication public class PostgraduateApplication { diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java index a4a22ec6..9df54273 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java @@ -2,7 +2,7 @@ import com.postgraduate.domain.mentoring.application.dto.req.MentoringDateRequest; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; -import com.postgraduate.domain.mentoring.domain.entity.constant.Status; +import com.postgraduate.domain.mentoring.domain.service.MentoringGetService; import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService; import com.postgraduate.domain.mentoring.exception.MentoringNotWaitingException; import com.postgraduate.domain.refuse.application.dto.req.MentoringRefuseRequest; @@ -16,9 +16,13 @@ import com.postgraduate.domain.salary.domain.service.SalaryUpdateService; import com.postgraduate.domain.user.domain.entity.User; import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; +import java.util.List; + import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.*; import static com.postgraduate.domain.salary.util.MonthFormat.getMonthFormat; import static java.time.LocalDate.now; @@ -29,6 +33,7 @@ public class MentoringManageUseCase { private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase; private final MentoringUpdateService mentoringUpdateService; + private final MentoringGetService mentoringGetService; private final RefuseSaveService refuseSaveService; private final SalaryGetService salaryGetService; private final SalarySaveService salarySaveService; @@ -68,4 +73,14 @@ public void updateExpected(User user, Long mentoringId, MentoringDateRequest dat mentoringUpdateService.updateDate(mentoring, dateRequest.getDate()); mentoringUpdateService.updateStatus(mentoring, EXPECTED); } + + @Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul") + public void updateCancel() { + LocalDate now = LocalDate.now(); + List mentorings = mentoringGetService.byStatusAndCreatedAt(WAITING, now); + for (Mentoring mentoring : mentorings) { + mentoringUpdateService.updateStatus(mentoring, CANCEL); + //TODO : 알림 보내거나 나머지 작업 + } + } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java b/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java index 0130c282..d52f139d 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java @@ -6,6 +6,7 @@ import com.postgraduate.domain.user.domain.entity.User; import org.springframework.data.jpa.repository.JpaRepository; +import java.time.LocalDate; import java.util.List; import java.util.Optional; @@ -13,5 +14,5 @@ public interface MentoringRepository extends JpaRepository { Optional findByMentoringId(Long mentoringId); Optional> findAllByUserAndStatus(User user, Status status); Optional> findAllBySeniorAndStatus(Senior senior, Status status); -// Optional> findAllByDeletedAtIsNull(); + List findAllByStatusAndCreatedAtIsBefore(Status status, LocalDate now); } diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java index f692ea15..736f53a9 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java @@ -9,6 +9,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -29,7 +30,7 @@ public Mentoring byMentoringId(Long mentoringId) { return mentoringRepository.findByMentoringId(mentoringId).orElseThrow(MentoringNotFoundException::new); } -// public List all() { -// return mentoringRepository.findAllByDeletedAtIsNull().orElse(new ArrayList<>()); -// } + public List byStatusAndCreatedAt(Status status, LocalDate now) { + return mentoringRepository.findAllByStatusAndCreatedAtIsBefore(status, now); + } } From 947e44deeae7eae4080ed217336689e9f0a247a7 Mon Sep 17 00:00:00 2001 From: yang Date: Mon, 20 Nov 2023 22:41:28 +0900 Subject: [PATCH 2/2] =?UTF-8?q?RAC-158=20fix=20:=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=EC=9E=90=EC=A0=95=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20private=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentoring/application/usecase/MentoringManageUseCase.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java index 9df54273..8ca84a16 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java @@ -74,8 +74,8 @@ public void updateExpected(User user, Long mentoringId, MentoringDateRequest dat mentoringUpdateService.updateStatus(mentoring, EXPECTED); } - @Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul") - public void updateCancel() { + @Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") + private void updateCancel() { LocalDate now = LocalDate.now(); List mentorings = mentoringGetService.byStatusAndCreatedAt(WAITING, now); for (Mentoring mentoring : mentorings) {