feat(修改): 🚀 删除不用的model
This commit is contained in:
parent
b7dfa43bbe
commit
d02c498011
|
@ -1,51 +0,0 @@
|
||||||
package cn.bunny.common.utils;
|
|
||||||
|
|
||||||
import cn.bunny.vo.system.comment.CommentVo;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CommentUtil {
|
|
||||||
/**
|
|
||||||
* 构建树型结构
|
|
||||||
*
|
|
||||||
* @param commentList 评论列表
|
|
||||||
* @return 结构列表
|
|
||||||
*/
|
|
||||||
public static List<CommentVo> buildTree(List<CommentVo> commentList) {
|
|
||||||
// 构建树形结构
|
|
||||||
List<CommentVo> tree = new ArrayList<>();
|
|
||||||
// 遍历评论列表
|
|
||||||
for (CommentVo comment : commentList) {
|
|
||||||
// 找到顶级评论(没有父评论)
|
|
||||||
if (comment.getPCommentId() == 0) {
|
|
||||||
// 递归构建子评论
|
|
||||||
comment.setChildren(getChildren(comment.getId(), commentList));
|
|
||||||
tree.add(comment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tree;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 递归获取子评论
|
|
||||||
*
|
|
||||||
* @param commentId 当前评论ID
|
|
||||||
* @param commentList 评论列表
|
|
||||||
* @return 子评论列表
|
|
||||||
*/
|
|
||||||
private static List<CommentVo> getChildren(Long commentId, List<CommentVo> commentList) {
|
|
||||||
List<CommentVo> children = new ArrayList<>();
|
|
||||||
|
|
||||||
// 遍历评论列表
|
|
||||||
for (CommentVo comment : commentList) {
|
|
||||||
// 找到当前评论的子评论
|
|
||||||
if (Long.valueOf(comment.getPCommentId()).equals(commentId)) {
|
|
||||||
// 递归构建子评论的子评论
|
|
||||||
comment.setChildren(getChildren(comment.getId(), commentList));
|
|
||||||
children.add(comment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
package cn.bunny.service.web.service.impl;
|
|
||||||
|
|
||||||
import cn.bunny.common.utils.CommentUtil;
|
|
||||||
import cn.bunny.dto.common.CommentQueryDto;
|
|
||||||
import cn.bunny.entity.system.article.ForumComment;
|
|
||||||
import cn.bunny.vo.system.comment.CommentVo;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class CommentServiceImplTest {
|
|
||||||
@Autowired
|
|
||||||
private CommentMapper commentMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取文章评论
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void loadComment() {
|
|
||||||
CommentQueryDto dto = new CommentQueryDto();
|
|
||||||
dto.setArticleId("RtiXj832TFL4nhW");
|
|
||||||
// 返回参数
|
|
||||||
ArrayList<CommentVo> list = new ArrayList<>();
|
|
||||||
// 查询
|
|
||||||
Page<ForumComment> page = new Page<>(1, 6);
|
|
||||||
IPage<ForumComment> commentList = commentMapper.loadComment(page, dto);
|
|
||||||
|
|
||||||
// 准备返回值
|
|
||||||
commentList.getRecords().forEach(forumComments -> {
|
|
||||||
CommentVo commentVo = new CommentVo();
|
|
||||||
BeanUtils.copyProperties(forumComments, commentVo);
|
|
||||||
list.add(commentVo);
|
|
||||||
});
|
|
||||||
|
|
||||||
List<CommentVo> buildTree = CommentUtil.buildTree(list);
|
|
||||||
System.out.println(buildTree);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue