123
This commit is contained in:
@@ -10,9 +10,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -29,10 +31,12 @@ public class RankJob {
|
||||
@Autowired
|
||||
private AnchorService anchorService;
|
||||
|
||||
|
||||
// 凌晨0点1分执行一次
|
||||
@Scheduled(cron = "0 1 0 * * ? ")
|
||||
public void persistentDb() {
|
||||
LocalDate date = LocalDate.now().plusDays(-1);
|
||||
LocalDate now = LocalDate.now();
|
||||
LocalDate date = now.plusDays(-1);
|
||||
try {
|
||||
rankService.saveDayRank(date,1);
|
||||
} catch (Exception e) {
|
||||
@@ -43,29 +47,30 @@ public class RankJob {
|
||||
} catch (Exception e) {
|
||||
log.error("保存邀请 日榜失败", e);
|
||||
}
|
||||
DayOfWeek week = date.getDayOfWeek();
|
||||
DayOfWeek week = now.getDayOfWeek();
|
||||
if (week.getValue() == 1) { // 昨天是周一 做一下持久化
|
||||
LocalDate lastWeekDate = now.plusDays(-7);
|
||||
try {
|
||||
rankService.saveWeekRank(date,1);
|
||||
rankService.saveWeekRank(lastWeekDate,1);
|
||||
} catch (Exception e) {
|
||||
log.error("保存魅力 周榜失败", e);
|
||||
}
|
||||
try {
|
||||
rankService.saveWeekRank(date,2);
|
||||
rankService.saveWeekRank(lastWeekDate,2);
|
||||
} catch (Exception e) {
|
||||
log.error("保存邀请 周榜失败", e);
|
||||
}
|
||||
}
|
||||
int month = date.getDayOfMonth();
|
||||
int month = now.getDayOfMonth();
|
||||
if (month == 1) { // 昨天是1号
|
||||
LocalDate lastMonthDate = now.plusMonths(-1);
|
||||
try {
|
||||
rankService.saveMonthRank(date,1);
|
||||
rankService.saveMonthRank(lastMonthDate,1);
|
||||
} catch (Exception e) {
|
||||
log.error("保存魅力 月榜失败", e);
|
||||
}
|
||||
try {
|
||||
|
||||
rankService.saveMonthRank(date,2);
|
||||
rankService.saveMonthRank(lastMonthDate,2);
|
||||
} catch (Exception e) {
|
||||
log.error("保存邀请 月榜失败", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user