From 347c636bba9e8dc27b3ef23d7d0dcbebaa8789fe Mon Sep 17 00:00:00 2001 From: crocusia Date: Mon, 11 Aug 2025 11:34:58 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20:=20Long=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=20=EB=A9=94=EC=84=9C=EB=93=9C=EC=97=90=20Que?= =?UTF-8?q?ry=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/example/cs25batch/aop/MailLogAspect.java | 5 +++-- .../domain/mail/repository/MailLogRepository.java | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java b/cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java index 2b50daec..89d00a0b 100644 --- a/cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java +++ b/cs25-batch/src/main/java/com/example/cs25batch/aop/MailLogAspect.java @@ -48,7 +48,7 @@ public Object logMailSend(ProceedingJoinPoint joinPoint) throws Throwable { caused = e.getMessage(); throw new CustomMailException(MailExceptionCode.EMAIL_SEND_FAILED_ERROR); } finally { - MailLog log = MailLog.builder() + MailLog mailLog = MailLog.builder() .subscription(subscription) .quiz(quiz) .sendDate(LocalDateTime.now()) @@ -56,10 +56,11 @@ public Object logMailSend(ProceedingJoinPoint joinPoint) throws Throwable { .caused(caused) .build(); - mailLogRepository.save(log); + mailLogRepository.save(mailLog); mailLogRepository.flush(); if (status == MailStatus.FAILED) { + log.info("메일 발송 실패 : subscriptionId - {}, cause - {}", subscription.getId(), caused); Map retryMessage = Map.of( "email", subscription.getEmail(), "subscriptionId", subscription.getId().toString(), diff --git a/cs25-entity/src/main/java/com/example/cs25entity/domain/mail/repository/MailLogRepository.java b/cs25-entity/src/main/java/com/example/cs25entity/domain/mail/repository/MailLogRepository.java index a9184764..6f4fae0a 100644 --- a/cs25-entity/src/main/java/com/example/cs25entity/domain/mail/repository/MailLogRepository.java +++ b/cs25-entity/src/main/java/com/example/cs25entity/domain/mail/repository/MailLogRepository.java @@ -7,6 +7,7 @@ import java.util.Optional; import java.util.Set; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository @@ -23,5 +24,10 @@ default MailLog findByIdOrElseThrow(Long id) { void deleteAllByIdIn(Collection ids); + @Query(""" + select distinct ml.quiz.id + from MailLog ml + where ml.subscription.id = :subscriptionId + """) Set findDistinctQuiz_IdBySubscription_Id(Long subscriptionId); } From f30f74f9b1f2ec993443370467b1cf02b75d50b3 Mon Sep 17 00:00:00 2001 From: crocusia Date: Mon, 11 Aug 2025 14:24:21 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor=20:=20=EC=BF=BC=EB=A6=AC=EB=AC=B8?= =?UTF-8?q?=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/mail/repository/MailLogRepository.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cs25-entity/src/main/java/com/example/cs25entity/domain/mail/repository/MailLogRepository.java b/cs25-entity/src/main/java/com/example/cs25entity/domain/mail/repository/MailLogRepository.java index 6f4fae0a..3431079d 100644 --- a/cs25-entity/src/main/java/com/example/cs25entity/domain/mail/repository/MailLogRepository.java +++ b/cs25-entity/src/main/java/com/example/cs25entity/domain/mail/repository/MailLogRepository.java @@ -8,6 +8,7 @@ import java.util.Set; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @Repository @@ -25,9 +26,10 @@ default MailLog findByIdOrElseThrow(Long id) { void deleteAllByIdIn(Collection ids); @Query(""" - select distinct ml.quiz.id - from MailLog ml - where ml.subscription.id = :subscriptionId - """) - Set findDistinctQuiz_IdBySubscription_Id(Long subscriptionId); + select distinct ml.quiz.id + from MailLog ml + where ml.subscription.id = :subscriptionId + and ml.status = com.example.cs25entity.domain.mail.enums.MailStatus.SENT + """) + Set findDistinctQuiz_IdBySubscription_Id(@Param("subscriptionId") Long subscriptionId); }