Commit c6e7860d by huangjy

fix:修复bug

parent 13dfe05c
...@@ -73,4 +73,6 @@ public interface PlatDeviceService extends IService<PlatDevice> { ...@@ -73,4 +73,6 @@ public interface PlatDeviceService extends IService<PlatDevice> {
PlatDeviceViewVO viewByDeviceId(String id); PlatDeviceViewVO viewByDeviceId(String id);
void batchEditProperties(PlatDeviceAttrDTO dto); void batchEditProperties(PlatDeviceAttrDTO dto);
void updateDeviceStatus(String messageType, String deviceId, String iot_tenantId);
} }
...@@ -607,7 +607,7 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -607,7 +607,7 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
@Override @Override
@TenantIdIgnore @TenantIdIgnore
public boolean updateDeviceStatus(String messageType, String deviceId, String iot_tenantId) { public void updateDeviceStatus(String messageType, String deviceId, String iot_tenantId) {
try { 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())) { if (org.apache.commons.lang3.StringUtils.equalsAnyIgnoreCase(messageType, com.makeit.module.iot.enums.DeviceState.offline.getValue(), com.makeit.module.iot.enums.DeviceState.online.getValue())) {
...@@ -618,17 +618,16 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -618,17 +618,16 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
LambdaQueryWrapper<PlatDevice> deviceLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<PlatDevice> deviceLambdaQueryWrapper = new LambdaQueryWrapper<>();
deviceLambdaQueryWrapper.eq(PlatDevice::getOriDeviceId, deviceId); deviceLambdaQueryWrapper.eq(PlatDevice::getOriDeviceId, deviceId);
List<PlatDevice> deviceList = list(deviceLambdaQueryWrapper); List<PlatDevice> deviceList = list(deviceLambdaQueryWrapper);
if (CollectionUtils.isNotEmpty(deviceList)) { if (CollectionUtils.isEmpty(deviceList)) {
return;
}
for (PlatDevice platDevice : deviceList) { for (PlatDevice platDevice : deviceList) {
platDevice.setStatus(messageType.toLowerCase()); platDevice.setStatus(messageType.toLowerCase());
} }
deviceCacheUtil.putAll(deviceList); deviceCacheUtil.putAll(deviceList);
} }
return true;
}
}catch (Exception e){ }catch (Exception e){
log.error("更新设备状态:",e); log.error("更新设备状态:",e);
} }
return false;
} }
} }
...@@ -58,8 +58,6 @@ public class PushCallback implements MqttCallback { ...@@ -58,8 +58,6 @@ public class PushCallback implements MqttCallback {
@Autowired @Autowired
private PlatDeviceService platDeviceService; private PlatDeviceService platDeviceService;
@Autowired @Autowired
private PlatTenantService platTenantService;
@Autowired
private StringRedisTemplate redisTemplate; private StringRedisTemplate redisTemplate;
...@@ -118,15 +116,13 @@ public class PushCallback implements MqttCallback { ...@@ -118,15 +116,13 @@ public class PushCallback implements MqttCallback {
String deviceId = device.getDeviceId(); String deviceId = device.getDeviceId();
String messageType = device.getMessageType(); String messageType = device.getMessageType();
//更新设备状态 //更新设备状态
boolean statusFlag = platDeviceService.updateDeviceStatus(messageType, deviceId, ""); 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");
JSONObject properties = device.getProperties(); JSONObject properties = device.getProperties();
//iot设备id //iot设备id
...@@ -172,32 +168,6 @@ public class PushCallback implements MqttCallback { ...@@ -172,32 +168,6 @@ public class PushCallback implements MqttCallback {
} }
@Transactional
@TenantIdIgnore
public void updateDeviceStatus(String messageType, String deviceId, String iot_tenantId) {
try {
if (StringUtils.equalsAnyIgnoreCase(messageType, DeviceState.offline.getValue(), DeviceState.online.getValue())) {
platDeviceService.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 = platDeviceService.list(deviceLambdaQueryWrapper);
if (CollectionUtils.isEmpty(deviceList)) {
return;
}
for (PlatDevice platDevice : deviceList) {
platDevice.setStatus(messageType.toLowerCase());
}
deviceCacheUtil.putAll(deviceList);
}
}catch (Exception e){
logger.error("更新设备状态:",e);
}
}
} }
......
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