Browse Source

优化评价代码

fangqing 6 tháng trước cách đây
mục cha
commit
c51bedc314

+ 6 - 3
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -149,7 +149,7 @@ public class CommunityArticleController extends BaseController {
     }
 
 
-    @ApiOperation("文章评")
+    @ApiOperation("文章评")
     @PostMapping("/comment")
     @Transactional
     public AjaxResult comment(@RequestBody CommunityArticleComment communityArticleComment) throws ParseException {
@@ -157,11 +157,14 @@ public class CommunityArticleController extends BaseController {
             return AjaxResult.error("文章不存在或异常!");
         }
 
+
+
+        //调用方法去判断当前评论的用户 是不是文章作者的关注列表
         Boolean aBoolean = communityArticleService.checkCommentPermission(communityArticleComment);
         communityArticleComment.setUserId(SecurityUtils.getUserId());
-        /*if (!aBoolean) {  // 当 aBoolean 为 false 时,进入这个条件
+        if (!aBoolean) {  // 当 aBoolean 为 false 时,进入这个条件
             return AjaxResult.success("您没有权限评论此文章,因为只允许关注的人评论您!");
-        }*/
+        }
         //新增评论
         communityArticleService.sendComment(communityArticleComment);
         return AjaxResult.success();

+ 3 - 4
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -619,7 +619,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         /**
          * 1.获取文章创建人ID
          * 2.通过文章创建人ID 查询隐私设置表 communityPrivacyService.selectUserPrivacy
-         * 3.查询是否开启 只允许我关注的人评论我  有则进入3,没有就返回,
+         * 3.查询权限表有没有开权限
          * 4.获取用户关注列表
          * 5.是否是关注的人评论我 有则评论成功,没有则返回失败
          */
@@ -660,11 +660,10 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         // 如果评论受限,则查询用户关注列表
         if (IsComment) {
             List<CommunityUserLikeVo> communityUserLikeVos = communityArticleService.selectCommunityUserLikeList(articleId);
-
             // 3. 检查评论者是否在关注列表中
             boolean isFollower = communityUserLikeVos.stream()
-                    .anyMatch(like -> like.getUserId().equals(SecurityUtils.getLoginUser().getUserId()));
-
+                    .anyMatch(like -> like.getLikeUserId().equals(SecurityUtils.getLoginUser().getUserId()));
+            System.out.println(SecurityUtils.getLoginUser().getUserId());
             // 如果不是关注者,返回失败
             if (!isFollower) {
                 //return AjaxResult.error("您没有权限评论此文章,因为只允许关注的人评论您!");