From 72b7d2c5ea19ed2047ee896b7f36da20d04bcea6 Mon Sep 17 00:00:00 2001
From: rain <1679827795@qq.com>
Date: Thu, 22 Jan 2026 17:22:15 +0800
Subject: [PATCH] 事件数量tab接口

---
 drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/controller/GdPatrolTaskController.java |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/controller/GdPatrolTaskController.java b/drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/controller/GdPatrolTaskController.java
index e3d518e..299abd7 100644
--- a/drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/controller/GdPatrolTaskController.java
+++ b/drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/controller/GdPatrolTaskController.java
@@ -50,9 +50,15 @@
 import org.springblade.core.tool.utils.DateUtil;
 import org.springblade.core.excel.util.ExcelUtil;
 import org.springblade.core.tool.constant.BladeConstant;
+import org.springblade.core.tool.utils.StringUtil;
 import org.sxkj.system.cache.SysCache;
 import springfox.documentation.annotations.ApiIgnore;
 
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
 import java.util.ArrayList;
 import java.util.Map;
 import java.util.List;
@@ -211,4 +217,47 @@
 		return R.status(result);
 	}
 
+	@PostMapping("/export-report")
+	@ApiOperationSupport(order = 13)
+	@ApiOperation(value = "导出巡查报告", notes = "传入巡查任务id")
+	public R<String> exportReport(@RequestParam Long id) {
+		if (id == null) {
+			return R.fail("巡查任务id不能为空");
+		}
+		File reportFile = gdPatrolTaskService.exportPatrolReport(id);
+		File savedFile = saveReportToResources(reportFile, id);
+		return R.data(savedFile.getAbsolutePath());
+	}
+
+	private File saveReportToResources(File reportFile, Long patrolTaskId) {
+		if (reportFile == null || !reportFile.exists()) {
+			throw new RuntimeException("生成的巡查报告文件不存在");
+		}
+		Path resourcesDir = resolveResourcesDir();
+		String fileName = "gd_patrol_report_" + patrolTaskId + "_" + DateUtil.time() + ".docx";
+		Path targetPath = resourcesDir.resolve(fileName);
+		try {
+			Files.createDirectories(resourcesDir);
+			Files.copy(reportFile.toPath(), targetPath, StandardCopyOption.REPLACE_EXISTING);
+			return targetPath.toFile();
+		} catch (Exception e) {
+			throw new RuntimeException("保存巡查报告失败", e);
+		}
+	}
+
+	private Path resolveResourcesDir() {
+		String userDir = System.getProperty("user.dir");
+		if (StringUtil.isBlank(userDir)) {
+			throw new RuntimeException("无法获取工作目录");
+		}
+		Path basePath = Paths.get(userDir);
+		if (basePath.endsWith("drone-gd")) {
+			return basePath.resolve("src").resolve("main").resolve("resources");
+		}
+		if (basePath.endsWith("drone-service")) {
+			return basePath.resolve("drone-gd").resolve("src").resolve("main").resolve("resources");
+		}
+		return basePath.resolve("drone-service").resolve("drone-gd").resolve("src").resolve("main").resolve("resources");
+	}
+
 }

--
Gitblit v1.9.3