28968 8 miesięcy temu
rodzic
commit
67e5d203b4

+ 1 - 1
taais-admin/src/main/resources/application.yml

@@ -9,7 +9,7 @@ taais:
   # 实例演示开关
   demoEnabled: true
   # 文件路径 示例( Windows配置D:/km/uploadPath,Linux配置 /home/km/uploadPath)
-  # profile: D:/taais/uploadPath
+  #profile: D:/taais/uploadPath
   # 后面不能有 /
   profile: /www/project
   # 获取ip地址开关

+ 68 - 1
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/DataAugmentationController.java

@@ -2,6 +2,7 @@ package com.taais.biz.controller;
 
 
 import java.io.*;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -22,7 +23,9 @@ import com.taais.biz.domain.bo.VideoStableStartResultBo;
 import com.taais.biz.domain.dto.Metric;
 import com.taais.biz.domain.vo.DataAugmentationVo;
 import com.taais.biz.domain.vo.TaskDictDataVo;
+import com.taais.biz.domain.vo.VideoUrl;
 import com.taais.biz.service.IVideoStableService;
+import com.taais.common.core.config.TaaisConfig;
 import com.taais.common.core.service.OssService;
 import com.taais.system.domain.SysDictData;
 import com.taais.system.domain.SysOss;
@@ -354,6 +357,18 @@ public class DataAugmentationController extends BaseController {
         return CommonResult.success();
     }
 
+    private String readLogFileWithEncoding(Path path, java.nio.charset.Charset charset) throws IOException {
+        try (BufferedReader reader = Files.newBufferedReader(path, charset)) {
+            StringBuilder content = new StringBuilder();
+            String line;
+            while ((line = reader.readLine()) != null) {
+                content.append(line).append("\n");
+            }
+            return content.toString();
+        } catch (IOException e) {
+            return null; // 读取失败,返回 null
+        }
+    }
     /**
      * 获取日志字符串
      */
@@ -367,8 +382,9 @@ public class DataAugmentationController extends BaseController {
             if (!Files.exists(path)) {
                 return CommonResult.fail( "日志文件" + filePath + "不存在!");
             }
+            String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
             // 读取文件内容
-            return CommonResult.success(new String(Files.readAllBytes(path)), "获取日志成功");
+            return CommonResult.success(content, "获取日志成功");
         } catch (Exception e) {
             return CommonResult.fail("日志文件" + filePath + "读取失败!");
         }
@@ -437,4 +453,55 @@ public class DataAugmentationController extends BaseController {
         }
         return CommonResult.success(taskDictDataVos);
     }
