Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .gradle/8.14.3/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/8.14.3/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.14.3/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/8.14.3/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/8.14.3/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/file-system.probe
Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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] 코스닥 데이터 업데이트 완료");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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] 주가 데이터 업데이트 완료");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,7 +61,7 @@ public Page<StockRankResponse> 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<StockPriceResponse> stockPriceResponseList = stockPriceRepository.findByStockAndBaseDateBetween(stock, startDate, endDate)
List<StockPriceResponse> stockPriceResponseList = stockPriceRepository.findByStockAndBaseDateBetweenOrderByBaseDateDesc(stock, startDate, endDate)
.stream().map(StockPriceResponse::of).toList();
return StockInfoResponse.of(stock, stockPriceResponseList);
}
Expand Down Expand Up @@ -113,13 +116,22 @@ public void updatePeriodicStockData(LocalDate startDate, LocalDate endDate) {
@Override
@Transactional
public void saveDailyStockData() {
LocalDate today = LocalDate.now();

Set<String> savedId = stockPriceRepository.findAllByBaseDate(today).stream()
.map(sp -> sp.getStock().getStockCd())
.collect(Collectors.toSet());
List<Stock> stockList = stockRepository.findAll();

List<StockPrice> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import java.util.List;

public interface StockPriceRepository extends JpaRepository<StockPrice, Long> {
List<StockPrice> findByStockAndBaseDateBetween(Stock stock, LocalDate startDate, LocalDate endDate);

boolean existsByStockAndBaseDate(Stock stock, LocalDate baseDate);
List<StockPrice> findByStockAndBaseDateBetweenOrderByBaseDateDesc(Stock stock, LocalDate startDate, LocalDate endDate);

@Query("""
select sp.baseDate
Expand All @@ -26,4 +24,6 @@ List<LocalDate> findAllBaseDatesByStockAndDateRange(
@Param("start") LocalDate start,
@Param("end") LocalDate end
);

List<StockPrice> findAllByBaseDate(LocalDate today);
}
Loading