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 {
...
@@ -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
(
"多人评论完成"
);
}
}
}
}
src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java
浏览文件 @
79a62152
...
@@ -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 ... ..."
);
}
}
}
src/main/java/com/kwan/springbootkwan/service/CsdnService.java
浏览文件 @
79a62152
...
@@ -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
src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
浏览文件 @
79a62152
...
@@ -42,6 +42,37 @@ public class CsdnServiceImpl implements CsdnService {
...
@@ -42,6 +42,37 @@ public class CsdnServiceImpl implements CsdnService {
@Override
@Override
public
void
singleArticle
(
String
username
)
{
public
void
singleArticle
(
String
username
)
{
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
);
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
isLike
=
csdnLikeService
.
isLike
(
articleId
,
username
);
if
(!
isLike
)
{
csdnLikeService
.
like
(
articleId
);
}
//评论
final
Boolean
comment
=
csdnCommentService
.
isComment
(
article
);
if
(!
comment
)
{
csdnCommentService
.
comment
(
articleId
);
}
//收藏
final
Boolean
collect
=
csdnCollectService
.
isCollect
(
articleId
);
if
(!
collect
)
{
csdnCollectService
.
collect
(
article
,
username
);
}
}
}
private
List
<
BusinessInfoResponse
.
ArticleData
.
Article
>
getArticles
(
String
username
)
{
HttpResponse
response
=
HttpUtil
.
createGet
(
url
)
HttpResponse
response
=
HttpUtil
.
createGet
(
url
)
.
header
(
"Cookie"
,
csdnCookie
)
.
header
(
"Cookie"
,
csdnCookie
)
.
form
(
"page"
,
1
)
.
form
(
"page"
,
1
)
...
@@ -53,14 +84,63 @@ public class CsdnServiceImpl implements CsdnService {
...
@@ -53,14 +84,63 @@ public class CsdnServiceImpl implements CsdnService {
final
String
body
=
response
.
body
();
final
String
body
=
response
.
body
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
BusinessInfoResponse
businessInfoResponse
;
BusinessInfoResponse
businessInfoResponse
;
List
<
BusinessInfoResponse
.
ArticleData
.
Article
>
list
=
null
;
try
{
try
{
businessInfoResponse
=
objectMapper
.
readValue
(
body
,
BusinessInfoResponse
.
class
);
businessInfoResponse
=
objectMapper
.
readValue
(
body
,
BusinessInfoResponse
.
class
);
final
BusinessInfoResponse
.
ArticleData
data
=
businessInfoResponse
.
getData
();
final
BusinessInfoResponse
.
ArticleData
data
=
businessInfoResponse
.
getData
();
final
List
<
BusinessInfoResponse
.
ArticleData
.
Article
>
list
=
data
.
getList
();
list
=
data
.
getList
();
if
(
CollectionUtil
.
isNotEmpty
(
list
))
{
}
catch
(
JsonProcessingException
e
)
{
final
int
size
=
list
.
size
();
e
.
printStackTrace
();
if
(
size
<
numOfArticlesPerPerson
)
{
}
numOfArticlesPerPerson
=
size
;
if
(
CollectionUtil
.
isEmpty
(
list
))
{
return
null
;
}
final
int
size
=
list
.
size
();
if
(
size
<
numOfArticlesPerPerson
)
{
numOfArticlesPerPerson
=
size
;
}
return
list
;
}
@Override
public
void
multiTriplet
()
{
final
List
<
CsdnUserInfo
>
list
=
csdnUserInfoService
.
list
();
if
(
CollectionUtil
.
isNotEmpty
(
list
))
{
for
(
CsdnUserInfo
csdnUserInfo
:
list
)
{
singleArticle
(
csdnUserInfo
.
getUserName
());
}
}
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
++)
{
for
(
int
i
=
0
;
i
<
numOfArticlesPerPerson
;
i
++)
{
final
BusinessInfoResponse
.
ArticleData
.
Article
article
=
list
.
get
(
i
);
final
BusinessInfoResponse
.
ArticleData
.
Article
article
=
list
.
get
(
i
);
...
@@ -70,37 +150,14 @@ public class CsdnServiceImpl implements CsdnService {
...
@@ -70,37 +150,14 @@ public class CsdnServiceImpl implements CsdnService {
}
}
final
String
urlInfo
=
article
.
getUrl
();
final
String
urlInfo
=
article
.
getUrl
();
String
articleId
=
urlInfo
.
substring
(
urlInfo
.
lastIndexOf
(
"/"
)
+
1
);
String
articleId
=
urlInfo
.
substring
(
urlInfo
.
lastIndexOf
(
"/"
)
+
1
);
//点赞
final
Boolean
isLike
=
csdnLikeService
.
isLike
(
articleId
,
username
);
if
(!
isLike
)
{
csdnLikeService
.
like
(
articleId
);
}
//评论
//评论
final
Boolean
comment
=
csdnCommentService
.
isComment
(
article
);
final
Boolean
comment
=
csdnCommentService
.
isComment
(
article
);
if
(!
comment
)
{
if
(!
comment
)
{
csdnCommentService
.
comment
(
articleId
);
csdnCommentService
.
comment
(
articleId
);
}
}
//收藏
final
Boolean
collect
=
csdnCollectService
.
isCollect
(
articleId
);
if
(!
collect
)
{
csdnCollectService
.
collect
(
article
,
username
);
}
}
}
}
}
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
}
}
}
log
.
info
(
"多人只评论完成"
);
@Override
public
void
multiTriplet
()
{
final
List
<
CsdnUserInfo
>
list
=
csdnUserInfoService
.
list
();
if
(
CollectionUtil
.
isNotEmpty
(
list
))
{
for
(
CsdnUserInfo
csdnUserInfo
:
list
)
{
singleArticle
(
csdnUserInfo
.
getUserName
());
}
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录