From bd6db650ab71f6a645ff13a1b1fdb9aff306407b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Sun, 29 Oct 2023 12:43:38 +0800 Subject: [PATCH] {query} --- .../controller/CsdnArticleInfoController.java | 42 +++++++++++-------- .../controller/CsdnController.java | 40 ++++++++++++++++-- .../CsdnTripletDayInfoController.java | 1 + .../springbootkwan/schedule/CsdnSchedule.java | 2 +- .../service/CsdnArticleInfoService.java | 14 +++++++ .../springbootkwan/service/CsdnService.java | 2 +- .../service/CsdnUserInfoService.java | 7 ++++ .../impl/CsdnArticleInfoServiceImpl.java | 30 +++++++++++-- .../service/impl/CsdnServiceImpl.java | 12 ++---- .../service/impl/CsdnUserInfoServiceImpl.java | 31 ++++++++++---- 10 files changed, 140 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java b/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java index 86b9667..35dfde3 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java @@ -1,5 +1,6 @@ package com.kwan.springbootkwan.controller; +import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.kwan.springbootkwan.entity.CsdnArticleInfo; @@ -90,19 +91,16 @@ public class CsdnArticleInfoController { addUserInfo.setUserName(userName); addUserInfo.setAddType(0); csdnUserInfoService.add(addUserInfo); - CsdnArticleInfo csdnArticleInfo = new CsdnArticleInfo(); - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("article_id", articleId); - wrapper.eq("is_delete", 0); - final CsdnArticleInfo one = this.csdnArticleInfoService.getOne(wrapper); - if (one == null) { + CsdnArticleInfo csdnArticleInfo = this.csdnArticleInfoService.getArticleByArticleId(articleId); + if (csdnArticleInfo == null) { + csdnArticleInfo = new CsdnArticleInfo(); csdnArticleInfo.setArticleId(articleId); csdnArticleInfo.setUserName(userName); csdnArticleInfo.setArticleTitle(article.getTitle()); csdnArticleInfo.setArticleDescription(article.getDescription()); csdnArticleInfo.setArticleUrl(article.getUrl()); csdnArticleInfo.setNickName(addUserInfo.getNickName()); - this.csdnArticleInfoService.save(csdnArticleInfo); + this.csdnArticleInfoService.saveArticle(csdnArticleInfo); } break; } @@ -136,19 +134,27 @@ public class CsdnArticleInfoController { @ApiOperation(value = "单篇文章三连", nickname = "单篇文章三连") @GetMapping("/triplet") public Result triplet(@RequestParam("articleId") Integer articleId) { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("article_id", articleId); - wrapper.eq("is_delete", 0); - final CsdnArticleInfo one = this.csdnArticleInfoService.getOne(wrapper); - if (one != null) { - final String userName = one.getUserName(); - CsdnUserInfo csdnUserInfo=csdnUserInfoService.getUserByUserName(userName); + final CsdnArticleInfo csdnArticleInfo = this.csdnArticleInfoService.getArticleByArticleId(articleId.toString()); + if (csdnArticleInfo != null) { + final String userName = csdnArticleInfo.getUserName(); + CsdnUserInfo csdnUserInfo = csdnUserInfoService.getUserByUserName(userName); BusinessInfoResponse.ArticleData.Article article = new BusinessInfoResponse.ArticleData.Article(); - article.setDescription(one.getArticleDescription()); - article.setTitle(one.getArticleTitle()); - article.setUrl(one.getArticleUrl()); - csdnService.tripletByArticle(csdnUserInfo, article, one); + article.setDescription(csdnArticleInfo.getArticleDescription()); + article.setTitle(csdnArticleInfo.getArticleTitle()); + article.setUrl(csdnArticleInfo.getArticleUrl()); + csdnService.tripletByArticle(csdnUserInfo, article, csdnArticleInfo); } return Result.ok("单篇文章三连完成"); } + + @ApiOperation(value = "多条blog三连", nickname = "多条blog三连") + @PostMapping("/multiTriplet") + public Result multiTriplet(@RequestBody List articleIds) { + if (CollectionUtil.isNotEmpty(articleIds)) { + for (String articleId : articleIds) { + triplet(Integer.valueOf(articleId)); + } + } + return Result.ok("重置多个人员新博客状态完成"); + } } \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/controller/CsdnController.java b/src/main/java/com/kwan/springbootkwan/controller/CsdnController.java index df4cf95..c738459 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/CsdnController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/CsdnController.java @@ -1,5 +1,6 @@ package com.kwan.springbootkwan.controller; +import cn.hutool.core.collection.CollectionUtil; import com.kwan.springbootkwan.entity.CsdnUserInfo; import com.kwan.springbootkwan.entity.Result; import com.kwan.springbootkwan.service.CsdnAutoReplyService; @@ -11,9 +12,12 @@ import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; import java.util.Objects; @Slf4j @@ -40,12 +44,23 @@ public class CsdnController { } @ApiOperation(value = "多人三连", nickname = "多人三连") - @GetMapping("/multiTriplet") - public Result multiTriplet() { - csdnService.multiTriplet(); + @PostMapping("/multiTriplet") + public Result multiTriplet(@RequestBody List userNames) { + if (CollectionUtil.isNotEmpty(userNames)) { + for (String userName : userNames) { + singleTriplet(userName); + } + } return Result.ok("多人三连完成"); } + @ApiOperation(value = "全员三连", nickname = "全员三连") + @GetMapping("/allTriplet") + public Result allTriplet() { + csdnService.allTriplet(); + return Result.ok("全员三连完成"); + } + @ApiOperation(value = "自动回复", nickname = "自动回复") @GetMapping("/autoReply") public Result autoReply() { @@ -70,10 +85,29 @@ public class CsdnController { return Result.ok("重置指定人员新博客状态完成"); } + @ApiOperation(value = "重置多个人员新博客", nickname = "重置多个人员新博客") + @PostMapping("/resetCsdnUserInfo") + public Result resetCsdnUserInfo(@RequestBody List userNames) { + if (CollectionUtil.isNotEmpty(userNames)) { + for (String userName : userNames) { + resetCsdnUserInfo(userName); + } + } + return Result.ok("重置多个人员新博客状态完成"); + } + @ApiOperation(value = "重置新一天用户状态", nickname = "重置新一天用户状态") @GetMapping("/resetUserDayStatus") public Result resetUserDayStatus() { csdnUserInfoService.resetUserDayStatus(); return Result.ok("重置新一天用户状态完成"); } + + @ApiOperation(value = "给指定人员添加10篇博客", nickname = "给指定人员添加10篇博客") + @GetMapping("/add10Blog") + public Result add10Blog(@Param("username") String username) { + csdnUserInfoService.add10Blog(username); + return Result.ok("给指定人员添加10篇博客完成"); + } + } diff --git a/src/main/java/com/kwan/springbootkwan/controller/CsdnTripletDayInfoController.java b/src/main/java/com/kwan/springbootkwan/controller/CsdnTripletDayInfoController.java index a9d3350..5799259 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/CsdnTripletDayInfoController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/CsdnTripletDayInfoController.java @@ -26,6 +26,7 @@ import java.util.Objects; @RestController @RequestMapping("/dayInfo") public class CsdnTripletDayInfoController { + @Autowired private CsdnTripletDayInfoService csdnTripletDayInfoService; diff --git a/src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java b/src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java index db7d3ed..7cbc5e2 100644 --- a/src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java +++ b/src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java @@ -25,7 +25,7 @@ public class CsdnSchedule { @Scheduled(cron = "0 0 8,10,12,14,16,18,20 * * ?") public void execute() { log.info("execute task is running ... ..."); - csdnService.multiTriplet(); + csdnService.allTriplet(); csdnAutoReplyService.commentSelf(); log.info("execute task is finish ... ..."); } diff --git a/src/main/java/com/kwan/springbootkwan/service/CsdnArticleInfoService.java b/src/main/java/com/kwan/springbootkwan/service/CsdnArticleInfoService.java index 6155654..8bb45f1 100644 --- a/src/main/java/com/kwan/springbootkwan/service/CsdnArticleInfoService.java +++ b/src/main/java/com/kwan/springbootkwan/service/CsdnArticleInfoService.java @@ -13,6 +13,20 @@ import java.util.List; * @since 2023-10-28 01:58:46 */ public interface CsdnArticleInfoService extends IService { + /** + * 通过文章id获取文章信息 + * + * @return + */ + CsdnArticleInfo getArticleByArticleId(String articleId); + + /** + * 保存文章Blog + * + * @return + */ + void saveArticle(CsdnArticleInfo csdnArticleInfo); + /** * 获取最新的10篇文章 diff --git a/src/main/java/com/kwan/springbootkwan/service/CsdnService.java b/src/main/java/com/kwan/springbootkwan/service/CsdnService.java index f79b7e9..ee8c3c9 100644 --- a/src/main/java/com/kwan/springbootkwan/service/CsdnService.java +++ b/src/main/java/com/kwan/springbootkwan/service/CsdnService.java @@ -23,7 +23,7 @@ public interface CsdnService { /** * 多人三连 */ - void multiTriplet(); + void allTriplet(); /** * 根据文章三连 diff --git a/src/main/java/com/kwan/springbootkwan/service/CsdnUserInfoService.java b/src/main/java/com/kwan/springbootkwan/service/CsdnUserInfoService.java index 7c63c94..be7753c 100644 --- a/src/main/java/com/kwan/springbootkwan/service/CsdnUserInfoService.java +++ b/src/main/java/com/kwan/springbootkwan/service/CsdnUserInfoService.java @@ -54,5 +54,12 @@ public interface CsdnUserInfoService extends IService { */ void add(CsdnUserInfoQuery addInfo); + /** + * 给指定人员添加10篇博客 + * + * @param username + */ + void add10Blog(String username); + } diff --git a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnArticleInfoServiceImpl.java b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnArticleInfoServiceImpl.java index cc4ffd4..4b46f1d 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnArticleInfoServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnArticleInfoServiceImpl.java @@ -3,6 +3,7 @@ package com.kwan.springbootkwan.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -14,6 +15,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Objects; /** * csdn文章信息(CsdnArticleInfo)表服务实现类 @@ -29,14 +31,37 @@ public class CsdnArticleInfoServiceImpl extends ServiceImpl wrapper = new QueryWrapper<>(); + wrapper.eq("is_delete", 0); + wrapper.eq("article_id", articleId) + .last("limit 1"); + return this.getOne(wrapper); + } + + @Override + public void saveArticle(CsdnArticleInfo add) { + final String articleId = add.getArticleId(); + CsdnArticleInfo csdnArticleInfo = this.getArticleByArticleId(articleId); + if (Objects.isNull(csdnArticleInfo)) { + csdnArticleInfo = new CsdnArticleInfo(); + csdnArticleInfo.setArticleId(articleId); + csdnArticleInfo.setUserName(add.getUserName()); + csdnArticleInfo.setArticleTitle(add.getArticleTitle()); + csdnArticleInfo.setArticleDescription(add.getArticleDescription()); + csdnArticleInfo.setArticleUrl(add.getArticleUrl()); + csdnArticleInfo.setNickName(add.getNickName()); + this.save(csdnArticleInfo); + } + } + @Override public List getArticles(String username) { HttpResponse response = HttpUtil.createGet(url) .header("Cookie", csdnCookie) .form("page", 1) .form("size", 10) -// .form("businessType", "blog") -// .form("blogType", "ViewCount") .form("businessType", "lately") .form("noMore", false) .form("username", username) @@ -65,7 +90,6 @@ public class CsdnArticleInfoServiceImpl extends ServiceImpl wrapper = new QueryWrapper<>(); final String articleUrl = article.getUrl(); String articleIdFormUrl = articleUrl.substring(articleUrl.lastIndexOf("/") + 1); final Object articleId = article.getArticleId(); if (Objects.isNull(articleId)) { article.setArticleId(articleIdFormUrl); } - wrapper.eq("article_id", article.getArticleId().toString()); - wrapper.eq("is_delete", 0); - CsdnArticleInfo csdnArticleInfo = this.csdnArticleInfoService.getOne(wrapper); - if (csdnArticleInfo == null) { + CsdnArticleInfo csdnArticleInfo = this.csdnArticleInfoService.getArticleByArticleId(article.getArticleId().toString()); + if (Objects.isNull(csdnArticleInfo)) { csdnArticleInfo = new CsdnArticleInfo(); csdnArticleInfo.setArticleId(article.getArticleId().toString()); csdnArticleInfo.setArticleUrl(articleUrl); @@ -79,7 +75,7 @@ public class CsdnServiceImpl implements CsdnService { csdnArticleInfo.setArticleDescription(article.getDescription()); csdnArticleInfo.setUserName(username); csdnArticleInfo.setNickName(csdnUserInfo.getNickName()); - this.csdnArticleInfoService.save(csdnArticleInfo); + this.csdnArticleInfoService.saveArticle(csdnArticleInfo); } this.tripletByArticle(csdnUserInfo, article, csdnArticleInfo); } @@ -134,7 +130,7 @@ public class CsdnServiceImpl implements CsdnService { } @Override - public void multiTriplet() { + public void allTriplet() { final List allUser = csdnUserInfoService.getAllUser(); if (CollectionUtil.isNotEmpty(allUser)) { for (CsdnUserInfo csdnUserInfo : allUser) { diff --git a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnUserInfoServiceImpl.java b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnUserInfoServiceImpl.java index ea471c4..641b52f 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnUserInfoServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnUserInfoServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.kwan.springbootkwan.constant.CsdnConstant; +import com.kwan.springbootkwan.entity.CsdnArticleInfo; import com.kwan.springbootkwan.entity.CsdnUserInfo; import com.kwan.springbootkwan.entity.query.CsdnUserInfoQuery; import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse; @@ -20,15 +21,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Objects; -/** - * csdn用户信息(CsdnUserInfo)表服务实现类 - * - * @author makejava - * @since 2023-10-23 16:03:14 - */ @Service("csdnUserInfoService") public class CsdnUserInfoServiceImpl extends ServiceImpl implements CsdnUserInfoService { + @Autowired private CsdnCollectService csdnCollectService; @Autowired @@ -71,7 +68,8 @@ public class CsdnUserInfoServiceImpl extends ServiceImpl blogs = csdnArticleInfoService.getBlogs(username); + for (BusinessInfoResponse.ArticleData.Article article : blogs) { + CsdnArticleInfo csdnArticleInfo = this.csdnArticleInfoService.getArticleByArticleId(article.getArticleId().toString()); + if (Objects.isNull(csdnArticleInfo)) { + csdnArticleInfo = new CsdnArticleInfo(); + csdnArticleInfo.setArticleId(article.getArticleId().toString()); + csdnArticleInfo.setArticleUrl(article.getUrl()); + csdnArticleInfo.setArticleTitle(article.getTitle()); + csdnArticleInfo.setArticleDescription(article.getDescription()); + csdnArticleInfo.setUserName(username); + csdnArticleInfo.setNickName(csdnUserInfo.getNickName()); + this.csdnArticleInfoService.saveArticle(csdnArticleInfo); + } + } + } + @Override public void resetUserDayStatus() { final List allUser = this.getAllUser(); -- GitLab