Commit c6e7860d by huangjy

fix:修复bug

parent 13dfe05c
......@@ -73,4 +73,6 @@ public interface PlatDeviceService extends IService<PlatDevice> {
PlatDeviceViewVO viewByDeviceId(String id);
void batchEditProperties(PlatDeviceAttrDTO dto);
void updateDeviceStatus(String messageType, String deviceId, String iot_tenantId);
}
......@@ -607,7 +607,7 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
@Override
@TenantIdIgnore
public boolean updateDeviceStatus(String messageType, String deviceId, String iot_tenantId) {
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())) {
......@@ -618,17 +618,16 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
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);
if (CollectionUtils.isEmpty(deviceList)) {
return;
}
return true;
for (PlatDevice platDevice : deviceList) {
platDevice.setStatus(messageType.toLowerCase());
}
deviceCacheUtil.putAll(deviceList);
}
}catch (Exception e){
log.error("更新设备状态:",e);
}
return false;
}
}
......@@ -58,8 +58,6 @@ public class PushCallback implements MqttCallback {
@Autowired
private PlatDeviceService platDeviceService;
@Autowired
private PlatTenantService platTenantService;
@Autowired
private StringRedisTemplate redisTemplate;
......@@ -118,15 +116,13 @@ public class PushCallback implements MqttCallback {
String deviceId = device.getDeviceId();
String messageType = device.getMessageType();
//更新设备状态
boolean statusFlag = platDeviceService.updateDeviceStatus(messageType, deviceId, "");
if (statusFlag) {
return;
}
platDeviceService.updateDeviceStatus(messageType,deviceId,"");
for (HeaderInfo.Bind binding : bindings) {
try {
String iot_tenantId = binding.getId();
StopWatch stopWatch = new StopWatch();
stopWatch.start("checkAlarm-1");
JSONObject properties = device.getProperties();
//iot设备id
......@@ -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