|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CityWeatherForecastMapper cityWeatherForecastMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //城市预测气象数据来源于,和风天气,逐小时天气预报(未来72小时)商业版 | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void insertCityWeatherForecast() { | 
|---|
|  |  |  | Date nextDay = DateUtils.addDays(new Date(), 1); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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)); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cityWeatherForecastMapper.insertCityWeatherForecast(cityWeatherForecasts); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void main(String[] args) { | 
|---|
|  |  |  | String time = "20221231"; | 
|---|
|  |  |  | long currentMils = DateUtils.getDate(time, DateUtils.yyyyMMdd_EN).getTime(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | long startMils = DateUtils.getDate("2022", DateUtils.yyyy).getTime(); | 
|---|
|  |  |  | long mss = currentMils - startMils; | 
|---|
|  |  |  | long days = mss / (1000 * 60 * 60 * 24); | 
|---|
|  |  |  | System.out.println(days + 1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|