From ac28ba233c55074c03ca2304b457707359a0bd41 Mon Sep 17 00:00:00 2001 From: xupei Date: Fri, 16 Aug 2024 10:32:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F-=E4=B8=80=E9=94=AE=E5=B7=B2=E8=AF=BB=EF=BC=9B?= =?UTF-8?q?=E5=8F=8D=E5=A4=8D=E7=82=B9=E8=B5=9E=E3=80=81=E5=85=B3=E6=B3=A8?= =?UTF-8?q?=E5=8F=8A=E5=8F=96=E6=B6=88=20=E6=95=B0=E6=8D=AE=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E5=A4=84=E7=90=86=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MessageCenterController.java | 7 ++++++ .../da/mapper/primary/NotificationMapper.java | 4 ++++ .../ai/da/service/MessageCenterService.java | 2 ++ .../impl/MessageCenterServiceImpl.java | 22 ++++++++++++++---- .../mapper/primary/NotificationMapper.xml | 23 +++++++++++++++++++ 5 files changed, 54 insertions(+), 4 deletions(-) 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 + + + + +