|
@@ -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);
|
|
|
+ }
|
|
|
}
|