{query}

上级 fcafd617
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<CsdnArticleInfo> 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<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();
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<String> articleIds) {
if (CollectionUtil.isNotEmpty(articleIds)) {
for (String articleId : articleIds) {
triplet(Integer.valueOf(articleId));
}
}
return Result.ok("重置多个人员新博客状态完成");
}
}
\ No newline at end of file
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<String> 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<String> 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篇博客完成");
}
}
......@@ -26,6 +26,7 @@ import java.util.Objects;
@RestController
@RequestMapping("/dayInfo")
public class CsdnTripletDayInfoController {
@Autowired
private CsdnTripletDayInfoService csdnTripletDayInfoService;
......
......@@ -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 ... ...");
}
......
......@@ -13,6 +13,20 @@ import java.util.List;
* @since 2023-10-28 01:58:46
*/
public interface CsdnArticleInfoService extends IService<CsdnArticleInfo> {
/**
* 通过文章id获取文章信息
*
* @return
*/
CsdnArticleInfo getArticleByArticleId(String articleId);
/**
* 保存文章Blog
*
* @return
*/
void saveArticle(CsdnArticleInfo csdnArticleInfo);
/**
* 获取最新的10篇文章
......
......@@ -23,7 +23,7 @@ public interface CsdnService {
/**
* 多人三连
*/
void multiTriplet();
void allTriplet();
/**
* 根据文章三连
......
......@@ -54,5 +54,12 @@ public interface CsdnUserInfoService extends IService<CsdnUserInfo> {
*/
void add(CsdnUserInfoQuery addInfo);
/**
* 给指定人员添加10篇博客
*
* @param username
*/
void add10Blog(String username);
}
......@@ -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<CsdnArticleInfoMappe
@Value("${csdn.url.user_article_url}")
private String url;
@Override
public CsdnArticleInfo getArticleByArticleId(String articleId) {
QueryWrapper<CsdnArticleInfo> 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<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)
......@@ -65,7 +90,6 @@ public class CsdnArticleInfoServiceImpl extends ServiceImpl<CsdnArticleInfoMappe
.form("page", 1)
.form("size", 10)
.form("businessType", "blog")
// .form("blogType", "ViewCount")
.form("noMore", false)
.form("username", username)
.execute();
......
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;
......@@ -61,17 +60,14 @@ public class CsdnServiceImpl implements CsdnService {
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 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<CsdnUserInfo> allUser = csdnUserInfoService.getAllUser();
if (CollectionUtil.isNotEmpty(allUser)) {
for (CsdnUserInfo csdnUserInfo : allUser) {
......
......@@ -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<CsdnUserInfoMapper, CsdnUserInfo> implements CsdnUserInfoService {
@Autowired
private CsdnCollectService csdnCollectService;
@Autowired
......@@ -71,7 +68,8 @@ public class CsdnUserInfoServiceImpl extends ServiceImpl<CsdnUserInfoMapper, Csd
final BusinessInfoResponse.ArticleData.Article article = articles.get(0);
final String type = article.getType();
if (StringUtils.equals(type, CsdnConstant.ARTICLE_TYPE)) {
final String articleId = article.getArticleId().toString();
final String articleUrl = article.getUrl();
String articleId = articleUrl.substring(articleUrl.lastIndexOf("/") + 1);
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());
......@@ -125,6 +123,25 @@ public class CsdnUserInfoServiceImpl extends ServiceImpl<CsdnUserInfoMapper, Csd
}
}
@Override
public void add10Blog(String username) {
final CsdnUserInfo csdnUserInfo = this.getUserByUserName(username);
final List<BusinessInfoResponse.ArticleData.Article> 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<CsdnUserInfo> allUser = this.getAllUser();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册