|
@@ -16,12 +16,14 @@ import com.ruoyi.generator.domain.Community.CommunityCommentReply;
|
|
|
import com.ruoyi.generator.mapper.community.CommunityArticleCommentMapper;
|
|
|
import com.ruoyi.generator.mapper.community.CommunityArticleMapper;
|
|
|
import com.ruoyi.generator.mapper.community.CommunityCommentLikeMapper;
|
|
|
+import com.ruoyi.generator.mapper.community.CommunityCommentReplyMapper;
|
|
|
import com.ruoyi.generator.service.ICommunityArticleCommentService;
|
|
|
import com.ruoyi.generator.service.ICommunityArticleService;
|
|
|
import com.ruoyi.generator.service.ICommunityCommentReplyService;
|
|
|
import com.ruoyi.generator.vo.CommunityArticleCommentVo;
|
|
|
import com.ruoyi.generator.vo.CommunityCommentRaffleVo;
|
|
|
import com.ruoyi.generator.vo.CommunityCommentReplyVo;
|
|
|
+import com.ruoyi.generator.vo.CommunitySearchCommentVo;
|
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
import com.ruoyi.system.service.impl.SysUserServiceImpl;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -75,6 +77,9 @@ public class CommunityCommentController extends BaseController {
|
|
|
@Autowired
|
|
|
private CommunityArticleCommentMapper communityArticleCommentMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CommunityCommentReplyMapper communityCommentReplyMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 获取文章评论
|
|
|
*/
|
|
@@ -248,9 +253,6 @@ public class CommunityCommentController extends BaseController {
|
|
|
}
|
|
|
communityCommentReply.setAddress(address);
|
|
|
communityCommentReplyService.save(communityCommentReply);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
} catch (Exception e) {
|
|
|
System.out.println(e.getMessage());
|
|
|
throw new ProjectException();
|
|
@@ -337,16 +339,52 @@ public class CommunityCommentController extends BaseController {
|
|
|
if (Objects.isNull(articleId)) {
|
|
|
return AjaxResult.error("参数异常!");
|
|
|
}
|
|
|
- List<CommunityArticleComment> communityArticleComments = null;
|
|
|
+ List<CommunitySearchCommentVo> commentVos = new ArrayList<>();
|
|
|
try {
|
|
|
int offset = (pageNum - 1) * pageSize;
|
|
|
- communityArticleComments = communityArticleCommentMapper.queryComment(articleId, comment,offset,pageSize);
|
|
|
+ //获取一二级评论
|
|
|
+ List<CommunityArticleComment> communityArticleComments = communityArticleCommentMapper.queryComment(articleId, comment,offset,pageSize);
|
|
|
+ //一二级评论合集Vo
|
|
|
+ CommunitySearchCommentVo commentVo = null;
|
|
|
+ for (CommunityArticleComment communityArticleComment : communityArticleComments) {
|
|
|
+ commentVo = new CommunitySearchCommentVo();
|
|
|
+ BeanUtils.copyProperties(communityArticleComment, commentVo);
|
|
|
+ commentVos.add(commentVo);
|
|
|
+ }
|
|
|
+ for (CommunitySearchCommentVo vo : commentVos) {
|
|
|
+ //拼接头像 信息
|
|
|
+ vo.setAvatar(sysUserService.selectUserById(vo.getUserId()).getAvatar());
|
|
|
+ vo.setNickName(sysUserService.selectUserById(vo.getUserId()).getNickName());
|
|
|
+ vo.setCommentLikeCount(communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", vo.getId())).size());
|
|
|
+
|
|
|
+ //如果是二级评论则执行这个接口
|
|
|
+ CommunityCommentReply communityCommentReply = communityCommentReplyMapper.selectOne(new QueryWrapper<CommunityCommentReply>().eq("id", vo.getId()).and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ }));
|
|
|
+
|
|
|
+ //如果二级评论不为空执行
|
|
|
+ if (!Objects.isNull(communityCommentReply)){
|
|
|
+ //点赞数量
|
|
|
+ List<CommunityCommentLike> commentLikeList = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
|
|
|
+ .eq("reply_id", communityCommentReply.getId()));
|
|
|
+ vo.setCommentLikeCount(commentLikeList.size());
|
|
|
+ //找到一级评论获取 父评论 用户头像和ID
|
|
|
+ CommunityArticleComment communityArticleComment = communityArticleCommentMapper.selectOne(new QueryWrapper<CommunityArticleComment>().eq("id", communityCommentReply.getCommentId()).and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ }));
|
|
|
+ SysUser sysUser1 = sysUserService.selectUserById(communityArticleComment.getUserId());
|
|
|
+ vo.setParentNickName(sysUser1.getNickName());
|
|
|
+ vo.setParentUserId(sysUser1.getUserId());
|
|
|
+ vo.setParentAvatar(sysUser1.getAvatar());
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
System.out.println(e.getMessage());
|
|
|
throw new ProjectException();
|
|
|
}
|
|
|
- return AjaxResult.success(communityArticleComments);
|
|
|
+ System.out.println(commentVos);
|
|
|
+ return AjaxResult.success(commentVos);
|
|
|
}
|
|
|
|
|
|
}
|