Просмотр исходного кода

优化评论,回复字段,新增剩余评论和用户昵称

fangzhen 7 месяцев назад
Родитель
Сommit
008379b8b4

+ 37 - 8
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityCommentController.java

@@ -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("未找到该回复!");
         }

+ 16 - 3
ruoyi-generator/src/main/java/com/ruoyi/generator/vo/CommunityArticleCommentVo.java

@@ -13,6 +13,7 @@ import lombok.NoArgsConstructor;
 
 import javax.validation.constraints.NotNull;
 import java.io.Serializable;
+import java.util.List;
 
 /**
 * 文章评价记录表
@@ -45,10 +46,10 @@ public class CommunityArticleCommentVo extends BaseEntity implements Serializabl
     private Long userId;
 
     /**
-     * 评论人用户名
+     * 评论人昵称
      */
-    @ApiModelProperty("评论人用户名")
-    private String username;
+    @ApiModelProperty("评论人昵称")
+    private String nickName;
 
     /**
      * 评论点赞数
@@ -73,4 +74,16 @@ public class CommunityArticleCommentVo extends BaseEntity implements Serializabl
      */
     @ApiModelProperty("评论内容")
     private String content;
+
+    /**
+     * 评论首条回复
+     */
+    @ApiModelProperty("评论首条回复")
+    private List<CommunityCommentReplyVo> firstReply;
+
+    /**
+     * 评论下回复总数
+     */
+    @ApiModelProperty("评论下回复剩余总数")
+    private int replyCount;
 }

+ 79 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/vo/CommunityCommentReplyVo.java

@@ -0,0 +1,79 @@
+package com.ruoyi.generator.vo;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.hibernate.validator.constraints.Length;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+* 文章评论回复表
+* @TableName community_comment_reply
+*/
+@Data
+@TableName("community_comment_reply")
+public class CommunityCommentReplyVo implements Serializable {
+
+    /**
+    * 唯一id
+    */
+    @NotNull(message="[唯一id]不能为空")
+    @ApiModelProperty("唯一id")
+    @TableId("id")
+    private Long id;
+    /**
+    * 评论id
+    */
+    @ApiModelProperty("评论id")
+    private Long commentId;
+    /**
+    * 父回复id
+    */
+    @ApiModelProperty("父回复id")
+    private Long parentReplyId;
+    /**
+    * 回复用户id
+    */
+    @ApiModelProperty("回复用户id")
+    private Long userId;
+    /**
+     * 回复用户昵称
+     */
+    @ApiModelProperty("回复用户昵称")
+    private String nickName;
+    /**
+    * 回复内容
+    */
+    @Size(max= -1,message="编码长度不能超过-1")
+    @ApiModelProperty("回复内容")
+    @Length(max= -1,message="编码长度不能超过-1")
+    private String content;
+    /**
+    * 创建时间
+    */
+    @ApiModelProperty("创建时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+    /**
+    * 创建人
+    */
+    @ApiModelProperty("创建人")
+    private Long createBy;
+    /**
+    * 更新时间
+    */
+    @ApiModelProperty("更新时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date updateTime;
+    /**
+    * 更新人
+    */
+    @ApiModelProperty("更新人")
+    private Long updateBy;
+}