xyc
1 天以前 bc822c6ca3e1ce3e16a38ba877449fc697be9511
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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<Map<String, Object>> 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<List<ObservationDateSummary>> dates() {
        return Result.ok(importService.listDateSummaries());
    }
 
    @GetMapping("/rows")
    public Result<List<ObservationStationFlow>> 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<Integer> delete(@RequestParam("date") String date) {
        try {
            return Result.ok(importService.deleteDate(LocalDate.parse(date)));
        } catch (Exception e) {
            return Result.error(400, e.getMessage());
        }
    }
}