包头bug修复

This commit is contained in:
guoshengxiong 2025-05-15 09:17:04 +08:00
parent 8505fd410a
commit 913d812c9b

View File

@ -140,7 +140,9 @@ public class ElectricalTask {
log.info("电箱实时数据" + execute.body()); log.info("电箱实时数据" + execute.body());
JSONObject result = JSONObject.parseObject(execute.body()).getJSONObject("result"); JSONObject result = JSONObject.parseObject(execute.body()).getJSONObject("result");
JSONObject metric = result.getJSONObject("metric"); JSONObject metric = result.getJSONObject("metric");
String temperatures = String.format("%.1f", Double.parseDouble(result.getJSONArray("temperatures").getJSONObject(0).getString("temperature"))); JSONArray jsonArray = result.getJSONArray("temperatures");
if (CollUtil.isNotEmpty(jsonArray)) {
String temperatures = String.format("%.1f", Double.parseDouble(jsonArray.getJSONObject(0).getString("temperature")));
ElectricalData electricalData = new ElectricalData(devId, ElectricalData electricalData = new ElectricalData(devId,
metric.getString("modified"), metric.getString("modified"),
String.format("%.1f", Double.parseDouble(metric.getString("voltage_a"))), String.format("%.1f", Double.parseDouble(metric.getString("voltage_a"))),
@ -153,6 +155,7 @@ public class ElectricalTask {
temperatures, temperatures, temperatures, temperatures, temperatures, temperatures,
temperatures); temperatures);
electricalDataService.saveElectricalData(electricalData); electricalDataService.saveElectricalData(electricalData);
}
return true; return true;
} }
return false; return false;