fix:多人评论

上级 c0611570
...@@ -33,12 +33,18 @@ public class CsdnController { ...@@ -33,12 +33,18 @@ public class CsdnController {
@GetMapping("/singleTriplet") @GetMapping("/singleTriplet")
public Result singleTriplet(@Param("username") String username) { public Result singleTriplet(@Param("username") String username) {
csdnService.singleArticle(username); csdnService.singleArticle(username);
return Result.ok("三连完成"); return Result.ok("单人三连完成");
} }
@GetMapping("/multiTriplet") @GetMapping("/multiTriplet")
public Result multiTriplet() { public Result multiTriplet() {
csdnService.multiTriplet(); csdnService.multiTriplet();
return Result.ok("三连完成"); return Result.ok("多人三连完成");
}
@GetMapping("/multiComment")
public Result multiComment() {
csdnService.multiComment();
return Result.ok("多人评论完成");
} }
} }
...@@ -21,5 +21,12 @@ public class CsdnSchedule { ...@@ -21,5 +21,12 @@ public class CsdnSchedule {
csdnService.multiTriplet(); csdnService.multiTriplet();
log.info("Scheduled task is finish ... ..."); log.info("Scheduled task is finish ... ...");
} }
@Scheduled(cron = "0 0/30 * * * ?")
public void executeMultiComment() {
log.info("Scheduled task is running ... ...");
csdnService.multiComment();
log.info("Scheduled task is finish ... ...");
}
} }
...@@ -20,4 +20,9 @@ public interface CsdnService { ...@@ -20,4 +20,9 @@ public interface CsdnService {
* 多人三连 * 多人三连
*/ */
void multiTriplet(); void multiTriplet();
/**
* 多人只评论
*/
void multiComment();
} }
\ No newline at end of file
...@@ -42,25 +42,9 @@ public class CsdnServiceImpl implements CsdnService { ...@@ -42,25 +42,9 @@ public class CsdnServiceImpl implements CsdnService {
@Override @Override
public void singleArticle(String username) { public void singleArticle(String username) {
HttpResponse response = HttpUtil.createGet(url) List<BusinessInfoResponse.ArticleData.Article> list = this.getArticles(username);
.header("Cookie", csdnCookie) if (list == null) {
.form("page", 1) return;
.form("size", 5)
.form("businessType", "lately")
.form("noMore", false)
.form("username", username)
.execute();
final String body = response.body();
ObjectMapper objectMapper = new ObjectMapper();
BusinessInfoResponse businessInfoResponse;
try {
businessInfoResponse = objectMapper.readValue(body, BusinessInfoResponse.class);
final BusinessInfoResponse.ArticleData data = businessInfoResponse.getData();
final List<BusinessInfoResponse.ArticleData.Article> list = data.getList();
if (CollectionUtil.isNotEmpty(list)) {
final int size = list.size();
if (size < numOfArticlesPerPerson) {
numOfArticlesPerPerson = size;
} }
for (int i = 0; i < numOfArticlesPerPerson; i++) { for (int i = 0; i < numOfArticlesPerPerson; i++) {
final BusinessInfoResponse.ArticleData.Article article = list.get(i); final BusinessInfoResponse.ArticleData.Article article = list.get(i);
...@@ -88,9 +72,34 @@ public class CsdnServiceImpl implements CsdnService { ...@@ -88,9 +72,34 @@ public class CsdnServiceImpl implements CsdnService {
} }
} }
private List<BusinessInfoResponse.ArticleData.Article> getArticles(String username) {
HttpResponse response = HttpUtil.createGet(url)
.header("Cookie", csdnCookie)
.form("page", 1)
.form("size", 5)
.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) { } catch (JsonProcessingException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (CollectionUtil.isEmpty(list)) {
return null;
}
final int size = list.size();
if (size < numOfArticlesPerPerson) {
numOfArticlesPerPerson = size;
}
return list;
} }
@Override @Override
...@@ -103,4 +112,52 @@ public class CsdnServiceImpl implements CsdnService { ...@@ -103,4 +112,52 @@ public class CsdnServiceImpl implements CsdnService {
} }
log.info("全部三连完成"); log.info("全部三连完成");
} }
// /**
// * 多人三连非数据库
// */
// @Override
// public void multiTriplet() {
// String[] userNames = new String[]{"user1", "user2", "user3", "xxxx"};
// for (String name : userNames) {
// singleArticle(name);
// }
// log.info("全部三连完成");
// }
@Override
public void multiComment() {
final List<CsdnUserInfo> userNames = csdnUserInfoService.list();
if (CollectionUtil.isNotEmpty(userNames)) {
for (CsdnUserInfo csdnUserInfo : userNames) {
final String userName = csdnUserInfo.getUserName();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
List<BusinessInfoResponse.ArticleData.Article> list = this.getArticles(userName);
if (list == null) {
continue;
}
for (int i = 0; i < numOfArticlesPerPerson; i++) {
final BusinessInfoResponse.ArticleData.Article article = list.get(i);
final String type = article.getType();
if (!StringUtils.equals("blog", type)) {
continue;
}
final String urlInfo = article.getUrl();
String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1);
//评论
final Boolean comment = csdnCommentService.isComment(article);
if (!comment) {
csdnCommentService.comment(articleId);
}
}
}
}
log.info("多人只评论完成");
}
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册