Commit 20e6891c by huangjy

fix:设备上下线报错问题

parent 2d65945b
...@@ -70,4 +70,7 @@ public interface PlatDeviceService extends IService<PlatDevice> { ...@@ -70,4 +70,7 @@ public interface PlatDeviceService extends IService<PlatDevice> {
void savePlatDevice(); void savePlatDevice();
PlatDeviceViewVO viewByDeviceId(String id); PlatDeviceViewVO viewByDeviceId(String id);
boolean updateDeviceStatus(String messageType, String deviceId, String iot_tenantId);
} }
...@@ -34,6 +34,7 @@ import com.makeit.enums.CommonEnum; ...@@ -34,6 +34,7 @@ import com.makeit.enums.CommonEnum;
import com.makeit.enums.HeaderConst; import com.makeit.enums.HeaderConst;
import com.makeit.enums.report.DeviceNameEnum; import com.makeit.enums.report.DeviceNameEnum;
import com.makeit.exception.BusinessException; import com.makeit.exception.BusinessException;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.mapper.platform.device.PlatDeviceMapper; import com.makeit.mapper.platform.device.PlatDeviceMapper;
import com.makeit.module.iot.service.IotDevicePropertiesOperateService; import com.makeit.module.iot.service.IotDevicePropertiesOperateService;
import com.makeit.module.iot.service.IotOrgService; import com.makeit.module.iot.service.IotOrgService;
...@@ -535,4 +536,31 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -535,4 +536,31 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
}); });
return deviceMap.values(); return deviceMap.values();
} }
@Override
@TenantIdIgnore
public boolean updateDeviceStatus(String messageType, String deviceId, String iot_tenantId) {
try {
if (org.apache.commons.lang3.StringUtils.equalsAnyIgnoreCase(messageType, com.makeit.module.iot.enums.DeviceState.offline.getValue(), com.makeit.module.iot.enums.DeviceState.online.getValue())) {
update(new UpdateWrapper<PlatDevice>().lambda()
.set(PlatDevice::getStatus, messageType.toLowerCase())
.eq(PlatDevice::getOriDeviceId, deviceId));
LambdaQueryWrapper<PlatDevice> deviceLambdaQueryWrapper = new LambdaQueryWrapper<>();
deviceLambdaQueryWrapper.eq(PlatDevice::getOriDeviceId, deviceId);
List<PlatDevice> deviceList = list(deviceLambdaQueryWrapper);
if (CollectionUtils.isNotEmpty(deviceList)) {
for (PlatDevice platDevice : deviceList) {
platDevice.setStatus(messageType.toLowerCase());
}
deviceCacheUtil.putAll(deviceList);
}
return true;
}
}catch (Exception e){
log.error("更新设备状态:",e);
}
return false;
}
} }
...@@ -120,16 +120,18 @@ public class PushCallback implements MqttCallback { ...@@ -120,16 +120,18 @@ public class PushCallback implements MqttCallback {
redisTemplate.opsForValue().set(DEVICE_FALL_DATA + device.getDeviceId(),JSON.toJSONString(device.getProperties()), redisTemplate.opsForValue().set(DEVICE_FALL_DATA + device.getDeviceId(),JSON.toJSONString(device.getProperties()),
1000, TimeUnit.MILLISECONDS); 1000, TimeUnit.MILLISECONDS);
} }
String deviceId = device.getDeviceId();
String messageType = device.getMessageType();
//更新设备状态
boolean statusFlag = platDeviceService.updateDeviceStatus(messageType, deviceId, "");
if (statusFlag) {
return;
}
for (HeaderInfo.Bind binding : bindings) { for (HeaderInfo.Bind binding : bindings) {
try { try {
String iot_tenantId = binding.getId(); String iot_tenantId = binding.getId();
StopWatch stopWatch = new StopWatch(); StopWatch stopWatch = new StopWatch();
stopWatch.start("checkAlarm-1"); stopWatch.start("checkAlarm-1");
String deviceId = device.getDeviceId();
String messageType = device.getMessageType();
//更新设备状态
updateDeviceStatus(messageType,deviceId,iot_tenantId);
JSONObject properties = device.getProperties(); JSONObject properties = device.getProperties();
//iot设备id //iot设备id
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment