diff --git a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceExportService.java b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceExportService.java index 551b81117..dc70220b3 100644 --- a/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceExportService.java +++ b/fys-modules/fys-equipment/src/main/java/com/fuyuanshen/equipment/service/impl/DeviceExportService.java @@ -14,6 +14,7 @@ import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.List; +import java.util.concurrent.Semaphore; import java.util.stream.Collectors; /** @@ -74,30 +75,39 @@ public class DeviceExportService { } + // 在DeviceExportService中添加并发控制 + private static final Semaphore imageLoadSemaphore = new Semaphore(5); // 最多同时加载5张图片 + private void handleDevicePic(Device device, DeviceExcelExportDTO dto) { String picUrl = device.getDevicePic(); - log.info("处理设备图片,设备ID: {}, 图片URL: {}", device.getId(), picUrl); + log.debug("处理设备图片,设备ID: {}, 图片URL: {}", device.getId(), picUrl); if (picUrl != null && !picUrl.trim().isEmpty()) { try { - // 自动将HTTP转换为HTTPS以避免重定向问题 - if (picUrl.startsWith("http://")) { - picUrl = "https://" + picUrl.substring(7); - log.info("自动将HTTP转换为HTTPS: {}", picUrl); + // 获取加载图片的许可 + imageLoadSemaphore.acquire(); + + try { + // 自动将HTTP转换为HTTPS以避免重定向问题 + if (picUrl.startsWith("http://")) { + picUrl = "https://" + picUrl.substring(7); + log.debug("自动将HTTP转换为HTTPS: {}", picUrl); + } + + // 尝试创建URL对象(会自动验证格式) + URL url = new URL(picUrl); + dto.setDevicePic(url); + log.debug("成功设置设备图片URL到DTO"); + } finally { + // 释放许可 + imageLoadSemaphore.release(); } - - // 尝试创建URL对象(会自动验证格式) - URL url = new URL(picUrl); - - dto.setDevicePic(url); - log.info("成功设置设备图片URL到DTO"); } catch (Exception e) { - // 不是有效URL时设置为null - log.info("设置设备图片失败,设备ID: {}, URL: {}, 错误: {}", device.getId(), picUrl, e.getMessage()); + log.warn("设置设备图片失败,设备ID: {}, URL: {}, 错误: {}", device.getId(), picUrl, e.getMessage()); dto.setDevicePic(null); } } else { - log.info("设备没有设置图片,设备ID: {}", device.getId()); + log.debug("设备没有设置图片,设备ID: {}", device.getId()); dto.setDevicePic(null); } }