diff --git a/src/main/java/com/ai/da/controller/MessageCenterController.java b/src/main/java/com/ai/da/controller/MessageCenterController.java index 385c7557..66bb764c 100644 --- a/src/main/java/com/ai/da/controller/MessageCenterController.java +++ b/src/main/java/com/ai/da/controller/MessageCenterController.java @@ -53,4 +53,11 @@ public class MessageCenterController { messageCenterService.publishSystemNotification(message); return Response.success("success"); } + + @ApiOperation(value = "一键已读") + @PostMapping("/oneClickRead") + public Response setReadAll(@RequestParam("type") String type) { + messageCenterService.setReadAll(type); + return Response.success("success"); + } } diff --git a/src/main/java/com/ai/da/mapper/primary/NotificationMapper.java b/src/main/java/com/ai/da/mapper/primary/NotificationMapper.java index 54427ace..bdce12a3 100644 --- a/src/main/java/com/ai/da/mapper/primary/NotificationMapper.java +++ b/src/main/java/com/ai/da/mapper/primary/NotificationMapper.java @@ -17,4 +17,8 @@ public interface NotificationMapper extends CommonMapper { void updateUniqueLikeAndFollow(Long id, LocalDateTime time); void deleteNotification(Long id, LocalDateTime time); + + void setPersonalNotificationAllRead(String type, Long receiverId, LocalDateTime time); + + List getUnreadSysNotification(Long accountId); } diff --git a/src/main/java/com/ai/da/service/MessageCenterService.java b/src/main/java/com/ai/da/service/MessageCenterService.java index f4f26f43..35930a5a 100644 --- a/src/main/java/com/ai/da/service/MessageCenterService.java +++ b/src/main/java/com/ai/da/service/MessageCenterService.java @@ -22,5 +22,7 @@ public interface MessageCenterService extends IService { Boolean setReadStatus(List notificationIdList, String type); + void setReadAll(String type); + void publishSystemNotification(PublishSysNotificationVO message); } diff --git a/src/main/java/com/ai/da/service/impl/MessageCenterServiceImpl.java b/src/main/java/com/ai/da/service/impl/MessageCenterServiceImpl.java index 114ac00c..02c69ff8 100644 --- a/src/main/java/com/ai/da/service/impl/MessageCenterServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/MessageCenterServiceImpl.java @@ -64,7 +64,6 @@ public class MessageCenterServiceImpl extends ServiceImpl getHistoryNotification(GetNotificationVO getNotificationVO) { @@ -127,14 +126,14 @@ public class MessageCenterServiceImpl extends ServiceImpl> resp = new ArrayList<>(); HashMap 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 unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId); + // 2、将未读的设为已读 + if (!unreadSysNotificationIds.isEmpty()) setReadStatusSystem(unreadSysNotificationIds); + } + pushMessage(type, accountId); + } // 发布系统消息 public void publishSystemNotification(PublishSysNotificationVO message) { diff --git a/src/main/resources/mapper/primary/NotificationMapper.xml b/src/main/resources/mapper/primary/NotificationMapper.xml index d6bc65e9..eaedaaa5 100644 --- a/src/main/resources/mapper/primary/NotificationMapper.xml +++ b/src/main/resources/mapper/primary/NotificationMapper.xml @@ -40,4 +40,27 @@ WHERE id = #{id} + + 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 + + + + +