소스 검색

feat: 可见光转红外结果下载

WANGKANG 9 달 전
부모
커밋
7681d78a63

+ 9 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/ToInfraredController.java

@@ -7,6 +7,7 @@ import com.taais.common.core.core.page.PageResult;
 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;
@@ -17,6 +18,7 @@ import com.taais.common.web.annotation.RepeatSubmit;
 import com.taais.common.web.core.BaseController;
 import jakarta.annotation.Resource;
 
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -116,4 +118,11 @@ public class ToInfraredController extends BaseController {
         return toInfraredService.stop(id);
     }
 
+    @GetMapping("/zip/{id}")
+    public ResponseEntity<org.springframework.core.io.Resource> zipFolder(@PathVariable("id") Long id) throws IOException {
+        /**
+         * 传VideoImage的ID
+         */
+        return toInfraredService.zipImages(id);
+    }
 }

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

@@ -8,6 +8,8 @@ import com.taais.biz.domain.vo.ToInfraredVo;
 import com.taais.common.core.core.domain.CommonResult;
 import com.taais.common.core.core.page.PageResult;
 import com.taais.common.orm.core.service.IBaseService;
+import org.springframework.core.io.Resource;
+import org.springframework.http.ResponseEntity;
 
 import java.util.List;
 
@@ -71,4 +73,6 @@ public interface IToInfraredService extends IBaseService<ToInfrared> {
     CommonResult stop(Long id);
 
     CommonResult getResult(ToInfraredStartResultBo toInfraredStartResultBo);
+
+    ResponseEntity<Resource> zipImages(Long id);
 }

+ 28 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/ToInfraredServiceImpl.java

@@ -1,5 +1,6 @@
 package com.taais.biz.service.impl;
 
+import java.io.File;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Arrays;
@@ -32,6 +33,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;
 
@@ -269,4 +274,27 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         updateById(toInfrared);
         return CommonResult.success();
     }
+
+    @Override
+    public ResponseEntity<org.springframework.core.io.Resource> zipImages(Long id) {
+        ToInfrared toInfrared = this.getById(id);
+        if (ObjectUtil.isNull(toInfrared)) {
+            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
+        }
+
+        String sourceFolderPath = toInfrared.getOutputPath();
+        String zipFilePath = Paths.get(sourceFolderPath).resolveSibling(toInfrared.getName() + ".zip").toString();
+
+        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);
+    }
 }