设备使用状态
This commit is contained in:
parent
af0a37eabe
commit
ad2f6bdfba
|
@ -716,6 +716,8 @@ public class DeviceServiceImpl implements DeviceService
|
|||
if (CollectionUtils.isEmptyElement(list)) {
|
||||
return;
|
||||
}
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
for (DeviceVO device : list) {
|
||||
try {
|
||||
if (StringUtils.isAnyBlank(device.getMac(), device.getModelProductId())) {
|
||||
|
@ -736,6 +738,19 @@ public class DeviceServiceImpl implements DeviceService
|
|||
data.setSurplusEle(deviceInfo.getM());
|
||||
}
|
||||
|
||||
// 判断设备是否正在使用
|
||||
// 时长优先级最高,若当前设备过期时间 > 当前时间,则正在使用
|
||||
boolean hasTime = device.getExpireTime().isAfter(now);
|
||||
// 若当前设备有电量,则正在使用
|
||||
boolean hasEle = device.getSurplusEle().compareTo(BigDecimal.ZERO) > 0;
|
||||
// 若开关开启,则正在使用
|
||||
boolean hasOpen = DevicePowerStatus.ON.getStatus().equals(device.getPowerStatus());
|
||||
if (hasTime || hasEle || hasOpen) {
|
||||
data.setStatus(DeviceStatus.USING.getStatus());
|
||||
} else {
|
||||
data.setStatus(DeviceStatus.NORMAL.getStatus());
|
||||
}
|
||||
|
||||
// 是否在线
|
||||
data.setOnlineStatus(iotService.getOnlineStatus(device.getMac(), device.getModelProductId()).getStatus());
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user