From decde473ddbfd8552deaef5057787aa3b4c73d54 Mon Sep 17 00:00:00 2001 From: sonjinyon <2476687577@qq.com> Date: Thu, 22 Aug 2024 09:59:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E5=B1=8F=E6=9C=AA=E6=9D=A5=E4=B8=89?= =?UTF-8?q?=E5=A4=A9=E5=A4=A9=E6=B0=94=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/app/weather/WeatherApi.java | 17 +++ .../datacenter/utlis/GoodWeatherUtil.java | 116 ++++++------------ .../src/main/resources/bootstrap.yaml | 2 +- .../src/main/resources/bootstrap.yaml | 2 +- .../src/main/resources/application-local.yaml | 13 +- .../src/main/resources/bootstrap.yaml | 2 +- .../src/main/resources/bootstrap.yaml | 2 +- 7 files changed, 61 insertions(+), 93 deletions(-) diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/app/weather/WeatherApi.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/app/weather/WeatherApi.java index 030b508e7..5b6f3e47a 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/app/weather/WeatherApi.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/controller/app/weather/WeatherApi.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.datacenter.controller.app.weather; import cn.iocoder.yudao.module.datacenter.controller.app.weather.vo.WeatherInfoVO; import cn.iocoder.yudao.module.datacenter.utlis.GoodWeatherUtil; import cn.iocoder.yudao.module.datacenter.utlis.ResponseVO; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; @@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("/h5/weather") @Validated public class WeatherApi { + @GetMapping(value = "/getWeather") @Operation(summary = "获得输入城市的天气") public ResponseVO getWeather(String cityCode) { @@ -25,4 +28,18 @@ public class WeatherApi { WeatherInfoVO weatherInfo = GoodWeatherUtil.GetWeather(weatherData); return new ResponseVO(200,"",weatherInfo,0); } + + /** + * 获取未来三天天气预报 + * @param cityCode + * @return + */ + @GetMapping(value = "/getFutureWeather") + public ResponseVO getFutureWeather(String cityCode) { + String weatherData = GoodWeatherUtil.getWeatherData(cityCode); + JSONObject dataOfJson = JSONObject.parseObject(weatherData); + JSONArray forecasts = dataOfJson.getJSONArray("forecasts"); + return new ResponseVO(200,"",forecasts,0); + } + } diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/utlis/GoodWeatherUtil.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/utlis/GoodWeatherUtil.java index 1dde195f3..96c8936ef 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/utlis/GoodWeatherUtil.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/utlis/GoodWeatherUtil.java @@ -18,15 +18,14 @@ public class GoodWeatherUtil { //高德地图 private static final String WEATHER_SERVICES_URL = "https://restapi.amap.com/v3/weather/weatherInfo?city="; private static final String WEATHER_KEY = "&key=172993e9541be0a4f824feedeb210b7e"; - - //和风天气 - private static final String WEATHER_SERVICES_URL2 = "https://geoapi.qweather.com/v2/city/lookup?"; - private static final String LOCATION = "location="; //区县名称 - private static final String ADM = "&adm="; //城市名称 - private static final String PRIVATE_KEY = "&key=1c0db79d181441258030a633197fb429"; - + private static final String WEATHER_TYPE = "&extensions=all"; + /** + * 今日实况天气 + * @param cityCode + * @return + */ public static String getWeatherData(String cityCode){ int codelength = cityCode.length(); if (6 != codelength){ @@ -53,6 +52,37 @@ public class GoodWeatherUtil { } + /** + * 获取未来三天天气预报 + * @param cityCode + * @return + */ + public static String getFutureWeather(String cityCode){ + int codelength = cityCode.length(); + if (6 != codelength){ + return "500"; + } + StringBuffer sb = new StringBuffer(); + try { + String weather_url = WEATHER_SERVICES_URL + cityCode + WEATHER_KEY + WEATHER_TYPE; + URL url = new URL(weather_url); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + connection.setRequestProperty("Charset", "utf-8"); + connection.connect(); + //读取URL的响应 + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8")); + String line = null; + while ((line = reader.readLine()) != null) + sb.append(line + " "); + reader.close(); + }catch (Exception e){ + e.printStackTrace(); + } + return sb.toString(); + } + + /* * 将JSON格式数据进行解析 ,返回一个weather对象 */ @@ -88,76 +118,4 @@ public class GoodWeatherUtil { return weatherInfoVO; } -// -// public static String getWeatherDataHF(String areaName,String cityName){ -// if (areaName == null && cityName == null){ -// return "500"; -// } -// StringBuffer sb = new StringBuffer(); -// try { -// String weather_url = WEATHER_SERVICES_URL2+LOCATION+areaName+ADM+cityName+PRIVATE_KEY; -// URL url = new URL(weather_url); -// HttpURLConnection connection = (HttpURLConnection) url.openConnection(); -// connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); -// connection.setRequestProperty("Charset", "utf-8"); -// connection.connect(); -// //读取URL的响应 -// BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8")); -// String line = null; -// while ((line = reader.readLine()) != null) -// sb.append(line + " "); -// reader.close(); -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return sb.toString(); -// } - - /* - * 将JSON格式数据进行解析 ,返回一个weather对象 - */ -// public static String GetWeatherHF(String weatherInfobyJson) { -// if ("500".equals(weatherInfobyJson)){ -// return null; -// } -// JSONObject dataOfJson = JSONObject.parseObject(weatherInfobyJson); -// System.out.println(dataOfJson); -// //创建WeatherInfo对象,提取所需的天气信息 -// WeatherInfoVO weatherInfoVO = new WeatherInfoVO(); -// -// //从json数据中提取数据 -// JSONArray location = dataOfJson.getJSONArray("location"); -// JSONObject weather = location.getJSONObject(0); -// -// // 取得当天的天气信息 -// weatherInfoVO.setWeatherInfo(weather.getString("weather")); -// -// // 设置气温 -// String temperature = weather.getString("temperature"); -// weatherInfoVO.setTemperature(Integer.parseInt(temperature)); -// -// //设置风力信息 -// String windPower = weather.getString("windpower"); -// weatherInfoVO.setWindPower(windPower); -// -// //设置风向信息 -// String windDirection = weather.getString("winddirection"); -// weatherInfoVO.setWindDirection(windDirection); -// -// return weatherInfoVO; -// } - - - - public static void main(String [] args) { - String weatherData = GoodWeatherUtil.getWeatherData("360730"); - - - WeatherInfoVO weatherInfoVO = GoodWeatherUtil.GetWeather(weatherData); - - System.out.println(weatherInfoVO); - - } - - } \ No newline at end of file diff --git a/ludu-module-ticketing/ludu-module-ticketing-biz/src/main/resources/bootstrap.yaml b/ludu-module-ticketing/ludu-module-ticketing-biz/src/main/resources/bootstrap.yaml index 9ced7261f..8122f7fe2 100644 --- a/ludu-module-ticketing/ludu-module-ticketing-biz/src/main/resources/bootstrap.yaml +++ b/ludu-module-ticketing/ludu-module-ticketing-biz/src/main/resources/bootstrap.yaml @@ -3,7 +3,7 @@ spring: name: ticket-server profiles: - active: dev + active: local server: port: 48088 diff --git a/yudao-gateway/src/main/resources/bootstrap.yaml b/yudao-gateway/src/main/resources/bootstrap.yaml index e7e8ccdea..3eed7be68 100644 --- a/yudao-gateway/src/main/resources/bootstrap.yaml +++ b/yudao-gateway/src/main/resources/bootstrap.yaml @@ -3,7 +3,7 @@ spring: name: gateway-server profiles: - active: dev + active: local server: port: 48080 diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml index 158ebba27..949441c08 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml @@ -66,7 +66,7 @@ spring: username: root password: 123456 ticketing: - url: jdbc:mysql://101.43.112.107:3306/ludu_ticketing?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 + url: jdbc:mysql://120.46.37.243:3306/ludu_ticketing?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 username: root password: xpower1234 @@ -97,16 +97,9 @@ spring: --- #################### 定时任务相关配置 #################### xxl: job: + enabled: false # 是否开启调度中心,默认为 true 开启 admin: - addresses: http://127.0.0.1:9090/xxl-job-admin - executor: - appname: ${spring.application.name} # 执行器 AppName - address: - ip: # 执行器IP [选填]:默认为空表示自动获取IP,多网卡时可手动设置指定IP,该IP不会绑定Host仅作为通讯实用;地址信息用于 "执行器注册" 和 "调度中心请求并触发任务"; - port: 0 # ### 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口; - logpath: ${user.home}/logs/xxl-job/${spring.application.name} # 执行器运行日志文件存储磁盘路径 - logretentiondays: 30 # 执行器日志文件保存天数 [选填] : 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能; - accessToken: # 执行器通讯TOKEN + addresses: http://127.0.0.1:9090/xxl-job-admin # 调度中心部署跟地址 --- #################### 服务保障相关配置 #################### diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/bootstrap.yaml b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/bootstrap.yaml index 5567d62f6..a276ad449 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/bootstrap.yaml +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/bootstrap.yaml @@ -3,7 +3,7 @@ spring: name: infra-server profiles: - active: dev + active: local server: port: 48082 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/bootstrap.yaml b/yudao-module-system/yudao-module-system-biz/src/main/resources/bootstrap.yaml index b97443e6e..273749c70 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/resources/bootstrap.yaml +++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/bootstrap.yaml @@ -3,7 +3,7 @@ spring: name: system-server profiles: - active: dev + active: local server: port: 48081