diff --git a/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java b/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java index 2a630fa728b5e1dd7647782f4cbd712c17cd8edb..b3836c86b3456fac2ad4912c0a51958d2fb410d9 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/CsdnArticleInfoController.java @@ -1,17 +1,21 @@ package com.kwan.springbootkwan.controller; - import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.kwan.springbootkwan.entity.CsdnArticleInfo; +import com.kwan.springbootkwan.entity.CsdnUserInfo; import com.kwan.springbootkwan.entity.Result; import com.kwan.springbootkwan.entity.dto.CsdnArticleInfoDTO; import com.kwan.springbootkwan.entity.query.CsdnArticleInfoQuery; +import com.kwan.springbootkwan.entity.query.CsdnUserInfoQuery; +import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse; import com.kwan.springbootkwan.service.CsdnArticleInfoService; +import com.kwan.springbootkwan.service.CsdnService; +import com.kwan.springbootkwan.service.CsdnUserInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.BeanUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -20,19 +24,26 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.util.List; import java.util.Objects; +@Slf4j @Api(tags = "csdn文章管理") @RestController @RequestMapping("/csdnArticleInfo") public class CsdnArticleInfoController { + @Resource + private CsdnService csdnService; + @Resource + private CsdnUserInfoService csdnUserInfoService; @Resource private CsdnArticleInfoService csdnArticleInfoService; @ApiOperation(value = "分页查询所有数据", nickname = "分页查询所有数据") @PostMapping("/page") public Result selectAll(@RequestBody CsdnArticleInfoQuery query) { + final String articleId = query.getArticleId(); final String nickName = query.getNickName(); final String userName = query.getUserName(); final Integer likeStatus = query.getLikeStatus(); @@ -43,6 +54,9 @@ public class CsdnArticleInfoController { pageParm.setSize(query.getPageSize()); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("is_delete", 0); + if (StringUtils.isNotEmpty(articleId)) { + wrapper.eq("article_id", articleId); + } if (StringUtils.isNotEmpty(userName)) { wrapper.eq("user_name", userName); } @@ -62,46 +76,35 @@ public class CsdnArticleInfoController { return Result.ok(CsdnArticleInfoDTO.Converter.INSTANCE.from(this.csdnArticleInfoService.page(pageParm, wrapper))); } - - @ApiOperation(value = "新增用户", nickname = "新增用户") + @ApiOperation(value = "新增文章", nickname = "新增文章") @PostMapping("/add") public Result add(@RequestBody CsdnArticleInfoQuery addInfo) { final String userName = addInfo.getUserName(); - final Integer addType = addInfo.getAddType(); final String articleId = addInfo.getArticleId(); - if (StringUtils.isNotEmpty(userName)) { - //批量添加 - if (addType == 1) { - final String[] split = articleId.split("\n"); - for (String str : split) { - str = str.trim(); - if (StringUtils.isNotEmpty(str)) { - CsdnArticleInfo csdnArticleInfo = new CsdnArticleInfo(); - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("article_id", str); - wrapper.eq("is_delete", 0); - final CsdnArticleInfo one = this.csdnArticleInfoService.getOne(wrapper); - if (one == null) { - BeanUtils.copyProperties(addInfo, csdnArticleInfo); - csdnArticleInfo.setArticleId(str); - csdnArticleInfo.setArticleUrl("https://blog.csdn.net/" + userName + "/article/details/" + articleId); - this.csdnArticleInfoService.save(csdnArticleInfo); - } + if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(articleId)) { + final List articles = this.csdnArticleInfoService.getBlogs(userName); + for (BusinessInfoResponse.ArticleData.Article article : articles) { + if (articleId.equals(article.getArticleId().toString())) { + //首先查询用户 + CsdnUserInfoQuery addUserInfo = new CsdnUserInfoQuery(); + 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.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); } - } - } else { - CsdnArticleInfo csdnArticleInfo = new CsdnArticleInfo(); - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("user_name", userName); - wrapper.eq("is_delete", 0); - final CsdnArticleInfo one = this.csdnArticleInfoService.getOne(wrapper); - if (one == null) { - BeanUtils.copyProperties(addInfo, csdnArticleInfo); - csdnArticleInfo.setArticleUrl("https://blog.csdn.net/" + userName + "/article/details/" + articleId); - this.csdnArticleInfoService.save(csdnArticleInfo); - return Result.ok(); - } else { - return Result.error("该用户已存在"); + break; } } } @@ -115,6 +118,8 @@ public class CsdnArticleInfoController { csdnUserInfo.setId(query.getId()); csdnUserInfo.setUserName(query.getUserName()); csdnUserInfo.setNickName(query.getNickName()); + csdnUserInfo.setArticleUrl(query.getArticleUrl()); + csdnUserInfo.setArticleId(query.getArticleId()); return Result.ok(this.csdnArticleInfoService.updateById(csdnUserInfo)); } @@ -127,5 +132,26 @@ public class CsdnArticleInfoController { wrapper.eq("id", id); return Result.ok(this.csdnArticleInfoService.update(csdnArticleInfo, wrapper)); } -} + @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(); + QueryWrapper wrapperUser = new QueryWrapper<>(); + wrapperUser.eq("user_name", userName); + wrapperUser.eq("is_delete", 0); + final CsdnUserInfo userInfo = this.csdnUserInfoService.getOne(wrapperUser); + 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); + } + return Result.ok("单篇文章三连完成"); + } +} \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/controller/CsdnUserController.java b/src/main/java/com/kwan/springbootkwan/controller/CsdnUserController.java index 52fb48d4a77d5aa2f90c5f11d838439a68e9be63..522f62ed7a4e8413aafcefd166da523da0837db1 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/CsdnUserController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/CsdnUserController.java @@ -11,7 +11,6 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -74,45 +73,7 @@ public class CsdnUserController { @ApiOperation(value = "新增用户", nickname = "新增用户") @PostMapping("/add") public Result add(@RequestBody CsdnUserInfoQuery addInfo) { - final String userName = addInfo.getUserName(); - final Integer addType = addInfo.getAddType(); - if (StringUtils.isEmpty(userName)) { - return Result.error("名字不能为空"); - } - //批量添加 - if (addType == 1) { - final String[] split = userName.split("\n"); - for (String str : split) { - str = str.trim(); - if (StringUtils.isNotEmpty(str)) { - CsdnUserInfo csdnUserInfo = new CsdnUserInfo(); - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("user_name", str); - wrapper.eq("is_delete", 0); - final CsdnUserInfo one = this.csdnUserInfoService.getOne(wrapper); - if (one == null) { - BeanUtils.copyProperties(addInfo, csdnUserInfo); - csdnUserInfo.setUserName(str); - csdnUserInfo.setUserHomeUrl("https://blog.csdn.net/" + str); - this.csdnUserInfoService.save(csdnUserInfo); - } - } - } - } else { - CsdnUserInfo csdnUserInfo = new CsdnUserInfo(); - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("user_name", userName); - wrapper.eq("is_delete", 0); - final CsdnUserInfo one = this.csdnUserInfoService.getOne(wrapper); - if (one == null) { - BeanUtils.copyProperties(addInfo, csdnUserInfo); - csdnUserInfo.setUserHomeUrl("https://blog.csdn.net/" + userName); - this.csdnUserInfoService.save(csdnUserInfo); - return Result.ok(); - } else { - return Result.error("该用户已存在"); - } - } + csdnUserInfoService.add(addInfo); return Result.ok(); } @@ -124,6 +85,7 @@ public class CsdnUserController { csdnUserInfo.setUserName(query.getUserName()); csdnUserInfo.setNickName(query.getNickName()); csdnUserInfo.setUserWeight(query.getUserWeight()); + csdnUserInfo.setUserHomeUrl(query.getUserHomeUrl()); return Result.ok(this.csdnUserInfoService.updateById(csdnUserInfo)); } diff --git a/src/main/java/com/kwan/springbootkwan/dao/CsdnArticleInfoDao.java b/src/main/java/com/kwan/springbootkwan/dao/CsdnArticleInfoDao.java deleted file mode 100644 index f8eccde282b255c5b0eba07c03db88be335c98f2..0000000000000000000000000000000000000000 --- a/src/main/java/com/kwan/springbootkwan/dao/CsdnArticleInfoDao.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.kwan.springbootkwan.dao; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.kwan.springbootkwan.entity.CsdnArticleInfo; - -/** - * csdn文章信息(CsdnArticleInfo)表数据库访问层 - * - * @author makejava - * @since 2023-10-28 01:58:46 - */ -public interface CsdnArticleInfoDao extends BaseMapper { - -} - diff --git a/src/main/java/com/kwan/springbootkwan/entity/CsdnArticleInfo.java b/src/main/java/com/kwan/springbootkwan/entity/CsdnArticleInfo.java index 5a2b2642c37a0e0ad99e943215cef2c811e27cf2..0382ab98a9ce9464cf66d1c11ad0d4ccf3493305 100644 --- a/src/main/java/com/kwan/springbootkwan/entity/CsdnArticleInfo.java +++ b/src/main/java/com/kwan/springbootkwan/entity/CsdnArticleInfo.java @@ -18,6 +18,10 @@ public class CsdnArticleInfo extends Model { private String articleId; @ApiModelProperty("文章URL") private String articleUrl; + @ApiModelProperty("文章标题") + private String articleTitle; + @ApiModelProperty("文章描述") + private String articleDescription; @ApiModelProperty("用户名称") private String userName; @ApiModelProperty("用户昵称") diff --git a/src/main/java/com/kwan/springbootkwan/entity/dto/CsdnArticleInfoDTO.java b/src/main/java/com/kwan/springbootkwan/entity/dto/CsdnArticleInfoDTO.java index cbb08bab541db7dbd0707ef7a764aa1c3e3461f6..0203de4b16e6e649d6aa9822d41555892910004b 100644 --- a/src/main/java/com/kwan/springbootkwan/entity/dto/CsdnArticleInfoDTO.java +++ b/src/main/java/com/kwan/springbootkwan/entity/dto/CsdnArticleInfoDTO.java @@ -22,6 +22,10 @@ public class CsdnArticleInfoDTO extends Model { private String articleId; @ApiModelProperty("文章URL") private String articleUrl; + @ApiModelProperty("文章标题") + private String articleTitle; + @ApiModelProperty("文章描述") + private String articleDescription; @ApiModelProperty("用户名称") private String userName; @ApiModelProperty("用户昵称") diff --git a/src/main/java/com/kwan/springbootkwan/entity/query/CsdnArticleInfoQuery.java b/src/main/java/com/kwan/springbootkwan/entity/query/CsdnArticleInfoQuery.java index 13edfe8c89ff939089ead25b151ea5584432355d..02fb063d3f67da3d06bea76c96278d21d6f8de8d 100644 --- a/src/main/java/com/kwan/springbootkwan/entity/query/CsdnArticleInfoQuery.java +++ b/src/main/java/com/kwan/springbootkwan/entity/query/CsdnArticleInfoQuery.java @@ -16,6 +16,8 @@ public class CsdnArticleInfoQuery extends BasePage { private String nickName; @ApiModelProperty("CSDN文章id") private String articleId; + @ApiModelProperty("CSDN文章URL") + private String articleUrl; @ApiModelProperty("点赞状态") private Integer likeStatus = 0; @ApiModelProperty("收藏状态") 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 f484ea80fda5fd9ebb742dd5bf282c25abdc34b6..19182c9529b1a740259fe74e84bee98589f6951d 100644 --- a/src/main/java/com/kwan/springbootkwan/entity/query/CsdnUserInfoQuery.java +++ b/src/main/java/com/kwan/springbootkwan/entity/query/CsdnUserInfoQuery.java @@ -24,6 +24,8 @@ public class CsdnUserInfoQuery extends BasePage { private Integer userWeight; @ApiModelProperty("文章类型") private String articleType; + @ApiModelProperty("用户主页") + private String userHomeUrl; @ApiModelProperty("添加类型") private Integer addType; } \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/entity/resp/BusinessInfoResponse.java b/src/main/java/com/kwan/springbootkwan/entity/resp/BusinessInfoResponse.java index d017ca68c2ec9ce035d02685fafdf160ffc68514..20c7cf04f3cc07114e40caa0c347b2ce95d840c1 100644 --- a/src/main/java/com/kwan/springbootkwan/entity/resp/BusinessInfoResponse.java +++ b/src/main/java/com/kwan/springbootkwan/entity/resp/BusinessInfoResponse.java @@ -43,9 +43,11 @@ public class BusinessInfoResponse { public Object fileType; public Object content; public Object status; -// public Integer articleId; -// public Object top; -// public Object forcePlan; + public Object articleId; + public Object top; + public Object forcePlan; + public Object solve; + public Object answersCount; } } diff --git a/src/main/java/com/kwan/springbootkwan/mapper/CsdnArticleInfoMapper.java b/src/main/java/com/kwan/springbootkwan/mapper/CsdnArticleInfoMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..6b5ceafd9ddbd0c4a716a0dfaf1efcc6cb0eb248 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/mapper/CsdnArticleInfoMapper.java @@ -0,0 +1,13 @@ +package com.kwan.springbootkwan.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.kwan.springbootkwan.entity.CsdnArticleInfo; +import org.apache.ibatis.annotations.Mapper; + + + +@Mapper +public interface CsdnArticleInfoMapper extends BaseMapper { + +} + diff --git a/src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java b/src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java index c2c0d1bb200445b8a3e337bf5befeccffc97881e..db7d3edf4a0df6c05aa86baac7868b9173541fe0 100644 --- a/src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java +++ b/src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java @@ -26,14 +26,8 @@ public class CsdnSchedule { public void execute() { log.info("execute task is running ... ..."); csdnService.multiTriplet(); - log.info("execute task is finish ... ..."); - } - - @Scheduled(cron = "0 0/50 0 * * ?") - public void executeReply() { - log.info("executeReply task is running ... ..."); csdnAutoReplyService.commentSelf(); - log.info("executeReply task is finish ... ..."); + log.info("execute task is finish ... ..."); } @Scheduled(cron = "0 0/30 * * * ?") @@ -43,17 +37,11 @@ public class CsdnSchedule { log.info("executeInit task is finish ... ..."); } - @Scheduled(cron = "0 0 2 * * ?") - public void resetUserDayStatus() { - log.info("executeInit task is running ... ..."); - csdnUserInfoService.resetUserDayStatus(); - log.info("executeInit task is finish ... ..."); - } - @Scheduled(cron = "0 0 1 * * ?") public void resetTripletDayInfo() { log.info("resetTripletDayInfo task is running ... ..."); //新增当前天的新的一条数据 + csdnUserInfoService.resetUserDayStatus(); csdnTripletDayInfoService.todayInfo(); log.info("resetTripletDayInfo task is finish ... ..."); } diff --git a/src/main/java/com/kwan/springbootkwan/schedule/ScheduleTest.java b/src/main/java/com/kwan/springbootkwan/schedule/ScheduleTest.java index 059cf87230ed3a8deb267515d592ad92e11e932a..a3df9d656b906c8bb261d14376cea34531cf9184 100644 --- a/src/main/java/com/kwan/springbootkwan/schedule/ScheduleTest.java +++ b/src/main/java/com/kwan/springbootkwan/schedule/ScheduleTest.java @@ -2,7 +2,6 @@ package com.kwan.springbootkwan.schedule; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -17,9 +16,25 @@ import org.springframework.stereotype.Component; @Slf4j public class ScheduleTest { +// @Scheduled(cron = "0/6 * * * * ?") + public void execute1() { + log.info("Scheduled execute1 is running ... ..."); + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + // @Scheduled(cron = "0/10 * * * * ?") - public void execute() { - log.info("Scheduled task is running ... ..."); + public void execute2() { + log.info("Scheduled execute2 is running ... ..."); + try { + Thread.sleep(30000); + } catch (InterruptedException e) { + e.printStackTrace(); + } } + } diff --git a/src/main/java/com/kwan/springbootkwan/service/CsdnArticleInfoService.java b/src/main/java/com/kwan/springbootkwan/service/CsdnArticleInfoService.java index 7144dc78158c1f5580d884ff4d473e115d17c9bf..6155654884df870d42fcb1f1adeb2dada37bef55 100644 --- a/src/main/java/com/kwan/springbootkwan/service/CsdnArticleInfoService.java +++ b/src/main/java/com/kwan/springbootkwan/service/CsdnArticleInfoService.java @@ -2,6 +2,9 @@ package com.kwan.springbootkwan.service; import com.baomidou.mybatisplus.extension.service.IService; import com.kwan.springbootkwan.entity.CsdnArticleInfo; +import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse; + +import java.util.List; /** * csdn文章信息(CsdnArticleInfo)表服务接口 @@ -11,5 +14,20 @@ import com.kwan.springbootkwan.entity.CsdnArticleInfo; */ public interface CsdnArticleInfoService extends IService { + /** + * 获取最新的10篇文章 + * + * @param username + * @return + */ + List getArticles(String username); + + /** + * 获取最新的10篇博客(只能是blog类型) + * + * @param username + * @return + */ + List getBlogs(String username); } diff --git a/src/main/java/com/kwan/springbootkwan/service/CsdnArticleService.java b/src/main/java/com/kwan/springbootkwan/service/CsdnArticleService.java deleted file mode 100644 index 24cdbd8a021f111046b356aa0acc53b9785fdd22..0000000000000000000000000000000000000000 --- a/src/main/java/com/kwan/springbootkwan/service/CsdnArticleService.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.kwan.springbootkwan.service; - -import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse; - -import java.util.List; - - -/** - * 获取最新的文章 - * - * @author : qinyingjie - * @version : 2.2.0 - * @date : 2023/10/25 18:44 - */ -public interface CsdnArticleService { - - /** - * 获取最新的5篇文章 - * - * @param username - * @return - */ - List getArticles(String username); -} \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/service/CsdnService.java b/src/main/java/com/kwan/springbootkwan/service/CsdnService.java index 675f4271e726fc079d04cd6ef454f598baa8c291..f79b7e991b8ef6f2e50e9e7de5232b26af3c4cd6 100644 --- a/src/main/java/com/kwan/springbootkwan/service/CsdnService.java +++ b/src/main/java/com/kwan/springbootkwan/service/CsdnService.java @@ -1,6 +1,8 @@ package com.kwan.springbootkwan.service; +import com.kwan.springbootkwan.entity.CsdnArticleInfo; import com.kwan.springbootkwan.entity.CsdnUserInfo; +import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse; /** * csdn博客自动化 @@ -22,4 +24,12 @@ public interface CsdnService { * 多人三连 */ void multiTriplet(); + + /** + * 根据文章三连 + * + * @param csdnUserInfo + * @param article + */ + void tripletByArticle(CsdnUserInfo csdnUserInfo, BusinessInfoResponse.ArticleData.Article article, CsdnArticleInfo csdnArticleInfo); } \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/service/CsdnUserInfoService.java b/src/main/java/com/kwan/springbootkwan/service/CsdnUserInfoService.java index 0a2a7666c9b1d9b0e746d49565c927c8def3e5bc..9ce23fa6541153165b3f4a3fa6a5da755115811d 100644 --- a/src/main/java/com/kwan/springbootkwan/service/CsdnUserInfoService.java +++ b/src/main/java/com/kwan/springbootkwan/service/CsdnUserInfoService.java @@ -2,6 +2,7 @@ package com.kwan.springbootkwan.service; import com.baomidou.mybatisplus.extension.service.IService; import com.kwan.springbootkwan.entity.CsdnUserInfo; +import com.kwan.springbootkwan.entity.query.CsdnUserInfoQuery; /** * csdn用户信息(CsdnUserInfo)表服务接口 @@ -26,5 +27,11 @@ public interface CsdnUserInfoService extends IService { */ void resetCsdnUserInfo(CsdnUserInfo csdnUserInfo); + /** + * 新增用户 + * @param addInfo + */ + void add(CsdnUserInfoQuery addInfo); + } 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 cded008928b99e6e29e4e125dfd947536a870cbe..cc4ffd4208d727e4bf460389bf74823befa9d324 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnArticleInfoServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnArticleInfoServiceImpl.java @@ -1,11 +1,20 @@ 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.extension.service.impl.ServiceImpl; -import com.kwan.springbootkwan.dao.CsdnArticleInfoDao; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.kwan.springbootkwan.entity.CsdnArticleInfo; +import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse; +import com.kwan.springbootkwan.mapper.CsdnArticleInfoMapper; import com.kwan.springbootkwan.service.CsdnArticleInfoService; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.util.List; + /** * csdn文章信息(CsdnArticleInfo)表服务实现类 * @@ -13,7 +22,68 @@ import org.springframework.stereotype.Service; * @since 2023-10-28 01:58:46 */ @Service("csdnArticleInfoService") -public class CsdnArticleInfoServiceImpl extends ServiceImpl implements CsdnArticleInfoService { +public class CsdnArticleInfoServiceImpl extends ServiceImpl implements CsdnArticleInfoService { + + @Value("${csdn.cookie}") + private String csdnCookie; + @Value("${csdn.url.user_article_url}") + private String url; + + @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) + .execute(); + final String body = response.body(); + ObjectMapper objectMapper = new ObjectMapper(); + BusinessInfoResponse businessInfoResponse; + List list = null; + try { + businessInfoResponse = objectMapper.readValue(body, BusinessInfoResponse.class); + final BusinessInfoResponse.ArticleData data = businessInfoResponse.getData(); + list = data.getList(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + if (CollectionUtil.isEmpty(list)) { + return null; + } + return list; + } + @Override + public List getBlogs(String username) { + HttpResponse response = HttpUtil.createGet(url) + .header("Cookie", csdnCookie) + .form("page", 1) + .form("size", 10) + .form("businessType", "blog") +// .form("blogType", "ViewCount") + .form("noMore", false) + .form("username", username) + .execute(); + final String body = response.body(); + ObjectMapper objectMapper = new ObjectMapper(); + BusinessInfoResponse businessInfoResponse; + List list = null; + try { + businessInfoResponse = objectMapper.readValue(body, BusinessInfoResponse.class); + final BusinessInfoResponse.ArticleData data = businessInfoResponse.getData(); + list = data.getList(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + if (CollectionUtil.isEmpty(list)) { + return null; + } + return list; + } } diff --git a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnArticleServiceImpl.java b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnArticleServiceImpl.java deleted file mode 100644 index 7e3ef9dd5306a5c1eefb87091c9a8595107ef493..0000000000000000000000000000000000000000 --- a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnArticleServiceImpl.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.kwan.springbootkwan.service.impl; - -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.http.HttpResponse; -import cn.hutool.http.HttpUtil; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse; -import com.kwan.springbootkwan.service.CsdnArticleService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -import java.util.List; - - -@Slf4j -@Service -public class CsdnArticleServiceImpl implements CsdnArticleService { - - @Value("${csdn.cookie}") - private String csdnCookie; - @Value("${csdn.url.user_article_url}") - private String url; - - @Override - public List getArticles(String username) { - HttpResponse response = HttpUtil.createGet(url) - .header("Cookie", csdnCookie) - .form("page", 1) - .form("size", 5) -// .form("businessType", "blog") -// .form("blogType", "ViewCount") - .form("businessType", "lately") - .form("noMore", false) - .form("username", username) - .execute(); - final String body = response.body(); - ObjectMapper objectMapper = new ObjectMapper(); - BusinessInfoResponse businessInfoResponse; - List list = null; - try { - businessInfoResponse = objectMapper.readValue(body, BusinessInfoResponse.class); - final BusinessInfoResponse.ArticleData data = businessInfoResponse.getData(); - list = data.getList(); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - if (CollectionUtil.isEmpty(list)) { - return null; - } - return list; - } -} 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 39cdbdad28f7fdfa8bb2b35d89453d3f31a3e806..ea08884467ec1269108eaaea926c58eaedaf9773 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnAutoReplyServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnAutoReplyServiceImpl.java @@ -10,7 +10,7 @@ import com.kwan.springbootkwan.entity.CsdnUserInfo; import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse; import com.kwan.springbootkwan.entity.resp.CommentListResponse; import com.kwan.springbootkwan.entity.resp.CommentResponse; -import com.kwan.springbootkwan.service.CsdnArticleService; +import com.kwan.springbootkwan.service.CsdnArticleInfoService; import com.kwan.springbootkwan.service.CsdnAutoReplyService; import com.kwan.springbootkwan.service.CsdnCommentService; import com.kwan.springbootkwan.service.CsdnService; @@ -38,7 +38,7 @@ public class CsdnAutoReplyServiceImpl implements CsdnAutoReplyService { @Autowired private CsdnService csdnService; @Autowired - private CsdnArticleService csdnArticleService; + private CsdnArticleInfoService csdnArticleInfoService; @Autowired private CsdnCommentService csdnCommentService; @Autowired @@ -46,7 +46,7 @@ public class CsdnAutoReplyServiceImpl implements CsdnAutoReplyService { @Override public void commentSelf() { - List list = csdnArticleService.getArticles(selfUserName); + List list = csdnArticleInfoService.getArticles(selfUserName); if (CollectionUtil.isNotEmpty(list)) { for (BusinessInfoResponse.ArticleData.Article article : list) { final String type = article.getType(); 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 6faf99f53787e822c6c0ee6885d8c2c727f63224..a62303bf67c7376a922f36a98fde5b4bd7c9380d 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java @@ -2,11 +2,12 @@ package com.kwan.springbootkwan.service.impl; import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.kwan.springbootkwan.entity.CsdnArticleInfo; import com.kwan.springbootkwan.entity.CsdnTripletDayInfo; import com.kwan.springbootkwan.entity.CsdnUserInfo; import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse; import com.kwan.springbootkwan.enums.CommentStatus; -import com.kwan.springbootkwan.service.CsdnArticleService; +import com.kwan.springbootkwan.service.CsdnArticleInfoService; import com.kwan.springbootkwan.service.CsdnCollectService; import com.kwan.springbootkwan.service.CsdnCommentService; import com.kwan.springbootkwan.service.CsdnLikeService; @@ -21,6 +22,7 @@ import org.springframework.stereotype.Service; import java.util.Date; import java.util.List; +import java.util.Objects; @Slf4j @@ -34,7 +36,7 @@ public class CsdnServiceImpl implements CsdnService { @Autowired private CsdnUserInfoService csdnUserInfoService; @Autowired - private CsdnArticleService csdnArticleService; + private CsdnArticleInfoService csdnArticleInfoService; @Autowired private CsdnCollectService csdnCollectService; @Autowired @@ -45,7 +47,7 @@ public class CsdnServiceImpl implements CsdnService { @Override public void singleArticle(CsdnUserInfo csdnUserInfo) { final String username = csdnUserInfo.getUserName(); - List list = csdnArticleService.getArticles(username); + List list = csdnArticleInfoService.getArticles(username); if (CollectionUtil.isNotEmpty(list)) { final int size = list.size(); numOfArticlesPerPerson = size < numOfArticlesPerPerson ? size : numOfArticlesPerPerson; @@ -58,39 +60,79 @@ public class CsdnServiceImpl implements CsdnService { csdnUserInfoService.updateById(csdnUserInfo); continue; } - //获取每日三连总信息 - final CsdnTripletDayInfo csdnTripletDayInfo = csdnTripletDayInfoService.todayInfo(); - final String urlInfo = article.getUrl(); - String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1); - //点赞 - final Boolean isLike = csdnLikeService.isLike(articleId, csdnUserInfo); - if (!isLike) { - csdnLikeService.like(articleId, csdnUserInfo, csdnTripletDayInfo); + //先去查询文章,没有查到的话就插入文章 + QueryWrapper 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); } - final Integer commentNum = csdnTripletDayInfo.getCommentNum(); - if (commentNum < 49) { - //评论 - final Boolean comment = csdnCommentService.isComment(article, csdnUserInfo); - if (!comment) { - csdnCommentService.comment(articleId, csdnUserInfo, csdnTripletDayInfo); - } - } else { - csdnUserInfo.setCommentStatus(CommentStatus.COMMENT_NUM_49.getCode()); + wrapper.eq("article_id", article.getArticleId().toString()); + wrapper.eq("is_delete", 0); + CsdnArticleInfo csdnArticleInfo = this.csdnArticleInfoService.getOne(wrapper); + if (csdnArticleInfo == null) { + csdnArticleInfo = new CsdnArticleInfo(); + csdnArticleInfo.setArticleId(article.getArticleId().toString()); + csdnArticleInfo.setArticleUrl(articleUrl); + csdnArticleInfo.setArticleTitle(article.getTitle()); + csdnArticleInfo.setArticleDescription(article.getDescription()); + csdnArticleInfo.setUserName(username); + csdnArticleInfo.setNickName(csdnUserInfo.getNickName()); + this.csdnArticleInfoService.save(csdnArticleInfo); } - //收藏 - final Boolean collect = csdnCollectService.isCollect(articleId, csdnUserInfo); - if (!collect) { - csdnCollectService.collect(article, csdnUserInfo, csdnTripletDayInfo); - } - csdnTripletDayInfo.setUpdateTime(new Date()); - csdnTripletDayInfoService.updateById(csdnTripletDayInfo); - csdnUserInfo.setUpdateTime(new Date()); - csdnUserInfoService.updateById(csdnUserInfo); + this.tripletByArticle(csdnUserInfo, article, csdnArticleInfo); } } } + /** + * 根据文章三连 + * + * @param csdnUserInfo + * @param article + */ + @Override + public void tripletByArticle(CsdnUserInfo csdnUserInfo, BusinessInfoResponse.ArticleData.Article article, CsdnArticleInfo csdnArticleInfo) { + //获取每日三连总信息 + final CsdnTripletDayInfo csdnTripletDayInfo = csdnTripletDayInfoService.todayInfo(); + final String urlInfo = article.getUrl(); + String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1); + //点赞 + final Boolean isLike = csdnLikeService.isLike(articleId, csdnUserInfo); + if (!isLike) { + csdnLikeService.like(articleId, csdnUserInfo, csdnTripletDayInfo); + } + final Integer commentNum = csdnTripletDayInfo.getCommentNum(); + if (commentNum < 49) { + //评论 + final Boolean comment = csdnCommentService.isComment(article, csdnUserInfo); + if (!comment) { + csdnCommentService.comment(articleId, csdnUserInfo, csdnTripletDayInfo); + } + } else { + csdnUserInfo.setCommentStatus(CommentStatus.COMMENT_NUM_49.getCode()); + } + //收藏 + final Boolean collect = csdnCollectService.isCollect(articleId, csdnUserInfo); + if (!collect) { + csdnCollectService.collect(article, csdnUserInfo, csdnTripletDayInfo); + } + + csdnTripletDayInfo.setUpdateTime(new Date()); + csdnTripletDayInfoService.updateById(csdnTripletDayInfo); + + csdnUserInfo.setUpdateTime(new Date()); + csdnUserInfoService.updateById(csdnUserInfo); + + csdnArticleInfo.setUpdateTime(new Date()); + csdnArticleInfo.setLikeStatus(csdnUserInfo.getLikeStatus()); + csdnArticleInfo.setCollectStatus(csdnUserInfo.getCollectStatus()); + csdnArticleInfo.setCommentStatus(csdnUserInfo.getCommentStatus()); + csdnArticleInfoService.updateById(csdnArticleInfo); + } + @Override public void multiTriplet() { QueryWrapper wrapper = new QueryWrapper<>(); 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 2900f9e99e8129fb1b71bc03ab6859b2597e1803..59f22aac7a3b788ce426a2842b597f626d7a67fc 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/CsdnUserInfoServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/CsdnUserInfoServiceImpl.java @@ -4,15 +4,17 @@ 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.entity.CsdnUserInfo; +import com.kwan.springbootkwan.entity.query.CsdnUserInfoQuery; import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse; import com.kwan.springbootkwan.enums.CollectStatus; import com.kwan.springbootkwan.enums.CommentStatus; import com.kwan.springbootkwan.enums.LikeStatus; import com.kwan.springbootkwan.mapper.CsdnUserInfoMapper; -import com.kwan.springbootkwan.service.CsdnArticleService; +import com.kwan.springbootkwan.service.CsdnArticleInfoService; import com.kwan.springbootkwan.service.CsdnCollectService; import com.kwan.springbootkwan.service.CsdnUserInfoService; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -31,7 +33,7 @@ public class CsdnUserInfoServiceImpl extends ServiceImpl articles = csdnArticleService.getArticles(userName); + final List articles = csdnArticleInfoService.getArticles(userName); if (CollectionUtil.isNotEmpty(articles)) { final BusinessInfoResponse.ArticleData.Article article = articles.get(0); final String type = article.getType(); @@ -75,6 +77,48 @@ 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); + } + addInfo.setNickName(one.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); + } + addInfo.setNickName(one.getNickName()); + } + } + } + @Override public void resetUserDayStatus() { QueryWrapper wrapper = new QueryWrapper<>(); @@ -83,7 +127,7 @@ public class CsdnUserInfoServiceImpl extends ServiceImpl articles = csdnArticleService.getArticles(userName); + final List articles = csdnArticleInfoService.getArticles(userName); if (CollectionUtil.isNotEmpty(articles)) { final BusinessInfoResponse.ArticleData.Article article = articles.get(0); final String type = article.getType();