From e16e1a8db4b4ff52567d3bc66fb2edbdc177ad7f Mon Sep 17 00:00:00 2001 From: x ronger Date: Wed, 9 Sep 2020 22:59:35 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=85=B3=E6=B3=A8=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E9=80=9A=E7=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/FollowServiceImpl.java | 5 +++ .../service/impl/NotificationServiceImpl.java | 32 ++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/service/impl/FollowServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/FollowServiceImpl.java index 8066718..ab7621f 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/FollowServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/FollowServiceImpl.java @@ -1,10 +1,12 @@ package com.rymcu.vertical.service.impl; +import com.rymcu.vertical.core.constant.NotificationConstant; import com.rymcu.vertical.core.service.AbstractService; import com.rymcu.vertical.entity.Follow; import com.rymcu.vertical.entity.User; import com.rymcu.vertical.mapper.FollowMapper; import com.rymcu.vertical.service.FollowService; +import com.rymcu.vertical.util.NotificationUtils; import com.rymcu.vertical.util.UserUtils; import com.rymcu.vertical.web.api.exception.BaseApiException; import org.springframework.stereotype.Service; @@ -32,6 +34,9 @@ public class FollowServiceImpl extends AbstractService implements Follow User tokenUser = UserUtils.getCurrentUserByToken(); follow.setFollowerId(tokenUser.getIdUser()); int result = followMapper.insertSelective(follow); + if (result > 0) { + NotificationUtils.saveNotification(follow.getFollowingId(), follow.getIdFollow(), NotificationConstant.Follow, tokenUser.getNickname() + " 关注了你!"); + } return result > 0; } 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 4bc3f54..5fc016e 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java @@ -5,14 +5,13 @@ import com.rymcu.vertical.dto.ArticleDTO; import com.rymcu.vertical.dto.Author; import com.rymcu.vertical.dto.NotificationDTO; import com.rymcu.vertical.entity.Comment; +import com.rymcu.vertical.entity.Follow; import com.rymcu.vertical.entity.Notification; import com.rymcu.vertical.entity.User; import com.rymcu.vertical.mapper.NotificationMapper; -import com.rymcu.vertical.service.ArticleService; -import com.rymcu.vertical.service.CommentService; -import com.rymcu.vertical.service.NotificationService; -import com.rymcu.vertical.service.UserService; +import com.rymcu.vertical.service.*; import com.rymcu.vertical.util.BeanCopierUtil; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -35,6 +34,10 @@ public class NotificationServiceImpl extends AbstractService imple private CommentService commentService; @Resource private UserService userService; + @Resource + private FollowService followService; + @Value("${resource.domain}") + private String domain; @Override public List findUnreadNotifications(Integer idUser) { @@ -59,6 +62,7 @@ public class NotificationServiceImpl extends AbstractService imple ArticleDTO article; Comment comment; User user; + Follow follow; switch (notification.getDataType()) { case "0": // 系统公告/帖子 @@ -70,6 +74,11 @@ public class NotificationServiceImpl extends AbstractService imple 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)); break; case "2": // 回帖 @@ -80,10 +89,25 @@ public class NotificationServiceImpl extends AbstractService imple user = userService.findById(comment.getCommentAuthorId().toString()); notificationDTO.setAuthor(genAuthor(user)); break; + default: + break; } return notificationDTO; } + private String getFollowLink(String followingType, String id) { + StringBuilder url = new StringBuilder(); + url.append(domain); + switch (followingType) { + case "0": + url = url.append("/user/").append(id); + break; + default: + url.append("/notification"); + } + return url.toString(); + } + private Author genAuthor(User user) { Author author = new Author(); author.setUserNickname(user.getNickname());