Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
79a62152
S
SpringBoot-kwan
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringBoot-kwan
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBoot-kwan
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
79a62152
编写于
10月 24, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:多人评论
上级
c0611570
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
106 addition
and
31 deletion
+106
-31
src/main/java/com/kwan/springbootkwan/controller/CsdnController.java
...va/com/kwan/springbootkwan/controller/CsdnController.java
+8
-2
src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java
...n/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java
+7
-0
src/main/java/com/kwan/springbootkwan/service/CsdnService.java
...ain/java/com/kwan/springbootkwan/service/CsdnService.java
+5
-0
src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
...com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
+86
-29
未找到文件。
src/main/java/com/kwan/springbootkwan/controller/CsdnController.java
浏览文件 @
79a62152
...
...
@@ -33,12 +33,18 @@ public class CsdnController {
@GetMapping
(
"/singleTriplet"
)
public
Result
singleTriplet
(
@Param
(
"username"
)
String
username
)
{
csdnService
.
singleArticle
(
username
);
return
Result
.
ok
(
"三连完成"
);
return
Result
.
ok
(
"
单人
三连完成"
);
}
@GetMapping
(
"/multiTriplet"
)
public
Result
multiTriplet
()
{
csdnService
.
multiTriplet
();
return
Result
.
ok
(
"三连完成"
);
return
Result
.
ok
(
"多人三连完成"
);
}
@GetMapping
(
"/multiComment"
)
public
Result
multiComment
()
{
csdnService
.
multiComment
();
return
Result
.
ok
(
"多人评论完成"
);
}
}
src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java
浏览文件 @
79a62152
...
...
@@ -21,5 +21,12 @@ public class CsdnSchedule {
csdnService
.
multiTriplet
();
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 ... ..."
);
}
}
src/main/java/com/kwan/springbootkwan/service/CsdnService.java
浏览文件 @
79a62152
...
...
@@ -20,4 +20,9 @@ public interface CsdnService {
* 多人三连
*/
void
multiTriplet
();
/**
* 多人只评论
*/
void
multiComment
();
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
浏览文件 @
79a62152
...
...
@@ -42,25 +42,9 @@ public class CsdnServiceImpl implements CsdnService {
@Override
public
void
singleArticle
(
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
;
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
;
List
<
BusinessInfoResponse
.
ArticleData
.
Article
>
list
=
this
.
getArticles
(
username
);
if
(
list
==
null
)
{
return
;
}
for
(
int
i
=
0
;
i
<
numOfArticlesPerPerson
;
i
++)
{
final
BusinessInfoResponse
.
ArticleData
.
Article
article
=
list
.
get
(
i
);
...
...
@@ -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
)
{
e
.
printStackTrace
();
}
if
(
CollectionUtil
.
isEmpty
(
list
))
{
return
null
;
}
final
int
size
=
list
.
size
();
if
(
size
<
numOfArticlesPerPerson
)
{
numOfArticlesPerPerson
=
size
;
}
return
list
;
}
@Override
...
...
@@ -103,4 +112,52 @@ public class CsdnServiceImpl implements CsdnService {
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录