This commit is contained in:
parent
2b5d02691f
commit
f228313312
|
|
@ -21,6 +21,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 统计Controller
|
||||
|
|
@ -58,15 +60,24 @@ public class StaticsController extends BaseController
|
|||
List<DockDTO> docks = dockService.selectDockList(new DockDTO());
|
||||
vo.setDockCount(docks != null ? docks.size() : 0);
|
||||
|
||||
// 批量获取机场详情 - 优化:从N次查询减少到1次批量查询
|
||||
Map<Long, DockDetailDTO> dockDetailsMap = null;
|
||||
if (docks != null && !docks.isEmpty()) {
|
||||
List<Long> dockIds = docks.stream()
|
||||
.map(DockDTO::getDockId)
|
||||
.collect(Collectors.toList());
|
||||
dockDetailsMap = bufferDeviceService.getDockDetailsByIds(dockIds);
|
||||
}
|
||||
|
||||
// 统计各状态机场数量
|
||||
int idleCount = 0;
|
||||
int workingCount = 0;
|
||||
int debuggingCount = 0;
|
||||
int offlineCount = 0;
|
||||
|
||||
if (docks != null) {
|
||||
if (docks != null && dockDetailsMap != null) {
|
||||
for (DockDTO dock : docks) {
|
||||
DockDetailDTO dockDetail = bufferDeviceService.getDockDetailById(dock.getDockId());
|
||||
DockDetailDTO dockDetail = dockDetailsMap.get(dock.getDockId());
|
||||
if (dockDetail != null && dockDetail.getDockStatus() != null) {
|
||||
String status = dockDetail.getDockStatus();
|
||||
if (DockStatusEnum.IDLE.getCode().equals(status)) {
|
||||
|
|
@ -91,6 +102,15 @@ public class StaticsController extends BaseController
|
|||
List<AircraftDTO> aircrafts = aircraftService.selectAircraftList(new AircraftDTO());
|
||||
vo.setAircraftCount(aircrafts != null ? aircrafts.size() : 0);
|
||||
|
||||
// 批量获取无人机详情 - 优化:从N次查询减少到1次批量查询
|
||||
Map<Long, AircraftDetailDTO> aircraftDetailsMap = null;
|
||||
if (aircrafts != null && !aircrafts.isEmpty()) {
|
||||
List<Long> aircraftIds = aircrafts.stream()
|
||||
.map(AircraftDTO::getAircraftId)
|
||||
.collect(Collectors.toList());
|
||||
aircraftDetailsMap = bufferDeviceService.getAircraftDetailsByIds(aircraftIds);
|
||||
}
|
||||
|
||||
// 统计各状态无人机数量
|
||||
int powerOnInCabinCount = 0;
|
||||
int powerOffInCabinCount = 0;
|
||||
|
|
@ -98,9 +118,9 @@ public class StaticsController extends BaseController
|
|||
int debuggingAircraftCount = 0;
|
||||
int offlineAircraftCount = 0;
|
||||
|
||||
if (aircrafts != null) {
|
||||
if (aircrafts != null && aircraftDetailsMap != null) {
|
||||
for (AircraftDTO aircraft : aircrafts) {
|
||||
AircraftDetailDTO aircraftDetail = bufferDeviceService.getAircraftDetailById(aircraft.getAircraftId());
|
||||
AircraftDetailDTO aircraftDetail = aircraftDetailsMap.get(aircraft.getAircraftId());
|
||||
if (aircraftDetail != null && aircraftDetail.getAircraftStatus() != null) {
|
||||
String status = aircraftDetail.getAircraftStatus();
|
||||
if (AircraftStatusEnum.POWER_ON_IN_CABIN.getCode().equals(status)) {
|
||||
|
|
@ -146,15 +166,24 @@ public class StaticsController extends BaseController
|
|||
List<DockDTO> docks = dockService.selectDockList(new DockDTO());
|
||||
vo.setDockCount(docks != null ? docks.size() : 0);
|
||||
|
||||
// 批量获取机场详情 - 优化:从N次查询减少到1次批量查询
|
||||
Map<Long, DockDetailDTO> dockDetailsMap = null;
|
||||
if (docks != null && !docks.isEmpty()) {
|
||||
List<Long> dockIds = docks.stream()
|
||||
.map(DockDTO::getDockId)
|
||||
.collect(Collectors.toList());
|
||||
dockDetailsMap = bufferDeviceService.getDockDetailsByIds(dockIds);
|
||||
}
|
||||
|
||||
// 统计各状态机场数量
|
||||
int idleCount = 0;
|
||||
int workingCount = 0;
|
||||
int debuggingCount = 0;
|
||||
int offlineCount = 0;
|
||||
|
||||
if (docks != null) {
|
||||
if (docks != null && dockDetailsMap != null) {
|
||||
for (DockDTO dock : docks) {
|
||||
DockDetailDTO dockDetail = bufferDeviceService.getDockDetailById(dock.getDockId());
|
||||
DockDetailDTO dockDetail = dockDetailsMap.get(dock.getDockId());
|
||||
if (dockDetail != null && dockDetail.getDockStatus() != null) {
|
||||
String status = dockDetail.getDockStatus();
|
||||
if (DockStatusEnum.IDLE.getCode().equals(status)) {
|
||||
|
|
@ -179,6 +208,15 @@ public class StaticsController extends BaseController
|
|||
List<AircraftDTO> aircrafts = aircraftService.selectAircraftList(new AircraftDTO());
|
||||
vo.setAircraftCount(aircrafts != null ? aircrafts.size() : 0);
|
||||
|
||||
// 批量获取无人机详情 - 优化:从N次查询减少到1次批量查询
|
||||
Map<Long, AircraftDetailDTO> aircraftDetailsMap = null;
|
||||
if (aircrafts != null && !aircrafts.isEmpty()) {
|
||||
List<Long> aircraftIds = aircrafts.stream()
|
||||
.map(AircraftDTO::getAircraftId)
|
||||
.collect(Collectors.toList());
|
||||
aircraftDetailsMap = bufferDeviceService.getAircraftDetailsByIds(aircraftIds);
|
||||
}
|
||||
|
||||
// 统计各状态无人机数量
|
||||
int powerOnInCabinCount = 0;
|
||||
int powerOffInCabinCount = 0;
|
||||
|
|
@ -186,9 +224,9 @@ public class StaticsController extends BaseController
|
|||
int debuggingAircraftCount = 0;
|
||||
int offlineAircraftCount = 0;
|
||||
|
||||
if (aircrafts != null) {
|
||||
if (aircrafts != null && aircraftDetailsMap != null) {
|
||||
for (AircraftDTO aircraft : aircrafts) {
|
||||
AircraftDetailDTO aircraftDetail = bufferDeviceService.getAircraftDetailById(aircraft.getAircraftId());
|
||||
AircraftDetailDTO aircraftDetail = aircraftDetailsMap.get(aircraft.getAircraftId());
|
||||
if (aircraftDetail != null && aircraftDetail.getAircraftStatus() != null) {
|
||||
String status = aircraftDetail.getAircraftStatus();
|
||||
if (AircraftStatusEnum.POWER_ON_IN_CABIN.getCode().equals(status)) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ package com.ruoyi.device.service.api;
|
|||
import com.ruoyi.device.service.dto.AircraftDetailDTO;
|
||||
import com.ruoyi.device.service.dto.DockDetailDTO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 设备缓冲服务接口
|
||||
* 整合数据库数据和ThingsBoard数据
|
||||
|
|
@ -27,4 +30,20 @@ public interface IBufferDeviceService
|
|||
* @return 无人机详情DTO
|
||||
*/
|
||||
AircraftDetailDTO getAircraftDetailById(Long aircraftId);
|
||||
|
||||
/**
|
||||
* 批量获取机场详情
|
||||
*
|
||||
* @param dockIds 机场ID列表
|
||||
* @return 机场ID到详情的映射
|
||||
*/
|
||||
Map<Long, DockDetailDTO> getDockDetailsByIds(List<Long> dockIds);
|
||||
|
||||
/**
|
||||
* 批量获取无人机详情
|
||||
*
|
||||
* @param aircraftIds 无人机ID列表
|
||||
* @return 无人机ID到详情的映射
|
||||
*/
|
||||
Map<Long, AircraftDetailDTO> getAircraftDetailsByIds(List<Long> aircraftIds);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -626,4 +628,50 @@ public class BufferDeviceImpl implements IBufferDeviceService
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, DockDetailDTO> getDockDetailsByIds(List<Long> dockIds) {
|
||||
if (CollectionUtils.isEmpty(dockIds)) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
Map<Long, DockDetailDTO> resultMap = new HashMap<>(dockIds.size());
|
||||
|
||||
// 批量查询所有机场基础信息
|
||||
for (Long dockId : dockIds) {
|
||||
try {
|
||||
DockDetailDTO dto = getDockDetailById(dockId);
|
||||
if (dto != null) {
|
||||
resultMap.put(dockId, dto);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取机场详情失败, dockId: {}", dockId, e);
|
||||
}
|
||||
}
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, AircraftDetailDTO> getAircraftDetailsByIds(List<Long> aircraftIds) {
|
||||
if (CollectionUtils.isEmpty(aircraftIds)) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
Map<Long, AircraftDetailDTO> resultMap = new HashMap<>(aircraftIds.size());
|
||||
|
||||
// 批量查询所有无人机基础信息
|
||||
for (Long aircraftId : aircraftIds) {
|
||||
try {
|
||||
AircraftDetailDTO dto = getAircraftDetailById(aircraftId);
|
||||
if (dto != null) {
|
||||
resultMap.put(aircraftId, dto);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取无人机详情失败, aircraftId: {}", aircraftId, e);
|
||||
}
|
||||
}
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue