fix:优化升级

上级 a1750c29
package com.kwan.springbootkwan.controller; package com.kwan.springbootkwan.controller;
import com.kwan.springbootkwan.entity.Result; import com.kwan.springbootkwan.entity.Result;
import com.kwan.springbootkwan.entity.resp.BusinessInfo;
import com.kwan.springbootkwan.service.CsdnService; import com.kwan.springbootkwan.service.CsdnService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -17,27 +16,18 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -17,27 +16,18 @@ import org.springframework.web.bind.annotation.RestController;
public class CsdnController { public class CsdnController {
@Autowired @Autowired
private CsdnService service; private CsdnService csdnService;
@ApiOperation(value = "获取数据", notes = "获取数据") @ApiOperation(value = "单人三连", notes = "单人三连")
@GetMapping("/list") @GetMapping("/singleTriplet")
public Result get() { public Result singleTriplet(@Param("username") String username) {
final BusinessInfo.ArticleData.Article article = service.list(); return Result.ok(csdnService.singleArticle(username));
final String type = article.getType(); }
if (!StringUtils.equals("blog", type)) {
return Result.ok("非博客不能评论"); @ApiOperation(value = "多人三连", notes = "多人三连")
} @GetMapping("/multiTriplet")
final String urlInfo = article.getUrl(); public Result multiTriplet() {
String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1); csdnService.multiTriplet();
System.out.println(articleId); return Result.ok("三连完成");
final Boolean articleInfo = service.getArticleInfo(articleId);
if (!articleInfo) {
//进行点赞和评论
service.like(articleId);
service.comment(articleId);
return Result.ok("三连完成");
} else {
return Result.ok("文章已经评论过,不能再次评论");
}
} }
} }
package com.kwan.springbootkwan.entity;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.util.Date;
/**
* csdn用户信息(CsdnUserInfo)表实体类
*
* @author makejava
* @since 2023-10-23 16:03:14
*/
@SuppressWarnings("serial")
public class CsdnUserInfo extends Model<CsdnUserInfo> {
//主键id
private Integer id;
private String userName;
//创建时间
private Date createTime;
//逻辑删除,0未删除,1已删除
private Integer isDelete;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Integer getIsDelete() {
return isDelete;
}
public void setIsDelete(Integer isDelete) {
this.isDelete = isDelete;
}
}
package com.kwan.springbootkwan.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
/**
* csdn用户信息(CsdnUserInfo)表数据库访问层
*
* @author makejava
* @since 2023-10-23 16:03:13
*/
public interface CsdnUserInfoMapper extends BaseMapper<CsdnUserInfo> {
}
package com.kwan.springbootkwan.schedule;
import com.kwan.springbootkwan.service.CsdnService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class CsdnSchedule {
@Autowired
private CsdnService csdnService;
@Scheduled(cron = "0 0 10,15,21 * * ?")
public void execute() {
log.info("Scheduled task is running ... ...");
csdnService.multiTriplet();
log.info("Scheduled task is finish ... ...");
}
}
...@@ -12,6 +12,7 @@ import java.util.concurrent.locks.Lock; ...@@ -12,6 +12,7 @@ import java.util.concurrent.locks.Lock;
@Component @Component
public class RedisLockRenewal { public class RedisLockRenewal {
private final StringRedisTemplate redisTemplate; private final StringRedisTemplate redisTemplate;
/** /**
* 定时任务线程池 * 定时任务线程池
......
package com.kwan.springbootkwan.service; package com.kwan.springbootkwan.service;
import com.kwan.springbootkwan.entity.resp.BusinessInfo;
/** /**
* csdn博客自动化 * csdn博客自动化
* *
...@@ -11,11 +9,11 @@ import com.kwan.springbootkwan.entity.resp.BusinessInfo; ...@@ -11,11 +9,11 @@ import com.kwan.springbootkwan.entity.resp.BusinessInfo;
*/ */
public interface CsdnService { public interface CsdnService {
/** /**
* 获取文章信息 * 查询单篇文章信息
* *
* @return * @return
*/ */
BusinessInfo.ArticleData.Article list(); String singleArticle(String username);
/** /**
* 查询是否评论过 * 查询是否评论过
...@@ -25,7 +23,6 @@ public interface CsdnService { ...@@ -25,7 +23,6 @@ public interface CsdnService {
*/ */
Boolean getArticleInfo(String articleId); Boolean getArticleInfo(String articleId);
/** /**
* 点赞 * 点赞
* *
...@@ -39,4 +36,9 @@ public interface CsdnService { ...@@ -39,4 +36,9 @@ public interface CsdnService {
* @param articleId * @param articleId
*/ */
void comment(String articleId); void comment(String articleId);
/**
* 三连
*/
void multiTriplet();
} }
\ No newline at end of file
package com.kwan.springbootkwan.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
/**
* csdn用户信息(CsdnUserInfo)表服务接口
*
* @author makejava
* @since 2023-10-23 16:03:14
*/
public interface CsdnUserInfoService extends IService<CsdnUserInfo> {
}
...@@ -5,14 +5,20 @@ import cn.hutool.http.HttpResponse; ...@@ -5,14 +5,20 @@ import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
import com.kwan.springbootkwan.entity.resp.BusinessInfo; import com.kwan.springbootkwan.entity.resp.BusinessInfo;
import com.kwan.springbootkwan.entity.resp.CommentData; import com.kwan.springbootkwan.entity.resp.CommentData;
import com.kwan.springbootkwan.service.CsdnService; import com.kwan.springbootkwan.service.CsdnService;
import com.kwan.springbootkwan.service.CsdnUserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@Slf4j
@Service @Service
public class CsdnServiceImpl implements CsdnService { public class CsdnServiceImpl implements CsdnService {
/** /**
...@@ -24,16 +30,15 @@ public class CsdnServiceImpl implements CsdnService { ...@@ -24,16 +30,15 @@ public class CsdnServiceImpl implements CsdnService {
*/ */
private static final String CUSTOM_HEADER_VALUE = "uuid_tt_dd=10_20285116700-1697522872601-604163; c_adb=1; loginbox_strategy=%7B%22taskId%22%3A308%2C%22abCheckTime%22%3A1697522874474%2C%22version%22%3A%22control%22%7D; UserName=qyj19920704; UserInfo=a7d3b88c53a841ebb5792202cb43c84f; UserToken=a7d3b88c53a841ebb5792202cb43c84f; UserNick=%E6%AA%80%E8%B6%8A%E5%89%91%E6%8C%87%E5%A4%A7%E5%8E%82; AU=769; UN=qyj19920704; BT=1697522886100; p_uid=U010000; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22qyj19920704%22%2C%22scope%22%3A1%7D%7D; management_ques=1697592152734; blog_details_recommend_nps=1697616147423; c_segment=3; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1697522874,1697551027,1697636661,1697683407; csrfToken=jTRD3_1IBVA703lu2FkVkazx; dc_sid=9f7a02ed8375e91d86271ddaf1cf2ce4; c_first_ref=default; c_first_page=https%3A//liucy.blog.csdn.net/article/details/133852303%3Fspm%3D1001.2014.3001.5502; c_segment=3; Hm_lvt_e5ef47b9f471504959267fd614d579cd=1697764951; Hm_lpvt_e5ef47b9f471504959267fd614d579cd=1697764951; 404_page_nps=1697764955523; ssxmod_itna=YqUxBD97kOGHD8D2BmYite44zxcYo1=WOiox0vmvqGzDAxn40iDtgeqODDwu0/DNMQiDpiDuWOntaV73S5fd3iPeaN3D84i7DKqibDCqD1D3qDktzDYA8Dt4DTD34DYDiO=DBRsUQDFATN/3wUjmGtDG4DgDB=DxBEl3djBAq4DCr4DbxPy7mrDtLNSeLLdXT0/nn5Yf445SOG5lipwm0GdG7vwBA4PlDxNt8v1wADoGGGQYf+IE75ep753zpDxD; ssxmod_itna2=YqUxBD97kOGHD8D2BmYite44zxcYo1=WOYxn9EenDDsYebDLGQCoqQuGvHdDQRKYubdD6QqomsRD3xyRI/W9Q5nhe8oeYUvimaWYrNsqwcDgL6mDjYUhZK09LYcY/t5hSuP2va/kclf6hRkNh+LPyDwic73=9i4d94Lvw/R=oQ7E+jT4jjjA2Y+=QplLm8nbePRb+7=Re1CpjmZ4wIrnNPSKofWnIj=WOtkFtphylt+GhUxr0KkGtTzDXKDEEkbn3qhIn3Sj/ezt1u2MO3M9h7zEL6RunrXaKE+YdkRnIKiTG93cqpGFq8Fwr7ehksk1ZSWhoN2hQydddqQ1bTOSW8ddX+7g24v4TZ0+52=Y8PsOwfhavW4ECY8+GZOK=ro97bK0=Yi3YD5ZGsq25FhPodIRGCD2O8xidfo8+NR88v+rq4+b=fUOEK2frPEPdLFuYkao9uCfM1+cFZQ7q6HEMfRLjf6bhof0=1YhEYO1U=NZCPvDDw2Psluciq4De13mDNBODwqLwwg44qwOiDf=j1fKK5q+8gd7DDjKDeMv/04YDmLGvrwqOz4cov79500D4D==; c_first_ref=default; c_first_page=https%3A//mp.csdn.net/; creative_btn_mp=3; c_hasSub=true; write_guide_show=3; log_Id_click=177; dc_session_id=11_1698022100317.787671; c_dsid=11_1698022100317.794351; log_Id_pv=149; log_Id_view=1105; c_pref=https%3A//i.csdn.net/; c_ref=https%3A//blog.csdn.net/imwucx; c_page_id=default; dc_session_id=11_1698022100317.787671; c_dsid=11_1698022100317.794351; log_Id_view=1106; dc_tos=s2yi9b; log_Id_click=178; c_pref=https%3A//blog.csdn.net/imwucx; log_Id_pv=150; creativeSetApiNew=%7B%22toolbarImg%22%3Anull%2C%22publishSuccessImg%22%3Anull%2C%22articleNum%22%3A895%2C%22type%22%3A0%2C%22oldUser%22%3Afalse%2C%22useSeven%22%3Afalse%2C%22userName%22%3A%22qyj19920704%22%7D; c_ref=https%3A//cxian.blog.csdn.net/article/details/131299195; c_page_id=default; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1698022433; dc_tos=s2yinc"; private static final String CUSTOM_HEADER_VALUE = "uuid_tt_dd=10_20285116700-1697522872601-604163; c_adb=1; loginbox_strategy=%7B%22taskId%22%3A308%2C%22abCheckTime%22%3A1697522874474%2C%22version%22%3A%22control%22%7D; UserName=qyj19920704; UserInfo=a7d3b88c53a841ebb5792202cb43c84f; UserToken=a7d3b88c53a841ebb5792202cb43c84f; UserNick=%E6%AA%80%E8%B6%8A%E5%89%91%E6%8C%87%E5%A4%A7%E5%8E%82; AU=769; UN=qyj19920704; BT=1697522886100; p_uid=U010000; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22qyj19920704%22%2C%22scope%22%3A1%7D%7D; management_ques=1697592152734; blog_details_recommend_nps=1697616147423; c_segment=3; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1697522874,1697551027,1697636661,1697683407; csrfToken=jTRD3_1IBVA703lu2FkVkazx; dc_sid=9f7a02ed8375e91d86271ddaf1cf2ce4; c_first_ref=default; c_first_page=https%3A//liucy.blog.csdn.net/article/details/133852303%3Fspm%3D1001.2014.3001.5502; c_segment=3; Hm_lvt_e5ef47b9f471504959267fd614d579cd=1697764951; Hm_lpvt_e5ef47b9f471504959267fd614d579cd=1697764951; 404_page_nps=1697764955523; ssxmod_itna=YqUxBD97kOGHD8D2BmYite44zxcYo1=WOiox0vmvqGzDAxn40iDtgeqODDwu0/DNMQiDpiDuWOntaV73S5fd3iPeaN3D84i7DKqibDCqD1D3qDktzDYA8Dt4DTD34DYDiO=DBRsUQDFATN/3wUjmGtDG4DgDB=DxBEl3djBAq4DCr4DbxPy7mrDtLNSeLLdXT0/nn5Yf445SOG5lipwm0GdG7vwBA4PlDxNt8v1wADoGGGQYf+IE75ep753zpDxD; ssxmod_itna2=YqUxBD97kOGHD8D2BmYite44zxcYo1=WOYxn9EenDDsYebDLGQCoqQuGvHdDQRKYubdD6QqomsRD3xyRI/W9Q5nhe8oeYUvimaWYrNsqwcDgL6mDjYUhZK09LYcY/t5hSuP2va/kclf6hRkNh+LPyDwic73=9i4d94Lvw/R=oQ7E+jT4jjjA2Y+=QplLm8nbePRb+7=Re1CpjmZ4wIrnNPSKofWnIj=WOtkFtphylt+GhUxr0KkGtTzDXKDEEkbn3qhIn3Sj/ezt1u2MO3M9h7zEL6RunrXaKE+YdkRnIKiTG93cqpGFq8Fwr7ehksk1ZSWhoN2hQydddqQ1bTOSW8ddX+7g24v4TZ0+52=Y8PsOwfhavW4ECY8+GZOK=ro97bK0=Yi3YD5ZGsq25FhPodIRGCD2O8xidfo8+NR88v+rq4+b=fUOEK2frPEPdLFuYkao9uCfM1+cFZQ7q6HEMfRLjf6bhof0=1YhEYO1U=NZCPvDDw2Psluciq4De13mDNBODwqLwwg44qwOiDf=j1fKK5q+8gd7DDjKDeMv/04YDmLGvrwqOz4cov79500D4D==; c_first_ref=default; c_first_page=https%3A//mp.csdn.net/; creative_btn_mp=3; c_hasSub=true; write_guide_show=3; log_Id_click=177; dc_session_id=11_1698022100317.787671; c_dsid=11_1698022100317.794351; log_Id_pv=149; log_Id_view=1105; c_pref=https%3A//i.csdn.net/; c_ref=https%3A//blog.csdn.net/imwucx; c_page_id=default; dc_session_id=11_1698022100317.787671; c_dsid=11_1698022100317.794351; log_Id_view=1106; dc_tos=s2yi9b; log_Id_click=178; c_pref=https%3A//blog.csdn.net/imwucx; log_Id_pv=150; creativeSetApiNew=%7B%22toolbarImg%22%3Anull%2C%22publishSuccessImg%22%3Anull%2C%22articleNum%22%3A895%2C%22type%22%3A0%2C%22oldUser%22%3Afalse%2C%22useSeven%22%3Afalse%2C%22userName%22%3A%22qyj19920704%22%7D; c_ref=https%3A//cxian.blog.csdn.net/article/details/131299195; c_page_id=default; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1698022433; dc_tos=s2yinc";
@Autowired
private CsdnUserInfoService csdnUserInfoService;
@Override @Override
public BusinessInfo.ArticleData.Article list() { public String singleArticle(String username) {
String url = "https://blog.csdn.net/community/home-api/v1/get-business-list"; String url = "https://blog.csdn.net/community/home-api/v1/get-business-list";
// 构建参数
// String username = "imwucx";
// String username = "qq_40332045";
String username = "m0_69323023";
// 使用Hutool发送GET请求 // 使用Hutool发送GET请求
HttpResponse response = HttpUtil.createGet(url) HttpResponse response = HttpUtil.createGet(url)
.header(CUSTOM_HEADER_NAME, CUSTOM_HEADER_VALUE) // 添加自定义header参数 .header(CUSTOM_HEADER_NAME, CUSTOM_HEADER_VALUE)
.form("page", 1) .form("page", 1)
.form("size", 2) .form("size", 2)
.form("businessType", "lately") .form("businessType", "lately")
...@@ -41,21 +46,33 @@ public class CsdnServiceImpl implements CsdnService { ...@@ -41,21 +46,33 @@ public class CsdnServiceImpl implements CsdnService {
.form("username", username) .form("username", username)
.execute(); .execute();
// 打印响应结果 // 打印响应结果
System.out.println("Response Status Code: " + response.getStatus());
final String body = response.body(); final String body = response.body();
System.out.println("Response Body: " + body);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
BusinessInfo businessInfo = null; BusinessInfo businessInfo = null;
try { try {
businessInfo = objectMapper.readValue(body, BusinessInfo.class); businessInfo = objectMapper.readValue(body, BusinessInfo.class);
System.out.println();
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); e.printStackTrace();
} }
final BusinessInfo.ArticleData data = businessInfo.getData(); final BusinessInfo.ArticleData data = businessInfo.getData();
final List<BusinessInfo.ArticleData.Article> list = data.getList(); final List<BusinessInfo.ArticleData.Article> list = data.getList();
final BusinessInfo.ArticleData.Article article = list.get(0); final BusinessInfo.ArticleData.Article article = list.get(0);
return article;
final String type = article.getType();
if (!StringUtils.equals("blog", type)) {
return "非博客不能评论";
}
final String urlInfo = article.getUrl();
String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1);
final Boolean articleInfo = this.getArticleInfo(articleId);
if (!articleInfo) {
//进行点赞和评论
this.like(articleId);
this.comment(articleId);
return "三连完成";
} else {
return "文章已经评论过,不能再次评论";
}
} }
@Override @Override
...@@ -69,14 +86,11 @@ public class CsdnServiceImpl implements CsdnService { ...@@ -69,14 +86,11 @@ public class CsdnServiceImpl implements CsdnService {
.form("fold", "unfold") .form("fold", "unfold")
.execute(); .execute();
// 打印响应结果 // 打印响应结果
System.out.println("Response Status Code: " + response.getStatus());
final String body = response.body(); final String body = response.body();
System.out.println("Response Body: " + body);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
CommentData articleInfo = null; CommentData articleInfo = null;
try { try {
articleInfo = objectMapper.readValue(body, CommentData.class); articleInfo = objectMapper.readValue(body, CommentData.class);
System.out.println();
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -105,7 +119,7 @@ public class CsdnServiceImpl implements CsdnService { ...@@ -105,7 +119,7 @@ public class CsdnServiceImpl implements CsdnService {
.execute(); .execute();
// 打印响应结果 // 打印响应结果
if (response.getStatus() == 200) { if (response.getStatus() == 200) {
System.out.println("点赞成功"); log.info("点赞成功");
} }
} }
...@@ -120,7 +134,20 @@ public class CsdnServiceImpl implements CsdnService { ...@@ -120,7 +134,20 @@ public class CsdnServiceImpl implements CsdnService {
.execute(); .execute();
// 打印响应结果 // 打印响应结果
if (response.getStatus() == 200) { if (response.getStatus() == 200) {
System.out.println("评论成功"); log.info("评论成功");
}
}
@Override
public void multiTriplet() {
final List<CsdnUserInfo> list = csdnUserInfoService.list();
if (CollectionUtil.isNotEmpty(list)) {
list.forEach(csdnUserInfo -> {
// 构建参数
String username = csdnUserInfo.getUserName();
final String res = singleArticle(username);
log.info("用户username:{}", res);
});
} }
} }
} }
\ No newline at end of file
package com.kwan.springbootkwan.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kwan.springbootkwan.mapper.CsdnUserInfoMapper;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
import com.kwan.springbootkwan.service.CsdnUserInfoService;
import org.springframework.stereotype.Service;
/**
* csdn用户信息(CsdnUserInfo)表服务实现类
*
* @author makejava
* @since 2023-10-23 16:03:14
*/
@Service("csdnUserInfoService")
public class CsdnUserInfoServiceImpl extends ServiceImpl<CsdnUserInfoMapper, CsdnUserInfo> implements CsdnUserInfoService {
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册