日志优化

This commit is contained in:
zhangzhicheng 2024-08-16 16:26:03 +08:00
parent 9f4a703415
commit be34547f7e

View File

@ -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<String, String> 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();