BUGFIX:新用户不能获取历史系统通知

This commit is contained in:
2025-12-24 11:47:11 +08:00
parent bf95b85841
commit cd767dce6f
3 changed files with 11 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ import com.ai.da.common.config.mybatis.plus.CommonMapper;
import com.ai.da.mapper.primary.entity.Notification;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -20,5 +21,5 @@ public interface NotificationMapper extends CommonMapper<Notification> {
void setPersonalNotificationAllRead(String type, Long receiverId, LocalDateTime time);
List<Long> getUnreadSysNotification(Long accountId);
List<Long> getUnreadSysNotification(Long accountId, Date createTime);
}

View File

@@ -79,6 +79,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
throw new BusinessException("type.cannot.be.empty");
}
Long accountId = UserContext.getUserHolder().getId();
Account account = accountService.getById(accountId);
// 查动态
if (!StringUtils.isNullOrEmpty(getNotificationDTO.getType()) && getNotificationDTO.getType().equals("newPosted")) {
return getNewPosted(accountId, getNotificationDTO.getPage(), getNotificationDTO.getSize());
@@ -92,6 +93,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
if (getNotificationDTO.getType().equals("system")) {
queryWrapper.lambda().eq(Notification::getType, "system")
.gt(Notification::getCreateTime, account.getCreateDate())
.and(wrapper -> wrapper
.isNull(Notification::getReceiverId)
.or()
@@ -103,7 +105,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
Page<Notification> notificationPage = baseMapper.selectPage(new Page<>(getNotificationDTO.getPage(), getNotificationDTO.getSize()), queryWrapper);
List<Long> unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId);
List<Long> unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId, account.getCreateDate());
IPage<NotificationVO> convert = notificationPage.convert(o -> {
NotificationVO notificationVO = CopyUtil.copyObject(o, NotificationVO.class);
Account senderAccount = accountService.getById(notificationVO.getSenderId());
@@ -247,9 +249,11 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
private Long getUnreadSystemNotification(Long receiverId) {
// Long accountId = UserContext.getUserHolder().getId();
Account account = accountService.getById(receiverId);
// 计算总的系统通知数量
QueryWrapper<Notification> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(Notification::getType, "system")
.gt(Notification::getCreateTime, account.getCreateDate())
.and(wrapper -> wrapper
.isNull(Notification::getReceiverId)
.or()
@@ -302,6 +306,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
// 一键已读
public void setReadAll(String type) {
Long accountId = UserContext.getUserHolder().getId();
Account account = accountService.getById(accountId);
// 指定某个用户的某种类型的数据,将未读数据全部已读
if (!type.equals("system")) {
// 个人消息已读
@@ -309,7 +314,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
} else {
// 系统消息已读
// 1、先确定当前用户未读的系统消息有哪些
List<Long> unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId);
List<Long> unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId, account.getCreateDate());
// 2、将未读的设为已读
if (!unreadSysNotificationIds.isEmpty()) setReadStatusSystem(unreadSysNotificationIds);
}