|
@@ -1,11 +1,22 @@
|
|
|
package com.sf.book.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.sf.book.dto.inner.InnerBookCommentRespDto;
|
|
|
+import com.sf.book.dto.resp.BookCommentRespDto;
|
|
|
+import com.sf.book.dto.resp.CommentInfoRespDto;
|
|
|
import com.sf.book.entity.BookComment;
|
|
|
import com.sf.book.mapper.BookCommentMapper;
|
|
|
import com.sf.book.service.IBookCommentService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.sf.core.dto.RestResp;
|
|
|
+import com.sf.user.client.UserFeign;
|
|
|
+import com.sf.user.client.dto.InnerUserCommentRespDto;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 小说评论 服务实现类
|
|
@@ -15,6 +26,53 @@ import org.springframework.stereotype.Service;
|
|
|
* @since 2024-08-06
|
|
|
*/
|
|
|
@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
public class BookCommentServiceImpl extends ServiceImpl<BookCommentMapper, BookComment> implements IBookCommentService {
|
|
|
|
|
|
+ private final BookCommentMapper bookCommentMapper;
|
|
|
+ private final UserFeign userFeign;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BookCommentRespDto commentNewestList(Long bookId) {
|
|
|
+ // select count(*) from book_comment where book_id = ''
|
|
|
+ LambdaQueryWrapper<BookComment> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(BookComment::getBookId, bookId);
|
|
|
+// Long count = bookCommentMapper.selectCount(queryWrapper);
|
|
|
+
|
|
|
+ // select * from book_comment where book_id = ''
|
|
|
+ List<BookComment> bookComments = bookCommentMapper.selectList(queryWrapper);
|
|
|
+ int count = bookComments.size();
|
|
|
+
|
|
|
+ Set<Long> userSet = new HashSet<>();
|
|
|
+ for (BookComment bookComment : bookComments) {
|
|
|
+ userSet.add(bookComment.getUserId());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CommentInfoRespDto> commentInfoRespDtoList = new ArrayList<>();
|
|
|
+ RestResp<List<InnerUserCommentRespDto>> listRestResp = userFeign.listUserInfoByIds(userSet);
|
|
|
+ List<InnerUserCommentRespDto> data = listRestResp.getData();
|
|
|
+ Map<Long, InnerUserCommentRespDto> collected =
|
|
|
+ data.stream().collect(Collectors.toMap(InnerUserCommentRespDto::getUserId, t -> t));
|
|
|
+
|
|
|
+ for (BookComment bookComment : bookComments) {
|
|
|
+ // select * from user_info where id = ''
|
|
|
+// UserInfo userInfo = userInfoMapper.selectById(bookComment.getUserId());
|
|
|
+ InnerUserCommentRespDto commentRespDto = collected.get(bookComment.getUserId());
|
|
|
+ CommentInfoRespDto commentInfoRespDto = CommentInfoRespDto.builder()
|
|
|
+ .id(bookComment.getId()).commentContent(bookComment.getCommentContent())
|
|
|
+ .commentUserId(bookComment.getUserId())
|
|
|
+ .commentUser(commentRespDto.getUsername())
|
|
|
+ .commentUserPhoto(commentRespDto.getUserPhoto())
|
|
|
+ .commentTime(bookComment.getUpdateTime())
|
|
|
+ .build();
|
|
|
+ commentInfoRespDtoList.add(commentInfoRespDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ BookCommentRespDto bookCommentRespDto = BookCommentRespDto.builder()
|
|
|
+ .commentTotal((long) count)
|
|
|
+ .comments(commentInfoRespDtoList)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ return bookCommentRespDto;
|
|
|
+ }
|
|
|
}
|