Skip to content

Commit

Permalink
fix : 버스위치 가공 스케줄러 등록
Browse files Browse the repository at this point in the history
  • Loading branch information
Gyaak committed Aug 30, 2024
1 parent 333ebae commit 663bb88
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
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));
}
}
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ public void saveBusLocations(List<BusLocationBodyDto> responseList, Integer apiC
.toList();
busLocationRepository.saveAll(entityList);
}

public List<BusLocationEntity> findAll() {
return busLocationRepository.findAll();
}

public List<BusLocationEntity> findByPeriod(LocalDateTime start, LocalDateTime end) {
return busLocationRepository.findByCreatedAtBetween(start, end);
}
}

0 comments on commit 663bb88

Please sign in to comment.