Переглянути джерело

新增评论删除评论更新评论数

xgb 3 тижнів тому
батько
коміт
7a35e80f8f

+ 5 - 0
fs-service/src/main/java/com/fs/course/mapper/FsUserVideoMapper.java

@@ -301,5 +301,10 @@ public interface FsUserVideoMapper
             "</if>" +
             "</script>"})
     List<FsUserVideoListUVO> selectFsUserVideoListUVOByUser(@Param("talentId") Long talentId, @Param("oneSelf") boolean oneSelf);
+
+    // 评论数加一
+    int addCommentCount(Long videoId);
+
+    int delCommentCount(Long videoId);
 }
 

+ 1 - 1
fs-service/src/main/java/com/fs/course/param/FsUserVideoCommentDelUParam.java

@@ -20,7 +20,7 @@ public class FsUserVideoCommentDelUParam implements Serializable
     private Long commentId;
 
 //    @NotNull(message = "视频ID不能为空")
-//    private Long videoId;
+    private Long videoId;
 
     private String parentId;
 }

+ 16 - 5
fs-service/src/main/java/com/fs/course/service/impl/FsUserVideoCommentServiceImpl.java

@@ -7,6 +7,7 @@ import java.util.stream.Collectors;
 import com.fs.common.core.domain.R;
 import com.fs.common.utils.DateUtils;
 import com.fs.course.mapper.FsUserVideoCommentLikeMapper;
+import com.fs.course.mapper.FsUserVideoMapper;
 import com.fs.course.param.FsUserVideoCommentAddUParam;
 import com.fs.course.param.FsUserVideoCommentDelUParam;
 import com.fs.course.param.FsUserVideoCommentUParam;
@@ -48,6 +49,9 @@ public class FsUserVideoCommentServiceImpl implements IFsUserVideoCommentService
     @Autowired
     private FsUserMapper fsUserMapper;
 
+    @Autowired
+    private FsUserVideoMapper fsUserVideoMapper;
+
     private static final String COMMENT_LIST_KEY_PREFIX = "comment:list:video:";
     private static final String COMMENT_HASH_KEY_PREFIX = "comment:hash:video:";
     private static final String REPLY_LIST_KEY_PREFIX = "reply:list:comment:";
@@ -60,6 +64,7 @@ public class FsUserVideoCommentServiceImpl implements IFsUserVideoCommentService
     private static final String COMMENT_REPLY_COUNT_KEY_PREFIX = "reply:count:comment:";
     private static final String VIDEO_COMMENT_COUNT_KEY_PREFIX = "comment:count:video:";
 
+
     /**
      * 查询课堂视频评论
      *
@@ -193,6 +198,9 @@ public class FsUserVideoCommentServiceImpl implements IFsUserVideoCommentService
         if (fsUserVideoCommentMapper.insertFsUserVideoComment(comment)>0){
             return R.ok().put("data",comment);
         };
+        // 更新对应的评论数
+        fsUserVideoMapper.addCommentCount(comment.getVideoId());
+
         return R.error("新增评论失败");
     }
 
@@ -485,12 +493,15 @@ public class FsUserVideoCommentServiceImpl implements IFsUserVideoCommentService
     @Override
     @Transactional
     public R delComment(FsUserVideoCommentDelUParam param) {
-        // 更新评论数
-        if (param.getParentId() == null) {
-            //除数据库中的回复
-            fsUserVideoCommentMapper.deleteByParentId(param.getCommentId().toString());
-        }
+        // 只删除自己的评论,回复保留
+//        if (param.getParentId() == null) {
+//            //除数据库中的回复
+//            fsUserVideoCommentMapper.deleteByParentId(param.getCommentId().toString());
+//        }
+
         fsUserVideoCommentMapper.deleteByCommentId(param.getCommentId());
+        // 评论数减一
+        fsUserVideoMapper.delCommentCount(param.getVideoId());
         return R.ok();
     }
 

+ 13 - 0
fs-service/src/main/resources/mapper/course/FsUserVideoMapper.xml

@@ -156,6 +156,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </trim>
     </insert>
 
+    <insert id="addCommentCount">
+        update fs_user_video
+        set comments = comments + 1
+        where video_id = #{videoId}
+    </insert>
+
+    <insert id="delCommentCount">
+        update fs_user_video
+        set comments = comments - 1
+        where video_id = #{videoId}
+    </insert>
+
+
     <update id="updateFsUserVideo" parameterType="FsUserVideo">
         update fs_user_video
         <trim prefix="SET" suffixOverrides=",">

+ 1 - 0
fs-user-app/src/main/java/com/fs/app/controller/VideoController.java

@@ -200,6 +200,7 @@ public class VideoController extends  AppBaseController{
         if (comment.getUserId()-Long.parseLong(getUserId())!=0){
             return R.error("不能修改别人的评论");
         }
+        param.setVideoId(comment.getVideoId());
         return videoCommentService.delComment(param);
     }