fix: 设备离线bug修复:设备通过保活时间离线后,无法切换为在线状态的bug

V0.5.x
gaoyoulong 2024-04-16 13:32:13 +08:00
parent 8368eb0822
commit 01354d2369
1 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,51 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.ruleengine.handler.sys;
import cc.iotkit.common.thing.ThingModelMessage;
import cc.iotkit.data.manager.IDeviceInfoData;
import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.ruleengine.handler.DeviceMessageHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import javax.transaction.Transactional;
/**
*
*/
@Slf4j
@Component
public class DeviceStateCheckHandler implements DeviceMessageHandler {
@Autowired
@Qualifier("deviceInfoDataCache")
private IDeviceInfoData deviceInfoData;
@Override
@Transactional
public void handle(ThingModelMessage msg) {
// 物模型->设备deviceName
String deviceName = msg.getDeviceName();
DeviceInfo realTimeDevice = deviceInfoData.findByDeviceName(deviceName);
if ( !realTimeDevice.getState().isOnline() ) {
// 切换状态,设备上线
DeviceInfo.State state = realTimeDevice.getState();
state.setOnline(true);
state.setOnlineTime(System.currentTimeMillis());
deviceInfoData.save(realTimeDevice);
}
}
}