-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
30 additions
and
7 deletions.
There are no files selected for viewing
25 changes: 18 additions & 7 deletions
25
server/src/main/java/com/talkka/server/bus/controller/BusLocationProcessController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
server/src/main/java/com/talkka/server/bus/dao/BusLocationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BusLocationEntity, Long> { | ||
List<BusLocationEntity> findByCreatedAtBetween(LocalDateTime startTime, LocalDateTime endTime); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters