screen-job/src/main/java/com/moral/api/service/impl/CityAqiServiceImpl.java
@@ -29,6 +29,7 @@ import java.util.List; import java.util.Map; import java.util.OptionalDouble; import java.util.stream.Collectors; import java.util.stream.DoubleStream; /** @@ -71,6 +72,24 @@ wrapper.select("city_code", "city_id").eq("is_delete", Constants.NOT_DELETE); List<CityConfigAqi> list = cityConfigAqiService.list(wrapper); //获取历史数据,用于计算臭氧滑动值 Map<Integer, List<Map<String, Object>>> cityData = null; if (start != null) { QueryWrapper<CityAqi> queryWrapper = new QueryWrapper<>(); List<Integer> cityCodes = list.stream().map(CityConfigAqi::getCityCode) .collect(Collectors.toList()); queryWrapper.select("city_code", "time", "value") .ge("time", DateUtils.dateToDateString(start)) .in("city_code", cityCodes); List<Map<String, Object>> selectMaps = cityAqiMapper.selectMaps(queryWrapper); //按city_code分组 cityData = selectMaps.stream() .collect(Collectors.groupingBy(o -> Integer.parseInt(o.get("city_code").toString()))); } List<CityAqi> cityAqiList = new ArrayList<>(); for (CityConfigAqi cityConfigAqi : list) { @@ -105,12 +124,9 @@ aqi.put("AQI", aqi.remove("value")); //o3滑动值计算 if (start != null) { QueryWrapper<CityAqi> queryWrapper = new QueryWrapper<>(); queryWrapper.select("time", "value") .eq("city_code", cityCode) .ge("time", DateUtils.dateToDateString(start)); List<Map<String, Object>> cityAqis = cityAqiMapper.selectMaps(queryWrapper); if (cityData != null) { List<Map<String, Object>> cityAqis = cityData.get(cityCode); Map<String, Object> params = new HashMap<>(); params.put("time", DateUtils.dateToDateString(dataTime, DateUtils.yyyy_MM_dd_HH_mm_ss_S_EN)); params.put("value", JSONObject.toJSONString(aqi)); screen-job/src/main/java/com/moral/api/service/impl/CityWeatherForecastServiceImpl.java
@@ -52,7 +52,6 @@ List<CityWeatherForecast> cityWeatherForecasts = new ArrayList<>(); for (CityConfigWeatherForecast cityConfigWeatherForecast : list) { CityWeatherForecast cityWeatherForecast = new CityWeatherForecast(); Integer cityCode = cityConfigWeatherForecast.getCityCode(); Integer locationId = cityConfigWeatherForecast.getLocationId(); Map<String, Object> data = restTemplate.getForObject("https://api.qweather.com/v7/weather/72h?key=da05c6c4852d4f7aa3364a9236ee9e26&gzip=n&location={1}", Map.class, locationId); @@ -62,6 +61,7 @@ String dayTime = fxTime.split("T")[0]; if (dayTime.equals(nextTime)) { String hourTime = fxTime.substring(0, 17).replaceAll("T", " "); CityWeatherForecast cityWeatherForecast = new CityWeatherForecast(); cityWeatherForecast.setCityCode(cityCode); cityWeatherForecast.setTime(DateUtils.getDate(hourTime, DateUtils.yyyy_MM_dd_HH_EN)); cityWeatherForecast.setValue(JSONObject.toJSONString(hourlyMap)); screen-job/src/main/java/com/moral/api/service/impl/ForecastServiceImpl.java
@@ -133,10 +133,7 @@ Map<String, Object> forecastMap = new HashMap<>(); for (Object obj : cityCodes) { Forecast forecast = new Forecast(); Integer cityCode = Integer.parseInt(obj.toString()); forecast.setCityCode(cityCode); //预测 List<CityWeatherForecast> cityWeatherForecasts = cityForecast.get(cityCode); @@ -172,6 +169,8 @@ } for (CityWeatherForecast cityWeatherForecast : cityWeatherForecasts) { Forecast forecast = new Forecast(); forecast.setCityCode(cityCode); Date time = cityWeatherForecast.getTime(); Map<String, Object> value = JSONObject.parseObject(cityWeatherForecast.getValue(), Map.class); String weather = value.get("text").toString();