Merge branch 'rem_scenic_device'

This commit is contained in:
2025-09-09 01:37:52 +08:00
23 changed files with 546 additions and 74 deletions

View File

@@ -17,6 +17,8 @@ import lombok.extern.slf4j.Slf4j;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
@Slf4j
@@ -165,4 +167,77 @@ public class DeviceRepository {
}
return List.of();
}
/**
* 批量获取设备信息
* @param deviceIds 设备ID列表
* @return 设备ID到设备实体的映射
*/
public Map<Long, DeviceEntity> batchGetDevices(List<Long> deviceIds) {
if (deviceIds == null || deviceIds.isEmpty()) {
return new HashMap<>();
}
Map<Long, DeviceEntity> result = new HashMap<>();
for (Long deviceId : deviceIds) {
try {
DeviceEntity device = getDevice(deviceId);
if (device != null) {
result.put(deviceId, device);
}
} catch (Exception e) {
log.warn("获取设备信息失败: {}, 错误: {}", deviceId, e.getMessage());
}
}
return result;
}
/**
* 批量根据设备编号获取设备信息
* @param deviceNos 设备编号列表
* @return 设备编号到设备实体的映射
*/
public Map<String, DeviceEntity> batchGetDevicesByNo(List<String> deviceNos) {
if (deviceNos == null || deviceNos.isEmpty()) {
return new HashMap<>();
}
Map<String, DeviceEntity> result = new HashMap<>();
for (String deviceNo : deviceNos) {
try {
DeviceEntity device = getDeviceByDeviceNo(deviceNo);
if (device != null) {
result.put(deviceNo, device);
}
} catch (Exception e) {
log.warn("根据设备编号获取设备信息失败: {}, 错误: {}", deviceNo, e.getMessage());
}
}
return result;
}
/**
* 批量获取设备名称
* @param deviceIds 设备ID列表
* @return 设备ID到设备名称的映射
*/
public Map<Long, String> batchGetDeviceNames(List<Long> deviceIds) {
if (deviceIds == null || deviceIds.isEmpty()) {
return new HashMap<>();
}
Map<Long, String> result = new HashMap<>();
for (Long deviceId : deviceIds) {
try {
DeviceEntity device = getDevice(deviceId);
if (device != null) {
result.put(deviceId, device.getName());
}
} catch (Exception e) {
log.warn("获取设备名称失败: {}, 错误: {}", deviceId, e.getMessage());
result.put(deviceId, "未知设备");
}
}
return result;
}
}

View File

@@ -25,6 +25,9 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.stream.Collectors;
@Component
public class ScenicRepository {
@@ -359,4 +362,79 @@ public class ScenicRepository {
return null;
}
/**
* 批量获取景区名称
* @param scenicIds 景区ID列表
* @return 景区ID到景区名称的映射
*/
public Map<Long, String> batchGetScenicNames(List<Long> scenicIds) {
if (scenicIds == null || scenicIds.isEmpty()) {
return new HashMap<>();
}
Map<Long, String> result = new HashMap<>();
for (Long scenicId : scenicIds) {
try {
ScenicV2DTO scenic = getScenicBasic(scenicId);
if (scenic != null) {
result.put(scenicId, scenic.getName());
}
} catch (Exception e) {
// 获取失败时使用默认值
result.put(scenicId, "未知景区");
}
}
return result;
}
/**
* 批量获取景区完整信息
* @param scenicIds 景区ID列表
* @return 景区ID到景区实体的映射
*/
public Map<Long, ScenicEntity> batchGetScenics(List<Long> scenicIds) {
if (scenicIds == null || scenicIds.isEmpty()) {
return new HashMap<>();
}
Map<Long, ScenicEntity> result = new HashMap<>();
for (Long scenicId : scenicIds) {
try {
ScenicEntity scenic = getScenic(scenicId);
if (scenic != null) {
result.put(scenicId, scenic);
}
} catch (Exception e) {
// 获取失败时记录日志但不中断处理
System.err.println("获取景区信息失败: " + scenicId + ", 错误: " + e.getMessage());
}
}
return result;
}
/**
* 批量获取景区基础信息DTO
* @param scenicIds 景区ID列表
* @return 景区ID到景区DTO的映射
*/
public Map<Long, ScenicV2DTO> batchGetScenicBasics(List<Long> scenicIds) {
if (scenicIds == null || scenicIds.isEmpty()) {
return new HashMap<>();
}
Map<Long, ScenicV2DTO> result = new HashMap<>();
for (Long scenicId : scenicIds) {
try {
ScenicV2DTO scenic = getScenicBasic(scenicId);
if (scenic != null) {
result.put(scenicId, scenic);
}
} catch (Exception e) {
// 获取失败时记录日志但不中断处理
System.err.println("获取景区基础信息失败: " + scenicId + ", 错误: " + e.getMessage());
}
}
return result;
}
}