lizijie
2022-01-05 d866a0c52c419156941801ea0008643d1c7f0e04
screen-job/src/main/java/com/moral/api/service/impl/CityWeatherServiceImpl.java
@@ -50,12 +50,12 @@
        QueryWrapper<CityConfigWeather> wrapper = new QueryWrapper<>();
        wrapper.select("city_code", "location_id").eq("is_delete", Constants.NOT_DELETE);
        List<CityConfigWeather> list = cityConfigWeatherService.list(wrapper);
        CityWeather cityWeather = new CityWeather();
        for (CityConfigWeather cityConfigWeather : list) {
            Integer cityCode = cityConfigWeather.getCityCode();
            Integer locationId = cityConfigWeather.getLocationId();
            Map<String, Object> data = restTemplate.getForObject("https://api.qweather.com/v7/weather/now?key=da05c6c4852d4f7aa3364a9236ee9e26&gzip=n&location={1}", Map.class, locationId);
            Map<String, Object> now = (Map<String, Object>) data.get("now");
            CityWeather cityWeather = new CityWeather();
            cityWeather.setCityCode(cityCode);
            //风速km/h->m/s
            double windSpeed = Double.parseDouble(now.get("windSpeed").toString());
@@ -83,4 +83,12 @@
        }
        return cityWeather;
    }
    @Override
    public List<CityWeather> getCityWeather() {
        String time = DateUtils.getDateStringOfHour(-1, DateUtils.yyyy_MM_dd_HH_EN) + ":00:00";
        QueryWrapper<CityWeather> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("time", time);
        return cityWeatherMapper.selectList(queryWrapper);
    }
}