|
|
@ -529,27 +529,61 @@ private VideoController videoController; |
|
|
|
decimalFormat.setRoundingMode(RoundingMode.HALF_UP); |
|
|
|
for (DcDevice dcDevice : dcDevices) { |
|
|
|
String deviceId = dcDevice.getIotDeviceId(); |
|
|
|
for (String propertyId : propertyIds) { |
|
|
|
// for (String propertyId : propertyIds) {
|
|
|
|
try (Response response = new OkHttpClient().newCall(new Request.Builder() |
|
|
|
.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()) |
|
|
|
.build()).execute()) { |
|
|
|
String responseBody = response.body().string(); |
|
|
|
JsonObject jsonObject = JsonParser.parseString(responseBody).getAsJsonObject(); |
|
|
|
if (jsonObject.has("data"))// 确认 "data" 字段是否存在
|
|
|
|
// JsonObject jsonObject = JsonParser.parseString(responseBody).getAsJsonObject();
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(responseBody); |
|
|
|
JSONArray jsonArray = jsonObject.getJSONArray("data"); |
|
|
|
if (jsonArray!=null)// 确认 "data" 字段是否存在
|
|
|
|
{ |
|
|
|
JsonObject data = jsonObject.getAsJsonObject("data"); |
|
|
|
String property = data.get("property").getAsString(); |
|
|
|
String formatValueStr = data.get("formatValue").getAsString(); |
|
|
|
String valueWithoutUnit = formatValueStr.replaceAll("[^\\d.]", ""); |
|
|
|
|
|
|
|
double value2 = Double.parseDouble(valueWithoutUnit); |
|
|
|
double value = Double.parseDouble(decimalFormat.format(value2)); |
|
|
|
// 在合并时重新应用格式化
|
|
|
|
attributeMap.merge(property, value, (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal))); |
|
|
|
// JsonArray data = jsonObject.getAsJsonArray("data");
|
|
|
|
List<Object> cumulativeElectricityConsumptionInTheYearList = jsonArray.stream().filter(item -> ((JSONObject) JSON.toJSON(item)).getString("property").equals("cumulativeElectricityConsumptionInTheYear")).collect(Collectors.toList()); |
|
|
|
String cumulativeElectricityConsumptionInTheYear = ""; |
|
|
|
if (cumulativeElectricityConsumptionInTheYearList.size()>0) { |
|
|
|
cumulativeElectricityConsumptionInTheYear = ((JSONObject) JSON.toJSON(cumulativeElectricityConsumptionInTheYearList.get(0))).getString("formatValue").replaceAll("[^\\d.]", ""); |
|
|
|
}else { |
|
|
|
cumulativeElectricityConsumptionInTheYear = "0"; |
|
|
|
} |
|
|
|
List<Object> cumulativeElectricityConsumptionOnTheDayList = jsonArray.stream().filter(item -> ((JSONObject) JSON.toJSON(item)).getString("property").equals("cumulativeElectricityConsumptionOnTheDay")).collect(Collectors.toList()); |
|
|
|
String cumulativeElectricityConsumptionOnTheDay = ""; |
|
|
|
if (cumulativeElectricityConsumptionOnTheDayList.size()>0) { |
|
|
|
cumulativeElectricityConsumptionOnTheDay = ((JSONObject) JSON.toJSON(cumulativeElectricityConsumptionOnTheDayList.get(0))).getString("formatValue").replaceAll("[^\\d.]", ""); |
|
|
|
}else { |
|
|
|
cumulativeElectricityConsumptionOnTheDay = "0"; |
|
|
|
} |
|
|
|
List<Object> theAccumulatedChargeOfTheYearList = jsonArray.stream().filter(item -> ((JSONObject) JSON.toJSON(item)).getString("property").equals("theAccumulatedChargeOfTheYear")).collect(Collectors.toList()); |
|
|
|
String theAccumulatedChargeOfTheYear = ""; |
|
|
|
if (theAccumulatedChargeOfTheYearList.size()>0) { |
|
|
|
theAccumulatedChargeOfTheYear = ((JSONObject) JSON.toJSON(theAccumulatedChargeOfTheYearList.get(0))).getString("formatValue").replaceAll("[^\\d.]", ""); |
|
|
|
}else { |
|
|
|
theAccumulatedChargeOfTheYear = "0"; |
|
|
|
} |
|
|
|
List<Object> dailyAccumulatedChargeList = jsonArray.stream().filter(item -> ((JSONObject) JSON.toJSON(item)).getString("property").equals("dailyAccumulatedCharge")).collect(Collectors.toList()); |
|
|
|
String dailyAccumulatedCharge = ""; |
|
|
|
if (theAccumulatedChargeOfTheYearList.size()>0) { |
|
|
|
dailyAccumulatedCharge = ((JSONObject) JSON.toJSON(dailyAccumulatedChargeList.get(0))).getString("formatValue").replaceAll("[^\\d.]", ""); |
|
|
|
}else { |
|
|
|
dailyAccumulatedCharge = "0"; |
|
|
|
} |
|
|
|
|
|
|
|
// String property = data.get("property").getAsString();
|
|
|
|
// String formatValueStr = data.get("formatValue").getAsString();
|
|
|
|
// String valueWithoutUnit = formatValueStr.replaceAll("[^\\d.]", "");
|
|
|
|
//
|
|
|
|
// double value2 = Double.parseDouble(valueWithoutUnit);
|
|
|
|
// double value = Double.parseDouble(decimalFormat.format(value2));
|
|
|
|
// // 在合并时重新应用格式化
|
|
|
|
attributeMap.merge("cumulativeElectricityConsumptionInTheYear", Double.parseDouble(decimalFormat.format(Double.parseDouble(cumulativeElectricityConsumptionInTheYear))), (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal))); |
|
|
|
attributeMap.merge("cumulativeElectricityConsumptionOnTheDay", Double.parseDouble(decimalFormat.format(Double.parseDouble(cumulativeElectricityConsumptionOnTheDay))), (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal))); |
|
|
|
attributeMap.merge("theAccumulatedChargeOfTheYear", Double.parseDouble(decimalFormat.format(Double.parseDouble(theAccumulatedChargeOfTheYear))), (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal))); |
|
|
|
attributeMap.merge("dailyAccumulatedCharge", Double.parseDouble(decimalFormat.format(Double.parseDouble(dailyAccumulatedCharge))), (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal))); |
|
|
|
// attributeMap.merge(property, value, (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal)));
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|