WANGKANG 9 сар өмнө
parent
commit
31748bbc74

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

@@ -1,5 +1,6 @@
 package com.taais.biz.controller;
 
+import java.io.File;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -46,6 +47,14 @@ public class VideoStableController extends BaseController {
     @Resource
     private IVideoStableService videoStableService;
 
+    @GetMapping("/compare/num/{task_id}")
+
+    public CommonResult getCompareNum(@PathVariable("task_id") Long taskId) {
+        return CommonResult.success(videoStableService.getCompareNum(taskId));
+    }
+
+
+
     @GetMapping("/compare/{task_id}/{idx}")
     public ResponseEntity<Map<String, String>> getCompareImages(@PathVariable("task_id") Long taskId, @PathVariable("idx") int idx) {
         try {

+ 2 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/service/IVideoStableService.java

@@ -68,4 +68,6 @@ public interface IVideoStableService extends IBaseService<VideoStable> {
     CommonResult start(Long id);
 
     CommonResult getResult(VideoStableStartResultBo videoStableStartResultBo);
+
+    Object getCompareNum(Long taskId);
 }

+ 68 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/VideoStableServiceImpl.java

@@ -6,6 +6,7 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 
 import cn.hutool.core.util.ObjectUtil;
@@ -273,4 +274,71 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
         updateById(videoStable);
         return CommonResult.success();
     }
+
+    @Override
+    public HashMap<String, Object> getCompareNum(Long taskId) {
+        VideoStable videoStable = getById(taskId);
+
+        Path inputPath = null;
+        Path outputPath = null;
+        String osName = System.getProperty("os.name");
+        // 判断是否是Windows环境
+        if (osName.toLowerCase().contains("windows")) {
+            inputPath = Paths.get("C:", videoStable.getInputPath());
+            outputPath = Paths.get("C:", videoStable.getOutputPath());
+        } else {
+            inputPath = Paths.get(videoStable.getInputPath());
+            outputPath = Paths.get(videoStable.getOutputPath());
+        }
+
+        // 创建File对象
+        File in_directory = new File(inputPath.toString());
+        File out_directory = new File(outputPath.toString());
+
+        // 调用方法获取文件数量
+        int in_fileCount = countFiles(in_directory);
+        int out_fileCount = countFiles(out_directory);
+
+        // 输出文件数量
+        log.info("inFileCount -> " + in_fileCount);
+        log.info("outFileCount -> " + out_fileCount);
+
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("inFileCount", in_fileCount);
+        map.put("outFileCount", out_fileCount);
+        return map;
+    }
+
+        /**
+     * 递归统计文件夹中的文件数量
+     *
+     * @param directory 文件夹对象
+     * @return 文件数量
+     */
+    public static int countFiles(File directory) {
+        // 检查文件夹是否存在且是一个目录
+        if (!directory.exists() || !directory.isDirectory()) {
+            System.out.println("指定的路径不是一个有效的文件夹");
+            return 0;
+        }
+
+        // 获取文件夹中的所有文件和子文件夹
+        File[] files = directory.listFiles();
+
+        // 初始化文件计数器
+        int count = 0;
+
+        // 遍历文件和子文件夹
+        for (File file : files) {
+            if (file.isFile()) {
+                // 如果是文件,计数器加1
+                count++;
+            } else if (file.isDirectory()) {
+                // 如果是子文件夹,递归调用countFiles方法
+                count += countFiles(file);
+            }
+        }
+
+        return count;
+    }
 }