|
|
@@ -11,18 +11,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.time.LocalTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import java.util.stream.IntStream;
|
|
|
|
|
|
@Component
|
|
|
@EnableScheduling
|
|
|
@@ -66,9 +61,9 @@ public class ScheduleTask {
|
|
|
ScheduleTournamentsReletionMapper scheduleTournamentsReletionMapper;
|
|
|
|
|
|
/**
|
|
|
- * 每天上午 11:15 执行
|
|
|
+ * 每天 00:10 执行
|
|
|
*/
|
|
|
- @Scheduled(cron = "0 35 15 * * ?")
|
|
|
+ @Scheduled(cron = "0 10 00 * * ?")
|
|
|
public void generateMatchesForToday() {
|
|
|
LocalDate today = LocalDate.now();
|
|
|
log.info("开始生成今日比赛: {}", today);
|
|
|
@@ -109,95 +104,6 @@ public class ScheduleTask {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-/* *//**
|
|
|
- * 每天凌晨1点执行:生成当天的比赛/任务
|
|
|
- *//*
|
|
|
- @Scheduled(cron = "0 15 11 * * ?") // 每天1:00 AM
|
|
|
- public void generateMatchesForToday() {
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
- log.info("Starting schedule task for date: {}", today);
|
|
|
-
|
|
|
- DayOfWeek dayOfWeek = today.getDayOfWeek();
|
|
|
- log.info("Starting schedule task for date: {}, day: {}", today, dayOfWeek);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // 查询所有今天有效的配置
|
|
|
- List<ScheduleConfigVo> activeConfigs = baseMapper.findActiveConfigsForDate(
|
|
|
- today);
|
|
|
-
|
|
|
- for (ScheduleConfigVo config : activeConfigs) {
|
|
|
- try {
|
|
|
- CreationSchemeVo scheme = schemeRepo.selectCreationSchemeById(config.getCreationSchemeId());
|
|
|
- if (scheme == null) {
|
|
|
- log.warn("No scheme found for config: {}", config.getId());
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // 👇 核心:根据方案类型决定是否生成、生成哪些日期
|
|
|
- List<LocalDate> datesToGenerate = determineDatesToGenerate(scheme, config, today);
|
|
|
- if (datesToGenerate.isEmpty()) {
|
|
|
- continue; // 无需生成
|
|
|
- }
|
|
|
-
|
|
|
- // 获取执行时间点(如 09:00, 14:30)
|
|
|
- List<LocalTime> execTimes = getExecTimes(config.getId());
|
|
|
- if (execTimes.isEmpty()) continue;
|
|
|
-
|
|
|
- // TODO 生成比赛
|
|
|
- generateMatches(config, datesToGenerate, execTimes);
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("Error generating matches for config: {}", config.getId(), e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- log.info("Schedule task completed for date: {}", today);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- *//**
|
|
|
- * 这些日期批量生成
|
|
|
- * @param config
|
|
|
- * @param targetDates
|
|
|
- * @param execTimes
|
|
|
- *//*
|
|
|
- private void generateMatches(
|
|
|
- ScheduleConfigVo config,
|
|
|
- List<LocalDate> targetDates,
|
|
|
- List<LocalTime> execTimes) {
|
|
|
-
|
|
|
- for (LocalDate date : targetDates) {
|
|
|
- // ✅ 判断该天是否满足重复规则
|
|
|
- if (!shouldGenerateOnDate(config.getId(), date)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- for (LocalTime time : execTimes) {
|
|
|
- LocalDateTime triggerTime = LocalDateTime.of(date, time);
|
|
|
-
|
|
|
- // ✅ 防重:检查是否已存在该场比赛
|
|
|
- if (scheduleTimeMapper.existsByConfigIdAndTime(config.getId(), triggerTime)) {
|
|
|
- log.debug("Match already exists: config={}, time={}", config.getId(), triggerTime);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // ✅ 创建比赛
|
|
|
- autowiredTournamentData(config.getTemplateId(), triggerTime);
|
|
|
- }
|
|
|
- }
|
|
|
- }*/
|
|
|
-
|
|
|
/**
|
|
|
* 自动组装赛事数据
|
|
|
* @param templateId
|
|
|
@@ -205,9 +111,7 @@ public class ScheduleTask {
|
|
|
*/
|
|
|
public Boolean autowiredTournamentData(Long templateId,LocalDateTime triggerTime) {
|
|
|
try {
|
|
|
-
|
|
|
TournamentsVo tournamentsVo = tournamentsTemplateMapper.selectVoByIdInfoTemplate(templateId);
|
|
|
-
|
|
|
// 模拟构造 TournamentsDto 数据
|
|
|
TournamentsDto bo = new TournamentsDto();
|
|
|
// 定义你想要的日期时间格式
|
|
|
@@ -291,61 +195,5 @@ public class ScheduleTask {
|
|
|
|
|
|
|
|
|
|
|
|
- private List<LocalTime> getExecTimes(Long configId) {
|
|
|
- return scheduleTimeMapper.selectScheduleTimeInfoById(configId)
|
|
|
- .stream()
|
|
|
- .map(ScheduleTimeVo::getExecTime)
|
|
|
- .collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
- private List<LocalDate> determineDatesToGenerate(
|
|
|
- CreationSchemeVo scheme, ScheduleConfigVo config, LocalDate today) {
|
|
|
-
|
|
|
- String code = scheme.getCode().toUpperCase();
|
|
|
-
|
|
|
- switch (code) {
|
|
|
- case "DAILY":
|
|
|
- return Collections.singletonList(today);
|
|
|
-
|
|
|
- case "WEEKLY":
|
|
|
- if (today.getDayOfWeek() == DayOfWeek.SUNDAY) {
|
|
|
- // 下周一
|
|
|
- LocalDate nextMonday = today.plusDays(1); // 周日 +1 = 周一
|
|
|
- return getDateRange(nextMonday, 0, 6); // 下周一 ~ 下周日
|
|
|
- }
|
|
|
- return Collections.emptyList();
|
|
|
-
|
|
|
- case "NEXT_3_DAYS":
|
|
|
- return getDateRange(today, 0, 2); // 今天、明天、后天
|
|
|
-
|
|
|
- default:
|
|
|
- log.warn("Unknown scheme code: {}", code);
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 辅助方法:生成从 today 起的连续 n 天
|
|
|
- private List<LocalDate> getDateRange(LocalDate start, int fromInclusive, int toInclusive) {
|
|
|
- return IntStream.rangeClosed(fromInclusive, toInclusive)
|
|
|
- .mapToObj(start::plusDays)
|
|
|
- .collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private boolean shouldGenerateOnDate(Long configId, LocalDate date) {
|
|
|
- List<ScheduleRepeatVo> repeats = scheduleRepeatMapper.selectScheduleRepeatByConfigId(configId);
|
|
|
- if (repeats.isEmpty()) return false;
|
|
|
-
|
|
|
- return repeats.stream().anyMatch(repeat -> {
|
|
|
- String type = repeat.getRepeatType();
|
|
|
- return "DAILY".equals(type) ||
|
|
|
- ("WEEKLY_MONDAY".equals(type) && date.getDayOfWeek() == DayOfWeek.MONDAY) ||
|
|
|
- ("WEEKLY_WEDNESDAY".equals(type) && date.getDayOfWeek() == DayOfWeek.WEDNESDAY);
|
|
|
- // 可扩展...
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
}
|