diff --git a/src/main/java/com/rymcu/forest/mapper/NotificationMapper.java b/src/main/java/com/rymcu/forest/mapper/NotificationMapper.java index 8a3dd6f..2ae27ad 100644 --- a/src/main/java/com/rymcu/forest/mapper/NotificationMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/NotificationMapper.java @@ -1,6 +1,7 @@ package com.rymcu.forest.mapper; import com.rymcu.forest.core.mapper.Mapper; +import com.rymcu.forest.dto.NotificationDTO; import com.rymcu.forest.entity.Notification; import org.apache.ibatis.annotations.Param; @@ -23,7 +24,7 @@ public interface NotificationMapper extends Mapper { * @param idUser * @return */ - List selectNotifications(@Param("idUser") Integer idUser); + List selectNotifications(@Param("idUser") Integer idUser); /** * 获取消息数据 diff --git a/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java index 7aef442..4883182 100644 --- a/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java @@ -49,13 +49,12 @@ public class NotificationServiceImpl extends AbstractService imple @Override public List findNotifications(Integer idUser) { - List list = notificationMapper.selectNotifications(idUser); - List notifications = new ArrayList<>(); + List list = notificationMapper.selectNotifications(idUser); list.forEach(notification -> { NotificationDTO notificationDTO = genNotification(notification); // 判断关联数据是否已删除 if (Objects.nonNull(notificationDTO.getAuthor())) { - notifications.add(notificationDTO); + BeanCopierUtil.copy(notificationDTO, notification); } else { // 关联数据已删除,且未读 if (unRead.equals(notification.getHasRead())) { @@ -66,10 +65,10 @@ public class NotificationServiceImpl extends AbstractService imple dto.setDataType("-1"); dto.setHasRead("1"); dto.setCreatedTime(notification.getCreatedTime()); - notifications.add(dto); + BeanCopierUtil.copy(dto, notification); } }); - return notifications; + return list; } private NotificationDTO genNotification(Notification notification) { diff --git a/src/main/java/mapper/NotificationMapper.xml b/src/main/java/mapper/NotificationMapper.xml index 81fa9b0..80ef662 100644 --- a/src/main/java/mapper/NotificationMapper.xml +++ b/src/main/java/mapper/NotificationMapper.xml @@ -10,6 +10,15 @@ + + + + + + + + + insert into forest_notification (id_user, data_type, data_id, data_summary, created_time) values (#{idUser}, #{dataType}, #{dataId}, #{dataSummary}, sysdate()) @@ -19,7 +28,7 @@ - select * from forest_notification where id_user = #{idUser} order by created_time desc