Jelajahi Sumber

fix: 可见光转红外预测显示

WANGKANG 8 bulan lalu
induk
melakukan
1d89832d75

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

@@ -34,6 +34,7 @@ import java.util.List;
 public class ToInfraredController extends BaseController {
     @Resource
     private IToInfraredService toInfraredService;
+    private Long ossId;
 
     /**
      * 查询可见光转红外列表
@@ -135,4 +136,9 @@ public class ToInfraredController extends BaseController {
     public CommonResult getModelList(@PathVariable("id") Long id) {
         return toInfraredService.getModelList(id);
     }
+
+    @GetMapping("/previewPredictResult/{id}")
+    public CommonResult previewPredictResult(@PathVariable("id") Long id) {
+        return toInfraredService.previewPredictResult(id);
+    }
 }

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

@@ -79,4 +79,6 @@ public interface IToInfraredService extends IBaseService<ToInfrared> {
     CommonResult getLog(Long id);
 
     CommonResult getModelList(Long id);
+
+    CommonResult previewPredictResult(Long id);
 }

+ 20 - 1
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/DataSeqServiceImpl.java

@@ -214,13 +214,32 @@ public class DataSeqServiceImpl extends BaseServiceImpl<DataSeqMapper, DataSeq>
         List<String> tmpList = Arrays.asList(files).stream().filter(file -> file.isFile() && isImageFile(file)).map(file -> urlPrefix + file.getPath().substring(TaaisConfig.getProfile().length()).replaceAll("\\\\", "/")).toList();
         imageList.addAll(tmpList);
 
-        for(File file :files) {
+        for (File file : files) {
             if (file.isDirectory()) {
                 filterImages(imageList, file, urlPrefix);
             }
         }
     }
 
+    public static List<String> calculateImagePath(String urlPrefix, File path) {
+        List<String> imageList = new ArrayList<>();
+        File[] files = path.listFiles();
+        if (files == null || files.length == 0) {
+            return null;
+        }
+        List<String> tmpList = Arrays.asList(files).stream().filter(file -> file.isFile() && isImageFile(file)).map(file -> urlPrefix + file.getPath().substring(TaaisConfig.getProfile().length()).replaceAll("\\\\", "/")).toList();
+        imageList.addAll(tmpList);
+        return imageList;
+    }
+
+    public static List<String> calculateImagePath(String urlPrefix, String path) {
+        File dir = new File(path);
+        if (!dir.exists() || !dir.isDirectory()) {
+            return null;
+        }
+        return calculateImagePath(urlPrefix, dir);
+    }
+
     @Override
     public List<String> getImages(Long inputOdssId, String subsystem, Boolean isInput, String dir) {
         // 检查input_oss_id是否存在

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

@@ -47,6 +47,8 @@ import org.springframework.transaction.annotation.Transactional;
 
 import static com.taais.biz.constant.BizConstant.VideoStatus.NOT_START;
 import static com.taais.biz.domain.table.ToInfraredTableDef.TO_INFRARED;
+import static com.taais.biz.service.impl.DataSeqServiceImpl.calculateImagePath;
+import static com.taais.biz.service.impl.DataSeqServiceImpl.isImageFile;
 import static com.taais.biz.service.impl.VideoStableServiceImpl.*;
 
 /**
@@ -397,15 +399,15 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
 
     public String readLogContent(String path) {
         String content = "";
-        try(BufferedReader br = new BufferedReader(new FileReader(path))) {
+        try (BufferedReader br = new BufferedReader(new FileReader(path))) {
             String line;
             while ((line = br.readLine()) != null) {
-                content += ( line + "<br />\n");
+                content += (line + "<br />\n");
             }
-        }catch(Exception e) {
+        } catch (Exception e) {
             e.printStackTrace();
             System.out.println("读取文件失败!" + e.getMessage());
-            content =  "读取文件失败!" + e.getMessage();
+            content = "读取文件失败!" + e.getMessage();
         }
 
         return content;
@@ -445,6 +447,63 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         return CommonResult.success(res, "success");
     }
 
+    @Override
+    public CommonResult previewPredictResult(Long id) {
+        ToInfrared entity = getById(id);
+
+        SysOssVo inputOssEntity = ossService.getById(entity.getInputOssId());
+
+        String filePath = inputOssEntity.getFileName();
+        String localPath = TaaisConfig.getProfile();
+        String resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
+
+        String fileName = StringUtils.substringAfterLast(filePath, "/");
+        String fileName_without_suffix = removeFileExtension(fileName);
+
+        Path path = Paths.get(resourcePath);
+        Path inputPath = path.resolveSibling(fileName_without_suffix + BizConstant.UNZIP_SUFFIX + File.separator + BizConstant.PREDICT_PATH);
+        Path outputPath = path.resolveSibling(entity.getId().toString() + BizConstant.TO_INFRARED_SUFFIX + File.separator + BizConstant.PREDICT_PATH);
+
+        String urlPrefix = inputOssEntity.getUrl().substring(0, inputOssEntity.getUrl().indexOf(Constants.RESOURCE_PREFIX) + Constants.RESOURCE_PREFIX.length());
+
+        return getCompareImage(urlPrefix, inputPath.toString(), outputPath.toString());
+    }
+
+    public static CommonResult getCompareImage(String urlPrefix, String inputPath, String outputPath) {
+        try {
+             List<String> inputImageList = calculateImagePath(urlPrefix, inputPath);
+            List<String> outputImageList = calculateImagePath(urlPrefix, outputPath);
+
+            HashMap<String,String> nameToUrl1 = new HashMap<>();
+
+            for (String imageUrl : inputImageList) {
+                String name = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
+                nameToUrl1.put(name, imageUrl);
+            }
+            HashMap<String,String> nameToUrl2 = new HashMap<>();
+            for (String imageUrl : outputImageList) {
+                String name = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
+                nameToUrl2.put(name, imageUrl);
+            }
+            List<String> inputImageNames = new ArrayList<>(nameToUrl1.keySet());
+
+            inputImageNames.sort(Comparator.naturalOrder());
+
+            List<Map<String, String>> resultList = new ArrayList<>();
+            for (String inputImageName : inputImageNames) {
+                Map<String, String> map = new HashMap<>();
+                map.put("inputUrl", nameToUrl1.get(inputImageName));
+                map.put("outputUrl", nameToUrl2.get(inputImageName));
+                resultList.add(map);
+            }
+
+            return CommonResult.success(resultList, "success");
+        } catch (Exception e) {
+            System.out.println("getImages error: " + e.getMessage());
+            return CommonResult.fail("getImages error: " + e.getMessage());
+        }
+    }
+
     private ResponseEntity<org.springframework.core.io.Resource> getPredictImages(ToInfrared toInfrared) {
         String outputPath = toInfrared.getOutputPath();
         String predictDir = outputPath + File.separator + BizConstant.PREDICT_PATH;