|
|
@@ -4,14 +4,13 @@ import cn.reghao.jutil.jdk.web.db.PageList;
|
|
|
import cn.reghao.jutil.jdk.string.SnowFlake;
|
|
|
import cn.reghao.tnb.auth.api.iface.AccountQuery;
|
|
|
import cn.reghao.tnb.common.auth.UserContext;
|
|
|
-import cn.reghao.tnb.content.api.dto.comment.CommentData;
|
|
|
import cn.reghao.tnb.search.app.comment.db.mongo.UserCommentMongo;
|
|
|
import cn.reghao.tnb.search.app.comment.model.po.UserComment;
|
|
|
import cn.reghao.tnb.user.api.dto.UserCard;
|
|
|
import cn.reghao.tnb.user.api.iface.UserService;
|
|
|
-import cn.reghao.tnb.content.api.dto.comment.CommentSbtDto;
|
|
|
-import cn.reghao.tnb.content.api.dto.comment.ReplyUser;
|
|
|
-import cn.reghao.tnb.content.api.dto.comment.UserReply;
|
|
|
+import cn.reghao.tnb.search.app.comment.model.dto.CommentSbtDto;
|
|
|
+import cn.reghao.tnb.search.app.comment.model.vo.ReplyUser;
|
|
|
+import cn.reghao.tnb.search.app.comment.model.vo.UserReply;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -29,6 +28,7 @@ public class CommentService {
|
|
|
@DubboReference(check = false, retries = 0, timeout = 60_000)
|
|
|
private AccountQuery accountQuery;
|
|
|
|
|
|
+ private int pageSize = 10;
|
|
|
private final SnowFlake idGenerator;
|
|
|
private final UserCommentMongo userCommentMongo;
|
|
|
|
|
|
@@ -39,25 +39,8 @@ public class CommentService {
|
|
|
|
|
|
public void saveComment(CommentSbtDto commentSbtDto) {
|
|
|
long commentId = idGenerator.nextId();
|
|
|
- CommentData commentData = commentSbtDto.getNewComment();
|
|
|
- String userIdStr = commentData.getUser().getUserId();
|
|
|
- long userId = accountQuery.getUserIdLong(userIdStr);
|
|
|
- String postId = commentData.getPostId();
|
|
|
-
|
|
|
- CommentData parent = commentSbtDto.getParent();
|
|
|
- long parentId = 0;
|
|
|
- if (parent != null) {
|
|
|
- parentId = parent.getId();
|
|
|
- }
|
|
|
-
|
|
|
- String imageUrl = commentData.getImageUrl();
|
|
|
- if (imageUrl != null) {
|
|
|
- commentData.getImageUrls().add(imageUrl);
|
|
|
- }
|
|
|
-
|
|
|
- UserComment userComment = new UserComment(commentId, commentData, parentId);
|
|
|
+ UserComment userComment = new UserComment(commentId, commentSbtDto);
|
|
|
userCommentMongo.save(userComment);
|
|
|
-
|
|
|
/*VideoPost videoPost = videoPostMapper.findByVideoId(postId);
|
|
|
if (videoPost != null) {
|
|
|
long publishBy = videoPost.getPublishBy();
|
|
|
@@ -71,7 +54,7 @@ public class CommentService {
|
|
|
|
|
|
@Deprecated
|
|
|
public void saveBiliComment(CommentSbtDto commentSbtDto) {
|
|
|
- long commentId = commentSbtDto.getNewComment().getId();
|
|
|
+ /*long commentId = commentSbtDto.getNewComment().getId();
|
|
|
UserComment userComment = userCommentMongo.findByCommentId(commentId);
|
|
|
if (userComment != null) {
|
|
|
return;
|
|
|
@@ -80,38 +63,20 @@ public class CommentService {
|
|
|
CommentData commentData = commentSbtDto.getNewComment();
|
|
|
long parentId = commentSbtDto.getParent().getId();
|
|
|
userComment = new UserComment(parentId, commentId, commentData);
|
|
|
- userCommentMongo.save(userComment);
|
|
|
+ userCommentMongo.save(userComment);*/
|
|
|
}
|
|
|
|
|
|
public PageList<UserReply> getUserComment(String videoId, int pageNumber) {
|
|
|
long total = userCommentMongo.countByPostId(videoId);
|
|
|
int pageSize = 10;
|
|
|
List<UserReply> list = userCommentMongo.findByPostId(videoId, pageNumber).stream()
|
|
|
- .map(userComment -> {
|
|
|
- long commentId = userComment.getCommentId();
|
|
|
- UserReply commentVo = getCommentVo(userComment);
|
|
|
- long total1 = userCommentMongo.countChildComment(commentId);
|
|
|
- commentVo.setTotal(total1);
|
|
|
- List<UserReply> childComments = userCommentMongo.findByParentId(commentId, 1, pageSize).stream()
|
|
|
- .map(this::getCommentVo)
|
|
|
- .collect(Collectors.toList());
|
|
|
- commentVo.setChildren(childComments);
|
|
|
- return commentVo;
|
|
|
- })
|
|
|
+ .map(this::getCommentVo)
|
|
|
.collect(Collectors.toList());
|
|
|
return PageList.pageList(pageNumber, pageSize, (int) total, list);
|
|
|
}
|
|
|
|
|
|
- private UserReply getCommentVo(UserComment userComment) {
|
|
|
- Long commentId = userComment.getCommentId();
|
|
|
- Long userId = userComment.getPublishBy();
|
|
|
+ private ReplyUser getReplyUser(long userId) {
|
|
|
String userIdStr = accountQuery.getUserIdStr(userId);
|
|
|
- String postId = userComment.getPostId();
|
|
|
- String content = userComment.getContent();
|
|
|
- Long createAt = userComment.getPublishAt();
|
|
|
- String imgSrc = userComment.getImgSrc();
|
|
|
- List<String> images = userComment.getCommentImages();
|
|
|
-
|
|
|
ReplyUser commentUser = new ReplyUser();
|
|
|
commentUser.setUserId(userIdStr);
|
|
|
UserCard userCard = userService.getUserAvatar(userId);
|
|
|
@@ -128,34 +93,38 @@ public class CommentService {
|
|
|
commentUser.setAuthor(true);
|
|
|
}
|
|
|
|
|
|
- UserReply commentVo = new UserReply();
|
|
|
- /*commentVo.setVideoId(postId);
|
|
|
- commentVo.setCommentId(commentId);*/
|
|
|
- commentVo.setId(commentId);
|
|
|
- commentVo.setContent(content);
|
|
|
- commentVo.setImgSrc(imgSrc);
|
|
|
- commentVo.setCreateAt(createAt);
|
|
|
- commentVo.setUser(commentUser);
|
|
|
- commentVo.setLikes(userComment.getLikes());
|
|
|
- commentVo.setLiked(false);
|
|
|
+ return commentUser;
|
|
|
+ }
|
|
|
|
|
|
- if (images != null && !images.isEmpty()) {
|
|
|
- commentVo.setImgSrc(images.get(0));
|
|
|
+ private UserReply getCommentVo(UserComment userComment) {
|
|
|
+ Long userId = userComment.getPublishBy();
|
|
|
+ ReplyUser commentUser = getReplyUser(userId);
|
|
|
+ UserReply userReply = new UserReply(userComment);
|
|
|
+ userReply.setUser(commentUser);
|
|
|
+
|
|
|
+ long commentId = userComment.getCommentId();
|
|
|
+ long total = userCommentMongo.countChildComment(commentId);
|
|
|
+ if (total > 0) {
|
|
|
+ List<UserReply> childComments = userCommentMongo.findByParentId(commentId, 1, 3).stream()
|
|
|
+ .map(userComment1 -> {
|
|
|
+ Long userId1 = userComment1.getPublishBy();
|
|
|
+ ReplyUser commentUser1 = getReplyUser(userId1);
|
|
|
+ UserReply userReply1 = new UserReply(userComment1);
|
|
|
+ userReply1.setUser(commentUser1);
|
|
|
+ return userReply1;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ userReply.setChildren(childComments);
|
|
|
+ userReply.setTotal(total);
|
|
|
}
|
|
|
-
|
|
|
- return commentVo;
|
|
|
+ return userReply;
|
|
|
}
|
|
|
|
|
|
public PageList<UserReply> getChildComment(long commentId, int pageNumber) {
|
|
|
- int pageSize = 10;
|
|
|
Long total = userCommentMongo.countChildComment(commentId);
|
|
|
List<UserReply> list = userCommentMongo.findByParentId(commentId, pageNumber, pageSize).stream()
|
|
|
.map(this::getCommentVo)
|
|
|
.collect(Collectors.toList());
|
|
|
- return PageList.pageList(pageNumber, 10, total.intValue(), list);
|
|
|
- }
|
|
|
-
|
|
|
- public long countPostComment(String videoId) {
|
|
|
- return userCommentMongo.countByPostId(videoId);
|
|
|
+ return PageList.pageList(pageNumber, pageSize, total.intValue(), list);
|
|
|
}
|
|
|
}
|