This commit is contained in:
张良(004796)
2024-01-22 11:15:07 +08:00
parent a30b615fc3
commit 6750a17cb5
17 changed files with 255 additions and 31 deletions

View File

@@ -1,6 +1,7 @@
package com.ruoyi.cai.job;
import com.ruoyi.cai.service.DynamicService;
import com.ruoyi.cai.service.UserChatRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
@@ -8,14 +9,17 @@ import org.springframework.stereotype.Component;
@Component
@Slf4j
public class ClearJob {
public class Clear2HoursJob {
@Autowired
private DynamicService dynamicService;
@Autowired
private UserChatRecordService userChatRecordService;
@Scheduled(cron = "0 1 0 * * ? ")
public void persistentDb() {
// 每隔小时执行一次
// @Scheduled(cron = "0 0 0/2 * * ? *")
public void clearRun() {
try {
log.info("定时删除动态== 开始");
dynamicService.clearDynamic(12);
@@ -24,9 +28,11 @@ public class ClearJob {
log.error("定时删除动态== 异常",e);
}
try {
log.info("定时删除聊天记录== 开始");
userChatRecordService.clearChatRecord(24);
log.info("定时删除聊天记录== 结束");
}catch (Exception e){
log.error("定时删除聊天记录== 异常",e);
}
}

View File

@@ -0,0 +1,31 @@
package com.ruoyi.cai.job;
import com.ruoyi.cai.service.DynamicService;
import com.ruoyi.cai.service.SmsVerifyService;
import com.ruoyi.cai.service.UserChatRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class ClearDaysJob {
@Autowired
private SmsVerifyService smsVerifyService;
// 凌晨8点执行
@Scheduled(cron = "0 0 8 * * ? ")
public void clearRun() {
try {
log.info("定时删除短信记录== 开始");
smsVerifyService.clearSmsVerify(7);
log.info("定时删除短信记录== 结束");
}catch (Exception e){
log.error("定时删除短信记录== 异常",e);
}
}
}