瀏覽代碼

feat: 获取结果接口

WANGKANG 8 月之前
父節點
當前提交
69be07f935

+ 2 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/constant/BizConstant.java

@@ -9,6 +9,8 @@ public class BizConstant {
 
     public static final String UNZIP_SUFFIX = "_unzip";
     public static final String TO_INFRARED_SUFFIX = "_to_infrared";
+    public static final String TRACK_SEQUENCE_SUFFIX = "_track_sequence";
+    public static final String TARGET_DETECTION_SUFFIX = "_target_detection";
 
     public static class ModelStatus {
         public static final String NOT_START = "0";

+ 10 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/TargetDetectionController.java

@@ -1,10 +1,12 @@
 package com.taais.biz.controller;
 
+import java.io.IOException;
 import java.util.List;
 
 import lombok.RequiredArgsConstructor;
 import jakarta.servlet.http.HttpServletResponse;
 import cn.dev33.satoken.annotation.SaCheckPermission;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.validation.annotation.Validated;
 import com.taais.common.core.core.domain.CommonResult;
@@ -116,4 +118,12 @@ public class TargetDetectionController extends BaseController {
     public CommonResult stop(@PathVariable("id") Long id) {
         return targetDetectionService.stop(id);
     }
+
+        @GetMapping("/zip/{id}")
+    public ResponseEntity<org.springframework.core.io.Resource> zipFolder(@PathVariable("id") Long id) throws IOException {
+        /**
+         * 传VideoImage的ID
+         */
+        return targetDetectionService.zipImages(id);
+    }
 }

+ 4 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/service/ITargetDetectionService.java

@@ -9,6 +9,8 @@ import com.taais.biz.domain.bo.TargetDetectionBo;
 import com.taais.common.core.core.domain.CommonResult;
 import com.taais.common.orm.core.service.IBaseService;
 import com.taais.common.core.core.page.PageResult;
+import org.springframework.core.io.Resource;
+import org.springframework.http.ResponseEntity;
 
 /**
  * 目标检测Service接口
@@ -70,4 +72,6 @@ public interface ITargetDetectionService extends IBaseService<TargetDetection> {
     CommonResult stop(Long id);
 
     CommonResult getResult(TaskTrackResultBo taskTrackResultBo);
+
+    ResponseEntity<Resource> zipImages(Long id);
 }

+ 37 - 2
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/TargetDetectionServiceImpl.java

@@ -1,5 +1,7 @@
 package com.taais.biz.service.impl;
 
+import java.io.File;
+import java.io.IOException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Arrays;
@@ -29,6 +31,10 @@ import com.taais.system.service.ISysOssService;
 import jakarta.annotation.Resource;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import com.taais.biz.mapper.TargetDetectionMapper;
@@ -235,8 +241,8 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
         String fileName_without_suffix = removeFileExtension(fileName);
 
         Path path = Paths.get(resourcePath);
-        Path inputPath = path.resolveSibling(fileName_without_suffix + "_images");
-        Path outputPath = path.resolveSibling(fileName_without_suffix + "_to_infrared");
+        Path inputPath = path.resolveSibling(fileName_without_suffix + BizConstant.UNZIP_SUFFIX);
+        Path outputPath = path.resolveSibling(fileName_without_suffix + BizConstant.TARGET_DETECTION_SUFFIX);
 
         makeDir(inputPath.toString());
         makeDir(outputPath.toString());
@@ -307,4 +313,33 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
         updateById(entity);
         return CommonResult.success();
     }
+
+    @Override
+    public ResponseEntity<org.springframework.core.io.Resource> zipImages(Long id) {
+        TargetDetection targetDetection = this.getById(id);
+        if (ObjectUtil.isNull(targetDetection)) {
+            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
+        }
+
+        String outputPath = targetDetection.getOutputPath();
+        String zipFilePath = outputPath + ".zip";
+
+        try {
+            ZipUtils.zipFolderFiles(outputPath, zipFilePath);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+        File file = new File(zipFilePath);
+
+        if (!file.exists() || !file.isFile()) {
+            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
+        }
+
+        org.springframework.core.io.Resource resource = new FileSystemResource(file);
+        return ResponseEntity.ok()
+            .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getName() + "\"")
+            .header(HttpHeaders.CONTENT_TYPE, "application/octet-stream")
+            .body(resource);
+    }
 }

+ 9 - 2
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/ToInfraredServiceImpl.java

@@ -1,6 +1,7 @@
 package com.taais.biz.service.impl;
 
 import java.io.File;
+import java.io.IOException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Arrays;
@@ -317,8 +318,14 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
             return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
         }
 
-        String sourceFolderPath = toInfrared.getOutputPath();
-        String zipFilePath = Paths.get(sourceFolderPath).resolveSibling(toInfrared.getName() + ".zip").toString();
+        String outputPath = toInfrared.getOutputPath();
+        String zipFilePath = outputPath + ".zip";
+
+        try {
+            ZipUtils.zipFolderFiles(outputPath, zipFilePath);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
 
         File file = new File(zipFilePath);
 

+ 11 - 4
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/TrackSequenceServiceImpl.java

@@ -1,6 +1,7 @@
 package com.taais.biz.service.impl;
 
 import java.io.File;
+import java.io.IOException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Arrays;
@@ -238,8 +239,8 @@ public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMappe
         String fileName_without_suffix = removeFileExtension(fileName);
 
         Path path = Paths.get(resourcePath);
-        Path inputPath = path.resolveSibling(fileName_without_suffix + "_images");
-        Path outputPath = path.resolveSibling(fileName_without_suffix + "_to_infrared");
+        Path inputPath = path.resolveSibling(fileName_without_suffix + BizConstant.UNZIP_SUFFIX);
+        Path outputPath = path.resolveSibling(fileName_without_suffix + BizConstant.TRACK_SEQUENCE_SUFFIX);
 
         makeDir(inputPath.toString());
         makeDir(outputPath.toString());
@@ -300,8 +301,14 @@ public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMappe
             return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
         }
 
-        String sourceFolderPath = trackSequence.getOutputPath();
-        String zipFilePath = Paths.get(sourceFolderPath).resolveSibling(trackSequence.getName() + ".zip").toString();
+        String outputPath = trackSequence.getOutputPath();
+        String zipFilePath = outputPath + ".zip";
+
+        try {
+            ZipUtils.zipFolderFiles(outputPath, zipFilePath);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
 
         File file = new File(zipFilePath);