Browse Source

太阳能数据

develop
王兴琳 4 months ago
parent
commit
5347de101b
  1. 25
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java

25
zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java

@ -534,16 +534,21 @@ private VideoController videoController;
.url(iotAddress + UniversalEnum.GETS_THE_LATEST_DATA_ABOUT_THE_SPECIFIED_ATTRIBUTES_OF_A_DEVICE.getValue() + deviceId + UniversalEnum.SLASH.getValue() + propertyId) .url(iotAddress + UniversalEnum.GETS_THE_LATEST_DATA_ABOUT_THE_SPECIFIED_ATTRIBUTES_OF_A_DEVICE.getValue() + deviceId + UniversalEnum.SLASH.getValue() + propertyId)
.build()).execute()) { .build()).execute()) {
String responseBody = response.body().string(); String responseBody = response.body().string();
JsonObject data = JsonParser.parseString(responseBody).getAsJsonObject().getAsJsonObject("data"); JsonObject jsonObject = JsonParser.parseString(responseBody).getAsJsonObject();
String property = data.get("property").getAsString(); if (jsonObject.has("data"))// 确认 "data" 字段是否存在
String formatValueStr = data.get("formatValue").getAsString(); {
String valueWithoutUnit = formatValueStr.replaceAll("[^\\d.]", ""); JsonObject data = jsonObject.getAsJsonObject("data");
String property = data.get("property").getAsString();
double value2 = Double.parseDouble(valueWithoutUnit); String formatValueStr = data.get("formatValue").getAsString();
double value = Double.parseDouble(decimalFormat.format(value2)); String valueWithoutUnit = formatValueStr.replaceAll("[^\\d.]", "");
// 在合并时重新应用格式化
attributeMap.merge(property, value, (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal))); double value2 = Double.parseDouble(valueWithoutUnit);
} double value = Double.parseDouble(decimalFormat.format(value2));
// 在合并时重新应用格式化
attributeMap.merge(property, value, (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal)));
}
}
} }
} }

Loading…
Cancel
Save