From 6041f44dd4f55022b77153c739bc8ddfa41a2fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Wed, 25 Oct 2023 13:59:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=AF=84=E8=AE=BA=E9=99=90=E5=88=B6?= =?UTF-8?q?=E8=A7=84=E9=81=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springbootkwan/enums/CommentStatus.java | 8 ++++++++ .../service/impl/CsdnCommentServiceImpl.java | 10 +++++++++- .../service/impl/CsdnServiceImpl.java | 20 +++++++++++++++---- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/kwan/springbootkwan/enums/CommentStatus.java b/src/main/java/com/kwan/springbootkwan/enums/CommentStatus.java index 47e525d..9900a48 100644 --- a/src/main/java/com/kwan/springbootkwan/enums/CommentStatus.java +++ b/src/main/java/com/kwan/springbootkwan/enums/CommentStatus.java @@ -26,6 +26,14 @@ public enum CommentStatus { * 评论太快 */ COMMENT_TOO_FAST(4, "评论太快"), + /** + * 评论已经到了49条 + */ + COMMENT_NUM_49(5, "评论已经到了49条"), + /** + * 其他错误 + */ + OTHER_ERRORS(8, "其他错误"), /** * 评论成功 */ diff --git a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnCommentServiceImpl.java b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnCommentServiceImpl.java index 1e335ed..158b518 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnCommentServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnCommentServiceImpl.java @@ -95,9 +95,17 @@ public class CsdnCommentServiceImpl implements CsdnCommentService { } else if (code == 400 && message.contains("因存在恶意评论嫌疑,您的账号已被禁言")) { log.info("因存在恶意评论嫌疑,您的账号已被禁言"); csdnUserInfo.setCommentStatus(CommentStatus.RESTRICTED_COMMENTS.getCode()); - } else { + } else if (code == 400 && StringUtils.equals(message, "您评论太快了,请休息一下!")) { log.info("您评论太快了,请休息一下!"); csdnUserInfo.setCommentStatus(CommentStatus.COMMENT_TOO_FAST.getCode()); + try { + Thread.sleep(20000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } else { + log.info("其他错误"); + csdnUserInfo.setCommentStatus(CommentStatus.OTHER_ERRORS.getCode()); } return true; } diff --git a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java index 7f1321c..9b2321e 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.kwan.springbootkwan.entity.CsdnUserInfo; import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse; +import com.kwan.springbootkwan.enums.CommentStatus; import com.kwan.springbootkwan.service.CsdnCollectService; import com.kwan.springbootkwan.service.CsdnCommentService; import com.kwan.springbootkwan.service.CsdnLikeService; @@ -62,10 +63,21 @@ public class CsdnServiceImpl implements CsdnService { if (!isLike) { csdnLikeService.like(articleId, csdnUserInfo); } - //评论 - final Boolean comment = csdnCommentService.isComment(article, csdnUserInfo); - if (!comment) { - csdnCommentService.comment(articleId, csdnUserInfo); + //查看已经评论总数量 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("is_delete", 0); + wrapper.eq("comment_status", 9); + final List comments = csdnUserInfoService.list(wrapper); + if (CollectionUtil.isNotEmpty(comments)) { + if (comments.size() >= 49) { + csdnUserInfo.setCommentStatus(CommentStatus.COMMENT_NUM_49.getCode()); + } else { + //评论 + final Boolean comment = csdnCommentService.isComment(article, csdnUserInfo); + if (!comment) { + csdnCommentService.comment(articleId, csdnUserInfo); + } + } } //收藏 final Boolean collect = csdnCollectService.isCollect(articleId, csdnUserInfo); -- GitLab