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 22b22d1..b571e6f 100644 --- a/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java @@ -23,12 +23,11 @@ public class NotificationServiceImpl extends AbstractService imple @Resource private NotificationMapper notificationMapper; - private final static String unRead = "0"; + private final static String UN_READ = "0"; @Override public List findUnreadNotifications(Integer idUser) { - List list = notificationMapper.selectUnreadNotifications(idUser); - return list; + return notificationMapper.selectUnreadNotifications(idUser); } @Override @@ -41,7 +40,7 @@ public class NotificationServiceImpl extends AbstractService imple BeanCopierUtil.copy(notificationDTO, notification); } else { // 关联数据已删除,且未读 - if (unRead.equals(notification.getHasRead())) { + if (UN_READ.equals(notification.getHasRead())) { notificationMapper.readNotification(notification.getIdNotification()); } NotificationDTO dto = new NotificationDTO(); diff --git a/src/main/java/com/rymcu/forest/web/api/notification/NotificationController.java b/src/main/java/com/rymcu/forest/web/api/notification/NotificationController.java index e4509f1..42c5072 100644 --- a/src/main/java/com/rymcu/forest/web/api/notification/NotificationController.java +++ b/src/main/java/com/rymcu/forest/web/api/notification/NotificationController.java @@ -11,11 +11,13 @@ import com.rymcu.forest.service.NotificationService; import com.rymcu.forest.util.UserUtils; import com.rymcu.forest.util.Utils; import com.rymcu.forest.web.api.exception.BaseApiException; +import com.rymcu.forest.web.api.exception.ErrorCode; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; import java.util.Map; +import java.util.Objects; /** * 消息通知 @@ -31,6 +33,9 @@ public class NotificationController { @GetMapping("/all") public GlobalResult notifications(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException { User user = UserUtils.getCurrentUserByToken(); + if (Objects.isNull(user)) { + throw new BaseApiException(ErrorCode.TOKEN_); + } PageHelper.startPage(page, rows); List list = notificationService.findNotifications(user.getIdUser()); PageInfo pageInfo = new PageInfo(list); @@ -41,6 +46,9 @@ public class NotificationController { @GetMapping("/unread") public GlobalResult unreadNotification(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException { User user = UserUtils.getCurrentUserByToken(); + if (Objects.isNull(user)) { + throw new BaseApiException(ErrorCode.TOKEN_); + } PageHelper.startPage(page, rows); List list = notificationService.findUnreadNotifications(user.getIdUser()); PageInfo pageInfo = new PageInfo(list);