fix:整理

上级 a21c9d2b
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.enums.CollectStatus;
import com.kwan.springbootkwan.enums.CommentStatus;
import com.kwan.springbootkwan.enums.LikeStatus;
import com.kwan.springbootkwan.service.CsdnCommentService;
import com.kwan.springbootkwan.service.CsdnAutoReplyService;
import com.kwan.springbootkwan.service.CsdnService;
import com.kwan.springbootkwan.service.CsdnUserInfoService;
import lombok.extern.slf4j.Slf4j;
......@@ -17,7 +13,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Objects;
@Slf4j
......@@ -28,7 +23,7 @@ public class CsdnController {
@Autowired
private CsdnService csdnService;
@Autowired
private CsdnCommentService csdnCommentService;
private CsdnAutoReplyService csdnAutoReplyService;
@Autowired
private CsdnUserInfoService csdnUserInfoService;
......@@ -52,23 +47,13 @@ public class CsdnController {
@GetMapping("/autoReply")
public Result autoReply() {
csdnCommentService.commentSelf();
csdnAutoReplyService.commentSelf();
return Result.ok("自动回复完成");
}
@GetMapping("/resetCurrentStatus")
public Result resetCurrentStatus() {
QueryWrapper<CsdnUserInfo> wrapper = new QueryWrapper<>();
wrapper.eq("is_delete", 0);
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.RESTRICTED_COMMENTS.getCode());
csdnUserInfoService.updateById(csdnUserInfo);
}
}
csdnUserInfoService.resetCurrentStatus();
return Result.ok("重置当天状态完成");
}
}
package com.kwan.springbootkwan.controller;
import com.kwan.springbootkwan.entity.Result;
import com.kwan.springbootkwan.service.CsdnTripletDayInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 每日三连监控(CsdnTripletDayInfo)表控制层
*
* @author makejava
* @since 2023-10-26 20:55:30
*/
@RestController
@RequestMapping("/dayInfo")
public class CsdnTripletDayInfoController {
@Autowired
private CsdnTripletDayInfoService csdnTripletDayInfoService;
@GetMapping("/add")
public Result autoReply() {
return Result.ok(csdnTripletDayInfoService.todayInfo());
}
}
package com.kwan.springbootkwan.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
/**
* 每日三连监控(CsdnTripletDayInfo)表实体类
*
* @author makejava
* @since 2023-10-26 20:55:31
*/
@Data
@TableName("csdn_triplet_day_info")
public class CsdnTripletDayInfo extends Model<CsdnTripletDayInfo> {
//主键id
private Integer id;
//三连日期
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date tripletDate;
//点赞数量
private Integer likeNum;
//收藏数量
private Integer collectNum;
//评论数量
private Integer commentNum;
//创建时间
private Date createTime;
//更新时间
private Date updateTime;
//逻辑删除,0未删除,1已删除
private Integer isDelete;
}
\ No newline at end of file
......@@ -29,7 +29,7 @@ public enum CommentStatus {
/**
* 评论已经到了49条
*/
COMMENT_NUM_49(5, "评论已经到了49条"),
COMMENT_NUM_49(5, "当日评论已经到了49条"),
/**
* 其他错误
*/
......
package com.kwan.springbootkwan.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kwan.springbootkwan.entity.CsdnTripletDayInfo;
/**
* 每日三连监控(CsdnTripletDayInfo)表数据库访问层
*
* @author makejava
* @since 2023-10-26 20:55:30
*/
public interface CsdnTripletDayInfoMapper extends BaseMapper<CsdnTripletDayInfo> {
}
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.CommentStatus;
import com.kwan.springbootkwan.enums.LikeStatus;
import com.kwan.springbootkwan.service.CsdnAutoReplyService;
import com.kwan.springbootkwan.service.CsdnCommentService;
import com.kwan.springbootkwan.service.CsdnService;
import com.kwan.springbootkwan.service.CsdnTripletDayInfoService;
import com.kwan.springbootkwan.service.CsdnUserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
@Slf4j
@Component
public class CsdnSchedule {
......@@ -28,6 +20,10 @@ public class CsdnSchedule {
private CsdnCommentService csdnCommentService;
@Autowired
private CsdnUserInfoService csdnUserInfoService;
@Autowired
private CsdnAutoReplyService csdnAutoReplyService;
@Autowired
private CsdnTripletDayInfoService csdnTripletDayInfoService;
@Scheduled(cron = "0 0 8,10,12,14,16,18,20 * * ?")
public void execute() {
......@@ -39,25 +35,22 @@ public class CsdnSchedule {
@Scheduled(cron = "0 0/30 0 * * ?")
public void executeReply() {
log.info("executeReply task is running ... ...");
csdnCommentService.commentSelf();
csdnAutoReplyService.commentSelf();
log.info("executeReply task is finish ... ...");
}
@Scheduled(cron = "0 0/30 * * * ?")
public void executeInit() {
log.info("executeInit task is running ... ...");
QueryWrapper<CsdnUserInfo> wrapper = new QueryWrapper<>();
wrapper.eq("is_delete", 0);
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.RESTRICTED_COMMENTS.getCode());
csdnUserInfoService.updateById(csdnUserInfo);
}
}
csdnUserInfoService.resetCurrentStatus();
log.info("executeInit task is finish ... ...");
}
}
@Scheduled(cron = "0 0 1 * * ?")
public void resetTripletDayInfo() {
log.info("resetTripletDayInfo task is running ... ...");
//新增当前天的新的一条数据
csdnTripletDayInfoService.todayInfo();
log.info("resetTripletDayInfo task is finish ... ...");
}
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ import java.util.List;
public interface CsdnArticleService {
/**
* 获取最新的文章
* 获取最新的5篇文章
*
* @param username
* @return
......
package com.kwan.springbootkwan.service;
/**
* 自动回复
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/10/24 01:25
*/
public interface CsdnAutoReplyService {
/**
* 评论自己的文章
*
* @return
*/
void commentSelf();
}
\ No newline at end of file
package com.kwan.springbootkwan.service;
import com.kwan.springbootkwan.entity.CsdnTripletDayInfo;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
......@@ -25,5 +26,5 @@ public interface CsdnCollectService {
*
* @return
*/
Boolean collect(BusinessInfoResponse.ArticleData.Article article, CsdnUserInfo csdnUserInfo);
Boolean collect(BusinessInfoResponse.ArticleData.Article article, CsdnUserInfo csdnUserInfo, CsdnTripletDayInfo csdnTripletDayInfo);
}
\ No newline at end of file
package com.kwan.springbootkwan.service;
import com.kwan.springbootkwan.entity.CsdnTripletDayInfo;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
import com.kwan.springbootkwan.entity.resp.CommentResponse;
/**
* 评论
......@@ -24,13 +26,15 @@ public interface CsdnCommentService {
*
* @return
*/
Boolean comment(String articleId, CsdnUserInfo csdnUserInfo);
Boolean comment(String articleId, CsdnUserInfo csdnUserInfo, CsdnTripletDayInfo csdnTripletDayInfo);
/**
* 评论自己的文章
* 评论文章
*
* @param articleId
* @param commentInfo
* @param commentId
* @return
*/
void commentSelf();
CommentResponse dealComment(String articleId, String commentInfo, Integer commentId);
}
\ No newline at end of file
package com.kwan.springbootkwan.service;
import com.kwan.springbootkwan.entity.CsdnTripletDayInfo;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
/**
......@@ -24,5 +25,5 @@ public interface CsdnLikeService {
*
* @return
*/
Boolean like(String articleId, CsdnUserInfo csdnUserInfo);
Boolean like(String articleId, CsdnUserInfo csdnUserInfo, CsdnTripletDayInfo csdnTripletDayInfo);
}
\ No newline at end of file
package com.kwan.springbootkwan.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.kwan.springbootkwan.entity.CsdnTripletDayInfo;
/**
* 每日三连监控(CsdnTripletDayInfo)表服务接口
*
* @author makejava
* @since 2023-10-26 20:55:31
*/
public interface CsdnTripletDayInfoService extends IService<CsdnTripletDayInfo> {
/**
* 重置每日三连监控
*/
CsdnTripletDayInfo todayInfo();
}
......@@ -11,5 +11,8 @@ import com.kwan.springbootkwan.entity.CsdnUserInfo;
*/
public interface CsdnUserInfoService extends IService<CsdnUserInfo> {
void resetCurrentStatus();
}
package com.kwan.springbootkwan.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
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.CommentListResponse;
import com.kwan.springbootkwan.entity.resp.CommentResponse;
import com.kwan.springbootkwan.service.CsdnArticleService;
import com.kwan.springbootkwan.service.CsdnAutoReplyService;
import com.kwan.springbootkwan.service.CsdnCommentService;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
@Slf4j
@Service
public class CsdnAutoReplyServiceImpl implements CsdnAutoReplyService {
@Value("${csdn.cookie}")
private String csdnCookie;
@Value("#{'${csdn.self_reply}'.split(';')}")
private String[] selfReply;
@Value("${csdn.self_user_name}")
private String selfUserName;
@Value("${csdn.url.is_comment_list_url}")
private String commentListUrl;
@Autowired
private CsdnService csdnService;
@Autowired
private CsdnArticleService csdnArticleService;
@Autowired
private CsdnCommentService csdnCommentService;
@Autowired
private CsdnUserInfoService csdnUserInfoService;
@Override
public void commentSelf() {
List<BusinessInfoResponse.ArticleData.Article> list = csdnArticleService.getArticles(selfUserName);
if (list == null) {
return;
}
for (BusinessInfoResponse.ArticleData.Article article : list) {
final String type = article.getType();
if (StringUtils.equals("blog", type)) {
final String urlInfo = article.getUrl();
String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1);
String url = commentListUrl + articleId;
HttpResponse response = HttpUtil.createPost(url)
.header("Cookie", csdnCookie)
.form("page", 1)
.form("size", 200)//获取当前文章的200条评论
.execute();
final String body = response.body();
ObjectMapper objectMapper = new ObjectMapper();
CommentListResponse articleInfo;
try {
articleInfo = objectMapper.readValue(body, CommentListResponse.class);
final CommentListResponse.DataInfo data = articleInfo.getData();
final List<CommentListResponse.Comment> otherCommentList = data.getList();
if (CollectionUtil.isNotEmpty(otherCommentList)) {
for (CommentListResponse.Comment oneComment : otherCommentList) {
final CommentListResponse.Info info = oneComment.getInfo();
final String userName = info.getUserName();
final String nickName = info.getNickName();
final Integer commentId = info.getCommentId();
if (!StringUtils.equals(userName, selfUserName)) {
final List<CommentListResponse.SubComment> sub = oneComment.getSub();
boolean flag = false;
if (CollectionUtil.isNotEmpty(sub)) {
for (CommentListResponse.SubComment subComment : sub) {
//如果没有自己的评论,需要评论
final String subUserName = subComment.getUserName();
if (StringUtils.equals(subUserName, selfUserName)) {
flag = true;
}
}
}
if (CollectionUtil.isEmpty(sub) || !flag) {
//需要评论
int start = -1;
int end = selfReply.length;
int temp_count = (int) (Math.floor(Math.random() * (start - end + 1)) + end);
CommentResponse reply = csdnCommentService.dealComment(articleId, selfReply[temp_count], commentId);
log.info(reply.toString());
}
//三连此评论人
QueryWrapper<CsdnUserInfo> wrapper = new QueryWrapper<>();
wrapper.eq("is_delete", 0);
wrapper.eq("user_name", userName).last("limit 1");
CsdnUserInfo csdnUserInfo = csdnUserInfoService.getOne(wrapper);
if (Objects.isNull(csdnUserInfo)) {
//新增用户
csdnUserInfo = new CsdnUserInfo();
csdnUserInfo.setUserName(userName);
csdnUserInfo.setNickName(nickName);
csdnUserInfo.setLikeStatus(0);
csdnUserInfo.setCollectStatus(0);
csdnUserInfo.setCommentStatus(0);
csdnUserInfo.setUserWeight(7);
csdnUserInfoService.save(csdnUserInfo);
}
csdnService.singleArticle(csdnUserInfo);
}
}
}
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
}
}
}
......@@ -4,6 +4,7 @@ import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kwan.springbootkwan.entity.CsdnTripletDayInfo;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
import com.kwan.springbootkwan.entity.resp.CollectInfoQuery;
......@@ -66,7 +67,7 @@ public class CsdnCollectServiceImpl implements CsdnCollectService {
}
@Override
public Boolean collect(BusinessInfoResponse.ArticleData.Article article, CsdnUserInfo csdnUserInfo) {
public Boolean collect(BusinessInfoResponse.ArticleData.Article article, CsdnUserInfo csdnUserInfo, CsdnTripletDayInfo csdnTripletDayInfo) {
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)) {
......@@ -104,6 +105,7 @@ public class CsdnCollectServiceImpl implements CsdnCollectService {
if (code == 200) {
log.info("文章{}收藏成功", articleId);
csdnUserInfo.setCollectStatus(CollectStatus.COLLECT_SUCCESSFUL.getCode());
csdnTripletDayInfo.setCollectNum(csdnTripletDayInfo.getCollectNum() + 1);
} else if (code == 400000101) {
log.info("收藏文章{}参数缺失", articleId);
csdnUserInfo.setCollectStatus(CollectStatus.MISSING_PARAMETER.getCode());
......
......@@ -5,16 +5,15 @@ import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kwan.springbootkwan.entity.CsdnTripletDayInfo;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
import com.kwan.springbootkwan.entity.resp.CommentListResponse;
import com.kwan.springbootkwan.entity.resp.CommentResponse;
import com.kwan.springbootkwan.enums.CommentStatus;
import com.kwan.springbootkwan.service.CsdnArticleService;
import com.kwan.springbootkwan.service.CsdnCommentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
......@@ -29,8 +28,6 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
private String csdnCookie;
@Value("#{'${csdn.self_comment}'.split(';')}")
private String[] selfComment;
@Value("#{'${csdn.self_reply}'.split(';')}")
private String[] selfReply;
@Value("${csdn.self_user_name}")
private String selfUserName;
@Value("${csdn.url.is_comment_list_url}")
......@@ -38,8 +35,6 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
@Value("${csdn.url.comment_url}")
private String commentUrl;
@Autowired
private CsdnArticleService csdnArticleService;
@Override
public Boolean isComment(BusinessInfoResponse.ArticleData.Article article, CsdnUserInfo csdnUserInfo) {
......@@ -56,7 +51,6 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
.header("Cookie", csdnCookie)
.form("page", 1)
.form("size", 50)
.form("fold", "unfold")
.execute();
final String body = response.body();
ObjectMapper objectMapper = new ObjectMapper();
......@@ -83,7 +77,7 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
}
@Override
public Boolean comment(String articleId, CsdnUserInfo csdnUserInfo) {
public Boolean comment(String articleId, CsdnUserInfo csdnUserInfo, CsdnTripletDayInfo csdnTripletDayInfo) {
final Integer commentStatus = csdnUserInfo.getCommentStatus();
if (CommentStatus.HAVE_ALREADY_COMMENT.getCode().equals(commentStatus)
|| CommentStatus.COMMENT_IS_FULL.getCode().equals(commentStatus)
......@@ -100,6 +94,7 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
if (code == 200) {
log.info("文章{}评论成功", articleId);
csdnUserInfo.setCommentStatus(CommentStatus.COMMENT_SUCCESSFUL.getCode());
csdnTripletDayInfo.setCommentNum(csdnTripletDayInfo.getCommentNum() + 1);
} else if (code == 400 && StringUtils.equals(message, "您已达到当日发送上限,请明天尝试!")) {
log.info(message);
csdnUserInfo.setCommentStatus(CommentStatus.COMMENT_IS_FULL.getCode());
......@@ -121,73 +116,14 @@ public class CsdnCommentServiceImpl implements CsdnCommentService {
return true;
}
@Override
public void commentSelf() {
List<BusinessInfoResponse.ArticleData.Article> list = csdnArticleService.getArticles(selfUserName);
if (list == null) {
return;
}
for (BusinessInfoResponse.ArticleData.Article article : list) {
final String type = article.getType();
if (!StringUtils.equals("blog", type)) {
continue;
}
final String urlInfo = article.getUrl();
String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1);
String url = commentListUrl + articleId;
HttpResponse response = HttpUtil.createPost(url)
.header("Cookie", csdnCookie)
.form("page", 1)
.form("size", 100)
.execute();
final String body = response.body();
ObjectMapper objectMapper = new ObjectMapper();
CommentListResponse articleInfo;
try {
articleInfo = objectMapper.readValue(body, CommentListResponse.class);
final CommentListResponse.DataInfo data = articleInfo.getData();
final List<CommentListResponse.Comment> otherCommentList = data.getList();
if (CollectionUtil.isNotEmpty(otherCommentList)) {
for (CommentListResponse.Comment oneComment : otherCommentList) {
final CommentListResponse.Info info = oneComment.getInfo();
final String userName = info.getUserName();
final Integer commentId = info.getCommentId();
if (!StringUtils.equals(userName, selfUserName)) {
final List<CommentListResponse.SubComment> sub = oneComment.getSub();
boolean flag = false;
if (CollectionUtil.isNotEmpty(sub)) {
for (CommentListResponse.SubComment subComment : sub) {
//如果没有自己的评论,需要评论
final String subUserName = subComment.getUserName();
if (StringUtils.equals(subUserName, selfUserName)) {
flag = true;
}
}
}
if (CollectionUtil.isEmpty(sub) || !flag) {
//需要评论
int start = -1;
int end = selfReply.length;
int temp_count = (int) (Math.floor(Math.random() * (start - end + 1)) + end);
CommentResponse reply = this.dealComment(articleId, selfReply[temp_count], commentId);
log.info(reply.toString());
}
}
}
}
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
}
/**
* 评论文章
*
* @param articleId
* @return
*/
private CommentResponse dealComment(String articleId, String commentInfo, Integer commentId) {
@Override
public CommentResponse dealComment(String articleId, String commentInfo, Integer commentId) {
HttpResponse response;
if (Objects.nonNull(commentId)) {
response = HttpUtil.createPost(commentUrl)
......
......@@ -4,6 +4,7 @@ import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kwan.springbootkwan.entity.CsdnTripletDayInfo;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
import com.kwan.springbootkwan.entity.resp.LikeResponse;
import com.kwan.springbootkwan.enums.LikeStatus;
......@@ -46,7 +47,7 @@ public class CsdnLikeServiceImpl implements CsdnLikeService {
}
@Override
public Boolean like(String articleId, CsdnUserInfo csdnUserInfo) {
public Boolean like(String articleId, CsdnUserInfo csdnUserInfo, CsdnTripletDayInfo csdnTripletDayInfo) {
final Integer likeStatus = csdnUserInfo.getLikeStatus();
if (LikeStatus.HAVE_ALREADY_LIKED.getCode().equals(likeStatus) || LikeStatus.LIKE_IS_FULL.getCode().equals(likeStatus)) {
return true;
......@@ -65,6 +66,7 @@ public class CsdnLikeServiceImpl implements CsdnLikeService {
if (status) {
log.info("文章{}点赞成功", articleId);
csdnUserInfo.setLikeStatus(LikeStatus.LIKE_SUCCESSFUL.getCode());
csdnTripletDayInfo.setLikeNum(csdnTripletDayInfo.getLikeNum() + 1);
} else {
log.info("文章{}点赞取消", articleId);
csdnUserInfo.setLikeStatus(LikeStatus.CANCEL_LIKES.getCode());
......
......@@ -2,6 +2,7 @@ package com.kwan.springbootkwan.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kwan.springbootkwan.entity.CsdnTripletDayInfo;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
import com.kwan.springbootkwan.enums.CommentStatus;
......@@ -10,6 +11,7 @@ import com.kwan.springbootkwan.service.CsdnCollectService;
import com.kwan.springbootkwan.service.CsdnCommentService;
import com.kwan.springbootkwan.service.CsdnLikeService;
import com.kwan.springbootkwan.service.CsdnService;
import com.kwan.springbootkwan.service.CsdnTripletDayInfoService;
import com.kwan.springbootkwan.service.CsdnUserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -27,7 +29,8 @@ public class CsdnServiceImpl implements CsdnService {
@Value("${csdn.num_of_articles_per_person}")
private Integer numOfArticlesPerPerson;
@Autowired
private CsdnLikeService csdnLikeService;
@Autowired
private CsdnUserInfoService csdnUserInfoService;
@Autowired
......@@ -37,15 +40,13 @@ public class CsdnServiceImpl implements CsdnService {
@Autowired
private CsdnCommentService csdnCommentService;
@Autowired
private CsdnLikeService csdnLikeService;
private CsdnTripletDayInfoService csdnTripletDayInfoService;
@Override
public void singleArticle(CsdnUserInfo csdnUserInfo) {
final String username = csdnUserInfo.getUserName();
List<BusinessInfoResponse.ArticleData.Article> list = csdnArticleService.getArticles(username);
if (list == null) {
return;
}
if (CollectionUtil.isNotEmpty(list)) {
final int size = list.size();
numOfArticlesPerPerson = size < numOfArticlesPerPerson ? size : numOfArticlesPerPerson;
for (int i = 0; i < numOfArticlesPerPerson; i++) {
......@@ -53,39 +54,41 @@ public class CsdnServiceImpl implements CsdnService {
final String type = article.getType();
if (!StringUtils.equals("blog", type)) {
csdnUserInfo.setArticleType(type);
csdnUserInfo.setUpdateTime(new Date());
csdnUserInfoService.updateById(csdnUserInfo);
continue;
}
//获取每日三连总信息
final CsdnTripletDayInfo csdnTripletDayInfo = csdnTripletDayInfoService.todayInfo();
final String urlInfo = article.getUrl();
String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1);
//点赞
final Boolean isLike = csdnLikeService.isLike(articleId, csdnUserInfo);
if (!isLike) {
csdnLikeService.like(articleId, csdnUserInfo);
csdnLikeService.like(articleId, csdnUserInfo, csdnTripletDayInfo);
}
//查看已经评论总数量
QueryWrapper<CsdnUserInfo> wrapper = new QueryWrapper<>();
wrapper.eq("is_delete", 0);
wrapper.eq("comment_status", 9);
final List<CsdnUserInfo> comments = csdnUserInfoService.list(wrapper);
if (CollectionUtil.isEmpty(comments) || comments.size() < 49) {
final Integer commentNum = csdnTripletDayInfo.getCommentNum();
if (commentNum < 49) {
//评论
final Boolean comment = csdnCommentService.isComment(article, csdnUserInfo);
if (!comment) {
csdnCommentService.comment(articleId, csdnUserInfo);
}
csdnCommentService.comment(articleId, csdnUserInfo, csdnTripletDayInfo);
}
if (CollectionUtil.isNotEmpty(comments) && comments.size() >= 49) {
} else {
csdnUserInfo.setCommentStatus(CommentStatus.COMMENT_NUM_49.getCode());
}
//收藏
final Boolean collect = csdnCollectService.isCollect(articleId, csdnUserInfo);
if (!collect) {
csdnCollectService.collect(article, csdnUserInfo);
}
csdnCollectService.collect(article, csdnUserInfo, csdnTripletDayInfo);
}
csdnTripletDayInfo.setUpdateTime(new Date());
csdnTripletDayInfoService.updateById(csdnTripletDayInfo);
csdnUserInfo.setUpdateTime(new Date());
csdnUserInfoService.updateById(csdnUserInfo);
}
}
}
@Override
......
package com.kwan.springbootkwan.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kwan.springbootkwan.entity.CsdnTripletDayInfo;
import com.kwan.springbootkwan.mapper.CsdnTripletDayInfoMapper;
import com.kwan.springbootkwan.service.CsdnTripletDayInfoService;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
/**
* 每日三连监控(CsdnTripletDayInfo)表服务实现类
*
* @author makejava
* @since 2023-10-26 20:55:31
*/
@Service("csdnTripletDayInfoService")
public class CsdnTripletDayInfoServiceImpl extends ServiceImpl<CsdnTripletDayInfoMapper, CsdnTripletDayInfo> implements CsdnTripletDayInfoService {
@Override
public CsdnTripletDayInfo todayInfo() {
Date currentDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String formattedDate = sdf.format(currentDate);
QueryWrapper<CsdnTripletDayInfo> wrapper = new QueryWrapper<>();
wrapper.eq("is_delete", 0);
wrapper.eq("triplet_date", formattedDate);
final CsdnTripletDayInfo one = this.getOne(wrapper);
if (Objects.isNull(one)) {
CsdnTripletDayInfo csdnTripletDayInfo = new CsdnTripletDayInfo();
csdnTripletDayInfo.setTripletDate(new Date());
csdnTripletDayInfo.setLikeNum(0);
csdnTripletDayInfo.setCollectNum(0);
csdnTripletDayInfo.setCommentNum(0);
csdnTripletDayInfo.setUpdateTime(new Date());
this.save(csdnTripletDayInfo);
}
return one;
}
}
package com.kwan.springbootkwan.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
import com.kwan.springbootkwan.entity.resp.BusinessInfoResponse;
import com.kwan.springbootkwan.enums.CollectStatus;
import com.kwan.springbootkwan.enums.CommentStatus;
import com.kwan.springbootkwan.enums.LikeStatus;
import com.kwan.springbootkwan.mapper.CsdnUserInfoMapper;
import com.kwan.springbootkwan.service.CsdnArticleService;
import com.kwan.springbootkwan.service.CsdnCollectService;
import com.kwan.springbootkwan.service.CsdnUserInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* csdn用户信息(CsdnUserInfo)表服务实现类
*
......@@ -15,5 +27,38 @@ import org.springframework.stereotype.Service;
@Service("csdnUserInfoService")
public class CsdnUserInfoServiceImpl extends ServiceImpl<CsdnUserInfoMapper, CsdnUserInfo> implements CsdnUserInfoService {
@Autowired
private CsdnCollectService csdnCollectService;
@Autowired
private CsdnArticleService csdnArticleService;
@Override
public void resetCurrentStatus() {
QueryWrapper<CsdnUserInfo> wrapper = new QueryWrapper<>();
wrapper.eq("is_delete", 0);
final List<CsdnUserInfo> list = this.list(wrapper);
if (CollectionUtil.isNotEmpty(list)) {
for (CsdnUserInfo csdnUserInfo : list) {
final String userName = csdnUserInfo.getUserName();
final List<BusinessInfoResponse.ArticleData.Article> articles = csdnArticleService.getArticles(userName);
if (CollectionUtil.isNotEmpty(articles)) {
final BusinessInfoResponse.ArticleData.Article article = articles.get(0);
final String type = article.getType();
if (StringUtils.equals(type, "blog")) {
final String urlInfo = article.getUrl();
String articleId = urlInfo.substring(urlInfo.lastIndexOf("/") + 1);
final Boolean collect = csdnCollectService.isCollect(articleId, csdnUserInfo);
if (!collect) {
csdnUserInfo.setLikeStatus(LikeStatus.UN_PROCESSED.getCode());
csdnUserInfo.setCollectStatus(CollectStatus.UN_PROCESSED.getCode());
csdnUserInfo.setCommentStatus(CommentStatus.UN_PROCESSED.getCode());
this.updateById(csdnUserInfo);
}
}
}
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册