添加投注定时器脚本

This commit is contained in:
2026-01-23 09:19:21 +08:00
parent 9c2153b05b
commit 96afd7fd27
4 changed files with 71 additions and 145 deletions

View File

@@ -0,0 +1,69 @@
package com.tem.bocai.schedules;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Component
public class BetSchedule {
// 从6:15分开始每隔5分钟投注一次6:15, 6:20, 6:25...23:25
@Scheduled(cron = "0 15/5 6-23 * * ?")
public void placeBet() {
LocalDateTime now = LocalDateTime.now();
int hour = now.getHour();
int minute = now.getMinute();
// 检查是否在6:15到23:25之间
if ((hour < 6) || (hour == 6 && minute < 15) ||
(hour > 23) || (hour == 23 && minute > 25)) {
String currentTime = now.format(
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
);
System.out.println(currentTime + " - 不在投注时间范围内,跳过执行");
return;
}
String currentTime = now.format(
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
);
System.out.println(currentTime + " - 开始执行投注...");
try {
// 模拟投注逻辑
executeBet();
System.out.println(currentTime + " - 投注执行完成");
} catch (Exception e) {
System.err.println(currentTime + " - 投注执行失败:");
e.printStackTrace();
}
}
/**
* 执行投注逻辑
*/
private void executeBet() {
// 这里实现具体的投注逻辑
// 1. 获取投注号码
// 2. 计算投注金额
// 3. 执行投注操作
// 4. 记录投注结果
// 模拟投注过程
System.out.println(" - 生成投注号码...");
System.out.println(" - 计算投注金额...");
System.out.println(" - 提交投注...");
System.out.println(" - 记录投注结果...");
// 模拟网络延迟
try {
Thread.sleep(1000); // 模拟1秒的处理时间
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}

View File

@@ -23,7 +23,7 @@ public class CrawlerSchedule {
// 每天凌晨2点执行爬取开奖结果
//@Scheduled(cron = "0 0 2 * * ?")
// 每7秒执行一次爬取开奖结果
//@Scheduled(cron = "*/9 * * * * ?")
@Scheduled(cron = "*/9 * * * * ?")
public void executeLotteryDraw() {
System.out.println("开始爬取开奖结果...");
int retryCount = 0;