|
@@ -68,10 +68,9 @@ public class CommunityCommentController extends BaseController {
|
|
|
return AjaxResult.error("参数异常!");
|
|
|
}
|
|
|
Page<CommunityArticleComment> page = new Page<>(currentPage, limit);
|
|
|
- List<CommunityArticleComment> records = communityArticleCommentService.page(page, new QueryWrapper<CommunityArticleComment>()
|
|
|
- .eq("article_id", articleId).and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- }).orderByDesc("create_time")).getRecords();
|
|
|
+ List<CommunityArticleComment> records = communityArticleCommentService.page(page, new QueryWrapper<CommunityArticleComment>().eq("article_id", articleId).and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ }).orderByDesc("create_time")).getRecords();
|
|
|
|
|
|
CommunityArticleCommentVo commentVo = null;
|
|
|
List<CommunityArticleCommentVo> commentVos = new ArrayList<>();
|
|
@@ -89,18 +88,14 @@ public class CommunityCommentController extends BaseController {
|
|
|
vo.setNickName(sysUser.getNickName());
|
|
|
vo.setAvatar(sysUser.getAvatar());
|
|
|
//当前登录用户是否已点赞
|
|
|
- List<CommunityCommentLike> commentLikes = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
|
|
|
- .eq("comment_id", vo.getId())
|
|
|
- .eq("user_id", userId));
|
|
|
+ List<CommunityCommentLike> commentLikes = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", vo.getId()).eq("user_id", userId));
|
|
|
vo.setCommentLike(!commentLikes.isEmpty());
|
|
|
//该评论的点赞数量
|
|
|
vo.setCommentLikeCount(communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", vo.getId())).size());
|
|
|
//设置首条评论
|
|
|
- List<CommunityCommentReply> replies = communityCommentReplyService.list(new QueryWrapper<CommunityCommentReply>()
|
|
|
- .eq("comment_id", vo.getId())
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- }).orderByAsc("create_time"));
|
|
|
+ List<CommunityCommentReply> replies = communityCommentReplyService.list(new QueryWrapper<CommunityCommentReply>().eq("comment_id", vo.getId()).and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ }).orderByAsc("create_time"));
|
|
|
|
|
|
CommunityCommentReplyVo replyVo = null;
|
|
|
List<CommunityCommentReplyVo> replyVos = new ArrayList<>();
|
|
@@ -108,12 +103,19 @@ public class CommunityCommentController extends BaseController {
|
|
|
replyVo = new CommunityCommentReplyVo();
|
|
|
BeanUtils.copyProperties(reply, replyVo);
|
|
|
replyVo.setNickName(sysUserService.selectUserById(replyVo.getUserId()).getNickName());
|
|
|
+ replyVo.setReply(true);
|
|
|
replyVos.add(replyVo);
|
|
|
+ //设置点赞数量和当前登录用户是否已点赞
|
|
|
+ List<CommunityCommentLike> commentLikeList = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
|
|
|
+ .eq("reply_id", replyVo.getId()));
|
|
|
+ replyVo.setLikeCount(commentLikeList.size());
|
|
|
+ replyVo.setLike(commentLikeList.stream().anyMatch(item -> SecurityUtils.getUserId().equals(item.getUserId())));
|
|
|
break;
|
|
|
}
|
|
|
vo.setFirstReply(replyVos);
|
|
|
//设置还剩多少评论
|
|
|
vo.setReplyCount(replies.isEmpty() ? 0 : replies.size() - 1);
|
|
|
+ vo.setReply(false);
|
|
|
}
|
|
|
|
|
|
return AjaxResult.success(commentVos);
|
|
@@ -131,12 +133,9 @@ public class CommunityCommentController extends BaseController {
|
|
|
return AjaxResult.error("参数异常!");
|
|
|
}
|
|
|
Page<CommunityCommentReply> page = new Page<>(currentPage, limit);
|
|
|
- List<CommunityCommentReply> replies = communityCommentReplyService
|
|
|
- .page(page, new QueryWrapper<CommunityCommentReply>()
|
|
|
- .eq("comment_id", commentId).and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- })
|
|
|
- .orderByDesc("create_time")).getRecords();
|
|
|
+ List<CommunityCommentReply> replies = communityCommentReplyService.page(page, new QueryWrapper<CommunityCommentReply>().eq("comment_id", commentId).and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ }).orderByDesc("create_time")).getRecords();
|
|
|
CommunityCommentReplyVo replyVo = null;
|
|
|
List<CommunityCommentReplyVo> replyVos = new ArrayList<>();
|
|
|
for (final CommunityCommentReply reply : replies) {
|
|
@@ -144,10 +143,8 @@ public class CommunityCommentController extends BaseController {
|
|
|
SysUser sysUser = sysUserService.selectUserById(reply.getUserId());
|
|
|
final Long parentReplyId = reply.getParentReplyId();
|
|
|
BeanUtils.copyProperties(reply, replyVo);
|
|
|
- if (Objects.nonNull(parentReplyId)) {
|
|
|
- CommunityCommentReply communityCommentReply = replies.stream()
|
|
|
- .filter(item -> item.getId().equals(parentReplyId))
|
|
|
- .collect(Collectors.toList()).get(0);
|
|
|
+ if (Objects.nonNull(parentReplyId) && !commentId.equalsIgnoreCase(Long.toString(parentReplyId))) {
|
|
|
+ CommunityCommentReply communityCommentReply = replies.stream().filter(item -> item.getId().equals(parentReplyId)).collect(Collectors.toList()).get(0);
|
|
|
SysUser sysUser1 = sysUserService.selectUserById(communityCommentReply.getUserId());
|
|
|
replyVo.setParentNickName(sysUser1.getNickName());
|
|
|
replyVo.setParentUserId(sysUser1.getUserId());
|
|
@@ -155,6 +152,12 @@ public class CommunityCommentController extends BaseController {
|
|
|
}
|
|
|
replyVo.setNickName(sysUser.getNickName());
|
|
|
replyVo.setAvatar(sysUser.getAvatar());
|
|
|
+ replyVo.setReply(true);
|
|
|
+ //设置点赞数量和当前登录用户是否已点赞
|
|
|
+ List<CommunityCommentLike> commentLikes = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
|
|
|
+ .eq("reply_id", replyVo.getId()));
|
|
|
+ replyVo.setLikeCount(commentLikes.size());
|
|
|
+ replyVo.setLike(commentLikes.stream().anyMatch(item -> SecurityUtils.getUserId().equals(item.getUserId())));
|
|
|
replyVos.add(replyVo);
|
|
|
}
|
|
|
return AjaxResult.success(replyVos);
|
|
@@ -169,8 +172,7 @@ public class CommunityCommentController extends BaseController {
|
|
|
@Transactional
|
|
|
//@Anonymous
|
|
|
public AjaxResult reply(@RequestBody CommunityCommentReply communityCommentReply) {
|
|
|
- if (Objects.isNull(communityCommentReply.getCommentId())
|
|
|
- || Objects.isNull(communityCommentReply.getContent())) {
|
|
|
+ if (Objects.isNull(communityCommentReply.getCommentId()) || Objects.isNull(communityCommentReply.getContent())) {
|
|
|
return AjaxResult.error("参数异常!");
|
|
|
}
|
|
|
|
|
@@ -195,11 +197,9 @@ public class CommunityCommentController extends BaseController {
|
|
|
return AjaxResult.error("参数异常!");
|
|
|
}
|
|
|
|
|
|
- CommunityCommentReply communityCommentReply = communityCommentReplyService.getOne(new QueryWrapper<CommunityCommentReply>()
|
|
|
- .eq("id", replyId)
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- }));
|
|
|
+ CommunityCommentReply communityCommentReply = communityCommentReplyService.getOne(new QueryWrapper<CommunityCommentReply>().eq("id", replyId).and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ }));
|
|
|
if (Objects.isNull(communityCommentReply)) {
|
|
|
return AjaxResult.error("未找到该回复!");
|
|
|
}
|