diff --git a/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java b/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java index 86b966702becf84c6faaef66e71118cece0318c3..35dfde3a6ee319878c160a4aa4d2fbdf73668c08 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 df4cf95738811db3d7b305b0613c75ad0695fce3..c73845946e2063ba83bbbde5d1c2b69732a87cd4 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 a9d3350bda61e8e9852f8612e469cf26d5c8e42f..5799259aabdb9a537c874d93b300d03a00498143 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 db7d3edf4a0df6c05aa86baac7868b9173541fe0..7cbc5e240164d3c8b440c6d7d673e60f982e050f 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 6155654884df870d42fcb1f1adeb2dada37bef55..8bb45f17267ab42d0f6a1f246eb03793cb5cbc64 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 f79b7e991b8ef6f2e50e9e7de5232b26af3c4cd6..ee8c3c91187a50233707d312091d90cd31841305 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 7c63c9452b7e92693225af69fabbe30d0519bafc..be7753cf8a3a6c3b9d8ef3cf1570d0711f9a3719 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 cc4ffd4208d727e4bf460389bf74823befa9d324..4b46f1d23c5fd74297c1ff163fde9d8fe6c9fa48 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 ea471c4a62284bda011249f819413dc5a997e7d9..641b52f2f5600e27856b8ccc57ba6543fa016aa0 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();