|
@@ -2,7 +2,9 @@ package com.hfln.portal.infrastructure.mqtt.handlers;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.hfln.portal.infrastructure.po.DevInfo;
|
|
|
+import com.hfln.portal.infrastructure.po.DevOnOffInfo;
|
|
|
import com.hfln.portal.infrastructure.service.DevInfoService;
|
|
|
+import com.hfln.portal.infrastructure.service.DevOnOffInfoService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
@@ -12,10 +14,15 @@ import java.time.LocalDateTime;
|
|
|
@Component
|
|
|
public class LoginHandler extends BaseMqttHandler implements MqttMessageHandler {
|
|
|
|
|
|
- private LoginHandler(DevInfoService devInfoService) {
|
|
|
+ private final DevOnOffInfoService devOnOffInfoService;
|
|
|
+
|
|
|
+ private LoginHandler(DevInfoService devInfoService,
|
|
|
+ DevOnOffInfoService devOnOffInfoService) {
|
|
|
super(devInfoService);
|
|
|
+ this.devOnOffInfoService = devOnOffInfoService;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public boolean supports(String action) {
|
|
|
return "login".equals(action);
|
|
@@ -30,7 +37,7 @@ public class LoginHandler extends BaseMqttHandler implements MqttMessageHandler
|
|
|
log.warn("Device not found for clientId: {}", clientId);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+ // 设备上线 更新设备状态
|
|
|
devInfoService.update(
|
|
|
new LambdaUpdateWrapper<DevInfo>()
|
|
|
.eq(DevInfo::getClientId, clientId)
|
|
@@ -39,5 +46,11 @@ public class LoginHandler extends BaseMqttHandler implements MqttMessageHandler
|
|
|
.set(DevInfo::getOnoffTime, LocalDateTime.now())
|
|
|
.set(DevInfo::getPresenceChangeTime, LocalDateTime.now())
|
|
|
);
|
|
|
+ // 设备上线 添加设备上线记录
|
|
|
+ DevOnOffInfo devOnOffInfo= new DevOnOffInfo();
|
|
|
+ devOnOffInfo.setTenantId(dev.getTenantId());
|
|
|
+ devOnOffInfo.setDevId(dev.getDevId());
|
|
|
+ devOnOffInfo.setType("on");
|
|
|
+ devOnOffInfoService.save(devOnOffInfo);
|
|
|
}
|
|
|
}
|