From 2a60666eecbce1521c54fc3d23d3e69b8c0bce36 Mon Sep 17 00:00:00 2001 From: wangsixiang <2970484253@qq.com> Date: Sat, 21 Dec 2024 16:08:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E6=97=B6=E6=8D=95=E6=8D=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcDeviceController.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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()); + } + } } /**