消息通知系统-一键已读;反复点赞、关注及取消 数据存储处理,
This commit is contained in:
@@ -53,4 +53,11 @@ public class MessageCenterController {
|
||||
messageCenterService.publishSystemNotification(message);
|
||||
return Response.success("success");
|
||||
}
|
||||
|
||||
@ApiOperation(value = "一键已读")
|
||||
@PostMapping("/oneClickRead")
|
||||
public Response<String> setReadAll(@RequestParam("type") String type) {
|
||||
messageCenterService.setReadAll(type);
|
||||
return Response.success("success");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,8 @@ public interface NotificationMapper extends CommonMapper<Notification> {
|
||||
void updateUniqueLikeAndFollow(Long id, LocalDateTime time);
|
||||
|
||||
void deleteNotification(Long id, LocalDateTime time);
|
||||
|
||||
void setPersonalNotificationAllRead(String type, Long receiverId, LocalDateTime time);
|
||||
|
||||
List<Long> getUnreadSysNotification(Long accountId);
|
||||
}
|
||||
|
||||
@@ -22,5 +22,7 @@ public interface MessageCenterService extends IService<Notification> {
|
||||
|
||||
Boolean setReadStatus(List<Long> notificationIdList, String type);
|
||||
|
||||
void setReadAll(String type);
|
||||
|
||||
void publishSystemNotification(PublishSysNotificationVO message);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,6 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
return msgTypeCount;
|
||||
}
|
||||
|
||||
|
||||
// 获取历史消息 可指定消息类型 分页查询
|
||||
@Override
|
||||
public PageBaseResponse<NotificationVO> getHistoryNotification(GetNotificationVO getNotificationVO) {
|
||||
@@ -127,14 +126,14 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
|
||||
|
||||
// 消息推送 只需要返回当前操作类型和该操作未读消息数量
|
||||
public void pushMessage(String type, Long senderId) {
|
||||
public void pushMessage(String type, Long receiverId) {
|
||||
// 推送消息到前端
|
||||
ArrayList<Map<String, Object>> resp = new ArrayList<>();
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
Long count;
|
||||
if (!type.equals("system")) {
|
||||
// 个人未读消息
|
||||
count = getUnreadCountByType(type, senderId);
|
||||
count = getUnreadCountByType(type, receiverId);
|
||||
} else {
|
||||
// 系统未读消息
|
||||
count = getUnreadSystemNotification();
|
||||
@@ -227,7 +226,22 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
||||
}
|
||||
}
|
||||
|
||||
// todo 全部已读
|
||||
// 一键已读
|
||||
public void setReadAll(String type){
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
// 指定某个用户的某种类型的数据,将未读数据全部已读
|
||||
if (!type.equals("system")){
|
||||
// 个人消息已读
|
||||
baseMapper.setPersonalNotificationAllRead(type, accountId, LocalDateTime.now());
|
||||
}else {
|
||||
// 系统消息已读
|
||||
// 1、先确定当前用户未读的系统消息有哪些
|
||||
List<Long> unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId);
|
||||
// 2、将未读的设为已读
|
||||
if (!unreadSysNotificationIds.isEmpty()) setReadStatusSystem(unreadSysNotificationIds);
|
||||
}
|
||||
pushMessage(type, accountId);
|
||||
}
|
||||
|
||||
// 发布系统消息
|
||||
public void publishSystemNotification(PublishSysNotificationVO message) {
|
||||
|
||||
@@ -40,4 +40,27 @@
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="setPersonalNotificationAllRead">
|
||||
update `t_notification`
|
||||
SET
|
||||
is_read = 1,
|
||||
update_time = #{time}
|
||||
WHERE type = #{type}
|
||||
AND receiver_id = #{receiverId}
|
||||
AND is_read = 0
|
||||
AND is_deleted = 0
|
||||
</update>
|
||||
|
||||
<select id="getUnreadSysNotification" resultType="Long">
|
||||
SELECT id
|
||||
FROM `t_notification`
|
||||
WHERE type = 'system'
|
||||
AND id NOT IN (
|
||||
SELECT system_notification_id
|
||||
FROM `t_sys_notification_read_status`
|
||||
WHERE account_id = #{accountId}
|
||||
)
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user