diff --git a/.gradle/8.14.3/executionHistory/executionHistory.bin b/.gradle/8.14.3/executionHistory/executionHistory.bin index e4eba04..16c706e 100644 Binary files a/.gradle/8.14.3/executionHistory/executionHistory.bin and b/.gradle/8.14.3/executionHistory/executionHistory.bin differ diff --git a/.gradle/8.14.3/executionHistory/executionHistory.lock b/.gradle/8.14.3/executionHistory/executionHistory.lock index 4d70860..f790f34 100644 Binary files a/.gradle/8.14.3/executionHistory/executionHistory.lock and b/.gradle/8.14.3/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.14.3/fileHashes/fileHashes.bin b/.gradle/8.14.3/fileHashes/fileHashes.bin index d3f2bf3..62a5f70 100644 Binary files a/.gradle/8.14.3/fileHashes/fileHashes.bin and b/.gradle/8.14.3/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.14.3/fileHashes/fileHashes.lock b/.gradle/8.14.3/fileHashes/fileHashes.lock index 0fa2cdc..5510219 100644 Binary files a/.gradle/8.14.3/fileHashes/fileHashes.lock and b/.gradle/8.14.3/fileHashes/fileHashes.lock differ diff --git a/.gradle/8.14.3/fileHashes/resourceHashesCache.bin b/.gradle/8.14.3/fileHashes/resourceHashesCache.bin index 5c3d280..1bc0848 100644 Binary files a/.gradle/8.14.3/fileHashes/resourceHashesCache.bin and b/.gradle/8.14.3/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 9a75d9e..95f84cb 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index e2acbad..15fac7c 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 63242b2..dec5468 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/src/main/java/com/stockport/server/application/scheduler/indexData/IndexDataScheduler.java b/src/main/java/com/stockport/server/application/scheduler/indexData/IndexDataScheduler.java index e13e2b1..9ae6404 100644 --- a/src/main/java/com/stockport/server/application/scheduler/indexData/IndexDataScheduler.java +++ b/src/main/java/com/stockport/server/application/scheduler/indexData/IndexDataScheduler.java @@ -13,15 +13,15 @@ public class IndexDataScheduler { private final IndexDataService indexDataService; -// @Scheduled(cron = "0 0/5 9-18 * * MON-FRI", zone = "Asia/Seoul") // todo: 공휴일/휴장일 스케쥴러 처리 필요. -// public void updateKospi() { -// indexDataService.updateCurrentIndexData(MarketType.KOSPI); -// log.info("[Scheduler] 코스피 데이터 업데이트 완료"); -// } -// -// @Scheduled(cron = "0 0/5 9-18 * * MON-FRI", zone = "Asia/Seoul") // todo: 공휴일/휴장일 스케쥴러 처리 필요. -// public void updateKosdaq() { -// indexDataService.updateCurrentIndexData(MarketType.KOSPI); -// log.info("[Scheduler] 코스닥 데이터 업데이트 완료"); -// } + @Scheduled(cron = "0 0/5 9-18 * * MON-FRI", zone = "Asia/Seoul") // todo: 공휴일/휴장일 스케쥴러 처리 필요. + public void updateKospi() { + indexDataService.updateCurrentIndexData(MarketType.KOSPI); + log.info("[Scheduler] 코스피 데이터 업데이트 완료"); + } + + @Scheduled(cron = "0 0/5 9-18 * * MON-FRI", zone = "Asia/Seoul") // todo: 공휴일/휴장일 스케쥴러 처리 필요. + public void updateKosdaq() { + indexDataService.updateCurrentIndexData(MarketType.KOSPI); + log.info("[Scheduler] 코스닥 데이터 업데이트 완료"); + } } diff --git a/src/main/java/com/stockport/server/application/scheduler/stock/StockScheduler.java b/src/main/java/com/stockport/server/application/scheduler/stock/StockScheduler.java index 51dae71..25f53b8 100644 --- a/src/main/java/com/stockport/server/application/scheduler/stock/StockScheduler.java +++ b/src/main/java/com/stockport/server/application/scheduler/stock/StockScheduler.java @@ -12,15 +12,15 @@ public class StockScheduler { private final StockService stockService; -// @Scheduled(cron = "0 5 18 * * MON-FRI", zone = "Asia/Seoul") // todo: 공휴일/휴장일 스케쥴러 처리 필요. -// public void saveDailyStockData() { -// stockService.saveDailyStockData(); -// log.info("[Scheduler] 일별 주가 데이터 업데이트 완료"); -// } -// -// @Scheduled(cron = "0 0/5 9-18 * * MON-FRI", zone = "Asia/Seoul") // todo: 공휴일/휴장일 스케쥴러 처리 필요. -// public void updateStockData() { -// stockService.updateCurrentStockData(); -// log.info("[Scheduler] 주가 데이터 업데이트 완료"); -// } + @Scheduled(cron = "0 5 18 * * MON-FRI", zone = "Asia/Seoul") // todo: 공휴일/휴장일 스케쥴러 처리 필요. + public void saveDailyStockData() { + stockService.saveDailyStockData(); + log.info("[Scheduler] 일별 주가 데이터 업데이트 완료"); + } + + @Scheduled(cron = "0 0/5 9-18 * * MON-FRI", zone = "Asia/Seoul") // todo: 공휴일/휴장일 스케쥴러 처리 필요. + public void updateStockData() { + stockService.updateCurrentStockData(); + log.info("[Scheduler] 주가 데이터 업데이트 완료"); + } } diff --git a/src/main/java/com/stockport/server/application/service/stock/StockServiceImpl.java b/src/main/java/com/stockport/server/application/service/stock/StockServiceImpl.java index b33a583..ad2b93d 100644 --- a/src/main/java/com/stockport/server/application/service/stock/StockServiceImpl.java +++ b/src/main/java/com/stockport/server/application/service/stock/StockServiceImpl.java @@ -27,8 +27,11 @@ import org.springframework.stereotype.Service; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; @Service @Slf4j @@ -58,7 +61,7 @@ public Page getStocksByMarketCap(Pageable pageable) { public StockInfoResponse getStockInfo(String stockCode, LocalDate startDate, LocalDate endDate) { Stock stock = stockRepository.findByStockCd(stockCode) .orElseThrow(() -> new GeneralException(ErrorStatus.STOCK_NOT_FOUND)); - List stockPriceResponseList = stockPriceRepository.findByStockAndBaseDateBetween(stock, startDate, endDate) + List stockPriceResponseList = stockPriceRepository.findByStockAndBaseDateBetweenOrderByBaseDateDesc(stock, startDate, endDate) .stream().map(StockPriceResponse::of).toList(); return StockInfoResponse.of(stock, stockPriceResponseList); } @@ -113,13 +116,22 @@ public void updatePeriodicStockData(LocalDate startDate, LocalDate endDate) { @Override @Transactional public void saveDailyStockData() { + LocalDate today = LocalDate.now(); + + Set savedId = stockPriceRepository.findAllByBaseDate(today).stream() + .map(sp -> sp.getStock().getStockCd()) + .collect(Collectors.toSet()); List stockList = stockRepository.findAll(); + + List savePriceList = new ArrayList<>(); for (Stock stock : stockList) { - if (stockPriceRepository.existsByStockAndBaseDate(stock, LocalDate.now())) + if (savedId.contains(stock.getStockCd())) continue; StockPrice stockPrice = stock.getCurrentPriceInfo().toStockPriceEntity(); stockPrice.updateStock(stock); - stockPriceRepository.save(stockPrice); + + savePriceList.add(stockPrice); } + stockPriceRepository.saveAll(savePriceList); } } diff --git a/src/main/java/com/stockport/server/domain/stock/repository/StockPriceRepository.java b/src/main/java/com/stockport/server/domain/stock/repository/StockPriceRepository.java index 3ee0dee..4a632c6 100644 --- a/src/main/java/com/stockport/server/domain/stock/repository/StockPriceRepository.java +++ b/src/main/java/com/stockport/server/domain/stock/repository/StockPriceRepository.java @@ -11,9 +11,7 @@ import java.util.List; public interface StockPriceRepository extends JpaRepository { - List findByStockAndBaseDateBetween(Stock stock, LocalDate startDate, LocalDate endDate); - - boolean existsByStockAndBaseDate(Stock stock, LocalDate baseDate); + List findByStockAndBaseDateBetweenOrderByBaseDateDesc(Stock stock, LocalDate startDate, LocalDate endDate); @Query(""" select sp.baseDate @@ -26,4 +24,6 @@ List findAllBaseDatesByStockAndDateRange( @Param("start") LocalDate start, @Param("end") LocalDate end ); + + List findAllByBaseDate(LocalDate today); }