From ac59e06e9b32704fb9afc8a56b1346b1c000f68d Mon Sep 17 00:00:00 2001 From: nowgnas Date: Fri, 19 Jan 2024 14:54:24 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=A0=95=EC=82=B0=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NotificationCommandService.java | 15 + .../helper/NotificationActionHelper.java | 280 +++++++++--------- 2 files changed, 152 insertions(+), 143 deletions(-) diff --git a/src/main/java/kr/bb/notification/domain/notification/application/NotificationCommandService.java b/src/main/java/kr/bb/notification/domain/notification/application/NotificationCommandService.java index 3f64b00..d1d6e09 100644 --- a/src/main/java/kr/bb/notification/domain/notification/application/NotificationCommandService.java +++ b/src/main/java/kr/bb/notification/domain/notification/application/NotificationCommandService.java @@ -5,6 +5,7 @@ import bloomingblooms.domain.notification.Role; import bloomingblooms.domain.resale.ResaleNotificationList; import java.util.List; +import java.util.stream.Collectors; import kr.bb.notification.domain.notification.entity.MemberNotification; import kr.bb.notification.domain.notification.entity.Notification; import kr.bb.notification.domain.notification.mapper.MemberNotificationCommand; @@ -49,4 +50,18 @@ public void saveSingleNotification(PublishNotificationInformation publishInforma public void updateNotificationIsRead(List notificationId, Long userId, Role role) { memberNotificationJpaRepository.updateNotificationIsRead(notificationId, userId, role); } + + public void saveMultipleNotification( + PublishNotificationInformation publishInformation, List storeIdList) { + Notification notification = NotificationCommand.toEntity(publishInformation); + List memberNotifications = + storeIdList.stream() + .map( + item -> + MemberNotificationCommand.toEntity( + 1L, publishInformation.getRole(), notification)) + .collect(Collectors.toList()); + notification.setMemberNotifications(memberNotifications); + notificationJpaRepository.save(notification); + } } diff --git a/src/main/java/kr/bb/notification/domain/notification/helper/NotificationActionHelper.java b/src/main/java/kr/bb/notification/domain/notification/helper/NotificationActionHelper.java index 163e03c..1b783ef 100644 --- a/src/main/java/kr/bb/notification/domain/notification/helper/NotificationActionHelper.java +++ b/src/main/java/kr/bb/notification/domain/notification/helper/NotificationActionHelper.java @@ -25,147 +25,141 @@ @RequiredArgsConstructor public class NotificationActionHelper { - private final SendSMS sms; - private final SendSSE sse; - private final NotificationCommandService notificationCommandService; - - public void publishResaleNotification(NotificationData notification) { - List data = - NotificationInformation.getResaleNotificationData(notification); - data.forEach( - item -> { - sms.publish(item); - sse.publish(item); - }); - - // save notification - notificationCommandService.saveResaleNotification(notification); - } - - public void publishQuestionRegisterNotification( - NotificationData notification) { - NotificationInformation sseNotification = - NotificationInformation.getSSEData( - notification.getPublishInformation(), - notification.getWhoToNotify().getStoreId()); - sse.publish(sseNotification); - - // save notification - notificationCommandService.saveSingleNotification( - notification.getPublishInformation(), notification.getWhoToNotify().getStoreId()); - } - - public void publishNewComerNotification(NotificationData notification) { - NotificationInformation sseNotification = - NotificationInformation.getSSEData(notification.getPublishInformation(), 100L); - sse.publish(sseNotification); - - // save notification - notificationCommandService.saveSingleNotification(notification.getPublishInformation(), - 100L); - } - - public void publishNewOrderNotification(NotificationData notification) { - NotificationInformation sseNotification = - NotificationInformation.getSSEData( - notification.getPublishInformation(), - notification.getWhoToNotify().getStoreId()); - sse.publish(sseNotification); - - // save notification - notificationCommandService.saveSingleNotification( - notification.getPublishInformation(), notification.getWhoToNotify().getStoreId()); - } - - @OutOfStockNotificationDuplicateCheck - public void publishOutOfStockNotification( - NotificationData outOfStockNotification) { - NotificationInformation sseData = - NotificationInformation.getSSEData( - outOfStockNotification.getPublishInformation(), - outOfStockNotification.getWhoToNotify().getStoreId()); - sse.publish(sseData); - - notificationCommandService.saveSingleNotification( - outOfStockNotification.getPublishInformation(), - outOfStockNotification.getWhoToNotify().getStoreId()); - } - - public void publishDeliveryStartNotification( - NotificationData notificationData) { - NotificationInformation notifyData = - NotificationInformation.getDeliveryNotificationData(notificationData); - sse.publish(notifyData); - sms.publish(notifyData); - - // save notification - notificationCommandService.saveSingleNotification( - notificationData.getPublishInformation(), - notificationData.getWhoToNotify().getUserId()); - } - - public void publishSettlementNotification( - NotificationData notification) { - NotificationInformation sseData = - NotificationInformation.getSSEData( - notification.getPublishInformation(), - notification.getWhoToNotify().getStoreId()); - sse.publish(sseData); - - notificationCommandService.saveSingleNotification( - notification.getPublishInformation(), notification.getWhoToNotify().getStoreId()); - } - - public void publishOrderCancelNotification( - NotificationData notification) { - NotificationInformation sseData = - NotificationInformation.getSSEData( - notification.getPublishInformation(), - notification.getWhoToNotify().getStoreId()); - sse.publish(sseData); - - notificationCommandService.saveSingleNotification( - notification.getPublishInformation(), notification.getWhoToNotify().getStoreId()); - } - - /** - * 문의 답변 등록 알림 - * - * @param notification - */ - public void publishInqueryResponseNotification( - NotificationData notification) { - NotificationInformation sseData = - NotificationInformation.getSSEData( - notification.getPublishInformation(), - notification.getWhoToNotify().getUserId()); - NotificationInformation smsData = NotificationInformation.getSMSData(notification); - sse.publish(sseData); - sms.publish(smsData); - - // save notification - notificationCommandService.saveSingleNotification( - notification.getPublishInformation(), notification.getWhoToNotify().getUserId()); - } - - /** - * 주문 상태 알림 - * - * @param notification - */ - public void publishNewOrderStatusNotification( - NotificationData notification) { - NotificationInformation sseData = - NotificationInformation.getSSEData( - notification.getPublishInformation(), - notification.getWhoToNotify().getUserId()); - NotificationInformation smsData = NotificationInformation.getNewOrderStatusData( - notification); - sse.publish(sseData); - sms.publish(smsData); - - // save notification - notificationCommandService.saveSingleNotification( - notification.getPublishInformation(), notification.getWhoToNotify().getUserId()); - } + private final SendSMS sms; + private final SendSSE sse; + private final NotificationCommandService notificationCommandService; + + public void publishResaleNotification(NotificationData notification) { + List data = + NotificationInformation.getResaleNotificationData(notification); + data.forEach( + item -> { + sms.publish(item); + sse.publish(item); + }); + + // save notification + notificationCommandService.saveResaleNotification(notification); + } + + public void publishQuestionRegisterNotification(NotificationData notification) { + NotificationInformation sseNotification = + NotificationInformation.getSSEData( + notification.getPublishInformation(), notification.getWhoToNotify().getStoreId()); + sse.publish(sseNotification); + + // save notification + notificationCommandService.saveSingleNotification( + notification.getPublishInformation(), notification.getWhoToNotify().getStoreId()); + } + + public void publishNewComerNotification(NotificationData notification) { + NotificationInformation sseNotification = + NotificationInformation.getSSEData(notification.getPublishInformation(), 100L); + sse.publish(sseNotification); + + // save notification + notificationCommandService.saveSingleNotification(notification.getPublishInformation(), 100L); + } + + public void publishNewOrderNotification(NotificationData notification) { + NotificationInformation sseNotification = + NotificationInformation.getSSEData( + notification.getPublishInformation(), notification.getWhoToNotify().getStoreId()); + sse.publish(sseNotification); + + // save notification + notificationCommandService.saveSingleNotification( + notification.getPublishInformation(), notification.getWhoToNotify().getStoreId()); + } + + @OutOfStockNotificationDuplicateCheck + public void publishOutOfStockNotification( + NotificationData outOfStockNotification) { + NotificationInformation sseData = + NotificationInformation.getSSEData( + outOfStockNotification.getPublishInformation(), + outOfStockNotification.getWhoToNotify().getStoreId()); + sse.publish(sseData); + + notificationCommandService.saveSingleNotification( + outOfStockNotification.getPublishInformation(), + outOfStockNotification.getWhoToNotify().getStoreId()); + } + + public void publishDeliveryStartNotification( + NotificationData notificationData) { + NotificationInformation notifyData = + NotificationInformation.getDeliveryNotificationData(notificationData); + sse.publish(notifyData); + sms.publish(notifyData); + + // save notification + notificationCommandService.saveSingleNotification( + notificationData.getPublishInformation(), notificationData.getWhoToNotify().getUserId()); + } + + public void publishSettlementNotification(NotificationData notification) { + notification + .getWhoToNotify() + .getStoreIdList() + .forEach( + item -> { + NotificationInformation sseData = + NotificationInformation.getSSEData(notification.getPublishInformation(), item); + sse.publish(sseData); + }); + + notificationCommandService.saveMultipleNotification( + notification.getPublishInformation(), notification.getWhoToNotify().getStoreIdList()); + } + + public void publishOrderCancelNotification( + NotificationData notification) { + NotificationInformation sseData = + NotificationInformation.getSSEData( + notification.getPublishInformation(), notification.getWhoToNotify().getStoreId()); + sse.publish(sseData); + + notificationCommandService.saveSingleNotification( + notification.getPublishInformation(), notification.getWhoToNotify().getStoreId()); + } + + /** + * 문의 답변 등록 알림 + * + * @param notification + */ + public void publishInqueryResponseNotification( + NotificationData notification) { + NotificationInformation sseData = + NotificationInformation.getSSEData( + notification.getPublishInformation(), notification.getWhoToNotify().getUserId()); + NotificationInformation smsData = NotificationInformation.getSMSData(notification); + sse.publish(sseData); + sms.publish(smsData); + + // save notification + notificationCommandService.saveSingleNotification( + notification.getPublishInformation(), notification.getWhoToNotify().getUserId()); + } + + /** + * 주문 상태 알림 + * + * @param notification + */ + public void publishNewOrderStatusNotification( + NotificationData notification) { + NotificationInformation sseData = + NotificationInformation.getSSEData( + notification.getPublishInformation(), notification.getWhoToNotify().getUserId()); + NotificationInformation smsData = NotificationInformation.getNewOrderStatusData(notification); + sse.publish(sseData); + sms.publish(smsData); + + // save notification + notificationCommandService.saveSingleNotification( + notification.getPublishInformation(), notification.getWhoToNotify().getUserId()); + } }