吉安感知网项目-后端
rain
2026-01-22 72b7d2c5ea19ed2047ee896b7f36da20d04bcea6
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;
@@ -184,10 +190,10 @@
   }
   /**
    * 审核巡查任务
    * 巡查任务执行完成-对外
    */
   @PostMapping("/auditExternal")
   @ApiOperationSupport(order = 10)
   @ApiOperationSupport(order = 11)
   @ApiOperation(value = "巡查任务执行完成-对外", notes = "只能使用执行完成操作")
   public R auditExternal(@Valid @RequestBody IdParam param) {
      if (param.getId() == null) {
@@ -203,7 +209,7 @@
    * 更新单个巡查任务信息
    */
   @PostMapping("/republish")
   @ApiOperationSupport(order = 11)
   @ApiOperationSupport(order = 12)
   @ApiOperation(value = "更新单个巡查任务信息", notes = "传入巡查任务信息")
   public R republish(@Valid @RequestBody GdPatrolTaskUpdateParam gdPatrolTask) {
       GdPatrolTaskEntity gdPatrolTaskEntity = Objects.requireNonNull(BeanUtil.copy(gdPatrolTask, GdPatrolTaskEntity.class));
@@ -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");
   }
}