package com.trafficaudit.observation.controller; import com.trafficaudit.common.Result; import com.trafficaudit.observation.dto.ObservationDateSummary; import com.trafficaudit.observation.entity.ObservationStationFlow; import com.trafficaudit.observation.service.ObservationStationImportService; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.time.LocalDate; import java.util.List; import java.util.Map; /** * Observation station raw data. Collected and stored only; not linked to holiday flow data. */ @Slf4j @RestController @RequestMapping("/api/observation") public class ObservationStationController { @Resource private ObservationStationImportService importService; @PostMapping("/import") public Result> importWorkbook(@RequestParam("file") MultipartFile file) { try { return Result.ok(importService.importWorkbook(file)); } catch (Exception e) { log.error("observation station import error", e); return Result.error(400, e.getMessage()); } } @GetMapping("/dates") public Result> dates() { return Result.ok(importService.listDateSummaries()); } @GetMapping("/rows") public Result> rows(@RequestParam(value = "date", required = false) String date, @RequestParam(value = "limit", defaultValue = "2000") int limit) { try { LocalDate target = (date == null || date.trim().isEmpty()) ? null : LocalDate.parse(date); return Result.ok(importService.listRows(target, limit)); } catch (Exception e) { return Result.error(400, e.getMessage()); } } @PostMapping("/delete") public Result delete(@RequestParam("date") String date) { try { return Result.ok(importService.deleteDate(LocalDate.parse(date))); } catch (Exception e) { return Result.error(400, e.getMessage()); } } }