|
|
|
@ -38,7 +38,7 @@ public class ScheduledService {
|
|
|
|
* @description: 从中央气象台获取省份列表
|
|
|
|
* @description: 从中央气象台获取省份列表
|
|
|
|
* @Param: null
|
|
|
|
* @Param: null
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
//@Scheduled(cron = "0 49 * * * *")
|
|
|
|
@Scheduled(cron = "0 14 * * * *")
|
|
|
|
public void getNmcWeatherProvince() {
|
|
|
|
public void getNmcWeatherProvince() {
|
|
|
|
System.out.println("scheduledGetWeather");
|
|
|
|
System.out.println("scheduledGetWeather");
|
|
|
|
System.out.println("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
|
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);
|
|
|
|
System.out.println(body);
|
|
|
|
if (StringUtils.hasText(body)) {
|
|
|
|
if (StringUtils.hasText(body)) {
|
|
|
|
Gson gson = new Gson();
|
|
|
|
Gson gson = new Gson();
|
|
|
|
List<NmcProvince> provinces = gson.fromJson(body, new TypeToken<List<NmcProvince>>() {
|
|
|
|
List<NmcProvince> provinces = gson.fromJson(body, new TypeToken<List<NmcProvince>>() {}.getType());
|
|
|
|
}.getType());
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
for (NmcProvince province : provinces) {
|
|
|
|
for (NmcProvince province : provinces) {
|
|
|
|
System.out.println(gson.toJson(province));
|
|
|
|
System.out.println(gson.toJson(province));
|
|
|
|
|
|
|
|
NmcProvince provinceDb=this.nmcCityService.findProvinceByCode(province.getCode());
|
|
|
|
|
|
|
|
if(provinceDb==null){
|
|
|
|
this.nmcCityService.saveProvince(province);
|
|
|
|
this.nmcCityService.saveProvince(province);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
getNmcWeatherCityByCode(province.getCode());
|
|
|
|
getNmcWeatherCityByCode(province.getCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Thread.sleep(500);
|
|
|
|
Thread.sleep(500);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
@ -114,13 +117,15 @@ public class ScheduledService {
|
|
|
|
System.out.println(body);
|
|
|
|
System.out.println(body);
|
|
|
|
if (StringUtils.hasText(body)) {
|
|
|
|
if (StringUtils.hasText(body)) {
|
|
|
|
Gson gson = new Gson();
|
|
|
|
Gson gson = new Gson();
|
|
|
|
List<NmcCity> citys = gson.fromJson(body, new TypeToken<List<NmcCity>>() {
|
|
|
|
List<NmcCity> citys = gson.fromJson(body, new TypeToken<List<NmcCity>>() {}.getType());
|
|
|
|
}.getType());
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
for (NmcCity city : citys) {
|
|
|
|
for (NmcCity city : citys) {
|
|
|
|
System.out.println(gson.toJson(city));
|
|
|
|
System.out.println(gson.toJson(city));
|
|
|
|
|
|
|
|
NmcCity cityDB=this.nmcCityService.findCityByCode(city.getCode());
|
|
|
|
|
|
|
|
if(cityDB==null){
|
|
|
|
this.nmcCityService.saveCity(city);
|
|
|
|
this.nmcCityService.saveCity(city);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
System.out.println(citys.size());
|
|
|
|
System.out.println(citys.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
@ -134,7 +139,7 @@ public class ScheduledService {
|
|
|
|
* @description: 从中央气象台获取天气数据
|
|
|
|
* @description: 从中央气象台获取天气数据
|
|
|
|
* @Param: null
|
|
|
|
* @Param: null
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Scheduled(cron = "0 15 * * * *")
|
|
|
|
//@Scheduled(cron = "0 15 * * * *")
|
|
|
|
public void getNmcNowWeather() {
|
|
|
|
public void getNmcNowWeather() {
|
|
|
|
System.out.println("scheduledGetWeather");
|
|
|
|
System.out.println("scheduledGetWeather");
|
|
|
|
System.out.println("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
|
System.out.println("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
|
|
|