fix:最近的文章

上级 83a7f5a1
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<CsdnArticleInfo> 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)) {
if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(articleId)) {
final List<BusinessInfoResponse.ArticleData.Article> 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<CsdnArticleInfo> wrapper = new QueryWrapper<>();
wrapper.eq("article_id", str);
wrapper.eq("article_id", articleId);
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);
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<CsdnArticleInfo> 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<CsdnArticleInfo> 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<CsdnUserInfo> 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
......@@ -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<CsdnUserInfo> 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<CsdnUserInfo> 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));
}
......
......@@ -18,6 +18,10 @@ public class CsdnArticleInfo extends Model<CsdnArticleInfo> {
private String articleId;
@ApiModelProperty("文章URL")
private String articleUrl;
@ApiModelProperty("文章标题")
private String articleTitle;
@ApiModelProperty("文章描述")
private String articleDescription;
@ApiModelProperty("用户名称")
private String userName;
@ApiModelProperty("用户昵称")
......
......@@ -22,6 +22,10 @@ public class CsdnArticleInfoDTO extends Model<CsdnArticleInfoDTO> {
private String articleId;
@ApiModelProperty("文章URL")
private String articleUrl;
@ApiModelProperty("文章标题")
private String articleTitle;
@ApiModelProperty("文章描述")
private String articleDescription;
@ApiModelProperty("用户名称")
private String userName;
@ApiModelProperty("用户昵称")
......
......@@ -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("收藏状态")
......
......@@ -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
......@@ -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;
}
}
......
package com.kwan.springbootkwan.dao;
package com.kwan.springbootkwan.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kwan.springbootkwan.entity.CsdnArticleInfo;
import org.apache.ibatis.annotations.Mapper;
/**
* csdn文章信息(CsdnArticleInfo)表数据库访问层
*
* @author makejava
* @since 2023-10-28 01:58:46
*/
public interface CsdnArticleInfoDao extends BaseMapper<CsdnArticleInfo> {
@Mapper
public interface CsdnArticleInfoMapper extends BaseMapper<CsdnArticleInfo> {
}
......@@ -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 ... ...");
}
......
......@@ -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();
}
}
}
......@@ -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<CsdnArticleInfo> {
/**
* 获取最新的10篇文章
*
* @param username
* @return
*/
List<BusinessInfoResponse.ArticleData.Article> getArticles(String username);
/**
* 获取最新的10篇博客(只能是blog类型)
*
* @param username
* @return
*/
List<BusinessInfoResponse.ArticleData.Article> getBlogs(String username);
}
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<BusinessInfoResponse.ArticleData.Article> getArticles(String username);
}
\ No newline at end of file
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
......@@ -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<CsdnUserInfo> {
*/
void resetCsdnUserInfo(CsdnUserInfo csdnUserInfo);
/**
* 新增用户
* @param addInfo
*/
void add(CsdnUserInfoQuery addInfo);
}
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<CsdnArticleInfoDao, CsdnArticleInfo> implements CsdnArticleInfoService {
public class CsdnArticleInfoServiceImpl extends ServiceImpl<CsdnArticleInfoMapper, CsdnArticleInfo> implements CsdnArticleInfoService {
@Value("${csdn.cookie}")
private String csdnCookie;
@Value("${csdn.url.user_article_url}")
private String url;
@Override
public List<BusinessInfoResponse.ArticleData.Article> 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<BusinessInfoResponse.ArticleData.Article> 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<BusinessInfoResponse.ArticleData.Article> 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<BusinessInfoResponse.ArticleData.Article> 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;
}
}
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<BusinessInfoResponse.ArticleData.Article> 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<BusinessInfoResponse.ArticleData.Article> 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;
}
}
......@@ -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<BusinessInfoResponse.ArticleData.Article> list = csdnArticleService.getArticles(selfUserName);
List<BusinessInfoResponse.ArticleData.Article> list = csdnArticleInfoService.getArticles(selfUserName);
if (CollectionUtil.isNotEmpty(list)) {
for (BusinessInfoResponse.ArticleData.Article article : list) {
final String type = article.getType();
......
......@@ -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<BusinessInfoResponse.ArticleData.Article> list = csdnArticleService.getArticles(username);
List<BusinessInfoResponse.ArticleData.Article> list = csdnArticleInfoService.getArticles(username);
if (CollectionUtil.isNotEmpty(list)) {
final int size = list.size();
numOfArticlesPerPerson = size < numOfArticlesPerPerson ? size : numOfArticlesPerPerson;
......@@ -58,6 +60,41 @@ public class CsdnServiceImpl implements CsdnService {
csdnUserInfoService.updateById(csdnUserInfo);
continue;
}
//先去查询文章,没有查到的话就插入文章
QueryWrapper<CsdnArticleInfo> 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 = 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);
}
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();
......@@ -82,14 +119,19 @@ public class CsdnServiceImpl implements CsdnService {
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() {
......
......@@ -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<CsdnUserInfoMapper, Csd
@Autowired
private CsdnCollectService csdnCollectService;
@Autowired
private CsdnArticleService csdnArticleService;
private CsdnArticleInfoService csdnArticleInfoService;
@Override
public void resetAllCurrentStatus() {
......@@ -50,7 +52,7 @@ public class CsdnUserInfoServiceImpl extends ServiceImpl<CsdnUserInfoMapper, Csd
final String userName = csdnUserInfo.getUserName();
final Integer commentStatus = csdnUserInfo.getCommentStatus();
final String articleType = csdnUserInfo.getArticleType();
final List<BusinessInfoResponse.ArticleData.Article> articles = csdnArticleService.getArticles(userName);
final List<BusinessInfoResponse.ArticleData.Article> 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<CsdnUserInfoMapper, Csd
}
}
@Override
public void add(CsdnUserInfoQuery addInfo) {
final String userName = addInfo.getUserName();
final Integer addType = addInfo.getAddType();
if (StringUtils.isNotEmpty(userName)) {
//批量添加
if (addType == 1) {
final String[] split = userName.split("\n");
for (String str : split) {
str = str.trim();
if (StringUtils.isNotEmpty(str)) {
QueryWrapper<CsdnUserInfo> 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<CsdnUserInfo> 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<CsdnUserInfo> wrapper = new QueryWrapper<>();
......@@ -83,7 +127,7 @@ public class CsdnUserInfoServiceImpl extends ServiceImpl<CsdnUserInfoMapper, Csd
if (CollectionUtil.isNotEmpty(list)) {
for (CsdnUserInfo csdnUserInfo : list) {
final String userName = csdnUserInfo.getUserName();
final List<BusinessInfoResponse.ArticleData.Article> articles = csdnArticleService.getArticles(userName);
final List<BusinessInfoResponse.ArticleData.Article> articles = csdnArticleInfoService.getArticles(userName);
if (CollectionUtil.isNotEmpty(articles)) {
final BusinessInfoResponse.ArticleData.Article article = articles.get(0);
final String type = article.getType();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册