From 1d02fb6664bf1aa0562cdf99bd0901fd12e9ef3f Mon Sep 17 00:00:00 2001 From: x ronger Date: Tue, 29 Sep 2020 19:02:23 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E5=85=B3=E8=81=94=E6=95=B0=E6=8D=AE=E5=88=A0=E9=99=A4=E5=90=8E?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/NotificationServiceImpl.java | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java index 7bfa3fd..86fa52c 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java @@ -51,7 +51,9 @@ public class NotificationServiceImpl extends AbstractService imple List notifications = new ArrayList<>(); list.forEach(notification -> { NotificationDTO notificationDTO = genNotification(notification); - notifications.add(notificationDTO); + if (Objects.nonNull(notificationDTO.getAuthor())) { + notifications.add(notificationDTO); + } }); return notifications; } @@ -67,37 +69,45 @@ public class NotificationServiceImpl extends AbstractService imple case "0": // 系统公告/帖子 article = articleService.findArticleDTOById(notification.getDataId(), 0); - notificationDTO.setDataTitle("系统公告"); - notificationDTO.setDataUrl(article.getArticlePermalink()); - user = userService.findById(article.getArticleAuthorId().toString()); - notificationDTO.setAuthor(genAuthor(user)); + if (Objects.nonNull(article)) { + notificationDTO.setDataTitle("系统公告"); + notificationDTO.setDataUrl(article.getArticlePermalink()); + user = userService.findById(article.getArticleAuthorId().toString()); + notificationDTO.setAuthor(genAuthor(user)); + } break; case "1": // 关注 follow = followService.findById(notification.getDataId().toString()); notificationDTO.setDataTitle("关注提醒"); - user = userService.findById(follow.getFollowerId().toString()); - notificationDTO.setDataUrl(getFollowLink(follow.getFollowingType(), user.getNickname())); - notificationDTO.setAuthor(genAuthor(user)); + if (Objects.nonNull(follow)) { + user = userService.findById(follow.getFollowerId().toString()); + notificationDTO.setDataUrl(getFollowLink(follow.getFollowingType(), user.getNickname())); + notificationDTO.setAuthor(genAuthor(user)); + } break; case "2": // 回帖 comment = commentService.findById(notification.getDataId().toString()); article = articleService.findArticleDTOById(comment.getCommentArticleId(), 0); - notificationDTO.setDataTitle(article.getArticleTitle()); - notificationDTO.setDataUrl(comment.getCommentSharpUrl()); - user = userService.findById(comment.getCommentAuthorId().toString()); - notificationDTO.setAuthor(genAuthor(user)); + if (Objects.nonNull(article)) { + notificationDTO.setDataTitle(article.getArticleTitle()); + notificationDTO.setDataUrl(comment.getCommentSharpUrl()); + user = userService.findById(comment.getCommentAuthorId().toString()); + notificationDTO.setAuthor(genAuthor(user)); + } break; case "3": // 关注用户发布文章 case "4": // 关注文章更新 article = articleService.findArticleDTOById(notification.getDataId(), 0); - notificationDTO.setDataTitle("关注通知"); - notificationDTO.setDataUrl(article.getArticlePermalink()); - user = userService.findById(article.getArticleAuthorId().toString()); - notificationDTO.setAuthor(genAuthor(user)); + if (Objects.nonNull(article)) { + notificationDTO.setDataTitle("关注通知"); + notificationDTO.setDataUrl(article.getArticlePermalink()); + user = userService.findById(article.getArticleAuthorId().toString()); + notificationDTO.setAuthor(genAuthor(user)); + } break; default: break;