From 663bb88c4590fee3badca522cec68087200aad1d Mon Sep 17 00:00:00 2001 From: PSH Date: Fri, 30 Aug 2024 16:49:18 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20=EB=B2=84=EC=8A=A4=EC=9C=84=EC=B9=98?= =?UTF-8?q?=20=EA=B0=80=EA=B3=B5=20=EC=8A=A4=EC=BC=80=EC=A4=84=EB=9F=AC=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusLocationProcessController.java | 25 +++++++++++++------ .../server/bus/dao/BusLocationRepository.java | 4 +++ .../bus/service/BusLocationService.java | 8 ++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/com/talkka/server/bus/controller/BusLocationProcessController.java b/server/src/main/java/com/talkka/server/bus/controller/BusLocationProcessController.java index 2b32bc6a..c61578c4 100644 --- a/server/src/main/java/com/talkka/server/bus/controller/BusLocationProcessController.java +++ b/server/src/main/java/com/talkka/server/bus/controller/BusLocationProcessController.java @@ -1,24 +1,35 @@ package com.talkka.server.bus.controller; +import java.time.LocalDateTime; + import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.talkka.server.bus.dao.BusLocationRepository; +import com.talkka.server.admin.scheduler.DynamicScheduled; import com.talkka.server.bus.service.BusLocationProcessor; +import com.talkka.server.bus.service.BusLocationService; import lombok.RequiredArgsConstructor; @RestController @RequiredArgsConstructor -@RequestMapping("/api/bus/stat") +@RequestMapping("/api/bus/process") public class BusLocationProcessController { private final BusLocationProcessor busLocationProcessor; - private final BusLocationRepository busLocationRepository; + private final BusLocationService busLocationService; + + @PostMapping("/all") + public void processAll() { + busLocationProcessor.start(busLocationService.findAll()); + } - @PostMapping("/process/all") - public String process() { - busLocationProcessor.start(busLocationRepository.findAll()); - return "success"; + @DynamicScheduled(name = "data_processing", cron = "0 0 3 * * *") + @PostMapping("/today") + public void processToday() { + LocalDateTime now = LocalDateTime.now(); + LocalDateTime end = now.withHour(3).withMinute(0).withSecond(0).withNano(0); + LocalDateTime start = end.minusDays(1); + busLocationProcessor.start(busLocationService.findByPeriod(start, end)); } } diff --git a/server/src/main/java/com/talkka/server/bus/dao/BusLocationRepository.java b/server/src/main/java/com/talkka/server/bus/dao/BusLocationRepository.java index adcec4db..54042404 100644 --- a/server/src/main/java/com/talkka/server/bus/dao/BusLocationRepository.java +++ b/server/src/main/java/com/talkka/server/bus/dao/BusLocationRepository.java @@ -1,8 +1,12 @@ package com.talkka.server.bus.dao; +import java.time.LocalDateTime; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface BusLocationRepository extends JpaRepository { + List findByCreatedAtBetween(LocalDateTime startTime, LocalDateTime endTime); } \ No newline at end of file diff --git a/server/src/main/java/com/talkka/server/bus/service/BusLocationService.java b/server/src/main/java/com/talkka/server/bus/service/BusLocationService.java index b86d69a9..fc332996 100644 --- a/server/src/main/java/com/talkka/server/bus/service/BusLocationService.java +++ b/server/src/main/java/com/talkka/server/bus/service/BusLocationService.java @@ -24,4 +24,12 @@ public void saveBusLocations(List responseList, Integer apiC .toList(); busLocationRepository.saveAll(entityList); } + + public List findAll() { + return busLocationRepository.findAll(); + } + + public List findByPeriod(LocalDateTime start, LocalDateTime end) { + return busLocationRepository.findByCreatedAtBetween(start, end); + } }