From 2186702b8f6e4b886a7e54b2e7edd56d0fe85589 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Tue, 6 Feb 2024 17:17:34 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E6=A0=B9=E6=8D=AE=E7=AB=99=E7=82=B9?= =?UTF-8?q?=E7=BC=96=E5=8F=B7=E3=80=81=E6=97=B6=E9=97=B4=E6=AE=B5=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E9=99=8D=E9=9B=A8=E9=87=8F=E6=8E=A5=E5=8F=A3=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 5618b6c1774cfeb2ee58a565eb0f58139f10fed2) --- .../hzims/hzimsweather/feign/IRainfallClient.java | 21 ++++++++ .../hnac/hzims/weather/feign/RainfallClient.java | 63 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 hzims-service-api/weather-api/src/main/java/com/hnac/hzims/hzimsweather/feign/IRainfallClient.java create mode 100644 hzims-service/weather/src/main/java/com/hnac/hzims/weather/feign/RainfallClient.java diff --git a/hzims-service-api/weather-api/src/main/java/com/hnac/hzims/hzimsweather/feign/IRainfallClient.java b/hzims-service-api/weather-api/src/main/java/com/hnac/hzims/hzimsweather/feign/IRainfallClient.java new file mode 100644 index 0000000..1bd3fed --- /dev/null +++ b/hzims-service-api/weather-api/src/main/java/com/hnac/hzims/hzimsweather/feign/IRainfallClient.java @@ -0,0 +1,21 @@ +package com.hnac.hzims.hzimsweather.feign; + +import com.hnac.hzims.hzimsweather.constants.WeatherConstant; +import org.springblade.core.tool.api.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; +import java.util.Map; + +@FeignClient(WeatherConstant.APP_NAME) +public interface IRainfallClient { + + String API_PREFIX = "/weather/rainfall"; + String GET_DURATION_RAIN_FALL = API_PREFIX + "/getDurationRainFall"; + + @GetMapping(GET_DURATION_RAIN_FALL) + R>> getDurationRainFall(@RequestParam String stationCode, @RequestParam String startDate, @RequestParam String endDate); + +} diff --git a/hzims-service/weather/src/main/java/com/hnac/hzims/weather/feign/RainfallClient.java b/hzims-service/weather/src/main/java/com/hnac/hzims/weather/feign/RainfallClient.java new file mode 100644 index 0000000..d4ccfa2 --- /dev/null +++ b/hzims-service/weather/src/main/java/com/hnac/hzims/weather/feign/RainfallClient.java @@ -0,0 +1,63 @@ +package com.hnac.hzims.weather.feign; + + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.collect.Lists; +import com.hnac.hzims.hzimsweather.entity.DailyHeWeatherEntity; +import com.hnac.hzims.hzimsweather.feign.IRainfallClient; +import com.hnac.hzims.weather.service.IDailyHeWeatherService; +import lombok.AllArgsConstructor; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.util.Assert; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.time.Duration; +import java.time.LocalDate; +import java.util.*; +import java.util.stream.Collectors; + +@RestController +@AllArgsConstructor +public class RainfallClient extends BladeController implements IRainfallClient { + + private final IDailyHeWeatherService dailyHeWeatherService; + + @Override + @GetMapping(GET_DURATION_RAIN_FALL) + public R>> getDurationRainFall(@RequestParam String stationCode, @RequestParam String startDate, @RequestParam String endDate) { + LocalDate start = LocalDate.parse(startDate, DateUtil.DATE_FORMATTER); + LocalDate end = LocalDate.parse(endDate, DateUtil.DATE_FORMATTER); + Assert.isTrue(start.isBefore(end) || start.isEqual(end),()-> { + throw new ServiceException("降雨量查询传参错误,开始时间必须小于等于结束时间"); + }); + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery().select(DailyHeWeatherEntity::getFxDate, DailyHeWeatherEntity::getPrecip) + .eq(DailyHeWeatherEntity::getStationCode, stationCode) + .ge(DailyHeWeatherEntity::getFxDate, startDate) + .le(DailyHeWeatherEntity::getFxDate, endDate); + List> precipList = dailyHeWeatherService.listMaps(queryWrapper); + List days = Lists.newArrayList(); + while(start.isBefore(end) || start.isEqual(end)) { + days.add(start); + start = start.plusDays(1); + } + List> result = days.stream().map(date -> { + String dateStr = DateUtil.format(date, DateUtil.PATTERN_DATE); + Optional> exit = precipList.stream().filter(m -> DateUtil.format((Date) m.get("fx_date"),DateUtil.PATTERN_DATE).equals(dateStr)).findFirst(); + if (exit.isPresent()) { + return exit.get(); + } else { + return new HashMap() {{ + put("fx_date", dateStr); + put("precip", null); + }}; + } + }).collect(Collectors.toList()); + return R.data(result); + } +}