+    private static boolean hasSupportedExtension(String filePath, List<String> extensions) {
+        for (String ext : extensions) {
+            if (filePath.toLowerCase().endsWith(ext)) {
+                return true;
+            }
+        }
+        return false;
+    }
+    public static String findFirstVideoFile(String dirPath, List<String> extensions) {
+        File dir = new File(dirPath);
+        if (!dir.exists() || !dir.isDirectory()) {
+            return null;
+        }
+
+        try (Stream<Path> stream = Files.list(Paths.get(dirPath))) {
+            return stream
+                .filter(Files::isRegularFile)
+                .map(Path::toString)
+                .filter(filePath -> hasSupportedExtension(filePath, extensions))
+                .findFirst()
+                .orElse(null);
+        } catch (IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    @SaCheckPermission("demo:dataAugmentation:query")
+    @GetMapping(value = "/videoUrl/{id}")
+    public CommonResult<VideoUrl> getVideoUrl(@PathVariable Long id) {
+        DataAugmentation byId = dataAugmentationService.getById(id);
+        String localPath = TaaisConfig.getProfile();
+        List<String> extensions = Arrays.asList(".mp4", ".avi", ".mkv", ".mov", ".flv", ".wmv");
+        String firstInputVideoFile = findFirstVideoFile(byId.getInputPath(), extensions);
+        if (firstInputVideoFile == null) {
+            return CommonResult.fail(byId.getInputPath() + "目录下不存在输入视频文件!");
+        }
+        String firstOutputVideoFile = findFirstVideoFile(byId.getOutputPath(), extensions);
+        if (firstOutputVideoFile == null) {
+            return CommonResult.fail(byId.getOutputPath() + "目录下不存在输出视频文件!");
+        }
+        Path localPathPath = Paths.get(localPath);
+        Path inputPath = Paths.get(firstInputVideoFile);
+        Path outputPath = Paths.get(firstOutputVideoFile);
+
+        // 替换路径
+        String input = inputPath.toString().replace(localPathPath.toString(), "/api/profile").replace("\\", "/");
+        String output = outputPath.toString().replace(localPathPath.toString(), "/api/profile").replace("\\", "/");
+        return  CommonResult.success(new VideoUrl(input, output));
+    }
+
 }

+ 30 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/vo/VideoUrl.java

@@ -0,0 +1,30 @@
+package com.taais.biz.domain.vo;
+
+import lombok.Data;
+
+@Data
+public class VideoUrl {
+    private String input;
+    private String output;
+
+    public VideoUrl(String input, String output) {
+        this.input = input;
+        this.output = output;
+    }
+
+    public String getInput() {
+        return input;
+    }
+
+    public void setInput(String input) {
+        this.input = input;
+    }
+
+    public String getOutput() {
+        return output;
+    }
+
+    public void setOutput(String output) {
+        this.output = output;
+    }
+}

+ 5 - 6
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/DataAugmentationServiceImpl.java

@@ -159,7 +159,7 @@ public class DataAugmentationServiceImpl extends BaseServiceImpl<DataAugmentatio
                     orWrapper.and(DATA_AUGMENTATION.TASK_TYPE.eq("图像增强"));
                     orWrapper.or(DATA_AUGMENTATION.TASK_TYPE.eq("图像逆光"));
                 });
-            });
+            }).orderBy(DATA_AUGMENTATION.CREATE_TIME, false);
         }
         else if ("imageMosaic".equals(type)) {
             queryWrapper.and(wrapper -> {
@@ -167,21 +167,21 @@ public class DataAugmentationServiceImpl extends BaseServiceImpl<DataAugmentatio
                     orWrapper.and(DATA_AUGMENTATION.TASK_TYPE.eq("侦察图像拼接算法_coordinate"));
                     orWrapper.or(DATA_AUGMENTATION.TASK_TYPE.eq("侦察图像拼接算法_sift"));
                 });
-            });
+            }).orderBy(DATA_AUGMENTATION.CREATE_TIME, false);;
         }
         else if ("targetDamageAcess".equals(type)) {
             queryWrapper.and(wrapper -> {
                 wrapper.or(orWrapper -> {
                     orWrapper.and(DATA_AUGMENTATION.TASK_TYPE.eq("目标毁伤评估"));
                 });
-            });
+            }).orderBy(DATA_AUGMENTATION.CREATE_TIME, false);;
         }
         else if ("targetTrack".equals(type)) {
             queryWrapper.and(wrapper -> {
                 wrapper.or(orWrapper -> {
                     orWrapper.and(DATA_AUGMENTATION.TASK_TYPE.eq("多目标跟踪"));
                 });
-            });
+            }).orderBy(DATA_AUGMENTATION.CREATE_TIME, false);
         }
 
         Page<DataAugmentationVo> page = this.pageAs(PageQuery.build(), queryWrapper, DataAugmentationVo.class);
@@ -307,10 +307,9 @@ public class DataAugmentationServiceImpl extends BaseServiceImpl<DataAugmentatio
             transmissionObject.setSourcePath(dataAugmentation.getInputPath());
             transmissionObject.setResultPath(dataAugmentation.getOutputPath());
             transmissionObject.setOtherParams(dataAugmentation.getHyperparameterConfiguration());
-            dataAugmentation.setStartTime(new Date());
-            updateById(dataAugmentation);
             HttpResponseEntity responseEntity = sendPostMsg(data_augmentation_start_url, transmissionObject);
             if (responseEntity != null && responseEntity.getStatus() == 200) {
+                dataAugmentation.setStartTime(new Date());
                 dataAugmentation.setStatus(BizConstant.ModelStatus.RUNNING);
                 updateById(dataAugmentation);
                 return CommonResult.success("任务开始成功,请等待完成");