Commit 4ea26e5f by huangjy

fix:修复bug

parent d4c2dc6e
...@@ -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);
} }
...@@ -32,6 +32,7 @@ import com.makeit.enums.CodeMessageEnum; ...@@ -32,6 +32,7 @@ import com.makeit.enums.CodeMessageEnum;
import com.makeit.enums.CommonEnum; import com.makeit.enums.CommonEnum;
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.dto.UserServerInfo; import com.makeit.module.iot.dto.UserServerInfo;
import com.makeit.module.iot.service.IotDevicePropertiesOperateService; import com.makeit.module.iot.service.IotDevicePropertiesOperateService;
...@@ -603,4 +604,30 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -603,4 +604,30 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
}); });
return deviceMap.values(); return deviceMap.values();
} }
@Override
@TenantIdIgnore
public void 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.isEmpty(deviceList)) {
return;
}
for (PlatDevice platDevice : deviceList) {
platDevice.setStatus(messageType.toLowerCase());
}
deviceCacheUtil.putAll(deviceList);
}
}catch (Exception e){
log.error("更新设备状态:",e);
}
}
} }
...@@ -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;
...@@ -115,15 +113,15 @@ public class PushCallback implements MqttCallback { ...@@ -115,15 +113,15 @@ 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();
//更新设备状态
platDeviceService.updateDeviceStatus(messageType,deviceId,"");
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();
...@@ -170,32 +168,6 @@ public class PushCallback implements MqttCallback { ...@@ -170,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