public PageDataListVO<CommentVO> getPageDataListVO(CommentSearchRequest request, BaseUserRequest baseUserRequest) {
request.setIsTop(IsTopEnum.IsTop.getCode());
// request.setParentUuid("");
Map<String, Object> params = BeanUtil.beanToMap(request);
int count = dao.countPageListVO(params);
if (count == 0) {
return new PageDataListVO<>(new ArrayList<>(), count);
}
List<CommentVO> parentList = dao.queryPageListVO(params);
List<CommentVO> childrenList = getListVO(request, parentList);
for (CommentVO parentVo : parentList) {
if (ObjectUtil.isNotEmpty(baseUserRequest)) {
if (parentVo.getCreateUser().equals(baseUserRequest.getAccount())) {
parentVo.setDeletable(true);
} else {
parentVo.setDeletable(false);
}
}
if (CollectionUtils.isNotEmpty(childrenList)) {
generateVoTree(parentVo, childrenList);
}
}
return new PageDataListVO<>(parentList, count);
}
public CommentVO generateVoTree(CommentVO parentVo, List<CommentVO> allVoList) {
List<CommentVO> childVoList = new ArrayList<>();
for (CommentVO vo : allVoList) {
String parentUuid = StringUtils.isNotEmpty(parentVo.getParentUuid()) ? parentVo.getParentUuid() + "," + parentVo.getUuid() : parentVo.getUuid();
if (parentUuid.equals(vo.getParentUuid())) {
childVoList.add(generateVoTree(vo, allVoList));
}
}
parentVo.setChildrenList(childVoList);
return parentVo;
}
获取评论树
最新推荐文章于 2024-11-13 20:43:20 发布