From 58be6a6d40aa9808b6a63ce7ebde68e6beef63f6 Mon Sep 17 00:00:00 2001 From: KJBig Date: Mon, 21 Oct 2024 17:00:27 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20=EC=95=8C=EB=A6=BC=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 특정 상황에서 알림이 발생하지 않는 버그 수정 --- .../impl/QuestionRepositoryImpl.java | 48 ++++++++++--------- .../com/sluv/infra/ai/AiModelService.java | 4 +- .../firebase/FcmNotificationService.java | 25 +++++----- .../alarm/service/CommentAlarmService.java | 7 ++- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/sluv-domain/src/main/java/com/sluv/domain/question/repository/impl/QuestionRepositoryImpl.java b/sluv-domain/src/main/java/com/sluv/domain/question/repository/impl/QuestionRepositoryImpl.java index 52ef68f5..66c20fd7 100644 --- a/sluv-domain/src/main/java/com/sluv/domain/question/repository/impl/QuestionRepositoryImpl.java +++ b/sluv-domain/src/main/java/com/sluv/domain/question/repository/impl/QuestionRepositoryImpl.java @@ -1,43 +1,43 @@ package com.sluv.domain.question.repository.impl; -import static com.sluv.domain.celeb.entity.QCeleb.celeb; -import static com.sluv.domain.celeb.entity.QNewCeleb.newCeleb; -import static com.sluv.domain.comment.entity.QComment.comment; -import static com.sluv.domain.question.entity.QDailyHotQuestion.dailyHotQuestion; -import static com.sluv.domain.question.entity.QQuestion.question; -import static com.sluv.domain.question.entity.QQuestionBuy.questionBuy; -import static com.sluv.domain.question.entity.QQuestionFind.questionFind; -import static com.sluv.domain.question.entity.QQuestionHowabout.questionHowabout; -import static com.sluv.domain.question.entity.QQuestionLike.questionLike; -import static com.sluv.domain.question.entity.QQuestionRecommend.questionRecommend; -import static com.sluv.domain.question.entity.QQuestionRecommendCategory.questionRecommendCategory; - import com.querydsl.core.BooleanBuilder; +import com.querydsl.core.types.ConstantImpl; import com.querydsl.core.types.Order; import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.core.types.dsl.EntityPathBase; import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.core.types.dsl.StringTemplate; import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; import com.sluv.domain.celeb.entity.Celeb; import com.sluv.domain.celeb.entity.QCeleb; -import com.sluv.domain.question.entity.Question; -import com.sluv.domain.question.entity.QuestionBuy; -import com.sluv.domain.question.entity.QuestionFind; -import com.sluv.domain.question.entity.QuestionHowabout; -import com.sluv.domain.question.entity.QuestionRecommend; +import com.sluv.domain.question.entity.*; import com.sluv.domain.question.enums.QuestionStatus; import com.sluv.domain.user.entity.User; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.support.PageableExecutionUtils; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import static com.sluv.domain.celeb.entity.QCeleb.celeb; +import static com.sluv.domain.celeb.entity.QNewCeleb.newCeleb; +import static com.sluv.domain.comment.entity.QComment.comment; +import static com.sluv.domain.question.entity.QDailyHotQuestion.dailyHotQuestion; +import static com.sluv.domain.question.entity.QQuestion.question; +import static com.sluv.domain.question.entity.QQuestionBuy.questionBuy; +import static com.sluv.domain.question.entity.QQuestionFind.questionFind; +import static com.sluv.domain.question.entity.QQuestionHowabout.questionHowabout; +import static com.sluv.domain.question.entity.QQuestionLike.questionLike; +import static com.sluv.domain.question.entity.QQuestionRecommend.questionRecommend; +import static com.sluv.domain.question.entity.QQuestionRecommendCategory.questionRecommendCategory; + @RequiredArgsConstructor public class QuestionRepositoryImpl implements QuestionRepositoryCustom { @@ -538,11 +538,13 @@ public List getSearchQuestionIds(String word) { @Override public List getEndTimeBetweenNow(int voteEndCheckPeriod) { int periodToMinutes = voteEndCheckPeriod / 1000 / 60; - LocalDateTime now = LocalDateTime.now(); + String dateFormat = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + String start = LocalDateTime.now().minusMinutes(periodToMinutes).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + StringTemplate formattedDate = Expressions.stringTemplate("DATE_FORMAT({0}, {1})", questionBuy.voteEndTime, ConstantImpl.create("%Y-%m-%d %H:%i:%s")); return jpaQueryFactory.selectFrom(questionBuy) .where(questionBuy.questionStatus.eq(QuestionStatus.ACTIVE) - .and(questionBuy.voteEndTime.between(now.minusMinutes(periodToMinutes), now)) + .and(formattedDate.between(start, dateFormat)) ) .fetch(); diff --git a/sluv-infra/src/main/java/com/sluv/infra/ai/AiModelService.java b/sluv-infra/src/main/java/com/sluv/infra/ai/AiModelService.java index 44207f95..05ce1a94 100644 --- a/sluv-infra/src/main/java/com/sluv/infra/ai/AiModelService.java +++ b/sluv-infra/src/main/java/com/sluv/infra/ai/AiModelService.java @@ -7,6 +7,7 @@ import com.sluv.domain.item.entity.ItemImg; import com.sluv.domain.item.repository.ItemImgRepository; import com.sluv.domain.item.repository.ItemRepository; +import com.sluv.infra.alarm.service.CommentAlarmService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; @@ -21,6 +22,7 @@ public class AiModelService { private final CommentRepository commentRepository; private final ItemRepository itemRepository; private final ItemImgRepository itemImgRepository; + private final CommentAlarmService commentAlarmService; @Transactional @@ -31,7 +33,7 @@ public void censorComment(Comment comment) { if (isMalicious) { comment.changeStatus(CommentStatus.BLOCKED); commentRepository.save(comment); -// commentAlarmService.sendAlarmAboutReportByAI(comment.getId(), null); + commentAlarmService.sendAlarmAboutReportByAI(comment.getId(), null); } } diff --git a/sluv-infra/src/main/java/com/sluv/infra/alarm/firebase/FcmNotificationService.java b/sluv-infra/src/main/java/com/sluv/infra/alarm/firebase/FcmNotificationService.java index c0d0092a..91c0e33b 100644 --- a/sluv-infra/src/main/java/com/sluv/infra/alarm/firebase/FcmNotificationService.java +++ b/sluv-infra/src/main/java/com/sluv/infra/alarm/firebase/FcmNotificationService.java @@ -7,7 +7,6 @@ import com.google.firebase.messaging.Notification; import com.sluv.domain.alarm.enums.AlarmType; import com.sluv.domain.user.entity.User; -import com.sluv.domain.user.exception.UserNotFoundException; import com.sluv.domain.user.repository.UserRepository; import com.sluv.infra.alarm.firebase.exception.FcmConnectException; import lombok.RequiredArgsConstructor; @@ -27,18 +26,18 @@ public class FcmNotificationService { public void sendFCMNotification(Long userId, String title, String body, AlarmType alarmType, HashMap ids) { - User user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); - - if (user.getAlarmStatus() && user.getFcmToken() != null) { // 알람 허용 시 - Message message = getMessage(title, body, user, alarmType, ids); - - try { - firebaseMessaging.send(message); - } catch (FirebaseMessagingException e) { - log.error(e.getMessage()); - throw new FcmConnectException(); - } - } +// User user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); +// +// if (user.getAlarmStatus() && user.getFcmToken() != null) { // 알람 허용 시 +// Message message = getMessage(title, body, user, alarmType, ids); +// +// try { +// firebaseMessaging.send(message); +// } catch (FirebaseMessagingException e) { +// log.error(e.getMessage()); +// throw new FcmConnectException(); +// } +// } } public void sendFCMNotificationMulticast(List userIds, String title, String body, AlarmType alarmType, diff --git a/sluv-infra/src/main/java/com/sluv/infra/alarm/service/CommentAlarmService.java b/sluv-infra/src/main/java/com/sluv/infra/alarm/service/CommentAlarmService.java index 3853d783..3cffc7ce 100644 --- a/sluv-infra/src/main/java/com/sluv/infra/alarm/service/CommentAlarmService.java +++ b/sluv-infra/src/main/java/com/sluv/infra/alarm/service/CommentAlarmService.java @@ -44,8 +44,7 @@ public void sendAlarmAboutCommentLike(Long senderId, Long commentId) { @Async("alarmThreadPoolExecutor") public void sendAlarmAboutComment(Long senderId, Long commentId) { Comment comment = commentDomainService.findById(commentId); - - if (!senderId.equals(comment.getUser().getId())) { + if (!senderId.equals(comment.getQuestion().getUser().getId())) { User sender = userDomainService.findById(senderId); String message = AlarmMessage.getMessageWithUserName(sender.getNickname(), AlarmMessage.QUESTION_COMMENT); sendMessageTypeComment(comment.getQuestion().getUser(), comment, message, sender); @@ -57,10 +56,10 @@ public void sendAlarmAboutComment(Long senderId, Long commentId) { public void sendAlarmAboutSubComment(Long senderId, Long commentId) { Comment comment = commentDomainService.findById(commentId); - if (!senderId.equals(comment.getUser().getId())) { + if (!senderId.equals(comment.getParent().getUser().getId()) && !senderId.equals(comment.getQuestion().getUser().getId())) { User sender = userDomainService.findById(senderId); String message = AlarmMessage.getMessageWithUserName(sender.getNickname(), AlarmMessage.COMMENT_SUB); - sendMessageTypeComment(comment.getUser(), comment, message, sender); + sendMessageTypeComment(comment.getParent().getUser(), comment, message, sender); } }