jinpengyong
2022-01-20 0aca12e52beb725c489a83a8624f00af355aa5fa
screen-job/src/main/java/com/moral/api/service/impl/CityWeatherForecastServiceImpl.java
@@ -15,6 +15,7 @@
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -47,8 +48,11 @@
        QueryWrapper<CityConfigWeatherForecast> wrapper = new QueryWrapper<>();
        wrapper.select("city_code", "location_id").eq("is_delete", Constants.NOT_DELETE);
        List<CityConfigWeatherForecast> list = cityConfigWeatherForecastService.list(wrapper);
        CityWeatherForecast cityWeatherForecast = new CityWeatherForecast();
        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);
@@ -61,9 +65,10 @@
                    cityWeatherForecast.setCityCode(cityCode);
                    cityWeatherForecast.setTime(DateUtils.getDate(hourTime, DateUtils.yyyy_MM_dd_HH_EN));
                    cityWeatherForecast.setValue(JSONObject.toJSONString(hourlyMap));
                    cityWeatherForecastMapper.insert(cityWeatherForecast);
                    cityWeatherForecasts.add(cityWeatherForecast);
                }
            }
        }
        cityWeatherForecastMapper.insertCityWeatherForecast(cityWeatherForecasts);
    }
}