🐛 消息通知关联数据删除后报错问题修复

This commit is contained in:
x ronger 2020-09-29 21:40:25 +08:00
parent 1d02fb6664
commit 794dee88f5

View File

@ -39,6 +39,8 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
@Value("${resource.domain}") @Value("${resource.domain}")
private String domain; private String domain;
private final static String unRead = "0";
@Override @Override
public List<Notification> findUnreadNotifications(Integer idUser) { public List<Notification> findUnreadNotifications(Integer idUser) {
List<Notification> list = notificationMapper.selectUnreadNotifications(idUser); List<Notification> list = notificationMapper.selectUnreadNotifications(idUser);
@ -51,8 +53,20 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
List<NotificationDTO> notifications = new ArrayList<>(); List<NotificationDTO> notifications = new ArrayList<>();
list.forEach(notification -> { list.forEach(notification -> {
NotificationDTO notificationDTO = genNotification(notification); NotificationDTO notificationDTO = genNotification(notification);
// 判断关联数据是否已删除
if (Objects.nonNull(notificationDTO.getAuthor())) { if (Objects.nonNull(notificationDTO.getAuthor())) {
notifications.add(notificationDTO); notifications.add(notificationDTO);
} else {
// 关联数据已删除,且未读
if (unRead.equals(notification.getHasRead())) {
notificationMapper.readNotification(notification.getIdNotification());
}
NotificationDTO dto = new NotificationDTO();
dto.setDataSummary("该消息已被撤销!");
dto.setDataType("-1");
dto.setHasRead("1");
dto.setCreatedTime(notification.getCreatedTime());
notifications.add(dto);
} }
}); });
return notifications; return notifications;