消息功能

This commit is contained in:
ronger 2020-01-03 19:28:10 +08:00
parent c9420b7c0a
commit 0d9ae829b5
10 changed files with 302 additions and 1 deletions

View File

@ -18,7 +18,6 @@ public class WebSocketStompConfig implements WebSocketMessageBrokerConfigurer {
*/
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
// 允许使用socketJs方式访问 即可通过http://IP:PORT/ws来和服务端websocket连接
registry.addEndpoint("/ws").setAllowedOrigins("*").withSockJS();
}

View File

@ -0,0 +1,59 @@
package com.rymcu.vertical.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
* @author ronger
*/
@Data
@Table(name="vertical_comment")
public class Comment implements Serializable,Cloneable{
/** 主键 */
@Id
@GeneratedValue(generator = "JDBC")
@Column(name = "id")
private Integer id;
/** 评论内容 */
@Column(name = "comment_content")
private String commentContent;
/** 作者 id */
@Column(name = "comment_author_id")
private Integer commentAuthorId;
/** 文章 id */
@Column(name = "comment_article_id")
private Integer commentArticleId;
/** 锚点 url */
@Column(name = "comment_sharp_url")
private String commentSharpUrl;
/** 父评论 id */
@Column(name = "comment_original_comment_id")
private Integer commentOriginalCommentId;
/** 状态 */
@Column(name = "comment_status")
private String commentStatus;
/** 评论 IP */
@Column(name = "comment_ip")
private String commentIP;
/** User-Agent */
@Column(name = "comment_ua")
private String commentUA;
/** 0公开回帖1匿名回帖 */
@Column(name = "comment_anonymous")
private String commentAnonymous;
/** 回帖计数 */
@Column(name = "comment_reply_count")
private Integer commentReplyCount;
/** 0所有人可见1仅楼主和自己可见 */
@Column(name = "comment_visible")
private String commentVisible;
/** 创建时间 */
@Column(name = "created_time")
private Date createdTime;
}

View File

@ -0,0 +1,31 @@
package com.rymcu.vertical.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
/**
* @author ronger
*/
@Data
@Table(name="vertical_follow")
public class Follow implements Serializable,Cloneable{
/** 主键 */
@Id
@GeneratedValue(generator = "JDBC")
@Column(name = "id")
private Integer idFollow;
/** 关注者 id */
@Column(name = "follower_id")
private Integer followerId;
/** 关注数据 id */
@Column(name = "following_id")
private Integer followingId;
/** 0用户1标签2帖子收藏3帖子关注 */
@Column(name = "following_type")
private String followingType;
}

View File

@ -0,0 +1,50 @@
package com.rymcu.vertical.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
/**
* @author ronger
*/
@Data
@Table(name="vertical_notification")
public class Notification implements Serializable,Cloneable {
/**
* 主键
*/
@Id
@GeneratedValue(generator = "JDBC")
@Column(name = "id")
private Integer idNotification;
/**
* 用户id
*/
@Column(name = "id_user")
private Integer idUser;
/**
* 数据类型
*/
@Column(name = "data_type")
private String dataType;
/**
* 数据id
*/
@Column(name = "data_id")
private Integer dataId;
/**
* 数据摘要
*/
@Column(name = "data_summary")
private String dataSummary ;
/**
* 是否已读
*/
@Column(name = "has_read")
private String hasRead;
}

View File

@ -0,0 +1,22 @@
package com.rymcu.vertical.mapper;
import com.rymcu.vertical.core.mapper.Mapper;
import com.rymcu.vertical.entity.Notification;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author ronger
*/
public interface NotificationMapper extends Mapper<Notification> {
/**
* 获取未读通知数据
* @param idUser
* @return
*/
List<Notification> selectUnreadNotifications(@Param("idUser") Integer idUser);
List<Notification> selectNotifications(@Param("idUser") Integer idUser);
}

View File

@ -0,0 +1,25 @@
package com.rymcu.vertical.service;
import com.rymcu.vertical.core.service.Service;
import com.rymcu.vertical.entity.Notification;
import java.util.List;
/**
* @author ronger
*/
public interface NotificationService extends Service<Notification> {
/**
* 获取未读消息数据
* @param idUser
* @return
*/
List<Notification> findUnreadNotifications(Integer idUser);
/**
* 获取消息数据
* @param idUser
* @return
*/
List<Notification> findNotifications(Integer idUser);
}

View File

@ -0,0 +1,32 @@
package com.rymcu.vertical.service.impl;
import com.rymcu.vertical.core.service.AbstractService;
import com.rymcu.vertical.entity.Notification;
import com.rymcu.vertical.mapper.NotificationMapper;
import com.rymcu.vertical.service.NotificationService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* @author ronger
*/
@Service
public class NotificationServiceImpl extends AbstractService<Notification> implements NotificationService {
@Resource
private NotificationMapper notificationMapper;
@Override
public List<Notification> findUnreadNotifications(Integer idUser){
List<Notification> list = notificationMapper.selectUnreadNotifications(idUser);
return list;
}
@Override
public List<Notification> findNotifications(Integer idUser) {
List<Notification> list = notificationMapper.selectNotifications(idUser);
return list;
}
}

View File

@ -2,6 +2,7 @@ package com.rymcu.vertical.util;
import com.github.pagehelper.PageInfo;
import com.rymcu.vertical.dto.ArticleDTO;
import com.rymcu.vertical.entity.Notification;
import com.rymcu.vertical.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.InvalidSessionException;
@ -143,4 +144,15 @@ public class Utils {
map.put("pagination", pagination);
return map;
}
public static Map getNotificationsGlobalResult(PageInfo<Notification> 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;
}
}

View File

@ -0,0 +1,53 @@
package com.rymcu.vertical.web.api.notification;
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.entity.Notification;
import com.rymcu.vertical.entity.User;
import com.rymcu.vertical.service.NotificationService;
import com.rymcu.vertical.util.UserUtils;
import com.rymcu.vertical.util.Utils;
import com.rymcu.vertical.web.api.exception.BaseApiException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* 消息通知
* @author ronger
*/
@RestController
@RequestMapping("/api/v1/notification")
public class NotificationController {
@Resource
private NotificationService notificationService;
@GetMapping("/all")
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);
return GlobalResultGenerator.genSuccessResult(map);
}
@GetMapping("/unread")
public GlobalResult unreadNotification(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException {
User user = UserUtils.getWxCurrentUser();
PageHelper.startPage(page, rows);
List<Notification> list = notificationService.findUnreadNotifications(user.getIdUser());
PageInfo<Notification> pageInfo = new PageInfo(list);
Map map = Utils.getNotificationsGlobalResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
}
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.rymcu.vertical.mapper.NotificationMapper">
<resultMap id="BaseResultMapper" type="com.rymcu.vertical.entity.Notification">
<id column="id" property="idNotification"></id>
<result column="id_user" property="idUser"></result>
<result column="data_type" property="dataType"></result>
<result column="data_id" property="dataId"></result>
<result column="data_summary" property="dataSummary"></result>
<result column="has_read" property="hasRead"></result>
</resultMap>
<select id="selectUnreadNotifications" resultMap="BaseResultMapper">
select * from vertical_notification where has_read = '0' and id_user = #{idUser}
</select>
<select id="selectNotifications" resultMap="BaseResultMapper">
select * from vertical_notification where id_user = #{idUser}
</select>
</mapper>