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..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 @@ -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 0 0 * * *", zone = "Asia/Seoul") + private 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); + } }