关注消息通知功能

This commit is contained in:
x ronger 2020-09-09 22:59:35 +08:00
parent e42e9e940e
commit e16e1a8db4
2 changed files with 33 additions and 4 deletions

View File

@ -1,10 +1,12 @@
package com.rymcu.vertical.service.impl; package com.rymcu.vertical.service.impl;
import com.rymcu.vertical.core.constant.NotificationConstant;
import com.rymcu.vertical.core.service.AbstractService; import com.rymcu.vertical.core.service.AbstractService;
import com.rymcu.vertical.entity.Follow; import com.rymcu.vertical.entity.Follow;
import com.rymcu.vertical.entity.User; import com.rymcu.vertical.entity.User;
import com.rymcu.vertical.mapper.FollowMapper; import com.rymcu.vertical.mapper.FollowMapper;
import com.rymcu.vertical.service.FollowService; import com.rymcu.vertical.service.FollowService;
import com.rymcu.vertical.util.NotificationUtils;
import com.rymcu.vertical.util.UserUtils; import com.rymcu.vertical.util.UserUtils;
import com.rymcu.vertical.web.api.exception.BaseApiException; import com.rymcu.vertical.web.api.exception.BaseApiException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -32,6 +34,9 @@ public class FollowServiceImpl extends AbstractService<Follow> implements Follow
User tokenUser = UserUtils.getCurrentUserByToken(); User tokenUser = UserUtils.getCurrentUserByToken();
follow.setFollowerId(tokenUser.getIdUser()); follow.setFollowerId(tokenUser.getIdUser());
int result = followMapper.insertSelective(follow); int result = followMapper.insertSelective(follow);
if (result > 0) {
NotificationUtils.saveNotification(follow.getFollowingId(), follow.getIdFollow(), NotificationConstant.Follow, tokenUser.getNickname() + " 关注了你!");
}
return result > 0; return result > 0;
} }

View File

@ -5,14 +5,13 @@ import com.rymcu.vertical.dto.ArticleDTO;
import com.rymcu.vertical.dto.Author; import com.rymcu.vertical.dto.Author;
import com.rymcu.vertical.dto.NotificationDTO; import com.rymcu.vertical.dto.NotificationDTO;
import com.rymcu.vertical.entity.Comment; import com.rymcu.vertical.entity.Comment;
import com.rymcu.vertical.entity.Follow;
import com.rymcu.vertical.entity.Notification; import com.rymcu.vertical.entity.Notification;
import com.rymcu.vertical.entity.User; import com.rymcu.vertical.entity.User;
import com.rymcu.vertical.mapper.NotificationMapper; import com.rymcu.vertical.mapper.NotificationMapper;
import com.rymcu.vertical.service.ArticleService; import com.rymcu.vertical.service.*;
import com.rymcu.vertical.service.CommentService;
import com.rymcu.vertical.service.NotificationService;
import com.rymcu.vertical.service.UserService;
import com.rymcu.vertical.util.BeanCopierUtil; import com.rymcu.vertical.util.BeanCopierUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -35,6 +34,10 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
private CommentService commentService; private CommentService commentService;
@Resource @Resource
private UserService userService; private UserService userService;
@Resource
private FollowService followService;
@Value("${resource.domain}")
private String domain;
@Override @Override
public List<Notification> findUnreadNotifications(Integer idUser) { public List<Notification> findUnreadNotifications(Integer idUser) {
@ -59,6 +62,7 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
ArticleDTO article; ArticleDTO article;
Comment comment; Comment comment;
User user; User user;
Follow follow;
switch (notification.getDataType()) { switch (notification.getDataType()) {
case "0": case "0":
// 系统公告/帖子 // 系统公告/帖子
@ -70,6 +74,11 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
break; break;
case "1": 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; break;
case "2": case "2":
// 回帖 // 回帖
@ -80,10 +89,25 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
user = userService.findById(comment.getCommentAuthorId().toString()); user = userService.findById(comment.getCommentAuthorId().toString());
notificationDTO.setAuthor(genAuthor(user)); notificationDTO.setAuthor(genAuthor(user));
break; break;
default:
break;
} }
return notificationDTO; 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) { private Author genAuthor(User user) {
Author author = new Author(); Author author = new Author();
author.setUserNickname(user.getNickname()); author.setUserNickname(user.getNickname());