Browse Source

优化天气服务接口

develop
zhaoxianglong 7 months ago
parent
commit
5065313971
  1. 8
      zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java

8
zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java

@ -104,7 +104,8 @@ public class WeatherForecastController extends BaseController {
JSONObject jsonResult = JSONObject.parseObject(response.body().string());
if (jsonResult.getInteger("code") == 200) {
jsonObject.put(weather.getString("METEOROLOGICALEARLYWARNING") + dcRegion.getId(), extracted(jsonResult, "warning"));
jsonObject.put("name",dcRegion.getRegionName());
jsonObject.put(weather.getString("METEOROLOGICALEARLYWARNING") + dcRegion.getId(), extracted(jsonResult,"warning"));
} else {
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败");
@ -177,6 +178,7 @@ public class WeatherForecastController extends BaseController {
JSONObject jsonResult = JSONObject.parseObject(response.body().string());
if (jsonResult.getInteger("code") == 200) {
jsonObject.put("name",dcRegion.getRegionName());
if (Objects.equals(redisKey, weather.getString("WEATHERFACTS"))) {
jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "now"));
@ -187,7 +189,7 @@ public class WeatherForecastController extends BaseController {
} else if (Objects.equals(redisKey, weather.getString("HOURLYWEATHER"))) {
jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "hourly"));
jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult,"hourly"));
}
} else {
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败");
@ -201,7 +203,7 @@ public class WeatherForecastController extends BaseController {
}
if (Objects.equals(redisKey, weather.getString("WEATHERFACTS"))) {
if (Objects.equals(redisKey, weather.getString("WEATHERFACTS"))) {
redisCache.setCacheObject(redisKey, jsonObject, 13, TimeUnit.MINUTES);

Loading…
Cancel
Save