159 lines
5.4 KiB
Java
159 lines
5.4 KiB
Java
package com.ruoyi.device.service.impl;
|
|
|
|
import com.ruoyi.device.domain.api.IAircraftDomain;
|
|
import com.ruoyi.device.domain.api.IDeviceDomain;
|
|
import com.ruoyi.device.domain.api.IDockDomain;
|
|
import com.ruoyi.device.domain.model.Aircraft;
|
|
import com.ruoyi.device.domain.model.Device;
|
|
import com.ruoyi.device.domain.model.Dock;
|
|
import com.ruoyi.device.service.api.IBufferDeviceService;
|
|
import com.ruoyi.device.service.dto.AircraftDetailDTO;
|
|
import com.ruoyi.device.service.dto.DockDetailDTO;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.context.annotation.Primary;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 默认设备缓冲服务实现
|
|
* 根据设备厂商自动路由到对应的服务实现
|
|
*
|
|
* @author ruoyi
|
|
* @date 2026-02-04
|
|
*/
|
|
@Service
|
|
@Primary
|
|
@Slf4j
|
|
public class DefaultBufferDeviceImpl implements IBufferDeviceService {
|
|
|
|
@Autowired
|
|
@Qualifier("daJiangBufferDeviceService")
|
|
private IBufferDeviceService daJiangBufferDeviceService;
|
|
|
|
@Autowired
|
|
@Qualifier("tuohengBufferDeviceService")
|
|
private IBufferDeviceService tuohengBufferDeviceService;
|
|
|
|
@Autowired
|
|
private IDockDomain dockDomain;
|
|
|
|
@Autowired
|
|
private IDeviceDomain deviceDomain;
|
|
|
|
@Autowired
|
|
private IAircraftDomain aircraftDomain;
|
|
|
|
@Override
|
|
public DockDetailDTO getDockDetailById(Long dockId) {
|
|
log.debug("DefaultBufferDeviceImpl.getDockDetailById: dockId={}", dockId);
|
|
|
|
// 查询机场信息
|
|
Dock dock = dockDomain.selectDockByDockId(dockId);
|
|
if (dock == null) {
|
|
log.warn("机场不存在: dockId={}", dockId);
|
|
return null;
|
|
}
|
|
|
|
// 查询设备信息,获取厂商
|
|
Device device = deviceDomain.selectDeviceByDeviceId(dock.getDeviceId());
|
|
if (device == null) {
|
|
log.warn("机场对应的设备不存在: deviceId={}", dock.getDeviceId());
|
|
return null;
|
|
}
|
|
|
|
// 根据厂商选择对应的服务
|
|
String manufacturer = device.getDeviceManufacturer();
|
|
if ("tuoheng".equals(manufacturer)) {
|
|
log.debug("路由到拓恒服务: dockId={}", dockId);
|
|
return tuohengBufferDeviceService.getDockDetailById(dockId);
|
|
} else {
|
|
log.debug("路由到大疆服务: dockId={}, manufacturer={}", dockId, manufacturer);
|
|
return daJiangBufferDeviceService.getDockDetailById(dockId);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public AircraftDetailDTO getAircraftDetailById(Long aircraftId) {
|
|
log.debug("DefaultBufferDeviceImpl.getAircraftDetailById: aircraftId={}", aircraftId);
|
|
|
|
// 查询无人机信息
|
|
Aircraft aircraft = aircraftDomain.selectAircraftByAircraftId(aircraftId);
|
|
if (aircraft == null) {
|
|
log.warn("无人机不存在: aircraftId={}", aircraftId);
|
|
return null;
|
|
}
|
|
|
|
// 查询设备信息,获取厂商
|
|
Device device = deviceDomain.selectDeviceByDeviceId(aircraft.getDeviceId());
|
|
if (device == null) {
|
|
log.warn("无人机对应的设备不存在: deviceId={}", aircraft.getDeviceId());
|
|
return null;
|
|
}
|
|
|
|
// 根据厂商选择对应的服务
|
|
String manufacturer = device.getDeviceManufacturer();
|
|
if ("tuoheng".equals(manufacturer)) {
|
|
log.debug("路由到拓恒服务: aircraftId={}", aircraftId);
|
|
return tuohengBufferDeviceService.getAircraftDetailById(aircraftId);
|
|
} else {
|
|
log.debug("路由到大疆服务: aircraftId={}, manufacturer={}", aircraftId, manufacturer);
|
|
return daJiangBufferDeviceService.getAircraftDetailById(aircraftId);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Map<Long, DockDetailDTO> getDockDetailsByIds(List<Long> dockIds) {
|
|
log.debug("DefaultBufferDeviceImpl.getDockDetailsByIds: dockIds.size={}",
|
|
dockIds != null ? dockIds.size() : 0);
|
|
|
|
if (dockIds == null || dockIds.isEmpty()) {
|
|
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) {
|
|
log.debug("DefaultBufferDeviceImpl.getAircraftDetailsByIds: aircraftIds.size={}",
|
|
aircraftIds != null ? aircraftIds.size() : 0);
|
|
|
|
if (aircraftIds == null || aircraftIds.isEmpty()) {
|
|
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;
|
|
}
|
|
}
|