commit
88dc0a737b
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")
|
@Column(name = "data_summary")
|
||||||
private String dataSummary ;
|
private String dataSummary;
|
||||||
/**
|
/**
|
||||||
* 是否已读
|
* 是否已读
|
||||||
*/
|
*/
|
||||||
|
@ -8,6 +8,9 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
public interface CommentService extends Service<Comment> {
|
public interface CommentService extends Service<Comment> {
|
||||||
|
|
||||||
List<CommentDTO> getArticleComments(Integer idArticle);
|
List<CommentDTO> getArticleComments(Integer idArticle);
|
||||||
|
@ -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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取消息数据
|
* 获取消息数据
|
||||||
@ -48,5 +48,5 @@ public interface NotificationService extends Service<Notification> {
|
|||||||
* 标记消息已读
|
* 标记消息已读
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
void readNotification(Integer id);
|
Integer readNotification(Integer id);
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ public class CommentServiceImpl extends AbstractService<Comment> implements Comm
|
|||||||
comment.setCreatedTime(new Date());
|
comment.setCreatedTime(new Date());
|
||||||
commentMapper.insertSelective(comment);
|
commentMapper.insertSelective(comment);
|
||||||
StringBuilder commentSharpUrl = new StringBuilder(article.getArticlePermalink());
|
StringBuilder commentSharpUrl = new StringBuilder(article.getArticlePermalink());
|
||||||
commentSharpUrl.append("/comment/").append(comment.getIdComment());
|
commentSharpUrl.append("#comment-").append(comment.getIdComment());
|
||||||
commentMapper.updateCommentSharpUrl(comment.getIdComment(), commentSharpUrl.toString());
|
commentMapper.updateCommentSharpUrl(comment.getIdComment(), commentSharpUrl.toString());
|
||||||
|
|
||||||
String commentContent = comment.getCommentContent();
|
String commentContent = comment.getCommentContent();
|
||||||
|
@ -1,12 +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 javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,31 +28,83 @@ 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) {
|
||||||
List<Notification> list = notificationMapper.selectUnreadNotifications(idUser);
|
List<Notification> list = notificationMapper.selectUnreadNotifications(idUser);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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":
|
||||||
|
// 关注
|
||||||
|
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));
|
||||||
|
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
|
||||||
public Notification findNotification(Integer idUser, Integer dataId, String dataType) {
|
public Notification findNotification(Integer idUser, Integer dataId, String dataType) {
|
||||||
return notificationMapper.selectNotification(idUser,dataId,dataType);
|
return notificationMapper.selectNotification(idUser, dataId, dataType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Integer save(Integer idUser, Integer dataId, String dataType, String dataSummary) {
|
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
|
@Override
|
||||||
public void readNotification(Integer id) {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
notificationMapper.readNotification(id);
|
public Integer readNotification(Integer id) {
|
||||||
|
return notificationMapper.readNotification(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,8 +49,12 @@ public class NotificationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/read/{id}")
|
@PutMapping("/read/{id}")
|
||||||
public void read(@PathVariable Integer id) {
|
public GlobalResult read(@PathVariable Integer id) {
|
||||||
notificationService.readNotification(id);
|
Integer result = notificationService.readNotification(id);
|
||||||
|
if (result == 0) {
|
||||||
|
return GlobalResultGenerator.genErrorResult("标记已读失败");
|
||||||
|
}
|
||||||
|
return GlobalResultGenerator.genSuccessResult("标记已读成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
BIN
src/main/resources/static/jetbrains.png
Normal file
BIN
src/main/resources/static/jetbrains.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 164 KiB |
Loading…
Reference in New Issue
Block a user