|
@@ -14,7 +14,9 @@ import com.ruoyi.generator.mapper.community.CommunityCommentLikeMapper;
|
|
|
import com.ruoyi.generator.service.ICommunityArticleCommentService;
|
|
|
import com.ruoyi.generator.service.ICommunityCommentReplyService;
|
|
|
import com.ruoyi.generator.vo.CommunityArticleCommentVo;
|
|
|
+import com.ruoyi.generator.vo.CommunityCommentReplyVo;
|
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
+import com.ruoyi.system.service.impl.SysUserServiceImpl;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -22,9 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 评论接口
|
|
@@ -48,6 +48,12 @@ public class CommunityCommentController extends BaseController {
|
|
|
@Autowired
|
|
|
private CommunityCommentLikeMapper communityCommentLikeMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysUserServiceImpl sysUserServiceImpl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserServiceImpl sysUserService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取文章评论
|
|
@@ -79,16 +85,31 @@ public class CommunityCommentController extends BaseController {
|
|
|
Long commentUserId = vo.getUserId();
|
|
|
//获取评论的用户信息
|
|
|
SysUser sysUser = sysUserMapper.selectUserById(commentUserId);
|
|
|
- vo.setUsername(sysUser.getUserName());
|
|
|
+ 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));
|
|
|
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");
|
|
|
+ }).orderByDesc("create_time"));
|
|
|
+
|
|
|
+ CommunityCommentReplyVo replyVo = null;
|
|
|
+ List<CommunityCommentReplyVo> replyVos = new ArrayList<>();
|
|
|
+ for (CommunityCommentReply reply : replies) {
|
|
|
+ replyVo = new CommunityCommentReplyVo();
|
|
|
+ BeanUtils.copyProperties(reply, replyVo);
|
|
|
+ replyVo.setNickName(sysUserService.selectUserById(replyVo.getUserId()).getNickName());
|
|
|
+ replyVos.add(replyVo);
|
|
|
+ }
|
|
|
+ vo.setFirstReply(replyVos);
|
|
|
+ //设置还剩多少评论
|
|
|
+ vo.setReplyCount(replies.isEmpty() ? 0 : replies.size() - 1);
|
|
|
}
|
|
|
|
|
|
return AjaxResult.success(commentVos);
|
|
@@ -112,7 +133,15 @@ public class CommunityCommentController extends BaseController {
|
|
|
wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
})
|
|
|
.orderByDesc("create_time")).getRecords();
|
|
|
- return AjaxResult.success(replies);
|
|
|
+ CommunityCommentReplyVo replyVo = null;
|
|
|
+ List<CommunityCommentReplyVo> replyVos = new ArrayList<>();
|
|
|
+ for (CommunityCommentReply reply : replies) {
|
|
|
+ replyVo = new CommunityCommentReplyVo();
|
|
|
+ BeanUtils.copyProperties(reply, replyVo);
|
|
|
+ replyVo.setNickName(sysUserService.selectUserById(replyVo.getUserId()).getNickName());
|
|
|
+ replyVos.add(replyVo);
|
|
|
+ }
|
|
|
+ return AjaxResult.success(replyVos);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -153,8 +182,8 @@ public class CommunityCommentController extends BaseController {
|
|
|
CommunityCommentReply communityCommentReply = communityCommentReplyService.getOne(new QueryWrapper<CommunityCommentReply>()
|
|
|
.eq("id", replyId)
|
|
|
.and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- }));
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ }));
|
|
|
if (Objects.isNull(communityCommentReply)) {
|
|
|
return AjaxResult.error("未找到该回复!");
|
|
|
}
|