Commit 2a978fc4 by 李小龙
parents fb8d8ce3 5248fa5c
......@@ -73,4 +73,6 @@ public interface PlatDeviceService extends IService<PlatDevice> {
PlatDeviceViewVO viewByDeviceId(String id);
void batchEditProperties(PlatDeviceAttrDTO dto);
boolean updateDeviceStatus(String messageType, String deviceId, String iot_tenantId);
}
......@@ -32,6 +32,7 @@ import com.makeit.enums.CodeMessageEnum;
import com.makeit.enums.CommonEnum;
import com.makeit.enums.report.DeviceNameEnum;
import com.makeit.exception.BusinessException;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.mapper.platform.device.PlatDeviceMapper;
import com.makeit.module.iot.dto.UserServerInfo;
import com.makeit.module.iot.service.IotDevicePropertiesOperateService;
......@@ -603,4 +604,31 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
});
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;
}
}
......@@ -58,8 +58,6 @@ public class PushCallback implements MqttCallback {
@Autowired
private PlatDeviceService platDeviceService;
@Autowired
private PlatTenantService platTenantService;
@Autowired
private StringRedisTemplate redisTemplate;
......@@ -115,15 +113,18 @@ public class PushCallback implements MqttCallback {
redisTemplate.opsForValue().set(DEVICE_FALL_DATA + device.getDeviceId(),JSON.toJSONString(device.getProperties()),
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) {
try {
String iot_tenantId = binding.getId();
StopWatch stopWatch = new StopWatch();
stopWatch.start("checkAlarm-1");
String deviceId = device.getDeviceId();
String messageType = device.getMessageType();
//更新设备状态
updateDeviceStatus(messageType,deviceId,iot_tenantId);
JSONObject properties = device.getProperties();
......@@ -170,32 +171,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