WANGKANG 8 сар өмнө
parent
commit
438ffbfcaa

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

@@ -125,4 +125,9 @@ public class ToInfraredController extends BaseController {
          */
         return toInfraredService.zipImages(id);
     }
+
+    @GetMapping("/log/{id}")
+    public CommonResult getLog(@PathVariable("id") Long id) {
+        return toInfraredService.getLog(id);
+    }
 }

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

@@ -75,4 +75,6 @@ public interface IToInfraredService extends IBaseService<ToInfrared> {
     CommonResult getResult(TaskTrackResultBo toInfraredStartResultBo);
 
     ResponseEntity<Resource> zipImages(Long id);
+
+    CommonResult getLog(Long id);
 }

+ 27 - 1
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/ToInfraredServiceImpl.java

@@ -1,7 +1,10 @@
 package com.taais.biz.service.impl;
 
+import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileReader;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Arrays;
@@ -265,7 +268,7 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
 
         startTaskConfig.setSource_dir(entity.getInputPath());
         startTaskConfig.setResult_dir(entity.getOutputPath());
-        startTaskConfig.setLog_path(entity.getOutputPath() + File.separator + "log.log");
+        startTaskConfig.setLog_path(entity.getOutputPath() + File.separator + getLogFileName(entity));
 
         if (BizConstant.AlgorithmType.REASONING.equals(algorithmConfigTrack.getType())) {
             startTaskConfig.setModel_path(algorithmModelTrack.getModelAddress());
@@ -284,6 +287,10 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         }
     }
 
+    private String getLogFileName(ToInfrared entity) {
+        return entity.getId() + BizConstant.TO_INFRARED_SUFFIX + ".log";
+    }
+
     @Override
     public CommonResult stop(Long id) {
         ToInfrared toInfrared = getById(id);
@@ -368,6 +375,25 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         }
     }
 
+    @Override
+    public CommonResult getLog(Long id) {
+        ToInfrared entity = getById(id);
+        String outPutPath = entity.getOutputPath();
+        String logPath = outPutPath + File.separator + getLogFileName(entity);
+        File file = new File(logPath);
+        if (!file.exists()) {
+            return CommonResult.fail("日志文件不存在!");
+        }
+        try (BufferedReader br = new BufferedReader(new FileReader(logPath))) {
+            String log = Files.readString(Paths.get(logPath));
+            log = log.replaceAll("\n", "<br/>\n");
+            return CommonResult.success(log, "success");
+        } catch (Exception e) {
+            e.printStackTrace();
+            return CommonResult.fail("读取日志失败!");
+        }
+    }
+
     private ResponseEntity<org.springframework.core.io.Resource> getPredictImages(ToInfrared toInfrared) {
         String outputPath = toInfrared.getOutputPath();
         String predictDir = outputPath + File.separator + BizConstant.PREDICT_PATH;