From a6f669e0eefe026b34e337b09ba8c22473438d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81=E6=BC=8F=E6=B4=9E?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=8C=E6=88=90?= <> Date: Tue, 11 Mar 2025 00:16:05 +0800 Subject: [PATCH] city change --- .../service/ScheduledService.java | 27 +++++++++++-------- .../src/main/resources/application.yml | 4 +-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/disruptor_nmc/src/main/java/com/rehome/disruptor_nmc/service/ScheduledService.java b/disruptor_nmc/src/main/java/com/rehome/disruptor_nmc/service/ScheduledService.java index 7bed31d..d6d810c 100644 --- a/disruptor_nmc/src/main/java/com/rehome/disruptor_nmc/service/ScheduledService.java +++ b/disruptor_nmc/src/main/java/com/rehome/disruptor_nmc/service/ScheduledService.java @@ -38,7 +38,7 @@ public class ScheduledService { * @description: 从中央气象台获取省份列表 * @Param: null */ - //@Scheduled(cron = "0 49 * * * *") + @Scheduled(cron = "0 14 * * * *") public void getNmcWeatherProvince() { System.out.println("scheduledGetWeather"); System.out.println("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); @@ -65,13 +65,16 @@ public class ScheduledService { System.out.println(body); if (StringUtils.hasText(body)) { Gson gson = new Gson(); - List provinces = gson.fromJson(body, new TypeToken>() { - }.getType()); - ; + List provinces = gson.fromJson(body, new TypeToken>() {}.getType()); + for (NmcProvince province : provinces) { System.out.println(gson.toJson(province)); - this.nmcCityService.saveProvince(province); - getNmcWeatherCityByCode(province.getCode()); + NmcProvince provinceDb=this.nmcCityService.findProvinceByCode(province.getCode()); + if(provinceDb==null){ + this.nmcCityService.saveProvince(province); + }else{ + getNmcWeatherCityByCode(province.getCode()); + } try { Thread.sleep(500); } catch (Exception e) { @@ -114,12 +117,14 @@ public class ScheduledService { System.out.println(body); if (StringUtils.hasText(body)) { Gson gson = new Gson(); - List citys = gson.fromJson(body, new TypeToken>() { - }.getType()); - ; + List citys = gson.fromJson(body, new TypeToken>() {}.getType()); + for (NmcCity city : citys) { System.out.println(gson.toJson(city)); - this.nmcCityService.saveCity(city); + NmcCity cityDB=this.nmcCityService.findCityByCode(city.getCode()); + if(cityDB==null){ + this.nmcCityService.saveCity(city); + } } System.out.println(citys.size()); } @@ -134,7 +139,7 @@ public class ScheduledService { * @description: 从中央气象台获取天气数据 * @Param: null */ - @Scheduled(cron = "0 15 * * * *") + //@Scheduled(cron = "0 15 * * * *") public void getNmcNowWeather() { System.out.println("scheduledGetWeather"); System.out.println("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); diff --git a/disruptor_nmc/src/main/resources/application.yml b/disruptor_nmc/src/main/resources/application.yml index 0b7ac3f..677bd73 100644 --- a/disruptor_nmc/src/main/resources/application.yml +++ b/disruptor_nmc/src/main/resources/application.yml @@ -9,8 +9,8 @@ spring: # url: jdbc:mysql://127.0.0.1:3306/head_office_data_center?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true&allowMultiQueries=true # url: jdbc:mysql://localhost:3306/head_office_data_center?useUnicode=true&characterEncoding=utf-8&useSSL=true&nullCatalogMeansCurrent=true&serverTimezone=UTC # url: jdbc:mysql://192.168.2.18:3306/disruptor_nmc?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true - #url: jdbc:mysql://192.168.3.7:3306/disruptor_nmc?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true - url: jdbc:mysql://127.0.0.1:3306/disruptor_nmc?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true + url: jdbc:mysql://192.168.3.7:3306/disruptor_nmc?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true + #url: jdbc:mysql://127.0.0.1:3306/disruptor_nmc?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true username: root password: Skyinno251, # driverClassName: oracle.jdbc.driver.OracleDriver