|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<CityWeather> cityWeathers = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (CityConfigWeather cityConfigWeather : list) { | 
|---|
|  |  |  | CityWeather cityWeather = new CityWeather(); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | cityWeather.setValue(JSONObject.toJSONString(now)); | 
|---|
|  |  |  | Date time = DateUtils.dataToTimeStampTime(new Date(), DateUtils.yyyy_MM_dd_HH_EN); | 
|---|
|  |  |  | cityWeather.setTime(time); | 
|---|
|  |  |  | //存入数据库 | 
|---|
|  |  |  | cityWeatherMapper.insert(cityWeather); | 
|---|
|  |  |  | cityWeathers.add(cityWeather); | 
|---|
|  |  |  | //存入redis | 
|---|
|  |  |  | redisTemplate.opsForHash().put(RedisConstants.CITY_WEATHER, String.valueOf(cityCode), now); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cityWeatherMapper.insertCityWeather(cityWeathers); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|