diff --git a/src/main/java/com/tem/bocai/schedules/BetSchedule.java b/src/main/java/com/tem/bocai/schedules/BetSchedule.java index 3891e37..3f9f91f 100644 --- a/src/main/java/com/tem/bocai/schedules/BetSchedule.java +++ b/src/main/java/com/tem/bocai/schedules/BetSchedule.java @@ -41,7 +41,7 @@ public class BetSchedule { private BetRecordRepository betRecordRepository; // 从7:02分钟起每5分钟执行一次 - // @Scheduled(cron = "30 2/5 * * * ?") + @Scheduled(cron = "30 2/5 * * * ?") public void placeBet() { LocalDateTime now = LocalDateTime.now(); int hour = now.getHour(); @@ -74,32 +74,32 @@ public class BetSchedule { return; } - // 检查winNum和loseNum字段是否合理 - Integer winNum = loginInfo.getWinNum(); - Integer loseNum = loginInfo.getLoseNum(); - - if (winNum != null || loseNum != null) { - // 根据LoginInfo的startTime 查询CompletedToday的resultAmount总和 判断是否达到 winNum 和 loseNum的值 - Date startTime = loginInfo.getStartTime(); - if (startTime != null) { - Double totalResultAmount = completedTodayRepository.sumResultAmountByCreateTimeAfter(startTime); - if (totalResultAmount != null) { - log.info(" - 今日盈亏总和: {}", totalResultAmount); - - // 判断是否达到止盈点 - if (totalResultAmount >= winNum) { - log.info("{}", currentTime + " - 已达到止盈点 " + winNum + ",跳过执行"); - return; - } - - // 判断是否达到止亏点 - if (totalResultAmount <= -loseNum) { - log.info("{}", currentTime + " - 已达到止亏点 " + loseNum + ",跳过执行"); - return; - } - } - } - } +// // 检查winNum和loseNum字段是否合理 +// Integer winNum = loginInfo.getWinNum(); +// Integer loseNum = loginInfo.getLoseNum(); +// +// if (winNum != null || loseNum != null) { +// // 根据LoginInfo的startTime 查询CompletedToday的resultAmount总和 判断是否达到 winNum 和 loseNum的值 +// Date startTime = loginInfo.getStartTime(); +// if (startTime != null) { +// Double totalResultAmount = completedTodayRepository.sumResultAmountByCreateTimeAfter(startTime); +// if (totalResultAmount != null) { +// log.info(" - 今日盈亏总和: {}", totalResultAmount); +// +// // 判断是否达到止盈点 +// if (totalResultAmount >= winNum) { +// log.info("{}", currentTime + " - 已达到止盈点 " + winNum + ",跳过执行"); +// return; +// } +// +// // 判断是否达到止亏点 +// if (totalResultAmount <= -loseNum) { +// log.info("{}", currentTime + " - 已达到止亏点 " + loseNum + ",跳过执行"); +// return; +// } +// } +// } +// } log.info("{}", currentTime + " - 开始执行投注..."); diff --git a/src/main/java/com/tem/bocai/schedules/CrawlerSchedule.java b/src/main/java/com/tem/bocai/schedules/CrawlerSchedule.java index cd38639..bfd099a 100644 --- a/src/main/java/com/tem/bocai/schedules/CrawlerSchedule.java +++ b/src/main/java/com/tem/bocai/schedules/CrawlerSchedule.java @@ -38,7 +38,7 @@ public class CrawlerSchedule { /*@Scheduled(cron = "0 6-59/5 7-23 * * ?") @Scheduled(cron = "0 0-55/5 0-6 * * ?")*/ // 从7:00分30秒起每5分钟执行一次 - // @Scheduled(cron = "30 0/5 * * * ?") + @Scheduled(cron = "30 0/5 * * * ?") public void executeLotteryDraw() { log.info("开始爬取开奖结果"); int retryCount = 0; diff --git a/src/main/java/com/tem/bocai/schedules/ExBetScriptSchedule.java b/src/main/java/com/tem/bocai/schedules/ExBetScriptSchedule.java index 414b6d9..9e389b0 100644 --- a/src/main/java/com/tem/bocai/schedules/ExBetScriptSchedule.java +++ b/src/main/java/com/tem/bocai/schedules/ExBetScriptSchedule.java @@ -41,91 +41,10 @@ public class ExBetScriptSchedule { @Value("${pypath}") private String pypath; - - /** - * 检查PyModel/current_data目录下最新的文件是否存在新数据 - * @return 如果存在新数据返回true,否则返回false - */ - private boolean checkNewDataExists() { - try { - File currentDataDir = new File(pypath, "current_data"); - if (!currentDataDir.exists() || !currentDataDir.isDirectory()) { - log.info("current_data目录不存在"); - return false; - } - File[] files = currentDataDir.listFiles(); - if (files == null || files.length == 0) { - log.info("current_data目录为空"); - return false; - } - - File latestFile = null; - FileTime latestTime = null; - - for (File file : files) { - if (file.getName().endsWith(".json")) { - Path path = Paths.get(file.getAbsolutePath()); - BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); - FileTime fileTime = attrs.lastModifiedTime(); - - if (latestTime == null || fileTime.compareTo(latestTime) > 0) { - latestTime = fileTime; - latestFile = file; - } - } - } - - if (latestFile == null) { - log.info("未找到JSON文件"); - return false; - } - - LocalDateTime fileModifiedTime = LocalDateTime.ofInstant( - latestTime.toInstant(), - ZoneId.systemDefault() - ); - - LocalDateTime now = LocalDateTime.now(); - LocalDateTime fiveMinutesAgo = now.minusMinutes(5); - - if (fileModifiedTime.isAfter(fiveMinutesAgo)) { - log.info("发现新数据文件: {}, 修改时间: {}", latestFile.getName(), fileModifiedTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); - return true; - } else { - log.info("最新数据文件: {}, 修改时间: {}, 超过5分钟,跳过执行", latestFile.getName(), fileModifiedTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); - return false; - } - - } catch (Exception e) { - log.error("检查新数据时发生错误:", e); - return false; - } - } - - /** - * 处理文件路径,确保路径正确 - * @param filePath 文件路径 - * @return 处理后的文件路径 - */ - private String handleFilePath(String filePath) { - // 处理路径分隔符,统一使用系统默认分隔符 - filePath = filePath.replace("/", System.getProperty("file.separator")); - filePath = filePath.replace("\\", System.getProperty("file.separator")); - - // 如果路径包含空格,确保路径被正确处理 - // Runtime.exec会自动处理带空格的路径,不需要手动添加引号 - - return filePath; - } - - public static void main(String[] args) { - ExBetScriptSchedule schedule = new ExBetScriptSchedule(); - schedule.executePythonScript(); - } // 从7:01分钟起每5分钟执行一次 - // @Scheduled(cron = "30 1/5 * * * ?") + @Scheduled(cron = "30 1/5 * * * ?") public void executePythonScript() { LocalDateTime now = LocalDateTime.now(); int hour = now.getHour(); @@ -387,4 +306,82 @@ public class ExBetScriptSchedule { log.error("保存投注记录到数据库失败:", e); } } + + + /** + * 检查PyModel/current_data目录下最新的文件是否存在新数据 + * @return 如果存在新数据返回true,否则返回false + */ + private boolean checkNewDataExists() { + try { + File currentDataDir = new File(pypath, "current_data"); + if (!currentDataDir.exists() || !currentDataDir.isDirectory()) { + log.info("current_data目录不存在"); + return false; + } + + File[] files = currentDataDir.listFiles(); + if (files == null || files.length == 0) { + log.info("current_data目录为空"); + return false; + } + + File latestFile = null; + FileTime latestTime = null; + + for (File file : files) { + if (file.getName().endsWith(".json")) { + Path path = Paths.get(file.getAbsolutePath()); + BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); + FileTime fileTime = attrs.lastModifiedTime(); + + if (latestTime == null || fileTime.compareTo(latestTime) > 0) { + latestTime = fileTime; + latestFile = file; + } + } + } + + if (latestFile == null) { + log.info("未找到JSON文件"); + return false; + } + + LocalDateTime fileModifiedTime = LocalDateTime.ofInstant( + latestTime.toInstant(), + ZoneId.systemDefault() + ); + + LocalDateTime now = LocalDateTime.now(); + LocalDateTime fiveMinutesAgo = now.minusMinutes(5); + + if (fileModifiedTime.isAfter(fiveMinutesAgo)) { + log.info("发现新数据文件: {}, 修改时间: {}", latestFile.getName(), fileModifiedTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); + return true; + } else { + log.info("最新数据文件: {}, 修改时间: {}, 超过5分钟,跳过执行", latestFile.getName(), fileModifiedTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); + return false; + } + + } catch (Exception e) { + log.error("检查新数据时发生错误:", e); + return false; + } + } + + /** + * 处理文件路径,确保路径正确 + * @param filePath 文件路径 + * @return 处理后的文件路径 + */ + private String handleFilePath(String filePath) { + // 处理路径分隔符,统一使用系统默认分隔符 + filePath = filePath.replace("/", System.getProperty("file.separator")); + filePath = filePath.replace("\\", System.getProperty("file.separator")); + + // 如果路径包含空格,确保路径被正确处理 + // Runtime.exec会自动处理带空格的路径,不需要手动添加引号 + + return filePath; + } }