fix:定时任务调整

上级 524e7c46
......@@ -54,6 +54,18 @@ public class CsdnController {
@GetMapping("/resetCurrentStatus")
public Result resetCurrentStatus() {
csdnUserInfoService.resetCurrentStatus();
return Result.ok("重置当天状态完成");
return Result.ok("重置新博客状态完成");
}
@GetMapping("/resetUserDayStatus")
public Result resetUserDayStatus() {
csdnUserInfoService.resetUserDayStatus();
return Result.ok("重置新一天用户状态完成");
}
@GetMapping("/resetDayStatus")
public Result resetDayStatus() {
csdnUserInfoService.resetUserDayStatus();
return Result.ok("重置新一天状态完成");
}
}
package com.kwan.springbootkwan.schedule;
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;
......@@ -17,8 +16,6 @@ public class CsdnSchedule {
@Autowired
private CsdnService csdnService;
@Autowired
private CsdnCommentService csdnCommentService;
@Autowired
private CsdnUserInfoService csdnUserInfoService;
@Autowired
private CsdnAutoReplyService csdnAutoReplyService;
......@@ -40,12 +37,19 @@ public class CsdnSchedule {
}
@Scheduled(cron = "0 0/30 * * * ?")
public void executeInit() {
public void resetCurrentStatus() {
log.info("executeInit task is running ... ...");
csdnUserInfoService.resetCurrentStatus();
log.info("executeInit task is finish ... ...");
}
@Scheduled(cron = "0 0 2 * * ?")
public void resetUserDayStatus() {
log.info("executeInit task is running ... ...");
csdnUserInfoService.resetUserDayStatus();
log.info("executeInit task is finish ... ...");
}
@Scheduled(cron = "0 0 1 * * ?")
public void resetTripletDayInfo() {
log.info("resetTripletDayInfo task is running ... ...");
......
......@@ -10,9 +10,15 @@ import com.kwan.springbootkwan.entity.CsdnUserInfo;
* @since 2023-10-23 16:03:14
*/
public interface CsdnUserInfoService extends IService<CsdnUserInfo> {
/**
* 重置新文章的状态
*/
void resetCurrentStatus();
/**
* 重置新一天的状态
*/
void resetUserDayStatus();
}
......@@ -5,10 +5,12 @@ 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 lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Objects;
/**
......@@ -17,13 +19,15 @@ import java.util.Objects;
* @author makejava
* @since 2023-10-26 20:55:31
*/
@Slf4j
@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");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
String formattedDate = sdf.format(currentDate);
log.info("当前日期是:{}", formattedDate);
QueryWrapper<CsdnTripletDayInfo> wrapper = new QueryWrapper<>();
wrapper.eq("is_delete", 0);
wrapper.eq("triplet_date", formattedDate);
......
......@@ -60,5 +60,39 @@ public class CsdnUserInfoServiceImpl extends ServiceImpl<CsdnUserInfoMapper, Csd
}
}
}
@Override
public void resetUserDayStatus() {
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 Integer likeStatus = csdnUserInfo.getLikeStatus();
if (!LikeStatus.HAVE_ALREADY_LIKED.getCode().equals(likeStatus) && !LikeStatus.LIKE_SUCCESSFUL.getCode().equals(likeStatus)) {
csdnUserInfo.setLikeStatus(LikeStatus.UN_PROCESSED.getCode());
}
final Integer collectStatus = csdnUserInfo.getCollectStatus();
if (!CollectStatus.COLLECT_SUCCESSFUL.getCode().equals(collectStatus) && !CollectStatus.HAVE_ALREADY_COLLECT.getCode().equals(collectStatus)) {
csdnUserInfo.setCollectStatus(CollectStatus.UN_PROCESSED.getCode());
}
final Integer commentStatus = csdnUserInfo.getCommentStatus();
if (!CommentStatus.COMMENT_SUCCESSFUL.getCode().equals(commentStatus) && !CommentStatus.HAVE_ALREADY_COMMENT.getCode().equals(commentStatus)) {
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.
先完成此消息的编辑!
想要评论请 注册