BUGFIX:新用户不能获取历史系统通知
This commit is contained in:
@@ -4,6 +4,7 @@ import com.ai.da.common.config.mybatis.plus.CommonMapper;
|
|||||||
import com.ai.da.mapper.primary.entity.Notification;
|
import com.ai.da.mapper.primary.entity.Notification;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -20,5 +21,5 @@ public interface NotificationMapper extends CommonMapper<Notification> {
|
|||||||
|
|
||||||
void setPersonalNotificationAllRead(String type, Long receiverId, LocalDateTime time);
|
void setPersonalNotificationAllRead(String type, Long receiverId, LocalDateTime time);
|
||||||
|
|
||||||
List<Long> getUnreadSysNotification(Long accountId);
|
List<Long> getUnreadSysNotification(Long accountId, Date createTime);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
|||||||
throw new BusinessException("type.cannot.be.empty");
|
throw new BusinessException("type.cannot.be.empty");
|
||||||
}
|
}
|
||||||
Long accountId = UserContext.getUserHolder().getId();
|
Long accountId = UserContext.getUserHolder().getId();
|
||||||
|
Account account = accountService.getById(accountId);
|
||||||
// 查动态
|
// 查动态
|
||||||
if (!StringUtils.isNullOrEmpty(getNotificationDTO.getType()) && getNotificationDTO.getType().equals("newPosted")) {
|
if (!StringUtils.isNullOrEmpty(getNotificationDTO.getType()) && getNotificationDTO.getType().equals("newPosted")) {
|
||||||
return getNewPosted(accountId, getNotificationDTO.getPage(), getNotificationDTO.getSize());
|
return getNewPosted(accountId, getNotificationDTO.getPage(), getNotificationDTO.getSize());
|
||||||
@@ -92,6 +93,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
|||||||
|
|
||||||
if (getNotificationDTO.getType().equals("system")) {
|
if (getNotificationDTO.getType().equals("system")) {
|
||||||
queryWrapper.lambda().eq(Notification::getType, "system")
|
queryWrapper.lambda().eq(Notification::getType, "system")
|
||||||
|
.gt(Notification::getCreateTime, account.getCreateDate())
|
||||||
.and(wrapper -> wrapper
|
.and(wrapper -> wrapper
|
||||||
.isNull(Notification::getReceiverId)
|
.isNull(Notification::getReceiverId)
|
||||||
.or()
|
.or()
|
||||||
@@ -103,7 +105,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
|||||||
|
|
||||||
Page<Notification> notificationPage = baseMapper.selectPage(new Page<>(getNotificationDTO.getPage(), getNotificationDTO.getSize()), queryWrapper);
|
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 -> {
|
IPage<NotificationVO> convert = notificationPage.convert(o -> {
|
||||||
NotificationVO notificationVO = CopyUtil.copyObject(o, NotificationVO.class);
|
NotificationVO notificationVO = CopyUtil.copyObject(o, NotificationVO.class);
|
||||||
Account senderAccount = accountService.getById(notificationVO.getSenderId());
|
Account senderAccount = accountService.getById(notificationVO.getSenderId());
|
||||||
@@ -247,9 +249,11 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
|||||||
|
|
||||||
private Long getUnreadSystemNotification(Long receiverId) {
|
private Long getUnreadSystemNotification(Long receiverId) {
|
||||||
// Long accountId = UserContext.getUserHolder().getId();
|
// Long accountId = UserContext.getUserHolder().getId();
|
||||||
|
Account account = accountService.getById(receiverId);
|
||||||
// 计算总的系统通知数量
|
// 计算总的系统通知数量
|
||||||
QueryWrapper<Notification> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<Notification> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.lambda().eq(Notification::getType, "system")
|
queryWrapper.lambda().eq(Notification::getType, "system")
|
||||||
|
.gt(Notification::getCreateTime, account.getCreateDate())
|
||||||
.and(wrapper -> wrapper
|
.and(wrapper -> wrapper
|
||||||
.isNull(Notification::getReceiverId)
|
.isNull(Notification::getReceiverId)
|
||||||
.or()
|
.or()
|
||||||
@@ -302,6 +306,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
|||||||
// 一键已读
|
// 一键已读
|
||||||
public void setReadAll(String type) {
|
public void setReadAll(String type) {
|
||||||
Long accountId = UserContext.getUserHolder().getId();
|
Long accountId = UserContext.getUserHolder().getId();
|
||||||
|
Account account = accountService.getById(accountId);
|
||||||
// 指定某个用户的某种类型的数据,将未读数据全部已读
|
// 指定某个用户的某种类型的数据,将未读数据全部已读
|
||||||
if (!type.equals("system")) {
|
if (!type.equals("system")) {
|
||||||
// 个人消息已读
|
// 个人消息已读
|
||||||
@@ -309,7 +314,7 @@ public class MessageCenterServiceImpl extends ServiceImpl<NotificationMapper, No
|
|||||||
} else {
|
} else {
|
||||||
// 系统消息已读
|
// 系统消息已读
|
||||||
// 1、先确定当前用户未读的系统消息有哪些
|
// 1、先确定当前用户未读的系统消息有哪些
|
||||||
List<Long> unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId);
|
List<Long> unreadSysNotificationIds = baseMapper.getUnreadSysNotification(accountId, account.getCreateDate());
|
||||||
// 2、将未读的设为已读
|
// 2、将未读的设为已读
|
||||||
if (!unreadSysNotificationIds.isEmpty()) setReadStatusSystem(unreadSysNotificationIds);
|
if (!unreadSysNotificationIds.isEmpty()) setReadStatusSystem(unreadSysNotificationIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,8 @@
|
|||||||
SELECT system_notification_id
|
SELECT system_notification_id
|
||||||
FROM `t_sys_notification_read_status`
|
FROM `t_sys_notification_read_status`
|
||||||
WHERE account_id = #{accountId}
|
WHERE account_id = #{accountId}
|
||||||
)
|
)
|
||||||
|
AND create_time > #{createTime}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user