🎨 消息中心展示方式优化
This commit is contained in:
parent
af17c90ef4
commit
9a2bc1cade
20
src/main/java/com/rymcu/vertical/dto/NotificationDTO.java
Normal file
20
src/main/java/com/rymcu/vertical/dto/NotificationDTO.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.rymcu.vertical.dto;
|
||||
|
||||
import com.rymcu.vertical.entity.Notification;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author ronger
|
||||
*/
|
||||
@Data
|
||||
public class NotificationDTO extends Notification {
|
||||
|
||||
private Integer idNotification;
|
||||
|
||||
private String dataTitle;
|
||||
|
||||
private String dataUrl;
|
||||
|
||||
private Author author;
|
||||
|
||||
}
|
@ -43,7 +43,7 @@ public class Notification implements Serializable,Cloneable {
|
||||
* 数据摘要
|
||||
*/
|
||||
@Column(name = "data_summary")
|
||||
private String dataSummary ;
|
||||
private String dataSummary;
|
||||
/**
|
||||
* 是否已读
|
||||
*/
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.rymcu.vertical.service;
|
||||
|
||||
import com.rymcu.vertical.core.service.Service;
|
||||
import com.rymcu.vertical.dto.NotificationDTO;
|
||||
import com.rymcu.vertical.entity.Notification;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -23,7 +23,7 @@ public interface NotificationService extends Service<Notification> {
|
||||
* @param idUser
|
||||
* @return
|
||||
*/
|
||||
List<Notification> findNotifications(Integer idUser);
|
||||
List<NotificationDTO> findNotifications(Integer idUser);
|
||||
|
||||
/**
|
||||
* 获取消息数据
|
||||
|
@ -1,13 +1,23 @@
|
||||
package com.rymcu.vertical.service.impl;
|
||||
|
||||
import com.rymcu.vertical.core.service.AbstractService;
|
||||
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.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.util.BeanCopierUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -18,28 +28,84 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
|
||||
|
||||
@Resource
|
||||
private NotificationMapper notificationMapper;
|
||||
@Resource
|
||||
private ArticleService articleService;
|
||||
@Resource
|
||||
private CommentService commentService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Override
|
||||
public List<Notification> findUnreadNotifications(Integer idUser){
|
||||
public List<Notification> findUnreadNotifications(Integer idUser) {
|
||||
List<Notification> list = notificationMapper.selectUnreadNotifications(idUser);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Notification> findNotifications(Integer idUser) {
|
||||
public List<NotificationDTO> findNotifications(Integer idUser) {
|
||||
List<Notification> list = notificationMapper.selectNotifications(idUser);
|
||||
return list;
|
||||
List<NotificationDTO> notifications = new ArrayList<>();
|
||||
list.forEach(notification -> {
|
||||
NotificationDTO notificationDTO = genNotification(notification);
|
||||
notifications.add(notificationDTO);
|
||||
});
|
||||
return notifications;
|
||||
}
|
||||
|
||||
private NotificationDTO genNotification(Notification notification) {
|
||||
NotificationDTO notificationDTO = new NotificationDTO();
|
||||
BeanCopierUtil.copy(notification, notificationDTO);
|
||||
ArticleDTO article;
|
||||
Comment comment;
|
||||
User user;
|
||||
switch (notification.getDataType()) {
|
||||
case "0":
|
||||
// 系统公告/帖子
|
||||
article = articleService.findArticleDTOById(notification.getDataId(), 0);
|
||||
notificationDTO.setDataTitle("系统公告");
|
||||
notificationDTO.setDataUrl(article.getArticlePermalink());
|
||||
user = userService.findById(article.getArticleAuthorId().toString());
|
||||
notificationDTO.setAuthor(genAuthor(user));
|
||||
break;
|
||||
case "1":
|
||||
// 评论
|
||||
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));
|
||||
break;
|
||||
case "2":
|
||||
// 回帖
|
||||
comment = commentService.findById(notification.getDataId().toString());
|
||||
Comment originalComment = commentService.findById(comment.getCommentOriginalCommentId().toString());
|
||||
notificationDTO.setDataTitle(originalComment.getCommentContent());
|
||||
notificationDTO.setDataUrl(comment.getCommentSharpUrl());
|
||||
user = userService.findById(comment.getCommentAuthorId().toString());
|
||||
notificationDTO.setAuthor(genAuthor(user));
|
||||
break;
|
||||
}
|
||||
return notificationDTO;
|
||||
}
|
||||
|
||||
private Author genAuthor(User user) {
|
||||
Author author = new Author();
|
||||
author.setUserNickname(user.getNickname());
|
||||
author.setUserAvatarURL(user.getAvatarUrl());
|
||||
author.setIdUser(user.getIdUser());
|
||||
return author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Notification findNotification(Integer idUser, Integer dataId, String dataType) {
|
||||
return notificationMapper.selectNotification(idUser,dataId,dataType);
|
||||
return notificationMapper.selectNotification(idUser, dataId, dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Integer save(Integer idUser, Integer dataId, String dataType, String dataSummary) {
|
||||
return notificationMapper.insertNotification(idUser,dataId,dataType,dataSummary);
|
||||
return notificationMapper.insertNotification(idUser, dataId, dataType, dataSummary);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,7 @@ package com.rymcu.vertical.util;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.rymcu.vertical.dto.ArticleDTO;
|
||||
import com.rymcu.vertical.dto.NotificationDTO;
|
||||
import com.rymcu.vertical.entity.Notification;
|
||||
import com.rymcu.vertical.entity.User;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
@ -182,4 +183,15 @@ public class Utils {
|
||||
|
||||
return ip;
|
||||
}
|
||||
|
||||
public static Map getNotificationDTOsGlobalResult(PageInfo<NotificationDTO> pageInfo) {
|
||||
Map map = new HashMap(2);
|
||||
map.put("notifications", pageInfo.getList());
|
||||
Map pagination = new HashMap(4);
|
||||
pagination.put("pageSize",pageInfo.getPageSize());
|
||||
pagination.put("total",pageInfo.getTotal());
|
||||
pagination.put("currentPage",pageInfo.getPageNum());
|
||||
map.put("pagination", pagination);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.rymcu.vertical.core.result.GlobalResult;
|
||||
import com.rymcu.vertical.core.result.GlobalResultGenerator;
|
||||
import com.rymcu.vertical.dto.NotificationDTO;
|
||||
import com.rymcu.vertical.entity.Notification;
|
||||
import com.rymcu.vertical.entity.User;
|
||||
import com.rymcu.vertical.service.NotificationService;
|
||||
@ -31,9 +32,9 @@ public class NotificationController {
|
||||
public GlobalResult notifications(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException {
|
||||
User user = UserUtils.getWxCurrentUser();
|
||||
PageHelper.startPage(page, rows);
|
||||
List<Notification> list = notificationService.findNotifications(user.getIdUser());
|
||||
PageInfo<Notification> pageInfo = new PageInfo(list);
|
||||
Map map = Utils.getNotificationsGlobalResult(pageInfo);
|
||||
List<NotificationDTO> list = notificationService.findNotifications(user.getIdUser());
|
||||
PageInfo<NotificationDTO> pageInfo = new PageInfo(list);
|
||||
Map map = Utils.getNotificationDTOsGlobalResult(pageInfo);
|
||||
return GlobalResultGenerator.genSuccessResult(map);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user