|
|
@ -104,8 +104,7 @@ public class WeatherForecastController extends BaseController { |
|
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
|
if (jsonResult.getInteger("code") == 200) { |
|
|
|
|
|
|
|
jsonResult.put("name",dcRegion.getRegionName()); |
|
|
|
jsonObject.put(weather.getString("METEOROLOGICALEARLYWARNING") + dcRegion.getId(), extracted(jsonResult,"warning")); |
|
|
|
jsonObject.put(weather.getString("METEOROLOGICALEARLYWARNING") + dcRegion.getId(), extracted(jsonResult, "warning", dcRegion)); |
|
|
|
|
|
|
|
} else { |
|
|
|
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); |
|
|
@ -178,19 +177,17 @@ public class WeatherForecastController extends BaseController { |
|
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
|
if (jsonResult.getInteger("code") == 200) { |
|
|
|
|
|
|
|
jsonObject.put("name",dcRegion.getRegionName()); |
|
|
|
jsonResult.put("name",dcRegion.getRegionName()); |
|
|
|
if (Objects.equals(redisKey, weather.getString("WEATHERFACTS"))) { |
|
|
|
|
|
|
|
jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "now")); |
|
|
|
jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "now", dcRegion)); |
|
|
|
|
|
|
|
} else if (Objects.equals(redisKey, weather.getString("METEOROLOGICALEARLYWARNING"))) { |
|
|
|
|
|
|
|
jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "warning")); |
|
|
|
jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "warning", dcRegion)); |
|
|
|
|
|
|
|
} else if (Objects.equals(redisKey, weather.getString("HOURLYWEATHER"))) { |
|
|
|
|
|
|
|
jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult,"hourly")); |
|
|
|
jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "hourly", dcRegion)); |
|
|
|
} |
|
|
|
} else { |
|
|
|
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); |
|
|
@ -204,7 +201,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); |
|
|
|
|
|
|
@ -221,14 +218,21 @@ public class WeatherForecastController extends BaseController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static Object extracted(JSONObject jsonResult, String type) { |
|
|
|
private static Object extracted(JSONObject jsonResult, String type, DcRegion dcRegion) { |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
jsonObject.put("code", jsonResult.getString("code")); |
|
|
|
if (Objects.equals(jsonResult.getString("code"), "200")) { |
|
|
|
if (Objects.equals(type, "now")) { |
|
|
|
return jsonResult.getJSONObject(type); |
|
|
|
|
|
|
|
JSONObject object = jsonResult.getJSONObject(type); |
|
|
|
object.put("name", dcRegion.getRegionName()); |
|
|
|
return object; |
|
|
|
} else { |
|
|
|
return jsonResult.getJSONArray(type); |
|
|
|
JSONArray jsonArray = jsonResult.getJSONArray(type); |
|
|
|
jsonArray.forEach(item -> { |
|
|
|
((JSONObject) item).put("name", dcRegion.getRegionName()); |
|
|
|
}); |
|
|
|
return jsonArray; |
|
|
|
} |
|
|
|
} else if (Objects.equals(jsonResult.getString("code"), "500")) { |
|
|
|
jsonObject.put("msg", "请求失败:无响应或超时"); |
|
|
@ -272,7 +276,7 @@ public class WeatherForecastController extends BaseController { |
|
|
|
|
|
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
|
if (jsonResult.getInteger("code") == 200) { |
|
|
|
jsonObject.put("weatherInTheAreaWhereTheIncidentOccurred",jsonResult); |
|
|
|
jsonObject.put("weatherInTheAreaWhereTheIncidentOccurred", jsonResult); |
|
|
|
} else { |
|
|
|
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); |
|
|
|
} |
|
|
|