fix:大屏查询记录GC问题

hhk
HuangHuiKang 3 weeks ago
parent cbc80dd6d1
commit 46abf68b04

@ -1192,15 +1192,20 @@ public class DeviceServiceImpl implements DeviceService {
try {
String deviceIdsJson = deviceMapper.selectDeviceIdsByGoviewId(goviewId);
log.info("deviceIdsJson: {}", deviceIdsJson);
if (StringUtils.isBlank(deviceIdsJson)) {
log.info("deviceIdsJson is blank, returning empty result");
return result;
}
// 1. 解析(允许重复 device
List<Map.Entry<Long, Set<Long>>> deviceAttributeList =
parseDeviceIdsJson(deviceIdsJson);
log.info("Parsed deviceAttributeList size: {}", deviceAttributeList.size());
if (CollectionUtils.isEmpty(deviceAttributeList)) {
log.info("deviceAttributeList is empty, returning empty result");
return result;
}
@ -1212,12 +1217,15 @@ public class DeviceServiceImpl implements DeviceService {
Set<Long> allAttributeIds = deviceAttributeList.stream()
.flatMap(e -> e.getValue().stream())
.collect(Collectors.toSet());
log.info("allDeviceIds: {}", allDeviceIds);
log.info("allAttributeIds: {}", allAttributeIds);
// 3. 批量查设备
Map<Long, DeviceDO> deviceMap = deviceMapper
.selectBatchIds(allDeviceIds)
.stream()
.collect(Collectors.toMap(DeviceDO::getId, Function.identity()));
log.info("deviceMap size: {}", deviceMap.size());
// 4. 批量查属性
Map<Long, DeviceContactModelDO> attributeMap =
@ -1228,23 +1236,32 @@ public class DeviceServiceImpl implements DeviceService {
DeviceContactModelDO::getId,
Function.identity()
));
log.info("attributeMap size: {}", attributeMap.size());
// 5. 批量查运行状态
Map<Long, DeviceOperationRecordDO> latestRecordMap =
getLatestDeviceOperationRecords(allDeviceIds);
log.info("latestRecordMap size: {}", latestRecordMap.size());
// 6. 批量查最新采集数据(需为批量方法)
Map<Long, Map<Long, Map<String, Object>>> deviceDataMap =
createDeviceDataMapBatch(allDeviceIds, attributeMap);
log.info("deviceDataMap size: {}", deviceDataMap.size());
// 7. 按原始结构组装(不合并重复设备)
for (Map.Entry<Long, Set<Long>> entry : deviceAttributeList) {
Long deviceId = entry.getKey();
Set<Long> attributeIds = entry.getValue();
log.info("Processing deviceId: {}, attributeIds: {}", deviceId, attributeIds);
DeviceDO device = deviceMap.get(deviceId);
if (device == null) {
log.info("Device not found for deviceId: {}", deviceId);
continue;
}
@ -1266,6 +1283,7 @@ public class DeviceServiceImpl implements DeviceService {
DeviceContactModelDO attribute = attributeMap.get(attributeId);
if (attribute == null) {
log.info("Attribute not found for attributeId: {}", attributeId);
continue;
}
@ -1289,7 +1307,7 @@ public class DeviceServiceImpl implements DeviceService {
deviceResult.put("attributes", attributeList);
result.add(deviceResult);
}
log.info("Final result size: {}", result.size());
} catch (Exception e) {
log.error("Failed to get multi-device attributes by goviewId: {}", goviewId, e);
}

Loading…
Cancel
Save