cjl
2 hours ago 084fcff73e6858862544c3901361adfe5742016c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.moral.api.controller;
 
import com.moral.api.service.RadarHourlySummaryService;
import com.moral.api.vo.ComparisonResponse;
import com.moral.api.vo.HourlyResponse;
import com.moral.constant.ResultMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
 
/**
 * @ClassName RadarProcessController
 * @Description TODO
 * @Author @cjl
 * @Date 2026-09-08 14:12
 * @Version 1.0
 */
@Slf4j
@Api(tags = {"雷达"})
@RestController
@RequestMapping("/radar")
public class RadarProcessController {
 
    @Autowired
    private RadarHourlySummaryService hourlySummaryService;
 
    /**
     * 处理上一完整小时
     * GET /radar/process-last
     */
    @GetMapping("/process-last")
    public ResultMessage processLastHour() {
        hourlySummaryService.processLastHour();
        return new ResultMessage();
 
    }
 
    /**
     * 处理指定小时
     * GET /radar/process?hour=2026-09-08 09:00:00
     */
    @GetMapping("/process")
    public ResultMessage processHour() {
        String startStr = "2026-09-08 14:00:00";
        String endStr = "2026-09-09 13:00:00";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startTime = LocalDateTime.parse(startStr, formatter);
        LocalDateTime endTime = LocalDateTime.parse(endStr, formatter);
        LocalDateTime current = startTime;
        while (!current.isAfter(endTime)) {
            // 将当前时间格式化为字符串并加入列表
            hourlySummaryService.processHour(current.format(formatter));
            // 时间增加 1 小时
            current = current.plusHours(1);
        }
 
        return new ResultMessage();
    }
 
    @GetMapping("/process1")
    public ResultMessage processHour1() {
        String startStr = "2026-09-01 00:00:00";
        hourlySummaryService.processHour(startStr);
        return new ResultMessage();
    }
 
    /**
     * 获取边界层对比数据
     * GET /radar/comparison?location=苏州&time=2026-09-09 09:00:00
     *
     * @param location 位置名称
     * @param time     请求时间,取前一整点作为 current
     */
    @GetMapping("/comparison")
    @ApiOperation("获取最近边界层数据")
    public ResultMessage getComparison(@RequestParam @ApiParam(value = "location",name = "地名") String location,
                                            @RequestParam @ApiParam(value = "time",name = "时间 yyyy-MM-dd HH:mm:ss") String time) {
        if(!location.equals("苏州")){
            return ResultMessage.ok("目前只有苏州区域有");
        }
        ComparisonResponse comparisonResponse = hourlySummaryService.getComparison(location, time);
 
        return ResultMessage.ok(comparisonResponse);
    }
 
    /**
     * 获取指定时间范围内每小时的雷达数据
     * GET /radar/hourly?location=苏州&startTime=2026-09-04 09:00:00&endTime=2026-09-09 09:00:00
     *
     * @param location  位置名称
     * @param startTime 起始时间(包含)
     * @param endTime   结束时间(不包含)
     */
    @GetMapping("/hourly")
    @ApiOperation("查询近5天逐小时边界层数据")
    public ResultMessage getHourly5Days(@RequestParam  @ApiParam(value = "location",name = "地名")  String location,
                                         @RequestParam  @ApiParam(value = "startTime",name = "开始时间")  String startTime,
                                         @RequestParam  @ApiParam(value = "endTime",name = "结束时间")  String endTime) {
        if(!location.equals("苏州")){
            return ResultMessage.ok("目前只有苏州区域有");
        }
 
        HourlyResponse getHourly5Days =  hourlySummaryService.getHourly5Days(location, startTime, endTime);
 
        return ResultMessage.ok(getHourly5Days);
    }
 
}