|
@ -8,7 +8,6 @@ import com.ruoyi.common.core.redis.RedisCache; |
|
|
import com.zc.business.domain.DcRegion; |
|
|
import com.zc.business.domain.DcRegion; |
|
|
import com.zc.business.service.impl.DcRegionServiceImpl; |
|
|
import com.zc.business.service.impl.DcRegionServiceImpl; |
|
|
import com.zc.common.core.httpclient.OkHttp; |
|
|
import com.zc.common.core.httpclient.OkHttp; |
|
|
import com.zc.common.core.httpclient.exception.HttpException; |
|
|
|
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
import okhttp3.Response; |
|
|
import okhttp3.Response; |
|
@ -17,7 +16,6 @@ import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
@ -53,7 +51,7 @@ public class WeatherForecastController extends BaseController { |
|
|
* */ |
|
|
* */ |
|
|
@ApiOperation("天气实况查询") |
|
|
@ApiOperation("天气实况查询") |
|
|
@PostMapping(value = "/weatherFacts") |
|
|
@PostMapping(value = "/weatherFacts") |
|
|
public AjaxResult weatherFacts() throws HttpException, IOException { |
|
|
public AjaxResult weatherFacts() { |
|
|
return getAjaxResult(WEATHERFACTSURI, WEATHERFACTSKEY, WEATHERFACTS); |
|
|
return getAjaxResult(WEATHERFACTSURI, WEATHERFACTSKEY, WEATHERFACTS); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -62,7 +60,7 @@ public class WeatherForecastController extends BaseController { |
|
|
* */ |
|
|
* */ |
|
|
@ApiOperation("气象预警查询") |
|
|
@ApiOperation("气象预警查询") |
|
|
@PostMapping(value = "/meteorologicalEarlyWarning") |
|
|
@PostMapping(value = "/meteorologicalEarlyWarning") |
|
|
public AjaxResult meteorologicalEarlyWarning() throws HttpException, IOException { |
|
|
public AjaxResult meteorologicalEarlyWarning() { |
|
|
return getAjaxResult(METEOROLOGICALEARLYWARNINGURI, METEOROLOGICALEARLYWARNINGKEY, METEOROLOGICALEARLYWARNING); |
|
|
return getAjaxResult(METEOROLOGICALEARLYWARNINGURI, METEOROLOGICALEARLYWARNINGKEY, METEOROLOGICALEARLYWARNING); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -71,7 +69,7 @@ public class WeatherForecastController extends BaseController { |
|
|
* */ |
|
|
* */ |
|
|
@ApiOperation("气象预警数量查询") |
|
|
@ApiOperation("气象预警数量查询") |
|
|
@PostMapping(value = "/queryTheNumberOfMeteorologicalWarning") |
|
|
@PostMapping(value = "/queryTheNumberOfMeteorologicalWarning") |
|
|
public AjaxResult queryTheNumberOfMeteorologicalWarning() throws HttpException, IOException { |
|
|
public AjaxResult queryTheNumberOfMeteorologicalWarning() { |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
JSONObject cacheObject = redisCache.getCacheObject(METEOROLOGICALEARLYWARNING); |
|
|
JSONObject cacheObject = redisCache.getCacheObject(METEOROLOGICALEARLYWARNING); |
|
|
|
|
|
|
|
@ -84,6 +82,7 @@ public class WeatherForecastController extends BaseController { |
|
|
|
|
|
|
|
|
for (DcRegion dcRegion : list) { |
|
|
for (DcRegion dcRegion : list) { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
OkHttp okHttp = new OkHttp(); |
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
Response response // 请求响应
|
|
@ -103,6 +102,9 @@ public class WeatherForecastController extends BaseController { |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return AjaxResult.error(500, "连接异常,请检查网络"); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
redisCache.setCacheObject(METEOROLOGICALEARLYWARNING, jsonObject, 13, TimeUnit.MINUTES); |
|
|
redisCache.setCacheObject(METEOROLOGICALEARLYWARNING, jsonObject, 13, TimeUnit.MINUTES); |
|
@ -131,11 +133,11 @@ public class WeatherForecastController extends BaseController { |
|
|
* */ |
|
|
* */ |
|
|
@ApiOperation("逐小时天气查询") |
|
|
@ApiOperation("逐小时天气查询") |
|
|
@PostMapping(value = "/hourlyWeather") |
|
|
@PostMapping(value = "/hourlyWeather") |
|
|
public AjaxResult hourlyWeather() throws HttpException, IOException { |
|
|
public AjaxResult hourlyWeather() { |
|
|
return getAjaxResult(HOURLYWEATHERURI, HOURLYWEATHERKEY, HOURLYWEATHER); |
|
|
return getAjaxResult(HOURLYWEATHERURI, HOURLYWEATHERKEY, HOURLYWEATHER); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private AjaxResult getAjaxResult(String uri, String accessKey, String redisKey) throws HttpException, IOException { |
|
|
private AjaxResult getAjaxResult(String uri, String accessKey, String redisKey) { |
|
|
|
|
|
|
|
|
JSONObject cacheObject = redisCache.getCacheObject(redisKey); |
|
|
JSONObject cacheObject = redisCache.getCacheObject(redisKey); |
|
|
|
|
|
|
|
@ -150,6 +152,9 @@ public class WeatherForecastController extends BaseController { |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
|
|
|
|
for (DcRegion dcRegion : list) { |
|
|
for (DcRegion dcRegion : list) { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
Response response // 请求响应
|
|
@ -179,6 +184,11 @@ public class WeatherForecastController extends BaseController { |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
|
|
|
|
return AjaxResult.error(500, "连接异常,请检查网络"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|