浏览代码

feat: 可辨识性分析日志添加完成

WANGKANG 8 月之前
父节点
当前提交
727fb61d88

+ 4 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/TargetDetectionController.java

@@ -126,4 +126,8 @@ public class TargetDetectionController extends BaseController {
          */
         return targetDetectionService.zipImages(id);
     }
+    @GetMapping("/log/{id}")
+    public CommonResult getLog(@PathVariable("id") Long id) {
+        return targetDetectionService.getLog(id);
+    }
 }

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

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

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

@@ -74,4 +74,6 @@ public interface ITargetDetectionService extends IBaseService<TargetDetection> {
     CommonResult getResult(TaskTrackResultBo taskTrackResultBo);
 
     ResponseEntity<Resource> zipImages(Long id);
+
+    CommonResult getLog(Long id);
 }

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

@@ -74,4 +74,6 @@ public interface ITrackSequenceService extends IBaseService<TrackSequence> {
     ResponseEntity<Resource> zipImages(Long id);
 
     CommonResult getResult(TaskTrackResultBo taskTrackResultBo);
+
+    CommonResult getLog(Long id);
 }

+ 30 - 4
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/TargetDetectionServiceImpl.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;
@@ -270,7 +273,7 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
 
         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())) {
             String modelPath = algorithmModelTrack.getModelAddress() + File.separator + algorithmModelTrack.getModelName();
@@ -328,11 +331,11 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
         algorithmModelTrack.setModelStatus("200".equals(status) ? BizConstant.ModelStatus.END : BizConstant.ModelStatus.FAILED);
 
         AlgorithmConfigTrack algorithmConfigTrack = algorithmConfigTrackService.getById(algorithmModelTrack.getAlgorithmId());
-        String params =  algorithmConfigTrack.getParameterConfig();
+        String params = algorithmConfigTrack.getParameterConfig();
         HashMap<String, Object> parse = (HashMap<String, Object>) JSON.parse((params));
 
-        if("200".equals(status) && ObjectUtil.isNull(algorithmModelTrack.getModelAddress())) {
-            algorithmModelTrack.setModelAddress(entity.getOutputPath() + File.separator + ((HashMap<String, String>)parse.get("dataset")).get("classes"));
+        if ("200".equals(status) && ObjectUtil.isNull(algorithmModelTrack.getModelAddress())) {
+            algorithmModelTrack.setModelAddress(entity.getOutputPath() + File.separator + ((HashMap<String, String>) parse.get("dataset")).get("classes"));
 
             System.out.println(parse.get("dataset"));
             algorithmModelTrackService.updateById(algorithmModelTrack);
@@ -392,4 +395,27 @@ public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionM
             .header(HttpHeaders.CONTENT_TYPE, "application/octet-stream")
             .body(resource);
     }
+
+    private String getLogFileName(TargetDetection entity) {
+        return entity.getId() + BizConstant.TARGET_DETECTION_SUFFIX + ".log";
+    }
+
+    @Override
+    public CommonResult getLog(Long id) {
+        TargetDetection 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("读取日志失败!");
+        }
+    }
 }

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

@@ -287,10 +287,6 @@ 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);
@@ -375,6 +371,10 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         }
     }
 
+    private String getLogFileName(ToInfrared entity) {
+        return entity.getId() + BizConstant.TO_INFRARED_SUFFIX + ".log";
+    }
+
     @Override
     public CommonResult getLog(Long id) {
         ToInfrared entity = getById(id);

+ 25 - 1
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/TrackSequenceServiceImpl.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;
@@ -268,7 +271,7 @@ public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMappe
 
         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())) {
             if(algorithmModelTrack.getModelName().startsWith("masc") || algorithmModelTrack.getModelName().startsWith("MASC")) {
@@ -393,4 +396,25 @@ public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMappe
         }
         return CommonResult.success();
     }
+    private String getLogFileName(TrackSequence entity) {
+        return entity.getId() + BizConstant.TRACK_SEQUENCE_SUFFIX + ".log";
+    }
+    @Override
+    public CommonResult getLog(Long id) {
+        TrackSequence 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("读取日志失败!");
+        }
+    }
 }