This commit is contained in:
dute7liang
2024-01-20 18:11:05 +08:00
parent a1fbc045a1
commit 414c176cef
6 changed files with 122 additions and 26 deletions

View File

@@ -0,0 +1,61 @@
package com.ruoyi.cai.job;
import com.ruoyi.cai.service.RankService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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;
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);
}
}
}
}