This commit is contained in:
张良(004796)
2024-01-30 21:11:28 +08:00
parent 5cbed4c929
commit d4c0f477bd
10 changed files with 34 additions and 10 deletions

View File

@@ -0,0 +1,39 @@
package com.ruoyi.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;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class Clear2HoursJob {
@Autowired
private DynamicService dynamicService;
@Autowired
private UserChatRecordService userChatRecordService;
// 每隔小时执行一次
// @Scheduled(cron = "0 0 0/2 * * ? *")
public void clearRun() {
try {
log.info("定时删除动态== 开始");
dynamicService.clearDynamic(12);
log.info("定时删除动态== 结束");
}catch (Exception e){
log.error("定时删除动态== 异常",e);
}
try {
log.info("定时删除聊天记录== 开始");
userChatRecordService.clearChatRecord(24);
log.info("定时删除聊天记录== 结束");
}catch (Exception e){
log.error("定时删除聊天记录== 异常",e);
}
}
}

View File

@@ -0,0 +1,29 @@
package com.ruoyi.job;
import com.ruoyi.cai.service.SmsVerifyService;
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);
}
}
}

View File

@@ -0,0 +1,36 @@
package com.ruoyi.job;
import com.ruoyi.cai.manager.UserForbidManager;
import com.ruoyi.cai.service.SysPushService;
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 ForbidJob {
@Autowired
private UserForbidManager userForbidManager;
@Autowired
private SysPushService sysPushService;
/**
* 每12小时执行一次
*/
@Scheduled(cron = "0 0 11,23 * * ? ")
public void checkForbid(){
try {
userForbidManager.checkAll();
}catch (Exception e){
log.error("黑名单失效检测失败!",e);
}
try {
sysPushService.checkAll();
}catch (Exception e){
log.error("系统推送定时任务检测失败!",e);
}
}
}

View File

@@ -0,0 +1,38 @@
package com.ruoyi.job;
import com.ruoyi.cai.manager.HomeManager;
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 HomeRecommendJob {
@Autowired
private HomeManager homeManager;
// 每6分钟执行一次
@Scheduled(cron = "0 0/6 * * * ? ")
public void clearRun() {
try {
homeManager.refreshHomeActiveCache();
}catch (Exception e){
log.error("刷新首页活跃用户失败",e);
}
try {
homeManager.refreshHomeNewCache();
}catch (Exception e){
log.error("刷新首页新用户失败",e);
}
try {
homeManager.refreshHomeRecommendCache();
}catch (Exception e){
log.error("刷新首页推荐用户失败",e);
}
}
}

View File

@@ -0,0 +1,25 @@
package com.ruoyi.job;
import com.ruoyi.cai.service.DayIncomeStatisticsService;
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.time.LocalDate;
@Component
@Slf4j
public class IncomeStatisticsJob {
@Autowired
private DayIncomeStatisticsService dayIncomeStatisticsService;
@Scheduled(cron = "0 0/6 * * * ?")
public void persistentDb() {
try {
dayIncomeStatisticsService.refreshByDate(LocalDate.now());
}catch (Exception e){
log.error("更新每日收益统计失败!",e);
}
}
}

View File

@@ -0,0 +1,80 @@
package com.ruoyi.job;
import com.ruoyi.cai.service.DayIncomeStatisticsService;
import com.ruoyi.cai.service.RankService;
import com.ruoyi.cai.service.UserService;
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.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Component
@Slf4j
public class RankJob {
@Autowired
private RankService rankService;
@Autowired
private DayIncomeStatisticsService dayIncomeStatisticsService;
@Scheduled(cron = "0 1 0 * * ? ")
public void persistentDb() {
LocalDate date = LocalDateTime.now().plusDays(-1).toLocalDate();
try {
rankService.saveDayRank(date,1);
} catch (Exception e) {
log.error("保存魅力 日榜失败", e);
}
try {
rankService.saveDayRank(date,2);
} catch (Exception e) {
log.error("保存邀请 日榜失败", e);
}
DayOfWeek week = date.getDayOfWeek();
if (week.getValue() == 1) { // 昨天是周一 做一下持久化
try {
rankService.saveWeekRank(date,1);
} catch (Exception e) {
log.error("保存魅力 周榜失败", e);
}
try {
rankService.saveWeekRank(date,2);
} catch (Exception e) {
log.error("保存邀请 周榜失败", e);
}
}
int month = date.getDayOfMonth();
if (month == 1) { // 昨天是1号
try {
rankService.saveMonthRank(date,1);
} catch (Exception e) {
log.error("保存魅力 月榜失败", e);
}
try {
rankService.saveMonthRank(date,2);
} catch (Exception e) {
log.error("保存邀请 月榜失败", e);
}
}
try {
dayIncomeStatisticsService.refreshByDate(date);
}catch (Exception e){
log.error("更新昨日收益统计失败!",e);
}
try {
userService.refreshByAge();
}catch (Exception e){
log.error("刷新用户年龄失败!",e);
}
}
@Autowired
private UserService userService;
}