|
@@ -0,0 +1,81 @@
|
|
|
|
+package com.sf.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.sf.dto.req.UserCommentReqDto;
|
|
|
|
+import com.sf.dto.resp.BookCommentRespDto;
|
|
|
|
+import com.sf.dto.resp.CommentInfoRespDto;
|
|
|
|
+import com.sf.entity.BookComment;
|
|
|
|
+import com.sf.entity.UserInfo;
|
|
|
|
+import com.sf.mapper.BookCommentMapper;
|
|
|
|
+import com.sf.mapper.UserInfoMapper;
|
|
|
|
+import com.sf.service.IBookCommentService;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 小说评论 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author baomidou
|
|
|
|
+ * @since 2024-06-12
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class BookCommentServiceImpl extends ServiceImpl<BookCommentMapper, BookComment> implements IBookCommentService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private BookCommentMapper bookCommentMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserInfoMapper userInfoMapper;
|
|
|
|
+
|
|
|
|
+ @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();
|
|
|
|
+
|
|
|
|
+ List<CommentInfoRespDto> commentInfoRespDtoList = new ArrayList<>();
|
|
|
|
+ for (BookComment bookComment : bookComments) {
|
|
|
|
+ // select * from user_info where id = ''
|
|
|
|
+ UserInfo userInfo = userInfoMapper.selectById(bookComment.getUserId());
|
|
|
|
+ CommentInfoRespDto commentInfoRespDto = CommentInfoRespDto.builder()
|
|
|
|
+ .id(bookComment.getId()).commentContent(bookComment.getCommentContent())
|
|
|
|
+ .commentUserId(bookComment.getUserId())
|
|
|
|
+ .commentUser(userInfo.getUsername())
|
|
|
|
+ .commentUserPhoto(userInfo.getUserPhoto())
|
|
|
|
+ .commentTime(bookComment.getUpdateTime())
|
|
|
|
+ .build();
|
|
|
|
+ commentInfoRespDtoList.add(commentInfoRespDto);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BookCommentRespDto bookCommentRespDto = BookCommentRespDto.builder()
|
|
|
|
+ .commentTotal((long)count)
|
|
|
|
+ .comments(commentInfoRespDtoList)
|
|
|
|
+ .build();
|
|
|
|
+
|
|
|
|
+ return bookCommentRespDto;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void saveComment(UserCommentReqDto userCommentReqDto) {
|
|
|
|
+ BookComment bookComment = BookComment.builder()
|
|
|
|
+ .bookId(userCommentReqDto.getBookId())
|
|
|
|
+ .userId(userCommentReqDto.getUserId())
|
|
|
|
+ .commentContent(userCommentReqDto.getCommentContent())
|
|
|
|
+ .createTime(LocalDateTime.now())
|
|
|
|
+ .updateTime(LocalDateTime.now())
|
|
|
|
+ .build();
|
|
|
|
+ bookCommentMapper.insert(bookComment);
|
|
|
|
+ }
|
|
|
|
+}
|