diff --git a/inspect-main/inspect-main-task/pom.xml b/inspect-main/inspect-main-task/pom.xml
index 05bfa30..cd5a570 100644
--- a/inspect-main/inspect-main-task/pom.xml
+++ b/inspect-main/inspect-main-task/pom.xml
@@ -49,5 +49,19 @@
jackson-core-asl
1.9.13
+
+
+
+ net.coobird
+ thumbnailator
+ 0.4.19
+
+
+
+
+ org.apache.poi
+ poi-ooxml
+ 5.2.3
+
\ No newline at end of file
diff --git a/inspect-main/inspect-main-task/src/main/java/com/inspect/task/controller/PatrolTaskController.java b/inspect-main/inspect-main-task/src/main/java/com/inspect/task/controller/PatrolTaskController.java
index 0357fd4..9af427e 100644
--- a/inspect-main/inspect-main-task/src/main/java/com/inspect/task/controller/PatrolTaskController.java
+++ b/inspect-main/inspect-main-task/src/main/java/com/inspect/task/controller/PatrolTaskController.java
@@ -61,6 +61,7 @@ import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
+import net.coobird.thumbnailator.Thumbnails;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -2453,26 +2454,39 @@ public class PatrolTaskController extends BaseController {
}
}
logger.info("图片总数: {}", uniqueImages.size());
- // 并行下载图片
+ logger.info("数据处理耗时: {} ms", (System.currentTimeMillis() - start));
+ long startDownImg = System.currentTimeMillis();
+// // 并行下载图片
Map streamHashMap = new ConcurrentHashMap<>();
+// uniqueImages.parallelStream().forEach(imagePath -> {
+// try {
+// sftpClient.downLoad(imagePath, (inputStream) -> {
+// byte[] shm = streamHashMap.get(imagePath);
+// byte[] bytes = getStringByInputStream(inputStream);
+// if (shm == null) {
+// streamHashMap.put(imagePath, bytes);
+// }
+//
+// });
+// } catch (Exception e) {
+// logger.warn("图片下载失败: {}", imagePath, e);
+// }
+// });
+ //
uniqueImages.parallelStream().forEach(imagePath -> {
- try {
- sftpClient.downLoad(imagePath, (inputStream) -> {
- byte[] shm = streamHashMap.get(imagePath);
- byte[] bytes = getStringByInputStream(inputStream);
- if (shm == null) {
- streamHashMap.put(imagePath, bytes);
- }
-
- });
- } catch (Exception e) {
- logger.warn("图片下载失败: {}", imagePath, e);
+ byte[] shm = streamHashMap.get(imagePath);
+ byte[] bytes = downloadAndCompressImage(imagePath);
+ if (shm == null) {
+ streamHashMap.put(imagePath, bytes);
}
});
logger.info("图片下载成功");
+ logger.info("图片下载耗时: {} ms", (System.currentTimeMillis() - startDownImg));
// exportExcel(response, newList);
+ long startExport = System.currentTimeMillis();
exportExcelStream(response, newList, streamHashMap);
- logger.info("任务详情导出耗时: {} ms", (System.currentTimeMillis() - start));
+ logger.info("任务详情导出耗时: {} ms", (System.currentTimeMillis() - startExport));
+ logger.info("任务详情导出总流程耗时: {} ms", (System.currentTimeMillis() - start));
return ResponseEntity.ok("数据导出成功!");
}
@@ -2510,6 +2524,25 @@ public class PatrolTaskController extends BaseController {
}
}
+ private byte[] downloadAndCompressImage(String imagePath) {
+ try {
+ // 直接下载并压缩图片
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ sftpClient.downLoad(imagePath, inputStream -> {
+ // 压缩图片
+ Thumbnails.of(inputStream)
+ .size(300, 300) // 限制最大尺寸
+ .outputQuality(0.5) // 50%质量
+ .outputFormat("JPEG")
+ .toOutputStream(output);
+ });
+ return output.toByteArray();
+ } catch (Exception e) {
+ logger.warn("图片下载压缩失败: {}", imagePath, e);
+ return null;
+ }
+ }
+
private void createHeaderRow(Sheet sheet) {
String[] headers = {
"编号", "设备", "相机名", "系统", "点位名称", "状态",
@@ -2556,16 +2589,16 @@ public class PatrolTaskController extends BaseController {
try {
// 获取第一张初筛图片(如果有)
String firstImage = getFirstImage(item.getImg());
- if (firstImage != null && imageCache.containsKey(firstImage)) {
- byte[] imageData = imageCache.get(firstImage);
+ if (firstImage != null) {
+ byte[] imageData = imageCache.getOrDefault(firstImage, new byte[0]);
// 插入筛选图片(第8列)
insertImage(workbook, drawing, row, 8, imageData);
}
// 获取第一张分析图片(如果有)
String firstImgAnalyse = getFirstImage(item.getImgAnalyse());
- if (firstImgAnalyse != null && imageCache.containsKey(firstImgAnalyse)) {
- byte[] imageData = imageCache.get(firstImgAnalyse);
+ if (firstImgAnalyse != null) {
+ byte[] imageData = imageCache.getOrDefault(firstImgAnalyse, new byte[0]);
// 插入分析图片(第10列)
insertImage(workbook, drawing, row, 10, imageData);
}