diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java index 0dbf335d..e34c5a56 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java @@ -765,11 +765,20 @@ private VideoController videoController; } OkHttp okHttp = new OkHttp(); - Response response // 请求响应 - = okHttp - .url(iotAddress + UniversalEnum.GETS_THE_LATEST_DATA_ABOUT_THE_SPECIFIED_ATTRIBUTES_OF_A_DEVICE.getValue() + deviceId + UniversalEnum.SLASH.getValue() + propertyId) // 请求地址 - .get(); // 请求方法 - return JSON.parseObject(response.body().string(), AjaxResult.class); + String requestUrl = iotAddress + UniversalEnum.GETS_THE_LATEST_DATA_ABOUT_THE_SPECIFIED_ATTRIBUTES_OF_A_DEVICE.getValue() + deviceId + UniversalEnum.SLASH.getValue() + propertyId; + + try { + Response response = okHttp.url(requestUrl).get(); + return JSON.parseObject(response.body().string(), AjaxResult.class); + } catch (HttpException | IOException e) { + if (e instanceof io.netty.handler.timeout.ReadTimeoutException) { + // 捕获到超时异常,返回稍后再试的提示 + return AjaxResult.success(""); + } else { + // 其他异常,返回错误 + return AjaxResult.error("请求失败:" + e.getMessage()); + } + } } /**