- 新增 /api/v1/sn/weather 与 /api/v1/client/weather 的 current、hourly、daily 端点,按区县 adCode 查询 - 新增 QWeatherClient 与 WeatherService,实况缓存 30 分钟、逐小时到整点刷新、逐天到当地午夜刷新,上游失败返回 stale 旧缓存 - 新增 NearbyWeatherController/Service,提供分钟级降水、天气预警与空气质量接口 - 打包大陆行政区划表 mainland-areas.tsv,补充 docs/weather-api.md 与时间戳单测
53 lines
2.8 KiB
Java
53 lines
2.8 KiB
Java
package com.youlai.boot.device.weather;
|
|
|
|
import com.youlai.boot.common.result.Result;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import lombok.RequiredArgsConstructor;
|
|
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;
|
|
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
@RequestMapping({"/api/v1/sn", "/api/v1/client"})
|
|
public class NearbyWeatherController {
|
|
private final NearbyWeatherService service;
|
|
|
|
@Operation(summary = "查询分钟级降水预报", tags = "分钟预报")
|
|
@GetMapping("/minutely/5m")
|
|
public Result<NearbyWeatherService.Response> minutely(@RequestParam String latitude, @RequestParam String longitude,
|
|
@RequestParam(defaultValue = "zh") String lang) {
|
|
return Result.success(service.get(NearbyWeatherService.Product.MINUTELY, latitude, longitude, lang));
|
|
}
|
|
|
|
@Operation(summary = "查询实时天气预警", tags = "预警")
|
|
@GetMapping("/weatheralert/current")
|
|
public Result<NearbyWeatherService.Response> alerts(@RequestParam String latitude, @RequestParam String longitude,
|
|
@RequestParam(defaultValue = "zh") String lang) {
|
|
return Result.success(service.get(NearbyWeatherService.Product.ALERTS, latitude, longitude, lang));
|
|
}
|
|
|
|
@Operation(summary = "查询实时空气质量", tags = "空气质量")
|
|
@GetMapping("/airquality/current")
|
|
public Result<NearbyWeatherService.Response> airCurrent(@RequestParam String latitude, @RequestParam String longitude,
|
|
@RequestParam(defaultValue = "zh") String lang) {
|
|
return Result.success(service.get(NearbyWeatherService.Product.AIR_CURRENT, latitude, longitude, lang));
|
|
}
|
|
|
|
@Operation(summary = "查询逐小时空气质量", tags = "空气质量")
|
|
@GetMapping("/airquality/hourly")
|
|
public Result<NearbyWeatherService.Response> airHourly(@RequestParam String latitude, @RequestParam String longitude,
|
|
@RequestParam(defaultValue = "zh") String lang) {
|
|
return Result.success(service.get(NearbyWeatherService.Product.AIR_HOURLY, latitude, longitude, lang));
|
|
}
|
|
|
|
@Operation(summary = "查询逐天空气质量", tags = "空气质量")
|
|
@GetMapping("/airquality/daily")
|
|
public Result<NearbyWeatherService.Response> airDaily(@RequestParam String latitude, @RequestParam String longitude,
|
|
@RequestParam(defaultValue = "zh") String lang) {
|
|
return Result.success(service.get(NearbyWeatherService.Product.AIR_DAILY, latitude, longitude, lang));
|
|
}
|
|
}
|
|
|