Browse Source

太阳能板,设备在线

develop
王兴琳 3 weeks ago
parent
commit
1556e912df
  1. 31
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java
  2. 2
      zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java
  3. 10
      zc-business/src/main/resources/mapper/OnlineSumMapper.xml

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

@ -455,10 +455,12 @@ public class DcDeviceController extends BaseController {
calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1,
calendar.get(Calendar.DAY_OF_MONTH), hour);
//转换为 double 类型,去除单位
//转换为 double 类型,去除单位
String valueWithoutUnit = formatValueStr.replaceAll("[^\\d.]", "");
double formatValue = Double.parseDouble(decimalFormat.format(valueWithoutUnit));
// double formatValue = Double.parseDouble(valueWithoutUnit);
double parsedValue = Double.parseDouble(valueWithoutUnit);
// 保留两位小数
double formatValue = Double.parseDouble(decimalFormat.format(parsedValue));
// 汇总每个小时的数据
deviceHourlyAggregates.merge(key, formatValue, Double::sum);
}
@ -505,7 +507,10 @@ public class DcDeviceController extends BaseController {
String property = data.get("property").getAsString();
String formatValueStr = data.get("formatValue").getAsString();
String valueWithoutUnit = formatValueStr.replaceAll("[^\\d.]", "");
double value = Double.parseDouble(decimalFormat.format(valueWithoutUnit));
double value2 = Double.parseDouble(valueWithoutUnit);
double value = Double.parseDouble(decimalFormat.format(value2));
attributeMap.merge(property, value, (oldVal, newVal) -> oldVal + newVal);
}
}
@ -897,8 +902,26 @@ public class DcDeviceController extends BaseController {
//获取要回滚的数据
JSONObject mdJSONObject = (JSONObject) JSON.toJSON(getDeviceLatestProperty(iotDeviceId, UniversalEnum.MD.getValue()).get("data"));
if (mdJSONObject==null) {
JSONObject result = new JSONObject();
result.put("device", device.getString("id"));
result.put("deviceType", device.getInteger("deviceType"));
result.put("functionId", UniversalEnum.MD.getValue());
result.put("result", AjaxResult.error());
resultArray.add(result);
break;
}
String mdValue = mdJSONObject.getString("value");
JSONObject tmJSONObject = (JSONObject) JSON.toJSON(getDeviceLatestProperty(iotDeviceId, UniversalEnum.TM.getValue()).get("data"));
if (tmJSONObject==null) {
JSONObject result = new JSONObject();
result.put("device", device.getString("id"));
result.put("deviceType", device.getInteger("deviceType"));
result.put("functionId", UniversalEnum.TM.getValue());
result.put("result", AjaxResult.error());
resultArray.add(result);
break;
}
String tmValue = tmJSONObject.getString("value");
//循环执行功能
for (Object function : functions) {

2
zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java

@ -496,7 +496,7 @@ public class DcDeviceOnlineController extends BaseController {
List<Double> lossRate = new ArrayList<>();
List<Double> rttAvg = new ArrayList<>();
onlineLogs.stream().sorted(Comparator.comparing(OnlineLog::getMonitorTime)).forEach(onlineLog -> {
xAxis.add(onlineLog.getMonitorTime().format(DateTimeFormatter.ofPattern("HH:mm")));
xAxis.add(onlineLog.getMonitorTime().format(DateTimeFormatter.ofPattern("HH:mm:ss")));
lossRate.add(onlineLog.getLossRate());
rttAvg.add(onlineLog.getRttAvg());
});

10
zc-business/src/main/resources/mapper/OnlineSumMapper.xml

@ -88,10 +88,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
offline_rate,loss_rate,rtt_avg,network_quality,statistical_date
from dc_device d
join dc_online_sum s on s.device_id = d.id
JOIN
(SELECT device_id, MAX(statistical_date) AS max_date
FROM dc_online_sum
WHERE DATE(statistical_date) = CURDATE()
GROUP BY device_id) s_max
ON
s.device_id = s_max.device_id AND s.statistical_date = s_max.max_date
where
DATE(s.statistical_date) = CURDATE()
<if test="type.length != 0">
and (d.device_type in
(d.device_type in
<foreach item="typeItem" collection="type" open="(" separator="," close=")">
#{typeItem}
</foreach>

Loading…
Cancel
Save