|
@@ -1,6 +1,7 @@
|
|
|
package com.ruoyi.generator.controller;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
@@ -94,14 +95,16 @@ public class CommunityCommentController extends BaseController {
|
|
|
List<CommunityArticleCommentVo> commentVos = new ArrayList<>();
|
|
|
try {
|
|
|
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;
|
|
|
|
|
|
for (CommunityArticleComment record : records) {
|
|
|
- if (record.getAddress() == null){
|
|
|
+ if (record.getAddress() == null) {
|
|
|
record.setAddress("未知");
|
|
|
}
|
|
|
|
|
@@ -111,6 +114,7 @@ public class CommunityCommentController extends BaseController {
|
|
|
}
|
|
|
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
+ List<Long> commentIds = new ArrayList<>();
|
|
|
for (CommunityArticleCommentVo vo : commentVos) {
|
|
|
Long commentUserId = vo.getUserId();
|
|
|
//获取评论的用户信息
|
|
@@ -118,14 +122,25 @@ 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());
|
|
|
+ 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"));
|
|
|
+
|
|
|
+ //如果评价用户id与当前登录用户id相符,则标记为已读
|
|
|
+ if (vo.getUserId().equals(userId) && !vo.isRead()) {
|
|
|
+ commentIds.add(vo.getId());
|
|
|
+ }
|
|
|
|
|
|
CommunityCommentReplyVo replyVo = null;
|
|
|
List<CommunityCommentReplyVo> replyVos = new ArrayList<>();
|
|
@@ -148,13 +163,16 @@ public class CommunityCommentController extends BaseController {
|
|
|
vo.setReplyCount(replies.isEmpty() ? 0 : replies.size() - 1);
|
|
|
vo.setReply(false);
|
|
|
}
|
|
|
+
|
|
|
+ //更新为已读
|
|
|
+ if (!commentIds.isEmpty()) {
|
|
|
+ communityArticleCommentService.update(new UpdateWrapper<CommunityArticleComment>().set("is_read", true).in("id", commentIds));
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
System.out.println(e.getMessage());
|
|
|
throw new ProjectException();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
return AjaxResult.success(commentVos);
|
|
|
}
|
|
|
|
|
@@ -171,22 +189,42 @@ public class CommunityCommentController extends BaseController {
|
|
|
}
|
|
|
List<CommunityCommentReplyVo> replyVos = new ArrayList<>();
|
|
|
try {
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
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");
|
|
|
- }).orderByAsc("create_time")).getRecords();
|
|
|
- CommunityCommentReplyVo replyVo = null;
|
|
|
+ List<CommunityCommentReply> replies = communityCommentReplyService.page(page, new QueryWrapper<CommunityCommentReply>()
|
|
|
+ .eq("comment_id", commentId)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true)
|
|
|
+ .or()
|
|
|
+ .isNull("is_delete");
|
|
|
+ }).orderByAsc("create_time")).getRecords();
|
|
|
|
|
|
+ CommunityCommentReplyVo replyVo = null;
|
|
|
+ List<Long> replyIds = new ArrayList<>();
|
|
|
for (final CommunityCommentReply reply : replies) {
|
|
|
replyVo = new CommunityCommentReplyVo();
|
|
|
- if (reply.getAddress() == null){
|
|
|
+ if (reply.getAddress() == null) {
|
|
|
reply.setAddress("未知");
|
|
|
}
|
|
|
+
|
|
|
+ //标记当前登录的用户被回复的信息
|
|
|
+ if (reply.getUserId().equals(userId)) {
|
|
|
+ List<CommunityCommentReply> communityCommentReplies = replies.stream()
|
|
|
+ .filter(item -> item.getParentReplyId().equals(reply.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (CommunityCommentReply communityCommentReply : communityCommentReplies) {
|
|
|
+ replyIds.add(communityCommentReply.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
SysUser sysUser = sysUserService.selectUserById(reply.getUserId());
|
|
|
final Long parentReplyId = reply.getParentReplyId();
|
|
|
BeanUtils.copyProperties(reply, replyVo);
|
|
|
if (Objects.nonNull(parentReplyId) && !commentId.equalsIgnoreCase(Long.toString(parentReplyId))) {
|
|
|
- CommunityCommentReply communityCommentReply = replies.stream().filter(item -> item.getId().equals(parentReplyId)).collect(Collectors.toList()).get(0);
|
|
|
+ List<CommunityCommentReply> communityCommentReplies = replies.stream()
|
|
|
+ .filter(item -> item.getId().equals(parentReplyId))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ CommunityCommentReply communityCommentReply = communityCommentReplies.get(0);
|
|
|
SysUser sysUser1 = sysUserService.selectUserById(communityCommentReply.getUserId());
|
|
|
replyVo.setParentNickName(sysUser1.getNickName());
|
|
|
replyVo.setParentUserId(sysUser1.getUserId());
|
|
@@ -200,16 +238,19 @@ public class CommunityCommentController extends BaseController {
|
|
|
.eq("reply_id", replyVo.getId()));
|
|
|
replyVo.setLikeCount(commentLikes.size());
|
|
|
replyVo.setLike(commentLikes.stream().anyMatch(item -> SecurityUtils.getUserId().equals(item.getUserId())));
|
|
|
-
|
|
|
-
|
|
|
replyVos.add(replyVo);
|
|
|
}
|
|
|
+
|
|
|
+ //更新回复的id为已读
|
|
|
+ if (!replyIds.isEmpty()) {
|
|
|
+ communityCommentReplyService.update(new UpdateWrapper<CommunityCommentReply>()
|
|
|
+ .set("is_read", true)
|
|
|
+ .in("id", replyIds));
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
System.out.println(e.getMessage());
|
|
|
throw new ProjectException();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
return AjaxResult.success(replyVos);
|
|
|
}
|
|
|
|
|
@@ -294,9 +335,8 @@ public class CommunityCommentController extends BaseController {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
- * @param articleId
|
|
|
- * @return
|
|
|
+ * @param articleId 文章id
|
|
|
+ * @return 抽奖结果
|
|
|
*/
|
|
|
@ApiOperation("评论抽奖")
|
|
|
@GetMapping("/raffleComment")
|
|
@@ -313,13 +353,13 @@ public class CommunityCommentController extends BaseController {
|
|
|
.and((wrapper) -> {
|
|
|
wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
}));
|
|
|
- if (communityArticle == null){
|
|
|
- return AjaxResult.error("非本人无法操作抽奖按钮!");
|
|
|
+ if (communityArticle == null) {
|
|
|
+ return AjaxResult.error("非本人无法操作抽奖按钮!");
|
|
|
}
|
|
|
|
|
|
CommunityCommentRaffleVo communityCommentRaffleVos = null;
|
|
|
try {
|
|
|
- communityCommentRaffleVos = communityArticleService.selectCommentRaffle(articleId);
|
|
|
+ communityCommentRaffleVos = communityArticleService.selectCommentRaffle(articleId);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
System.out.println(e.getMessage());
|
|
@@ -333,7 +373,7 @@ public class CommunityCommentController extends BaseController {
|
|
|
@GetMapping("/queryComment")
|
|
|
@Transactional
|
|
|
//@Anonymous
|
|
|
- public AjaxResult queryComment(Long articleId,String comment) {
|
|
|
+ public AjaxResult queryComment(Long articleId, String comment) {
|
|
|
int pageNum = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
|
|
|
int pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
|
|
|
if (Objects.isNull(articleId)) {
|
|
@@ -344,7 +384,7 @@ public class CommunityCommentController extends BaseController {
|
|
|
try {
|
|
|
int offset = (pageNum - 1) * pageSize;
|
|
|
//获取一二级评论
|
|
|
- List<CommunityArticleComment> communityArticleComments = communityArticleCommentMapper.queryComment(articleId, comment,offset,pageSize);
|
|
|
+ List<CommunityArticleComment> communityArticleComments = communityArticleCommentMapper.queryComment(articleId, comment, offset, pageSize);
|
|
|
//一二级评论合集Vo
|
|
|
CommunitySearchCommentVo commentVo = null;
|
|
|
for (CommunityArticleComment communityArticleComment : communityArticleComments) {
|
|
@@ -358,28 +398,36 @@ public class CommunityCommentController extends BaseController {
|
|
|
vo.setNickName(sysUserService.selectUserById(vo.getUserId()).getNickName());
|
|
|
vo.setCommentLikeCount(communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", vo.getId())).size());
|
|
|
//设置当前用户是否点赞
|
|
|
- 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());
|
|
|
//如果是二级评论则执行这个接口
|
|
|
- CommunityCommentReply communityCommentReply = communityCommentReplyMapper.selectOne(new QueryWrapper<CommunityCommentReply>().eq("id", vo.getId()).and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- }));
|
|
|
+ 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)){
|
|
|
+ if (!Objects.isNull(communityCommentReply)) {
|
|
|
//点赞数量
|
|
|
List<CommunityCommentLike> commentLikeList = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
|
|
|
.eq("reply_id", communityCommentReply.getId()));
|
|
|
vo.setCommentLikeCount(commentLikeList.size());
|
|
|
|
|
|
//二级评论是否点赞
|
|
|
- List<CommunityCommentLike> commentLikesReply = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("reply_id", vo.getId()).eq("user_id", userId));
|
|
|
+ List<CommunityCommentLike> commentLikesReply = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
|
|
|
+ .eq("reply_id", vo.getId())
|
|
|
+ .eq("user_id", userId));
|
|
|
vo.setCommentLike(!commentLikesReply.isEmpty());
|
|
|
|
|
|
//找到一级评论获取 父评论 用户头像和ID
|
|
|
- CommunityArticleComment communityArticleComment = communityArticleCommentMapper.selectOne(new QueryWrapper<CommunityArticleComment>().eq("id", communityCommentReply.getCommentId()).and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- }));
|
|
|
+ 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());
|
|
@@ -395,4 +443,15 @@ public class CommunityCommentController extends BaseController {
|
|
|
return AjaxResult.success(commentVos);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取当前登录用户的评论和回复
|
|
|
+ *
|
|
|
+ * @return 评论和回复
|
|
|
+ */
|
|
|
+ @GetMapping("/getComments")
|
|
|
+ @ApiOperation("获取当前登录用户的评论和回复")
|
|
|
+ public AjaxResult getCommentInfoByUserId() {
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+ return success(communityArticleCommentService.getCommentInfoByUserId(userId));
|
|
|
+ }
|
|
|
}
|