🎨 优化代码

This commit is contained in:
ronger 2021-12-24 20:58:20 +08:00
parent c2967818ae
commit 568d14d413
2 changed files with 11 additions and 4 deletions

View File

@ -23,12 +23,11 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
@Resource
private NotificationMapper notificationMapper;
private final static String unRead = "0";
private final static String UN_READ = "0";
@Override
public List<Notification> findUnreadNotifications(Integer idUser) {
List<Notification> list = notificationMapper.selectUnreadNotifications(idUser);
return list;
return notificationMapper.selectUnreadNotifications(idUser);
}
@Override
@ -41,7 +40,7 @@ public class NotificationServiceImpl extends AbstractService<Notification> 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();

View File

@ -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<NotificationDTO> list = notificationService.findNotifications(user.getIdUser());
PageInfo<NotificationDTO> 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<Notification> list = notificationService.findUnreadNotifications(user.getIdUser());
PageInfo<Notification> pageInfo = new PageInfo(list);