diff --git a/src/main/java/com/kwan/springbootkwan/enums/CommentStatus.java b/src/main/java/com/kwan/springbootkwan/enums/CommentStatus.java index 47e525dbed49b2c682f26a93bc6992f985236f24..9900a48fc3b157dd99fae6e3eade2b22d3690c70 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 1e335ed14c66afff8e076a4ce200f108ad48cd3a..158b518ab337c5d30163183f78bb429f51d48b0a 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 7f1321cdee570802013b23b23a5f7bb01e5b93f8..9b2321e285432f63835133fddec7a676b2381e34 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);