🎨 消息中心展示方式优化
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;
|
||||||
|
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
package com.rymcu.vertical.service;
|
package com.rymcu.vertical.service;
|
||||||
|
|
||||||
import com.rymcu.vertical.core.service.Service;
|
import com.rymcu.vertical.core.service.Service;
|
||||||
|
import com.rymcu.vertical.dto.NotificationDTO;
|
||||||
import com.rymcu.vertical.entity.Notification;
|
import com.rymcu.vertical.entity.Notification;
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ public interface NotificationService extends Service<Notification> {
|
|||||||
* @param idUser
|
* @param idUser
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<Notification> findNotifications(Integer idUser);
|
List<NotificationDTO> findNotifications(Integer idUser);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取消息数据
|
* 获取消息数据
|
||||||
|
@ -1,13 +1,23 @@
|
|||||||
package com.rymcu.vertical.service.impl;
|
package com.rymcu.vertical.service.impl;
|
||||||
|
|
||||||
import com.rymcu.vertical.core.service.AbstractService;
|
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.Notification;
|
||||||
|
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.CommentService;
|
||||||
import com.rymcu.vertical.service.NotificationService;
|
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.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,6 +28,12 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private NotificationMapper notificationMapper;
|
private NotificationMapper notificationMapper;
|
||||||
|
@Resource
|
||||||
|
private ArticleService articleService;
|
||||||
|
@Resource
|
||||||
|
private CommentService commentService;
|
||||||
|
@Resource
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Notification> findUnreadNotifications(Integer idUser) {
|
public List<Notification> findUnreadNotifications(Integer idUser) {
|
||||||
@ -26,9 +42,59 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Notification> findNotifications(Integer idUser) {
|
public List<NotificationDTO> findNotifications(Integer idUser) {
|
||||||
List<Notification> list = notificationMapper.selectNotifications(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
|
@Override
|
||||||
|
@ -2,6 +2,7 @@ package com.rymcu.vertical.util;
|
|||||||
|
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.rymcu.vertical.dto.ArticleDTO;
|
import com.rymcu.vertical.dto.ArticleDTO;
|
||||||
|
import com.rymcu.vertical.dto.NotificationDTO;
|
||||||
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 org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
@ -182,4 +183,15 @@ public class Utils {
|
|||||||
|
|
||||||
return ip;
|
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.github.pagehelper.PageInfo;
|
||||||
import com.rymcu.vertical.core.result.GlobalResult;
|
import com.rymcu.vertical.core.result.GlobalResult;
|
||||||
import com.rymcu.vertical.core.result.GlobalResultGenerator;
|
import com.rymcu.vertical.core.result.GlobalResultGenerator;
|
||||||
|
import com.rymcu.vertical.dto.NotificationDTO;
|
||||||
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.service.NotificationService;
|
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 {
|
public GlobalResult notifications(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException {
|
||||||
User user = UserUtils.getWxCurrentUser();
|
User user = UserUtils.getWxCurrentUser();
|
||||||
PageHelper.startPage(page, rows);
|
PageHelper.startPage(page, rows);
|
||||||
List<Notification> list = notificationService.findNotifications(user.getIdUser());
|
List<NotificationDTO> list = notificationService.findNotifications(user.getIdUser());
|
||||||
PageInfo<Notification> pageInfo = new PageInfo(list);
|
PageInfo<NotificationDTO> pageInfo = new PageInfo(list);
|
||||||
Map map = Utils.getNotificationsGlobalResult(pageInfo);
|
Map map = Utils.getNotificationDTOsGlobalResult(pageInfo);
|
||||||
return GlobalResultGenerator.genSuccessResult(map);
|
return GlobalResultGenerator.genSuccessResult(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user