Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
0b6afd55
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看板
提交
0b6afd55
编写于
10月 25, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:添加状态
上级
60b4ecf5
变更
14
显示空白变更内容
内联
并排
Showing
14 changed file
with
276 addition
and
121 deletion
+276
-121
src/main/java/com/kwan/springbootkwan/controller/CsdnController.java
...va/com/kwan/springbootkwan/controller/CsdnController.java
+15
-13
src/main/java/com/kwan/springbootkwan/entity/CsdnUserInfo.java
...ain/java/com/kwan/springbootkwan/entity/CsdnUserInfo.java
+41
-47
src/main/java/com/kwan/springbootkwan/enums/CollectStatus.java
...ain/java/com/kwan/springbootkwan/enums/CollectStatus.java
+37
-0
src/main/java/com/kwan/springbootkwan/enums/CommentStatus.java
...ain/java/com/kwan/springbootkwan/enums/CommentStatus.java
+41
-0
src/main/java/com/kwan/springbootkwan/enums/LikeStatus.java
src/main/java/com/kwan/springbootkwan/enums/LikeStatus.java
+37
-0
src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java
...n/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java
+30
-2
src/main/java/com/kwan/springbootkwan/service/CsdnCollectService.java
...a/com/kwan/springbootkwan/service/CsdnCollectService.java
+3
-2
src/main/java/com/kwan/springbootkwan/service/CsdnCommentService.java
...a/com/kwan/springbootkwan/service/CsdnCommentService.java
+3
-2
src/main/java/com/kwan/springbootkwan/service/CsdnLikeService.java
...java/com/kwan/springbootkwan/service/CsdnLikeService.java
+4
-2
src/main/java/com/kwan/springbootkwan/service/CsdnService.java
...ain/java/com/kwan/springbootkwan/service/CsdnService.java
+3
-1
src/main/java/com/kwan/springbootkwan/service/impl/CsdnCollectServiceImpl.java
...n/springbootkwan/service/impl/CsdnCollectServiceImpl.java
+17
-13
src/main/java/com/kwan/springbootkwan/service/impl/CsdnCommentServiceImpl.java
...n/springbootkwan/service/impl/CsdnCommentServiceImpl.java
+20
-8
src/main/java/com/kwan/springbootkwan/service/impl/CsdnLikeServiceImpl.java
...kwan/springbootkwan/service/impl/CsdnLikeServiceImpl.java
+14
-9
src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
...com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
+11
-22
未找到文件。
src/main/java/com/kwan/springbootkwan/controller/CsdnController.java
浏览文件 @
0b6afd55
package
com.kwan.springbootkwan.controller
;
package
com.kwan.springbootkwan.controller
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.kwan.springbootkwan.entity.CsdnUserInfo
;
import
com.kwan.springbootkwan.entity.Result
;
import
com.kwan.springbootkwan.entity.Result
;
import
com.kwan.springbootkwan.service.CsdnLikeService
;
import
com.kwan.springbootkwan.service.CsdnService
;
import
com.kwan.springbootkwan.service.CsdnService
;
import
com.kwan.springbootkwan.service.CsdnUserInfoService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -10,6 +13,8 @@ import org.springframework.web.bind.annotation.GetMapping;
...
@@ -10,6 +13,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@Slf4j
@Slf4j
@RestController
@RestController
@RequestMapping
(
"/csdn"
)
@RequestMapping
(
"/csdn"
)
...
@@ -18,21 +23,18 @@ public class CsdnController {
...
@@ -18,21 +23,18 @@ public class CsdnController {
@Autowired
@Autowired
private
CsdnService
csdnService
;
private
CsdnService
csdnService
;
@Autowired
@Autowired
private
CsdnLikeService
csdnLikeService
;
private
CsdnUserInfoService
csdnUserInfoService
;
@GetMapping
(
"/isLike"
)
public
Result
isLike
(
@Param
(
"articleId"
)
String
articleId
,
@Param
(
"userName"
)
String
userName
)
{
return
Result
.
ok
(
csdnLikeService
.
isLike
(
articleId
,
userName
));
}
@GetMapping
(
"/singleLike"
)
public
Result
singleLike
(
@Param
(
"articleId"
)
String
articleId
)
{
return
Result
.
ok
(
csdnLikeService
.
like
(
articleId
));
}
@GetMapping
(
"/singleTriplet"
)
@GetMapping
(
"/singleTriplet"
)
public
Result
singleTriplet
(
@Param
(
"username"
)
String
username
)
{
public
Result
singleTriplet
(
@Param
(
"username"
)
String
username
)
{
csdnService
.
singleArticle
(
username
);
QueryWrapper
<
CsdnUserInfo
>
wrapper
=
new
QueryWrapper
<>();
wrapper
.
eq
(
"is_delete"
,
0
);
wrapper
.
eq
(
"user_name"
,
username
);
final
List
<
CsdnUserInfo
>
list
=
csdnUserInfoService
.
list
(
wrapper
);
if
(
CollectionUtil
.
isNotEmpty
(
list
))
{
final
CsdnUserInfo
csdnUserInfo
=
list
.
get
(
0
);
csdnService
.
singleArticle
(
csdnUserInfo
);
}
return
Result
.
ok
(
"单人三连完成"
);
return
Result
.
ok
(
"单人三连完成"
);
}
}
...
...
src/main/java/com/kwan/springbootkwan/entity/CsdnUserInfo.java
浏览文件 @
0b6afd55
package
com.kwan.springbootkwan.entity
;
package
com.kwan.springbootkwan.entity
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.baomidou.mybatisplus.extension.activerecord.Model
;
import
com.baomidou.mybatisplus.extension.activerecord.Model
;
import
lombok.Data
;
import
java.util.Date
;
import
java.util.Date
;
/**
@Data
* csdn用户信息(CsdnUserInfo)表实体类
@TableName
(
"csdn_user_info"
)
*
* @author makejava
* @since 2023-10-23 16:03:14
*/
@SuppressWarnings
(
"serial"
)
public
class
CsdnUserInfo
extends
Model
<
CsdnUserInfo
>
{
public
class
CsdnUserInfo
extends
Model
<
CsdnUserInfo
>
{
//主键id
/**
* 主键id
*/
private
Integer
id
;
private
Integer
id
;
/**
* 用户code
*/
private
String
userName
;
private
String
userName
;
//创建时间
/**
* CSDN用户名称
*/
private
String
nickName
;
/**
* 点赞状态
*/
private
Integer
likeStatus
;
/**
* 收藏状态
*/
private
Integer
collectStatus
;
/**
* 评论状态
*/
private
Integer
commentStatus
;
/**
* 用户权重
*/
private
Integer
userWeight
;
/**
* 文章类型
*/
private
String
articleType
;
/**
* 创建时间
*/
private
Date
createTime
;
private
Date
createTime
;
//逻辑删除,0未删除,1已删除
/**
* 逻辑删除,0未删除,1已删除
*/
private
Integer
isDelete
;
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
;
}
}
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/enums/CollectStatus.java
0 → 100644
浏览文件 @
0b6afd55
package
com.kwan.springbootkwan.enums
;
import
lombok.Getter
;
import
lombok.ToString
;
@Getter
@ToString
public
enum
CollectStatus
{
/**
* 未处理
*/
UN_PROCESSED
(
0
,
"未处理"
),
/**
* 已经收藏过
*/
HAVE_ALREADY_COLLECT
(
1
,
"已经收藏过"
),
/**
* 收藏已满
*/
COLLECT_IS_FULL
(
2
,
"收藏已满"
),
/**
* 参数缺失
*/
MISSING_PARAMETER
(
3
,
"参数缺失"
),
/**
* 收藏成功
*/
COLLECT_SUCCESSFUL
(
9
,
"收藏成功"
);
private
Integer
code
;
private
String
name
;
CollectStatus
(
Integer
code
,
String
name
)
{
this
.
code
=
code
;
this
.
name
=
name
;
}
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/enums/CommentStatus.java
0 → 100644
浏览文件 @
0b6afd55
package
com.kwan.springbootkwan.enums
;
import
lombok.Getter
;
import
lombok.ToString
;
@Getter
@ToString
public
enum
CommentStatus
{
/**
* 未处理
*/
UN_PROCESSED
(
0
,
"未处理"
),
/**
* 已经评论过
*/
HAVE_ALREADY_COMMENT
(
1
,
"已经评论过"
),
/**
* 评论已满
*/
COMMENT_IS_FULL
(
2
,
"评论已满"
),
/**
* 禁言
*/
RESTRICTED_COMMENTS
(
3
,
"禁言"
),
/**
* 评论太快
*/
COMMENT_TOO_FAST
(
4
,
"评论太快"
),
/**
* 评论成功
*/
COMMENT_SUCCESSFUL
(
9
,
"评论成功"
);
private
Integer
code
;
private
String
name
;
CommentStatus
(
Integer
code
,
String
name
)
{
this
.
code
=
code
;
this
.
name
=
name
;
}
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/enums/LikeStatus.java
0 → 100644
浏览文件 @
0b6afd55
package
com.kwan.springbootkwan.enums
;
import
lombok.Getter
;
import
lombok.ToString
;
@Getter
@ToString
public
enum
LikeStatus
{
/**
* 未处理
*/
UN_PROCESSED
(
0
,
"未处理"
),
/**
* 已经点过赞
*/
HAVE_ALREADY_LIKED
(
1
,
"已经点过赞"
),
/**
* 点赞已满
*/
LIKE_IS_FULL
(
2
,
"点赞已满"
),
/**
* 取消点赞
*/
CANCEL_LIKES
(
3
,
"取消点赞"
),
/**
* 点赞成功
*/
LIKE_SUCCESSFUL
(
9
,
"点赞成功"
);
private
Integer
code
;
private
String
name
;
LikeStatus
(
Integer
code
,
String
name
)
{
this
.
code
=
code
;
this
.
name
=
name
;
}
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/schedule/CsdnSchedule.java
浏览文件 @
0b6afd55
package
com.kwan.springbootkwan.schedule
;
package
com.kwan.springbootkwan.schedule
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.kwan.springbootkwan.entity.CsdnUserInfo
;
import
com.kwan.springbootkwan.enums.CollectStatus
;
import
com.kwan.springbootkwan.enums.LikeStatus
;
import
com.kwan.springbootkwan.service.CsdnService
;
import
com.kwan.springbootkwan.service.CsdnService
;
import
com.kwan.springbootkwan.service.CsdnUserInfoService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
@Slf4j
@Slf4j
@Component
@Component
...
@@ -14,12 +22,32 @@ public class CsdnSchedule {
...
@@ -14,12 +22,32 @@ public class CsdnSchedule {
@Autowired
@Autowired
private
CsdnService
csdnService
;
private
CsdnService
csdnService
;
@Autowired
private
CsdnUserInfoService
csdnUserInfoService
;
@Scheduled
(
cron
=
"0 0 8,10,12,14,16,18,20 * * ?"
)
@Scheduled
(
cron
=
"0 0 8,10,12,14,16,18,20 * * ?"
)
public
void
execute
()
{
public
void
execute
()
{
log
.
info
(
"
Scheduled
task is running ... ..."
);
log
.
info
(
"
execute
task is running ... ..."
);
csdnService
.
multiTriplet
();
csdnService
.
multiTriplet
();
log
.
info
(
"Scheduled task is finish ... ..."
);
log
.
info
(
"execute task is finish ... ..."
);
}
@Scheduled
(
cron
=
"0 0 3 * * ?"
)
public
void
executeInit
()
{
log
.
info
(
"executeInit task is running ... ..."
);
QueryWrapper
<
CsdnUserInfo
>
wrapper
=
new
QueryWrapper
<>();
wrapper
.
eq
(
"is_delete"
,
0
);
wrapper
.
orderByAsc
(
"rand()"
);
final
List
<
CsdnUserInfo
>
list
=
csdnUserInfoService
.
list
(
wrapper
);
if
(
CollectionUtil
.
isNotEmpty
(
list
))
{
for
(
CsdnUserInfo
csdnUserInfo
:
list
)
{
csdnUserInfo
.
setLikeStatus
(
LikeStatus
.
UN_PROCESSED
.
getCode
());
csdnUserInfo
.
setCollectStatus
(
CollectStatus
.
UN_PROCESSED
.
getCode
());
// csdnUserInfo.setCommentStatus(CommentStatus.UN_PROCESSED.getCode());
csdnUserInfoService
.
updateById
(
csdnUserInfo
);
}
}
log
.
info
(
"executeInit task is finish ... ..."
);
}
}
}
}
src/main/java/com/kwan/springbootkwan/service/CsdnCollectService.java
浏览文件 @
0b6afd55
package
com.kwan.springbootkwan.service
;
package
com.kwan.springbootkwan.service
;
import
com.kwan.springbootkwan.entity.CsdnUserInfo
;
import
com.kwan.springbootkwan.entity.resp.BusinessInfoResponse
;
import
com.kwan.springbootkwan.entity.resp.BusinessInfoResponse
;
/**
/**
...
@@ -17,12 +18,12 @@ public interface CsdnCollectService {
...
@@ -17,12 +18,12 @@ public interface CsdnCollectService {
*
*
* @return
* @return
*/
*/
Boolean
isCollect
(
String
articleId
);
Boolean
isCollect
(
String
articleId
,
CsdnUserInfo
csdnUserInfo
);
/**
/**
* 点赞和取消点赞接口,true,点过,false,没有点过
* 点赞和取消点赞接口,true,点过,false,没有点过
*
*
* @return
* @return
*/
*/
Boolean
collect
(
BusinessInfoResponse
.
ArticleData
.
Article
article
,
String
username
);
Boolean
collect
(
BusinessInfoResponse
.
ArticleData
.
Article
article
,
CsdnUserInfo
csdnUserInfo
);
}
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/service/CsdnCommentService.java
浏览文件 @
0b6afd55
package
com.kwan.springbootkwan.service
;
package
com.kwan.springbootkwan.service
;
import
com.kwan.springbootkwan.entity.CsdnUserInfo
;
import
com.kwan.springbootkwan.entity.resp.BusinessInfoResponse
;
import
com.kwan.springbootkwan.entity.resp.BusinessInfoResponse
;
/**
/**
...
@@ -16,12 +17,12 @@ public interface CsdnCommentService {
...
@@ -16,12 +17,12 @@ public interface CsdnCommentService {
*
*
* @return
* @return
*/
*/
Boolean
isComment
(
BusinessInfoResponse
.
ArticleData
.
Article
article
);
Boolean
isComment
(
BusinessInfoResponse
.
ArticleData
.
Article
article
,
CsdnUserInfo
csdnUserInfo
);
/**
/**
* 点赞和取消点赞接口,true,点过,false,没有点过
* 点赞和取消点赞接口,true,点过,false,没有点过
*
*
* @return
* @return
*/
*/
Boolean
comment
(
String
articleId
);
Boolean
comment
(
String
articleId
,
CsdnUserInfo
csdnUserInfo
);
}
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/service/CsdnLikeService.java
浏览文件 @
0b6afd55
package
com.kwan.springbootkwan.service
;
package
com.kwan.springbootkwan.service
;
import
com.kwan.springbootkwan.entity.CsdnUserInfo
;
/**
/**
* 点赞
* 点赞
*
*
...
@@ -16,12 +18,12 @@ public interface CsdnLikeService {
...
@@ -16,12 +18,12 @@ public interface CsdnLikeService {
*
*
* @return
* @return
*/
*/
Boolean
isLike
(
String
articleId
,
String
userName
);
Boolean
isLike
(
String
articleId
,
CsdnUserInfo
csdnUserInfo
);
/**
/**
* 点赞和取消点赞接口,true,点过,false,没有点过
* 点赞和取消点赞接口,true,点过,false,没有点过
*
*
* @return
* @return
*/
*/
Boolean
like
(
String
articleId
);
Boolean
like
(
String
articleId
,
CsdnUserInfo
csdnUserInfo
);
}
}
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/service/CsdnService.java
浏览文件 @
0b6afd55
package
com.kwan.springbootkwan.service
;
package
com.kwan.springbootkwan.service
;
import
com.kwan.springbootkwan.entity.CsdnUserInfo
;
/**
/**
* csdn博客自动化
* csdn博客自动化
*
*
...
@@ -14,7 +16,7 @@ public interface CsdnService {
...
@@ -14,7 +16,7 @@ public interface CsdnService {
*
*
* @return
* @return
*/
*/
void
singleArticle
(
String
username
);
void
singleArticle
(
CsdnUserInfo
csdnUserInfo
);
/**
/**
* 多人三连
* 多人三连
...
...
src/main/java/com/kwan/springbootkwan/service/impl/CsdnCollectServiceImpl.java
浏览文件 @
0b6afd55
...
@@ -4,16 +4,19 @@ import cn.hutool.http.HttpResponse;
...
@@ -4,16 +4,19 @@ 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.BusinessInfoResponse
;
import
com.kwan.springbootkwan.entity.resp.BusinessInfoResponse
;
import
com.kwan.springbootkwan.entity.resp.CollectInfoQuery
;
import
com.kwan.springbootkwan.entity.resp.CollectInfoQuery
;
import
com.kwan.springbootkwan.entity.resp.CollectResponse
;
import
com.kwan.springbootkwan.entity.resp.CollectResponse
;
import
com.kwan.springbootkwan.entity.resp.IsCollectResponse
;
import
com.kwan.springbootkwan.entity.resp.IsCollectResponse
;
import
com.kwan.springbootkwan.enums.CollectStatus
;
import
com.kwan.springbootkwan.service.CsdnCollectService
;
import
com.kwan.springbootkwan.service.CsdnCollectService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
@Slf4j
@Slf4j
@Service
@Service
...
@@ -30,15 +33,10 @@ public class CsdnCollectServiceImpl implements CsdnCollectService {
...
@@ -30,15 +33,10 @@ public class CsdnCollectServiceImpl implements CsdnCollectService {
@Value
(
"${csdn.url.add_collect_url}"
)
@Value
(
"${csdn.url.add_collect_url}"
)
private
String
addCollectUrl
;
private
String
addCollectUrl
;
/**
* 收藏满了
*/
private
static
boolean
COLLECT_IS_FULL
=
false
;
@Override
@Override
public
Boolean
isCollect
(
String
articleId
)
{
public
Boolean
isCollect
(
String
articleId
,
CsdnUserInfo
csdnUserInfo
)
{
if
(
COLLECT_IS_FULL
)
{
final
Integer
collectStatus
=
csdnUserInfo
.
getCollectStatus
();
if
(
CollectStatus
.
HAVE_ALREADY_COLLECT
.
getCode
().
equals
(
collectStatus
)
||
CollectStatus
.
COLLECT_IS_FULL
.
getCode
().
equals
(
collectStatus
))
{
return
true
;
return
true
;
}
}
HttpResponse
response
=
HttpUtil
.
createGet
(
isCollectUrl
)
HttpResponse
response
=
HttpUtil
.
createGet
(
isCollectUrl
)
...
@@ -54,8 +52,10 @@ public class CsdnCollectServiceImpl implements CsdnCollectService {
...
@@ -54,8 +52,10 @@ public class CsdnCollectServiceImpl implements CsdnCollectService {
final
boolean
status
=
data
.
status
;
final
boolean
status
=
data
.
status
;
if
(
status
)
{
if
(
status
)
{
log
.
info
(
"文章{}已经收藏过"
,
articleId
);
log
.
info
(
"文章{}已经收藏过"
,
articleId
);
csdnUserInfo
.
setCommentStatus
(
CollectStatus
.
HAVE_ALREADY_COLLECT
.
getCode
());
}
else
{
}
else
{
log
.
info
(
"文章{}未收藏"
,
articleId
);
log
.
info
(
"文章{}未收藏"
,
articleId
);
csdnUserInfo
.
setCommentStatus
(
CollectStatus
.
UN_PROCESSED
.
getCode
());
}
}
return
status
;
return
status
;
}
}
...
@@ -66,8 +66,10 @@ public class CsdnCollectServiceImpl implements CsdnCollectService {
...
@@ -66,8 +66,10 @@ public class CsdnCollectServiceImpl implements CsdnCollectService {
}
}
@Override
@Override
public
Boolean
collect
(
BusinessInfoResponse
.
ArticleData
.
Article
article
,
String
username
)
{
public
Boolean
collect
(
BusinessInfoResponse
.
ArticleData
.
Article
article
,
CsdnUserInfo
csdnUserInfo
)
{
if
(
COLLECT_IS_FULL
)
{
final
String
userName
=
csdnUserInfo
.
getUserName
();
final
Integer
collectStatus
=
csdnUserInfo
.
getCollectStatus
();
if
(
CollectStatus
.
HAVE_ALREADY_COLLECT
.
getCode
().
equals
(
collectStatus
)
||
CollectStatus
.
COLLECT_IS_FULL
.
getCode
().
equals
(
collectStatus
))
{
return
true
;
return
true
;
}
}
final
String
urlInfo
=
article
.
getUrl
();
final
String
urlInfo
=
article
.
getUrl
();
...
@@ -77,10 +79,10 @@ public class CsdnCollectServiceImpl implements CsdnCollectService {
...
@@ -77,10 +79,10 @@ public class CsdnCollectServiceImpl implements CsdnCollectService {
CollectInfoQuery
collectInfoQuery
=
new
CollectInfoQuery
();
CollectInfoQuery
collectInfoQuery
=
new
CollectInfoQuery
();
collectInfoQuery
.
setSourceId
(
Integer
.
valueOf
(
articleId
));
collectInfoQuery
.
setSourceId
(
Integer
.
valueOf
(
articleId
));
collectInfoQuery
.
setFromType
(
"PC"
);
collectInfoQuery
.
setFromType
(
"PC"
);
collectInfoQuery
.
setAuthor
(
user
n
ame
);
collectInfoQuery
.
setAuthor
(
user
N
ame
);
collectInfoQuery
.
setDescription
(
article
.
getDescription
());
collectInfoQuery
.
setDescription
(
article
.
getDescription
());
collectInfoQuery
.
setSource
(
"blog"
);
collectInfoQuery
.
setSource
(
"blog"
);
Array
List
<
Integer
>
list
=
new
ArrayList
<>();
List
<
Integer
>
list
=
new
ArrayList
<>();
list
.
add
(
selfFolderId
);
list
.
add
(
selfFolderId
);
collectInfoQuery
.
setFolderIdList
(
list
);
collectInfoQuery
.
setFolderIdList
(
list
);
collectInfoQuery
.
setTitle
(
article
.
getTitle
());
collectInfoQuery
.
setTitle
(
article
.
getTitle
());
...
@@ -101,11 +103,13 @@ public class CsdnCollectServiceImpl implements CsdnCollectService {
...
@@ -101,11 +103,13 @@ public class CsdnCollectServiceImpl implements CsdnCollectService {
final
Long
code
=
collectResponse
.
code
;
final
Long
code
=
collectResponse
.
code
;
if
(
code
.
equals
(
200
))
{
if
(
code
.
equals
(
200
))
{
log
.
info
(
"文章{}收藏成功"
,
articleId
);
log
.
info
(
"文章{}收藏成功"
,
articleId
);
csdnUserInfo
.
setCollectStatus
(
CollectStatus
.
COLLECT_SUCCESSFUL
.
getCode
());
}
else
if
(
code
.
equals
(
400000101
))
{
}
else
if
(
code
.
equals
(
400000101
))
{
log
.
info
(
"收藏文章{}参数缺失"
,
articleId
);
log
.
info
(
"收藏文章{}参数缺失"
,
articleId
);
csdnUserInfo
.
setCollectStatus
(
CollectStatus
.
MISSING_PARAMETER
.
getCode
());
}
else
if
(
code
.
equals
(
400
))
{
}
else
if
(
code
.
equals
(
400
))
{
COLLECT_IS_FULL
=
true
;
log
.
info
(
"今日收藏次数已达上限!"
);
log
.
info
(
"今日收藏次数已达上限!"
);
csdnUserInfo
.
setCollectStatus
(
CollectStatus
.
COLLECT_IS_FULL
.
getCode
());
}
}
return
true
;
return
true
;
}
}
...
...
src/main/java/com/kwan/springbootkwan/service/impl/CsdnCommentServiceImpl.java
浏览文件 @
0b6afd55
...
@@ -5,9 +5,11 @@ import cn.hutool.http.HttpResponse;
...
@@ -5,9 +5,11 @@ 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.BusinessInfoResponse
;
import
com.kwan.springbootkwan.entity.resp.BusinessInfoResponse
;
import
com.kwan.springbootkwan.entity.resp.CommentListResponse
;
import
com.kwan.springbootkwan.entity.resp.CommentListResponse
;
import
com.kwan.springbootkwan.entity.resp.CommentResponse
;
import
com.kwan.springbootkwan.entity.resp.CommentResponse
;
import
com.kwan.springbootkwan.enums.CommentStatus
;
import
com.kwan.springbootkwan.service.CsdnCommentService
;
import
com.kwan.springbootkwan.service.CsdnCommentService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
@@ -36,21 +38,22 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
...
@@ -36,21 +38,22 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
private
static
boolean
COMMENT_IS_FULL
=
false
;
private
static
boolean
COMMENT_IS_FULL
=
false
;
@Override
@Override
public
Boolean
isComment
(
BusinessInfoResponse
.
ArticleData
.
Article
article
)
{
public
Boolean
isComment
(
BusinessInfoResponse
.
ArticleData
.
Article
article
,
CsdnUserInfo
csdnUserInfo
)
{
if
(
COMMENT_IS_FULL
)
{
final
Integer
commentStatus
=
csdnUserInfo
.
getCommentStatus
();
if
(
CommentStatus
.
HAVE_ALREADY_COMMENT
.
getCode
().
equals
(
commentStatus
)
||
CommentStatus
.
COMMENT_IS_FULL
.
getCode
().
equals
(
commentStatus
)
||
CommentStatus
.
RESTRICTED_COMMENTS
.
getCode
().
equals
(
commentStatus
))
{
return
true
;
return
true
;
}
}
final
String
urlInfo
=
article
.
getUrl
();
final
String
urlInfo
=
article
.
getUrl
();
String
articleId
=
urlInfo
.
substring
(
urlInfo
.
lastIndexOf
(
"/"
)
+
1
);
String
articleId
=
urlInfo
.
substring
(
urlInfo
.
lastIndexOf
(
"/"
)
+
1
);
String
url
=
commentListUrl
+
articleId
;
String
url
=
commentListUrl
+
articleId
;
// 使用Hutool发送GET请求
HttpResponse
response
=
HttpUtil
.
createPost
(
url
)
HttpResponse
response
=
HttpUtil
.
createPost
(
url
)
.
header
(
"Cookie"
,
csdnCookie
)
.
header
(
"Cookie"
,
csdnCookie
)
.
form
(
"page"
,
1
)
.
form
(
"page"
,
1
)
.
form
(
"size"
,
50
)
.
form
(
"size"
,
50
)
.
form
(
"fold"
,
"unfold"
)
.
form
(
"fold"
,
"unfold"
)
.
execute
();
.
execute
();
// 打印响应结果
final
String
body
=
response
.
body
();
final
String
body
=
response
.
body
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
CommentListResponse
articleInfo
;
CommentListResponse
articleInfo
;
...
@@ -63,8 +66,8 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
...
@@ -63,8 +66,8 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
final
CommentListResponse
.
Info
info
=
comment
.
getInfo
();
final
CommentListResponse
.
Info
info
=
comment
.
getInfo
();
final
String
userName
=
info
.
getUserName
();
final
String
userName
=
info
.
getUserName
();
if
(
StringUtils
.
equals
(
userName
,
selfUserName
))
{
if
(
StringUtils
.
equals
(
userName
,
selfUserName
))
{
//评论过
log
.
info
(
"文章{}已经评论过"
,
articleId
);
log
.
info
(
"文章{}已经评论过"
,
articleId
);
csdnUserInfo
.
setCommentStatus
(
CommentStatus
.
HAVE_ALREADY_COMMENT
.
getCode
());
return
true
;
return
true
;
}
}
}
}
...
@@ -72,12 +75,16 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
...
@@ -72,12 +75,16 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
}
catch
(
JsonProcessingException
e
)
{
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
csdnUserInfo
.
setCommentStatus
(
CommentStatus
.
UN_PROCESSED
.
getCode
());
return
false
;
return
false
;
}
}
@Override
@Override
public
Boolean
comment
(
String
articleId
)
{
public
Boolean
comment
(
String
articleId
,
CsdnUserInfo
csdnUserInfo
)
{
if
(
COMMENT_IS_FULL
)
{
final
Integer
commentStatus
=
csdnUserInfo
.
getCommentStatus
();
if
(
CommentStatus
.
HAVE_ALREADY_COMMENT
.
getCode
().
equals
(
commentStatus
)
||
CommentStatus
.
COMMENT_IS_FULL
.
getCode
().
equals
(
commentStatus
)
||
CommentStatus
.
RESTRICTED_COMMENTS
.
getCode
().
equals
(
commentStatus
))
{
return
true
;
return
true
;
}
}
//评论
//评论
...
@@ -86,11 +93,16 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
...
@@ -86,11 +93,16 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
final
String
message
=
comment
.
getMessage
();
final
String
message
=
comment
.
getMessage
();
if
(
code
==
200
)
{
if
(
code
==
200
)
{
log
.
info
(
"文章{}评论成功"
,
articleId
);
log
.
info
(
"文章{}评论成功"
,
articleId
);
csdnUserInfo
.
setCommentStatus
(
CommentStatus
.
COMMENT_SUCCESSFUL
.
getCode
());
}
else
if
(
code
==
400
&&
StringUtils
.
equals
(
message
,
"您已达到当日发送上限,请明天尝试!"
))
{
}
else
if
(
code
==
400
&&
StringUtils
.
equals
(
message
,
"您已达到当日发送上限,请明天尝试!"
))
{
log
.
info
(
message
);
log
.
info
(
message
);
COMMENT_IS_FULL
=
true
;
csdnUserInfo
.
setCommentStatus
(
CommentStatus
.
COMMENT_IS_FULL
.
getCode
());
}
else
if
(
code
==
400
&&
message
.
contains
(
"因存在恶意评论嫌疑,您的账号已被禁言"
))
{
log
.
info
(
"因存在恶意评论嫌疑,您的账号已被禁言"
);
csdnUserInfo
.
setCommentStatus
(
CommentStatus
.
RESTRICTED_COMMENTS
.
getCode
());
}
else
{
}
else
{
log
.
info
(
"您评论太快了,请休息一下!"
);
log
.
info
(
"您评论太快了,请休息一下!"
);
csdnUserInfo
.
setCommentStatus
(
CommentStatus
.
COMMENT_TOO_FAST
.
getCode
());
}
}
return
true
;
return
true
;
}
}
...
...
src/main/java/com/kwan/springbootkwan/service/impl/CsdnLikeServiceImpl.java
浏览文件 @
0b6afd55
...
@@ -4,7 +4,9 @@ import cn.hutool.http.HttpResponse;
...
@@ -4,7 +4,9 @@ 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.LikeResponse
;
import
com.kwan.springbootkwan.entity.resp.LikeResponse
;
import
com.kwan.springbootkwan.enums.LikeStatus
;
import
com.kwan.springbootkwan.service.CsdnLikeService
;
import
com.kwan.springbootkwan.service.CsdnLikeService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
...
@@ -18,14 +20,12 @@ public class CsdnLikeServiceImpl implements CsdnLikeService {
...
@@ -18,14 +20,12 @@ public class CsdnLikeServiceImpl implements CsdnLikeService {
private
String
csdnCookie
;
private
String
csdnCookie
;
@Value
(
"${csdn.url.like_url}"
)
@Value
(
"${csdn.url.like_url}"
)
private
String
url
;
private
String
url
;
/**
* 点赞满了
*/
private
static
boolean
LIKE_IS_FULL
=
false
;
@Override
@Override
public
Boolean
isLike
(
String
articleId
,
String
userName
)
{
public
Boolean
isLike
(
String
articleId
,
CsdnUserInfo
csdnUserInfo
)
{
if
(
LIKE_IS_FULL
)
{
final
String
userName
=
csdnUserInfo
.
getUserName
();
final
Integer
likeStatus
=
csdnUserInfo
.
getLikeStatus
();
if
(
LikeStatus
.
HAVE_ALREADY_LIKED
.
getCode
().
equals
(
likeStatus
)
||
LikeStatus
.
LIKE_IS_FULL
.
getCode
().
equals
(
likeStatus
))
{
return
true
;
return
true
;
}
}
String
url
=
"https://blog.csdn.net/"
+
userName
+
"/article/details/"
+
articleId
;
String
url
=
"https://blog.csdn.net/"
+
userName
+
"/article/details/"
+
articleId
;
...
@@ -36,16 +36,19 @@ public class CsdnLikeServiceImpl implements CsdnLikeService {
...
@@ -36,16 +36,19 @@ public class CsdnLikeServiceImpl implements CsdnLikeService {
final
String
body
=
response
.
body
();
final
String
body
=
response
.
body
();
if
(
body
.
contains
(
"isLikeStatus = true"
))
{
if
(
body
.
contains
(
"isLikeStatus = true"
))
{
log
.
info
(
"文章{}已经点过赞"
,
articleId
);
log
.
info
(
"文章{}已经点过赞"
,
articleId
);
csdnUserInfo
.
setLikeStatus
(
LikeStatus
.
HAVE_ALREADY_LIKED
.
getCode
());
return
true
;
return
true
;
}
else
{
}
else
{
log
.
info
(
"文章{}未点过赞"
,
articleId
);
log
.
info
(
"文章{}未点过赞"
,
articleId
);
csdnUserInfo
.
setLikeStatus
(
LikeStatus
.
UN_PROCESSED
.
getCode
());
return
false
;
return
false
;
}
}
}
}
@Override
@Override
public
Boolean
like
(
String
articleId
)
{
public
Boolean
like
(
String
articleId
,
CsdnUserInfo
csdnUserInfo
)
{
if
(
LIKE_IS_FULL
)
{
final
Integer
likeStatus
=
csdnUserInfo
.
getLikeStatus
();
if
(
LikeStatus
.
HAVE_ALREADY_LIKED
.
getCode
().
equals
(
likeStatus
)
||
LikeStatus
.
LIKE_IS_FULL
.
getCode
().
equals
(
likeStatus
))
{
return
true
;
return
true
;
}
}
HttpResponse
response
=
HttpUtil
.
createPost
(
url
)
HttpResponse
response
=
HttpUtil
.
createPost
(
url
)
...
@@ -61,13 +64,15 @@ public class CsdnLikeServiceImpl implements CsdnLikeService {
...
@@ -61,13 +64,15 @@ public class CsdnLikeServiceImpl implements CsdnLikeService {
final
boolean
status
=
data
.
status
;
final
boolean
status
=
data
.
status
;
if
(
status
)
{
if
(
status
)
{
log
.
info
(
"文章{}点赞成功"
,
articleId
);
log
.
info
(
"文章{}点赞成功"
,
articleId
);
csdnUserInfo
.
setLikeStatus
(
LikeStatus
.
LIKE_SUCCESSFUL
.
getCode
());
}
else
{
}
else
{
log
.
info
(
"文章{}点赞取消"
,
articleId
);
log
.
info
(
"文章{}点赞取消"
,
articleId
);
csdnUserInfo
.
setLikeStatus
(
LikeStatus
.
CANCEL_LIKES
.
getCode
());
}
}
return
status
;
return
status
;
}
else
if
(
code
==
400
)
{
}
else
if
(
code
==
400
)
{
LIKE_IS_FULL
=
true
;
log
.
info
(
"今日点赞次数已达上限!"
);
log
.
info
(
"今日点赞次数已达上限!"
);
csdnUserInfo
.
setLikeStatus
(
LikeStatus
.
LIKE_IS_FULL
.
getCode
());
}
}
}
catch
(
JsonProcessingException
e
)
{
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
...
src/main/java/com/kwan/springbootkwan/service/impl/CsdnServiceImpl.java
浏览文件 @
0b6afd55
...
@@ -42,7 +42,8 @@ public class CsdnServiceImpl implements CsdnService {
...
@@ -42,7 +42,8 @@ public class CsdnServiceImpl implements CsdnService {
private
CsdnLikeService
csdnLikeService
;
private
CsdnLikeService
csdnLikeService
;
@Override
@Override
public
void
singleArticle
(
String
username
)
{
public
void
singleArticle
(
CsdnUserInfo
csdnUserInfo
)
{
final
String
username
=
csdnUserInfo
.
getUserName
();
List
<
BusinessInfoResponse
.
ArticleData
.
Article
>
list
=
this
.
getArticles
(
username
);
List
<
BusinessInfoResponse
.
ArticleData
.
Article
>
list
=
this
.
getArticles
(
username
);
if
(
list
==
null
)
{
if
(
list
==
null
)
{
return
;
return
;
...
@@ -51,26 +52,28 @@ public class CsdnServiceImpl implements CsdnService {
...
@@ -51,26 +52,28 @@ public class CsdnServiceImpl implements CsdnService {
final
BusinessInfoResponse
.
ArticleData
.
Article
article
=
list
.
get
(
i
);
final
BusinessInfoResponse
.
ArticleData
.
Article
article
=
list
.
get
(
i
);
final
String
type
=
article
.
getType
();
final
String
type
=
article
.
getType
();
if
(!
StringUtils
.
equals
(
"blog"
,
type
))
{
if
(!
StringUtils
.
equals
(
"blog"
,
type
))
{
csdnUserInfo
.
setArticleType
(
type
);
continue
;
continue
;
}
}
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
);
final
Boolean
isLike
=
csdnLikeService
.
isLike
(
articleId
,
csdnUserInfo
);
if
(!
isLike
)
{
if
(!
isLike
)
{
csdnLikeService
.
like
(
articleId
);
csdnLikeService
.
like
(
articleId
,
csdnUserInfo
);
}
}
//评论
//评论
final
Boolean
comment
=
csdnCommentService
.
isComment
(
article
);
final
Boolean
comment
=
csdnCommentService
.
isComment
(
article
,
csdnUserInfo
);
if
(!
comment
)
{
if
(!
comment
)
{
csdnCommentService
.
comment
(
articleId
);
csdnCommentService
.
comment
(
articleId
,
csdnUserInfo
);
}
}
//收藏
//收藏
final
Boolean
collect
=
csdnCollectService
.
isCollect
(
articleId
);
final
Boolean
collect
=
csdnCollectService
.
isCollect
(
articleId
,
csdnUserInfo
);
if
(!
collect
)
{
if
(!
collect
)
{
csdnCollectService
.
collect
(
article
,
username
);
csdnCollectService
.
collect
(
article
,
csdnUserInfo
);
}
}
}
}
csdnUserInfoService
.
updateById
(
csdnUserInfo
);
}
}
private
List
<
BusinessInfoResponse
.
ArticleData
.
Article
>
getArticles
(
String
username
)
{
private
List
<
BusinessInfoResponse
.
ArticleData
.
Article
>
getArticles
(
String
username
)
{
...
@@ -111,23 +114,9 @@ public class CsdnServiceImpl implements CsdnService {
...
@@ -111,23 +114,9 @@ public class CsdnServiceImpl implements CsdnService {
final
List
<
CsdnUserInfo
>
list
=
csdnUserInfoService
.
list
(
wrapper
);
final
List
<
CsdnUserInfo
>
list
=
csdnUserInfoService
.
list
(
wrapper
);
if
(
CollectionUtil
.
isNotEmpty
(
list
))
{
if
(
CollectionUtil
.
isNotEmpty
(
list
))
{
for
(
CsdnUserInfo
csdnUserInfo
:
list
)
{
for
(
CsdnUserInfo
csdnUserInfo
:
list
)
{
final
String
userName
=
csdnUserInfo
.
getUserName
();
singleArticle
(
csdnUserInfo
);
singleArticle
(
userName
);
}
}
}
}
log
.
info
(
"全部三连完成"
);
log
.
info
(
"全部三连完成"
);
}
}
// /**
// * 多人三连非数据库
// */
// @Override
// public void multiTriplet() {
// String[] userNames = new String[]{"user1", "user2", "user3", "xxxx"};
// for (String name : userNames) {
// singleArticle(name);
// }
// 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录