From be34547f7ee68fe4d67d3561dc8ff3a2715478f7 Mon Sep 17 00:00:00 2001 From: zhangzhicheng Date: Fri, 16 Aug 2024 16:26:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/dromara/web/service/IotService.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/IotService.java b/ruoyi-admin/src/main/java/org/dromara/web/service/IotService.java index 13765377e..e36c0a738 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/IotService.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/IotService.java @@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.github.benmanes.caffeine.cache.Cache; +import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.utils.MessageUtils; import org.dromara.web.config.CommonYmlConfig; import org.dromara.web.device.iot.DeviceCtlDto; @@ -26,6 +27,7 @@ import java.util.Map; * @Discription : iot相关服务 **/ @Service +@Slf4j public class IotService { @Resource private Cache tokenCache; @@ -102,8 +104,15 @@ public class IotService { map.put("entityId",deviceCode); map.put("scope","SERVER_SCOPE"); String send = getSend(CommonYmlConfig.URL_IOT_SCOPE_ATTRIBUTE + "?keys=active", map); - if (send.startsWith("{")) throw new RuntimeException("获取服务端属性信息失败"); - JSONArray jsonObject = JSON.parseArray(send); + log.info("设备信息获取成功,设备编号:{},IOT接口返回:{}", deviceCode, send); + if (send.startsWith("{")) throw new RuntimeException(MessageUtils.message("message.fault.device.notfound")); + JSONArray jsonObject = null; + try { + jsonObject = JSON.parseArray(send); + } catch (Exception e) { + log.error("设备信息获取失败,请检查设备编号是否正确,设备编号:{},IOT接口返回:{}", deviceCode, send); + throw new RuntimeException(MessageUtils.message("message.fault.device.notfound")); + } String resultString = JSON.toJSONString(jsonObject.get(0)); Object value = JSON.parseObject(resultString).get("value"); DeviceServerMsgDto result = new DeviceServerMsgDto();