From f2ee01ec0fab82c29deb5d9cc6a40e758de957c0 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 17:32:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=B7=BB=E5=8A=A0=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CsdnUserController.java | 20 +++++++++++-------- .../kwan/springbootkwan/entity/BasePage.java | 9 +++++++++ .../entity/query/CsdnUserInfoQuery.java | 3 ++- .../service/impl/CsdnServiceImpl.java | 17 ++++++++-------- 4 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/kwan/springbootkwan/entity/BasePage.java diff --git a/src/main/java/com/kwan/springbootkwan/controller/CsdnUserController.java b/src/main/java/com/kwan/springbootkwan/controller/CsdnUserController.java index ee48946..b3aefbd 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/CsdnUserController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/CsdnUserController.java @@ -18,6 +18,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.Objects; + @Slf4j @RestController @RequestMapping("/csdn/user") @@ -32,27 +34,29 @@ public class CsdnUserController { * * @return 所有数据 */ - @GetMapping("/page") - public Result selectAll(@RequestParam Integer page - , @RequestParam Integer pageSize - , @RequestParam String userName - , @RequestParam String nickName) { + @PostMapping("/page") + public Result selectAll(@RequestBody CsdnUserInfoQuery query) { + final Integer userWeight = query.getUserWeight(); + final String nickName = query.getNickName(); + final String userName = query.getUserName(); Page pageParm = new Page<>(); - pageParm.setCurrent(page); - pageParm.setSize(pageSize); + pageParm.setCurrent(query.getPage()); + pageParm.setSize(query.getPageSize()); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.orderByDesc("user_weight"); wrapper.eq("is_delete", 0); if (StringUtils.isNotEmpty(userName)) { wrapper.eq("user_name", userName); } + if (Objects.nonNull(userWeight)) { + wrapper.eq("user_weight", userWeight); + } if (StringUtils.isNotEmpty(nickName)) { wrapper.like("nick_name", nickName); } return Result.ok(CsdnUserInfoDTO.Converter.INSTANCE.from(this.csdnUserInfoService.page(pageParm, wrapper))); } - /** * 新增用户 * diff --git a/src/main/java/com/kwan/springbootkwan/entity/BasePage.java b/src/main/java/com/kwan/springbootkwan/entity/BasePage.java new file mode 100644 index 0000000..6df12fe --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/entity/BasePage.java @@ -0,0 +1,9 @@ +package com.kwan.springbootkwan.entity; + +import lombok.Data; + +@Data +public class BasePage { + private Integer page; + private Integer pageSize; +} diff --git a/src/main/java/com/kwan/springbootkwan/entity/query/CsdnUserInfoQuery.java b/src/main/java/com/kwan/springbootkwan/entity/query/CsdnUserInfoQuery.java index 09673bd..b806b6a 100644 --- a/src/main/java/com/kwan/springbootkwan/entity/query/CsdnUserInfoQuery.java +++ b/src/main/java/com/kwan/springbootkwan/entity/query/CsdnUserInfoQuery.java @@ -1,9 +1,10 @@ package com.kwan.springbootkwan.entity.query; +import com.kwan.springbootkwan.entity.BasePage; import lombok.Data; @Data -public class CsdnUserInfoQuery { +public class CsdnUserInfoQuery extends BasePage { /** * 主键id */ 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 9b2321e..6414d71 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java @@ -68,17 +68,16 @@ public class CsdnServiceImpl implements CsdnService { 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); - } + if (CollectionUtil.isEmpty(comments) || comments.size() < 49) { + //评论 + final Boolean comment = csdnCommentService.isComment(article, csdnUserInfo); + if (!comment) { + csdnCommentService.comment(articleId, csdnUserInfo); } } + if (CollectionUtil.isNotEmpty(comments) && comments.size() >= 49) { + csdnUserInfo.setCommentStatus(CommentStatus.COMMENT_NUM_49.getCode()); + } //收藏 final Boolean collect = csdnCollectService.isCollect(articleId, csdnUserInfo); if (!collect) { -- GitLab