diff --git a/src/main/kotlin/report/TradingReportManager.kt b/src/main/kotlin/report/TradingReportManager.kt index 6e82d06..e0b12e1 100644 --- a/src/main/kotlin/report/TradingReportManager.kt +++ b/src/main/kotlin/report/TradingReportManager.kt @@ -114,23 +114,41 @@ object TradingReportManager : TradingReportService { } } - // 2. 정규장 마감 리포트 (15:35 ~ 15:45) + // 2. 정규장 마감 리포트 (15:35 이후 ~ 19:30 이전, 당일 마감 미발송 시 자동 캡처) val endKey = "${today}_END" - if (now.isAfter(LocalTime.of(15, 34)) && now.isBefore(LocalTime.of(15, 45))) { + if (now.isAfter(LocalTime.of(15, 34)) && now.isBefore(LocalTime.of(19, 30))) { if (!reportedSnapshotMap.containsKey(endKey)) { - reportedSnapshotMap[endKey] = true - println("🏁 [Report] 15:35 정규장 마감 스냅샷 및 텔레그램 리포트 자동 실행") - recordAssetSnapshot(SnapshotType.END, balance, "정규장 마감 운용 스냅샷") + val alreadyExistsInDb = transaction(DatabaseFactory.reportDb) { + AssetSnapshotTable.select { + (AssetSnapshotTable.date eq today) and (AssetSnapshotTable.snapshotType eq SnapshotType.END.name) + }.count() > 0 + } + if (!alreadyExistsInDb) { + reportedSnapshotMap[endKey] = true + println("🏁 [Report] 정규장 마감 스냅샷 및 텔레그램 리포트 자동 실행 (시각: $now)") + recordAssetSnapshot(SnapshotType.END, balance, "정규장 마감 운용 스냅샷") + } else { + reportedSnapshotMap[endKey] = true + } } } - // 3. 애프터 마켓(시간외) 거래 종료 마감 결산 (19:30 ~ 19:45) + // 3. 애프터 마켓(시간외) 거래 종료 마감 결산 (19:30 이후 ~ 당일 업무 종료) val afterKey = "${today}_AFTER_CLOSE" - if (now.isAfter(LocalTime.of(19, 29)) && now.isBefore(LocalTime.of(19, 45))) { + if (now.isAfter(LocalTime.of(19, 29))) { if (!reportedSnapshotMap.containsKey(afterKey)) { - reportedSnapshotMap[afterKey] = true - println("🌙 [Report] 19:30 애프터마켓(시간외) 거래 종료 최종 스냅샷 및 텔레그램 리포트 자동 실행") - recordAssetSnapshot(SnapshotType.AFTER_CLOSE, balance, "애프터마켓 19:30 마감 최종 결산 스냅샷") + val alreadyExistsInDb = transaction(DatabaseFactory.reportDb) { + AssetSnapshotTable.select { + (AssetSnapshotTable.date eq today) and (AssetSnapshotTable.snapshotType eq SnapshotType.AFTER_CLOSE.name) + }.count() > 0 + } + if (!alreadyExistsInDb) { + reportedSnapshotMap[afterKey] = true + println("🌙 [Report] 19:30 애프터마켓(시간외) 거래 종료 최종 스냅샷 및 텔레그램 리포트 자동 실행 (시각: $now)") + recordAssetSnapshot(SnapshotType.AFTER_CLOSE, balance, "애프터마켓 19:30 마감 최종 결산 스냅샷") + } else { + reportedSnapshotMap[afterKey] = true + } } } }