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);
|
}
|
|
}
|