Commit 2ee7c12d by huangjy

fix: 更新设备状态

parent b2048f88
......@@ -449,7 +449,7 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
List<PlatDevice> deviceListSpace = getSpaceDevice(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
List<PlatDevice> deviceListFall = getFallDevice(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
///List<PlatDevice> deviceListFall = getFallDevice(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
int count = 20;
for (PlatDevice platDevice : deviceListSpace) {
for (int i = 0; i < count; i++) {
......
......@@ -3,6 +3,7 @@ package com.makeit.mqtt;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.makeit.common.entity.BaseBusEntity;
import com.makeit.common.entity.BaseEntity;
import com.makeit.dto.platform.alarm.PlatAlarmCheckDTO;
......@@ -154,27 +155,20 @@ public class PushCallback implements MqttCallback {
@Transactional
public void updateDeviceStatus(String messageType, String deviceId, String iot_tenantId) {
if(StringUtils.equalsAnyIgnoreCase(messageType, DeviceState.offline.getValue(),DeviceState.online.getValue())){
LambdaQueryWrapper<PlatTenant> platTenantLambdaQueryWrapper = new LambdaQueryWrapper<>();
platTenantLambdaQueryWrapper.eq(PlatTenant::getIotOrgId,iot_tenantId);
List<PlatTenant> platTenants = platTenantService.list(platTenantLambdaQueryWrapper);
if(CollectionUtils.isEmpty(platTenants)){
return;
}
List<String> tenantIdList = platTenants.stream().map(BaseEntity::getId).collect(Collectors.toList());
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)
.in(BaseBusEntity::getTenantId,tenantIdList);
deviceLambdaQueryWrapper.eq(PlatDevice::getOriDeviceId,deviceId);
List<PlatDevice> deviceList = platDeviceService.list(deviceLambdaQueryWrapper);
if(CollectionUtils.isEmpty(deviceList)){
return;
}
for (PlatDevice platDevice : deviceList) {
platDevice.setStatus(messageType.toLowerCase());
}
platDeviceService.updateBatchById(deviceList);
deviceCacheUtil.putAll(deviceList);
}
......
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