BUGFIX: 获取系统通知未读数

This commit is contained in:
2025-11-18 17:45:11 +08:00
parent 97f0c8f65f
commit cefdac133e

View File

@@ -64,7 +64,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
.collect(Collectors.toMap( .collect(Collectors.toMap(
map -> (String) map.get("type"), map -> (String) map.get("type"),
map -> Objects.isNull(map.get("count")) ? 0L : (Long) map.get("count"))); map -> Objects.isNull(map.get("count")) ? 0L : (Long) map.get("count")));
msgTypeCount.put("system", getUnreadSystemNotification()); msgTypeCount.put("system", getUnreadSystemNotification(accountId));
msgTypeCount.put("newPosted", getNewPostedCount(accountId)); msgTypeCount.put("newPosted", getNewPostedCount(accountId));
log.info(msgTypeCount.toString()); log.info(msgTypeCount.toString());
// 整理数据 加上系统消息未读数 // 整理数据 加上系统消息未读数
@@ -194,7 +194,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
count = getUnreadCountByType(type, receiverId); count = getUnreadCountByType(type, receiverId);
} else { } else {
// 系统未读消息 // 系统未读消息
count = getUnreadSystemNotification(); count = getUnreadSystemNotification(receiverId);
} }
if (type.equals("follow")) { if (type.equals("follow")) {
HashMap<String, Object> followee = new HashMap<>(); HashMap<String, Object> followee = new HashMap<>();
@@ -245,21 +245,21 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
return baseMapper.selectCount(queryWrapper); return baseMapper.selectCount(queryWrapper);
} }
private Long getUnreadSystemNotification() { private Long getUnreadSystemNotification(Long receiverId) {
Long accountId = UserContext.getUserHolder().getId(); // Long accountId = UserContext.getUserHolder().getId();
// 计算总的系统通知数量 // 计算总的系统通知数量
QueryWrapper<Notification> queryWrapper = new QueryWrapper<>(); QueryWrapper<Notification> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(Notification::getType, "system") queryWrapper.lambda().eq(Notification::getType, "system")
.and(wrapper -> wrapper .and(wrapper -> wrapper
.isNull(Notification::getReceiverId) .isNull(Notification::getReceiverId)
.or() .or()
.eq(Notification::getReceiverId, accountId) .eq(Notification::getReceiverId, receiverId)
); );
Long totalSysCount = baseMapper.selectCount(queryWrapper); Long totalSysCount = baseMapper.selectCount(queryWrapper);
// 计算单个用户读了多少条系统数据 // 计算单个用户读了多少条系统数据
QueryWrapper<SysNotificationReadStatus> wrapper = new QueryWrapper<>(); QueryWrapper<SysNotificationReadStatus> wrapper = new QueryWrapper<>();
wrapper.eq("account_id", accountId); wrapper.eq("account_id", receiverId);
Long readCount = sysNotificationReadStatusMapper.selectCount(wrapper); Long readCount = sysNotificationReadStatusMapper.selectCount(wrapper);
// 计算差 // 计算差
@@ -416,7 +416,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
notification.setIsRead(0); notification.setIsRead(0);
notification.setCreateTime(LocalDateTime.now()); notification.setCreateTime(LocalDateTime.now());
save(notification); save(notification);
// 这里推送消息是在接受到视频生成结束后发生的所以UserContext中没有用户信息
pushMessage("system", userId); pushMessage("system", userId);
} }