diff --git a/README.md b/README.md index f9d826c6afb4f80e310b22d2edd9189a97a0341e..858cad55e083257f673a01ff126569e4c8d16743 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## 一.说明 -主要是SpringBoot学习 +主要是SpringBoot学习,一键部署 ### 二.主要集成 diff --git a/src/main/java/com/kwan/springbootkwan/constant/CsdnConstant.java b/src/main/java/com/kwan/springbootkwan/constant/CsdnConstant.java new file mode 100644 index 0000000000000000000000000000000000000000..7b12a5306774e5cdf234c0013d060b93fc765a5b --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/constant/CsdnConstant.java @@ -0,0 +1,16 @@ +package com.kwan.springbootkwan.constant; + + +/** + * csdn常量管理 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/10/29 10:12 + */ +public class CsdnConstant { + /** + * 文章类型 + */ + public static final String ARTICLE_TYPE = "blog"; +} diff --git a/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java b/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java index b3836c86b3456fac2ad4912c0a51958d2fb410d9..86b966702becf84c6faaef66e71118cece0318c3 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java @@ -142,15 +142,12 @@ public class CsdnArticleInfoController { final CsdnArticleInfo one = this.csdnArticleInfoService.getOne(wrapper); if (one != null) { final String userName = one.getUserName(); - QueryWrapper wrapperUser = new QueryWrapper<>(); - wrapperUser.eq("user_name", userName); - wrapperUser.eq("is_delete", 0); - final CsdnUserInfo userInfo = this.csdnUserInfoService.getOne(wrapperUser); + 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(userInfo, article, one); + csdnService.tripletByArticle(csdnUserInfo, article, one); } return Result.ok("单篇文章三连完成"); } diff --git a/src/main/java/com/kwan/springbootkwan/controller/CsdnController.java b/src/main/java/com/kwan/springbootkwan/controller/CsdnController.java index 7c0f1f0b81e328717c15e2fea13a215328105e56..df4cf95738811db3d7b305b0613c75ad0695fce3 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/CsdnController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/CsdnController.java @@ -1,6 +1,5 @@ package com.kwan.springbootkwan.controller; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.kwan.springbootkwan.entity.CsdnUserInfo; import com.kwan.springbootkwan.entity.Result; import com.kwan.springbootkwan.service.CsdnAutoReplyService; @@ -33,10 +32,7 @@ public class CsdnController { @ApiOperation(value = "单人三连", nickname = "单人三连") @GetMapping("/singleTriplet") public Result singleTriplet(@Param("username") String username) { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("is_delete", 0); - wrapper.eq("user_name", username).last("limit 1"); - final CsdnUserInfo csdnUserInfo = csdnUserInfoService.getOne(wrapper); + CsdnUserInfo csdnUserInfo = csdnUserInfoService.getUserByUserName(username); if (Objects.nonNull(csdnUserInfo)) { csdnService.singleArticle(csdnUserInfo); } @@ -67,10 +63,7 @@ public class CsdnController { @ApiOperation(value = "重置指定人员新博客状态", nickname = "重置指定人员新博客状态") @GetMapping("/resetCsdnUserInfo") public Result resetCsdnUserInfo(@Param("username") String username) { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("is_delete", 0); - wrapper.eq("user_name", username).last("limit 1"); - final CsdnUserInfo csdnUserInfo = csdnUserInfoService.getOne(wrapper); + CsdnUserInfo csdnUserInfo = csdnUserInfoService.getUserByUserName(username); if (Objects.nonNull(csdnUserInfo)) { csdnUserInfoService.resetCsdnUserInfo(csdnUserInfo); } diff --git a/src/main/java/com/kwan/springbootkwan/service/CsdnUserInfoService.java b/src/main/java/com/kwan/springbootkwan/service/CsdnUserInfoService.java index 9ce23fa6541153165b3f4a3fa6a5da755115811d..7c63c9452b7e92693225af69fabbe30d0519bafc 100644 --- a/src/main/java/com/kwan/springbootkwan/service/CsdnUserInfoService.java +++ b/src/main/java/com/kwan/springbootkwan/service/CsdnUserInfoService.java @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.kwan.springbootkwan.entity.CsdnUserInfo; import com.kwan.springbootkwan.entity.query.CsdnUserInfoQuery; +import java.util.List; + /** * csdn用户信息(CsdnUserInfo)表服务接口 * @@ -11,6 +13,23 @@ import com.kwan.springbootkwan.entity.query.CsdnUserInfoQuery; * @since 2023-10-23 16:03:14 */ public interface CsdnUserInfoService extends IService { + + + /** + * 通过用户名获取user信息 + * + * @return + */ + CsdnUserInfo getUserByUserName(String username); + + /** + * 通过用户名获取user信息 + * + * @return + */ + List getAllUser(); + + /** * 重置新文章的状态 */ @@ -20,6 +39,7 @@ public interface CsdnUserInfoService extends IService { * 重置新一天的状态 */ void resetUserDayStatus(); + /** * 重置某个人某一天的状态 * @@ -29,6 +49,7 @@ public interface CsdnUserInfoService extends IService { /** * 新增用户 + * * @param addInfo */ void add(CsdnUserInfoQuery addInfo); diff --git a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnAutoReplyServiceImpl.java b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnAutoReplyServiceImpl.java index 13a123252e8fcde7e1ea263b00796aa004fe8749..6d0036a3cba088bbf744ba86d1eb2a878c155895 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnAutoReplyServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnAutoReplyServiceImpl.java @@ -3,7 +3,6 @@ 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.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.kwan.springbootkwan.entity.CsdnUserInfo; @@ -93,10 +92,7 @@ public class CsdnAutoReplyServiceImpl implements CsdnAutoReplyService { log.info(reply.toString()); } //三连此评论人 - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("is_delete", 0); - wrapper.eq("user_name", userName).last("limit 1"); - CsdnUserInfo csdnUserInfo = csdnUserInfoService.getOne(wrapper); + CsdnUserInfo csdnUserInfo=csdnUserInfoService.getUserByUserName(userName); if (Objects.isNull(csdnUserInfo)) { //新增用户 csdnUserInfo = new CsdnUserInfo(); 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 a62303bf67c7376a922f36a98fde5b4bd7c9380d..e10d342574abec190dc6ac00ff4e4827918ebc01 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java @@ -135,12 +135,9 @@ public class CsdnServiceImpl implements CsdnService { @Override public void multiTriplet() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("is_delete", 0); - wrapper.orderByDesc("user_weight"); - final List list = csdnUserInfoService.list(wrapper); - if (CollectionUtil.isNotEmpty(list)) { - for (CsdnUserInfo csdnUserInfo : list) { + final List allUser = csdnUserInfoService.getAllUser(); + if (CollectionUtil.isNotEmpty(allUser)) { + for (CsdnUserInfo csdnUserInfo : allUser) { singleArticle(csdnUserInfo); } } 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 59f22aac7a3b788ce426a2842b597f626d7a67fc..ea471c4a62284bda011249f819413dc5a997e7d9 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnUserInfoServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnUserInfoServiceImpl.java @@ -3,6 +3,7 @@ package com.kwan.springbootkwan.service.impl; 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.CsdnUserInfo; import com.kwan.springbootkwan.entity.query.CsdnUserInfoQuery; import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse; @@ -28,20 +29,33 @@ import java.util.List; */ @Service("csdnUserInfoService") public class CsdnUserInfoServiceImpl extends ServiceImpl implements CsdnUserInfoService { - - @Autowired private CsdnCollectService csdnCollectService; @Autowired private CsdnArticleInfoService csdnArticleInfoService; @Override - public void resetAllCurrentStatus() { + public CsdnUserInfo getUserByUserName(String username) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("is_delete", 0); + wrapper.eq("user_name", username) + .last("limit 1"); + return this.getOne(wrapper); + } + + @Override + public List getAllUser() { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("is_delete", 0); - final List list = this.list(wrapper); - if (CollectionUtil.isNotEmpty(list)) { - for (CsdnUserInfo csdnUserInfo : list) { + wrapper.orderByAsc("rand()"); + return this.list(wrapper); + } + + @Override + public void resetAllCurrentStatus() { + final List allUser = this.getAllUser(); + if (CollectionUtil.isNotEmpty(allUser)) { + for (CsdnUserInfo csdnUserInfo : allUser) { this.resetCsdnUserInfo(csdnUserInfo); } } @@ -49,16 +63,15 @@ public class CsdnUserInfoServiceImpl extends ServiceImpl articles = csdnArticleInfoService.getArticles(userName); if (CollectionUtil.isNotEmpty(articles)) { final BusinessInfoResponse.ArticleData.Article article = articles.get(0); final String type = article.getType(); - if (StringUtils.equals(type, "blog")) { - final String urlInfo = article.getUrl(); - String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1); + if (StringUtils.equals(type, CsdnConstant.ARTICLE_TYPE)) { + final String articleId = article.getArticleId().toString(); final Boolean collect = csdnCollectService.isCollect(articleId, csdnUserInfo); if (!collect || CommentStatus.COMMENT_TOO_FAST.getCode().equals(commentStatus) || !StringUtils.equals(articleType, type)) { csdnUserInfo.setLikeStatus(LikeStatus.UN_PROCESSED.getCode()); @@ -88,44 +101,35 @@ public class CsdnUserInfoServiceImpl extends ServiceImpl wrapper = new QueryWrapper<>(); - wrapper.eq("user_name", str); - wrapper.eq("is_delete", 0); - CsdnUserInfo one = this.getOne(wrapper); - if (one == null) { - one = new CsdnUserInfo(); - BeanUtils.copyProperties(addInfo, one); - one.setUserName(str); - one.setUserHomeUrl("https://blog.csdn.net/" + str); - this.save(one); + CsdnUserInfo csdnUserInfo = this.getUserByUserName(str); + if (csdnUserInfo == null) { + csdnUserInfo = new CsdnUserInfo(); + BeanUtils.copyProperties(addInfo, csdnUserInfo); + csdnUserInfo.setUserName(str); + csdnUserInfo.setUserHomeUrl("https://blog.csdn.net/" + str); + this.save(csdnUserInfo); } - addInfo.setNickName(one.getNickName()); + addInfo.setNickName(csdnUserInfo.getNickName()); } } } else { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("user_name", userName); - wrapper.eq("is_delete", 0); - CsdnUserInfo one = this.getOne(wrapper); - if (one == null) { - one = new CsdnUserInfo(); - BeanUtils.copyProperties(addInfo, one); - one.setUserHomeUrl("https://blog.csdn.net/" + userName); - this.save(one); + CsdnUserInfo csdnUserInfo = this.getUserByUserName(userName); + if (csdnUserInfo == null) { + csdnUserInfo = new CsdnUserInfo(); + BeanUtils.copyProperties(addInfo, csdnUserInfo); + csdnUserInfo.setUserHomeUrl("https://blog.csdn.net/" + userName); + this.save(csdnUserInfo); } - addInfo.setNickName(one.getNickName()); + addInfo.setNickName(csdnUserInfo.getNickName()); } } } @Override public void resetUserDayStatus() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("is_delete", 0); - final List list = this.list(wrapper); - if (CollectionUtil.isNotEmpty(list)) { - for (CsdnUserInfo csdnUserInfo : list) { + final List allUser = this.getAllUser(); + if (CollectionUtil.isNotEmpty(allUser)) { + for (CsdnUserInfo csdnUserInfo : allUser) { final String userName = csdnUserInfo.getUserName(); final List articles = csdnArticleInfoService.getArticles(userName); if (CollectionUtil.isNotEmpty(articles)) { @@ -151,6 +155,4 @@ public class CsdnUserInfoServiceImpl extends ServiceImpl