You've already forked FrameTour-BE
fix(device): 添加空值检查避免空指针异常- 在设置设备在线状态时添加对 lastActiveTime 和 clientIP 的空值检查
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good
- 在判断设备是否在线时,增加对 keepaliveAt 时间的空值判断 - 防止因空值导致的 NullPointerException 异常- 提高代码健壮性和稳定性
This commit is contained in:
@@ -75,8 +75,13 @@ public class DeviceRepository {
|
||||
if (statusDto != null) {
|
||||
// Boolean转Integer: true→1, false→0
|
||||
entity.setOnline(statusDto.getIsOnline() != null && statusDto.getIsOnline() ? 1 : 0);
|
||||
entity.setKeepaliveAt(statusDto.getLastActiveTime());
|
||||
entity.setIpAddr(statusDto.getClientIP());
|
||||
// 添加空值检查,避免NullPointerException
|
||||
if (statusDto.getLastActiveTime() != null) {
|
||||
entity.setKeepaliveAt(statusDto.getLastActiveTime());
|
||||
}
|
||||
if (statusDto.getClientIP() != null) {
|
||||
entity.setIpAddr(statusDto.getClientIP());
|
||||
}
|
||||
} else {
|
||||
// 默认离线状态
|
||||
entity.setOnline(0);
|
||||
|
Reference in New Issue
Block a user