|
@@ -1,15 +1,20 @@
|
|
|
package com.sf.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.sf.dto.req.PageReqDto;
|
|
|
import com.sf.dto.req.UserCommentReqDto;
|
|
|
-import com.sf.dto.resp.BookCommentRespDto;
|
|
|
-import com.sf.dto.resp.CommentInfoRespDto;
|
|
|
+import com.sf.dto.resp.*;
|
|
|
import com.sf.entity.BookComment;
|
|
|
+import com.sf.entity.BookInfo;
|
|
|
import com.sf.entity.UserInfo;
|
|
|
import com.sf.mapper.BookCommentMapper;
|
|
|
+import com.sf.mapper.BookInfoMapper;
|
|
|
import com.sf.mapper.UserInfoMapper;
|
|
|
import com.sf.service.IBookCommentService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -33,6 +38,8 @@ public class BookCommentServiceImpl extends ServiceImpl<BookCommentMapper, BookC
|
|
|
|
|
|
@Autowired
|
|
|
private UserInfoMapper userInfoMapper;
|
|
|
+ @Autowired
|
|
|
+ private BookInfoMapper bookInfoMapper;
|
|
|
|
|
|
@Override
|
|
|
public BookCommentRespDto commentNewestList(Long bookId) {
|
|
@@ -60,7 +67,7 @@ public class BookCommentServiceImpl extends ServiceImpl<BookCommentMapper, BookC
|
|
|
}
|
|
|
|
|
|
BookCommentRespDto bookCommentRespDto = BookCommentRespDto.builder()
|
|
|
- .commentTotal((long)count)
|
|
|
+ .commentTotal((long) count)
|
|
|
.comments(commentInfoRespDtoList)
|
|
|
.build();
|
|
|
|
|
@@ -78,4 +85,36 @@ public class BookCommentServiceImpl extends ServiceImpl<BookCommentMapper, BookC
|
|
|
.build();
|
|
|
bookCommentMapper.insert(bookComment);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageRespDto<UserCommentRespDto> getCommentList(Long userId, PageReqDto pageReqDto) {
|
|
|
+ // 根据userId获取评论信息
|
|
|
+ LambdaQueryWrapper<BookComment> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(BookComment::getUserId, userId);
|
|
|
+ queryWrapper.orderByDesc(BookComment::getCreateTime);
|
|
|
+ // 传入分页的参数 当前页和每页的大小
|
|
|
+ IPage page = new Page(pageReqDto.getPageNum(), pageReqDto.getPageSize());
|
|
|
+ // 进行分页查询 select * from book_comment where userId = '' order by create_time limit 0,10
|
|
|
+ IPage selected = bookCommentMapper.selectPage(page, queryWrapper);
|
|
|
+ List<BookComment> bookComments = selected.getRecords();
|
|
|
+
|
|
|
+ // 将每一个查询到的book_comment 映射成最终要返回的dto
|
|
|
+ List<UserCommentRespDto> userCommentRespDtos = bookComments.stream().map(bookComment -> {
|
|
|
+ // 映射的逻辑是
|
|
|
+ // 先通过查询到的book_id 找到book信息
|
|
|
+ BookInfo bookInfo = bookInfoMapper.selectById(bookComment.getBookId());
|
|
|
+ // 将book_info中的名字和封皮放入对应参数
|
|
|
+ // 将book_comment中评论的内容和时间 放入对应参数
|
|
|
+ return UserCommentRespDto.builder()
|
|
|
+ .commentBook(bookInfo.getBookName())
|
|
|
+ .commentBookPic(bookInfo.getPicUrl())
|
|
|
+ .commentContent(bookComment.getCommentContent())
|
|
|
+ .commentTime(bookComment.getCreateTime())
|
|
|
+ .build();
|
|
|
+ }).toList();
|
|
|
+ // 再将数据赋值给要返回的分页对象
|
|
|
+ PageRespDto<UserCommentRespDto> pageRespDto = PageRespDto.of(
|
|
|
+ pageReqDto.getPageNum(), pageReqDto.getPageSize(), page.getTotal(), userCommentRespDtos);
|
|
|
+ return pageRespDto;
|
|
|
+ }
|
|
|
}
|