From 0d9ae829b5c6a17c5886deb61b6033ff311a1c79 Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 3 Jan 2020 19:28:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vertical/config/WebSocketStompConfig.java | 1 - .../com/rymcu/vertical/entity/Comment.java | 59 +++++++++++++++++++ .../com/rymcu/vertical/entity/Follow.java | 31 ++++++++++ .../rymcu/vertical/entity/Notification.java | 50 ++++++++++++++++ .../vertical/mapper/NotificationMapper.java | 22 +++++++ .../vertical/service/NotificationService.java | 25 ++++++++ .../service/impl/NotificationServiceImpl.java | 32 ++++++++++ .../java/com/rymcu/vertical/util/Utils.java | 12 ++++ .../notification/NotificationController.java | 53 +++++++++++++++++ src/main/java/mapper/NotificationMapper.xml | 18 ++++++ 10 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/rymcu/vertical/entity/Comment.java create mode 100644 src/main/java/com/rymcu/vertical/entity/Follow.java create mode 100644 src/main/java/com/rymcu/vertical/entity/Notification.java create mode 100644 src/main/java/com/rymcu/vertical/mapper/NotificationMapper.java create mode 100644 src/main/java/com/rymcu/vertical/service/NotificationService.java create mode 100644 src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java create mode 100644 src/main/java/com/rymcu/vertical/web/api/notification/NotificationController.java create mode 100644 src/main/java/mapper/NotificationMapper.xml diff --git a/src/main/java/com/rymcu/vertical/config/WebSocketStompConfig.java b/src/main/java/com/rymcu/vertical/config/WebSocketStompConfig.java index 9aeab12..a0fb1c8 100644 --- a/src/main/java/com/rymcu/vertical/config/WebSocketStompConfig.java +++ b/src/main/java/com/rymcu/vertical/config/WebSocketStompConfig.java @@ -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(); } diff --git a/src/main/java/com/rymcu/vertical/entity/Comment.java b/src/main/java/com/rymcu/vertical/entity/Comment.java new file mode 100644 index 0000000..6bf348a --- /dev/null +++ b/src/main/java/com/rymcu/vertical/entity/Comment.java @@ -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; +} diff --git a/src/main/java/com/rymcu/vertical/entity/Follow.java b/src/main/java/com/rymcu/vertical/entity/Follow.java new file mode 100644 index 0000000..14fc8d8 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/entity/Follow.java @@ -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; +} diff --git a/src/main/java/com/rymcu/vertical/entity/Notification.java b/src/main/java/com/rymcu/vertical/entity/Notification.java new file mode 100644 index 0000000..09cfba2 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/entity/Notification.java @@ -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; +} diff --git a/src/main/java/com/rymcu/vertical/mapper/NotificationMapper.java b/src/main/java/com/rymcu/vertical/mapper/NotificationMapper.java new file mode 100644 index 0000000..cfdeca1 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/mapper/NotificationMapper.java @@ -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 { + + /** + * 获取未读通知数据 + * @param idUser + * @return + */ + List selectUnreadNotifications(@Param("idUser") Integer idUser); + + List selectNotifications(@Param("idUser") Integer idUser); +} diff --git a/src/main/java/com/rymcu/vertical/service/NotificationService.java b/src/main/java/com/rymcu/vertical/service/NotificationService.java new file mode 100644 index 0000000..dd6a7d5 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/service/NotificationService.java @@ -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 { + /** + * 获取未读消息数据 + * @param idUser + * @return + */ + List findUnreadNotifications(Integer idUser); + + /** + * 获取消息数据 + * @param idUser + * @return + */ + List findNotifications(Integer idUser); +} diff --git a/src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java new file mode 100644 index 0000000..c384fc7 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java @@ -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 implements NotificationService { + + @Resource + private NotificationMapper notificationMapper; + + @Override + public List findUnreadNotifications(Integer idUser){ + List list = notificationMapper.selectUnreadNotifications(idUser); + return list; + } + + @Override + public List findNotifications(Integer idUser) { + List list = notificationMapper.selectNotifications(idUser); + return list; + } +} diff --git a/src/main/java/com/rymcu/vertical/util/Utils.java b/src/main/java/com/rymcu/vertical/util/Utils.java index db4060c..635098e 100644 --- a/src/main/java/com/rymcu/vertical/util/Utils.java +++ b/src/main/java/com/rymcu/vertical/util/Utils.java @@ -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 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; + } } diff --git a/src/main/java/com/rymcu/vertical/web/api/notification/NotificationController.java b/src/main/java/com/rymcu/vertical/web/api/notification/NotificationController.java new file mode 100644 index 0000000..77ca658 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/web/api/notification/NotificationController.java @@ -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 list = notificationService.findNotifications(user.getIdUser()); + PageInfo 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 list = notificationService.findUnreadNotifications(user.getIdUser()); + PageInfo pageInfo = new PageInfo(list); + Map map = Utils.getNotificationsGlobalResult(pageInfo); + return GlobalResultGenerator.genSuccessResult(map); + } + +} diff --git a/src/main/java/mapper/NotificationMapper.xml b/src/main/java/mapper/NotificationMapper.xml new file mode 100644 index 0000000..4d63bb7 --- /dev/null +++ b/src/main/java/mapper/NotificationMapper.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file