فهرست منبع

feat: 添加可见光数据集对比图片接口

WANGKANG 9 ماه پیش
والد
کامیت
1e81e61f65

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

@@ -120,4 +120,9 @@ public class DataSeqController extends BaseController {
     public CommonResult<List<String>> getImages(@PathVariable Long inputOdssId, @PathVariable String subsystem, @PathVariable Boolean ifInput, @PathVariable String dir) {
         return CommonResult.success(dataSeqService.getImages(inputOdssId, subsystem, ifInput, dir));
     }
+
+    @GetMapping("/getCOMPImages/{inputOssId}")
+    public CommonResult getImagesCOMP(@PathVariable Long inputOssId) {
+        return dataSeqService.getImagesCOMP(inputOssId);
+    }
 }

+ 3 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/service/IDataSeqService.java

@@ -9,6 +9,7 @@ import java.util.List;
 import com.taais.biz.domain.DataSeq;
 import com.taais.biz.domain.vo.DataSeqVo;
 import com.taais.biz.domain.bo.DataSeqBo;
+import com.taais.common.core.core.domain.CommonResult;
 import com.taais.common.orm.core.service.IBaseService;
 import com.taais.common.core.core.page.PageResult;
 
@@ -69,4 +70,6 @@ public interface IDataSeqService extends IBaseService<DataSeq> {
 
     List<String> getAllImages(Long inputOdssId);
     List<String> getImages(Long inputOdssId, String subsystem, Boolean ifInput, String dir);
+
+    CommonResult getImagesCOMP(Long inputOdssId);
 }

+ 67 - 5
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/DataSeqServiceImpl.java

@@ -9,12 +9,14 @@ import com.mybatisflex.core.paginate.Page;
 import com.mybatisflex.core.query.QueryWrapper;
 import com.taais.biz.constant.BizConstant;
 import com.taais.biz.domain.DataSeq;
+import com.taais.biz.domain.TrackSequence;
 import com.taais.biz.domain.bo.DataSeqBo;
 import com.taais.biz.domain.vo.DataSeqVo;
 import com.taais.biz.mapper.DataSeqMapper;
 import com.taais.biz.service.IDataSeqService;
 import com.taais.common.core.config.TaaisConfig;
 import com.taais.common.core.constant.Constants;
+import com.taais.common.core.core.domain.CommonResult;
 import com.taais.common.core.core.page.PageResult;
 import com.taais.common.core.utils.MapstructUtils;
 import com.taais.common.core.utils.StringUtils;
@@ -28,12 +30,14 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.*;
 
 import static com.taais.biz.domain.table.DataSeqTableDef.DATA_SEQ;
+import static com.taais.biz.service.impl.VideoStableServiceImpl.removeFileExtension;
 import static com.taais.biz.utils.ZipUtils.unzip;
+import static java.lang.Math.min;
 
 /**
  * 数据管理Service业务层处理
@@ -94,7 +98,7 @@ public class DataSeqServiceImpl extends BaseServiceImpl<DataSeqMapper, DataSeq>
     @Override
     public List<DataSeqVo> selectList(DataSeqBo dataSeqBo) {
         QueryWrapper queryWrapper = buildQueryWrapper(dataSeqBo);
-        queryWrapper.orderBy(DATA_SEQ.CREATE_TIME,Boolean.FALSE);
+        queryWrapper.orderBy(DATA_SEQ.CREATE_TIME, Boolean.FALSE);
         return this.listAs(queryWrapper, DataSeqVo.class);
     }
 
@@ -107,7 +111,7 @@ public class DataSeqServiceImpl extends BaseServiceImpl<DataSeqMapper, DataSeq>
     @Override
     public PageResult<DataSeqVo> selectPage(DataSeqBo dataSeqBo) {
         QueryWrapper queryWrapper = buildQueryWrapper(dataSeqBo);
-        queryWrapper.orderBy(DATA_SEQ.CREATE_TIME,Boolean.FALSE);
+        queryWrapper.orderBy(DATA_SEQ.CREATE_TIME, Boolean.FALSE);
         Page<DataSeqVo> page = this.pageAs(PageQuery.build(), queryWrapper, DataSeqVo.class);
         return PageResult.build(page);
     }
@@ -272,6 +276,64 @@ public class DataSeqServiceImpl extends BaseServiceImpl<DataSeqMapper, DataSeq>
         }
     }
 
+    @Override
+    public CommonResult getImagesCOMP(Long inputOdssId) {
+        SysOssVo inputOssEntity = ossService.getById(inputOdssId);
+        if (ObjectUtil.isNull(inputOssEntity)) {
+            return CommonResult.fail("没有找到对应的数据集文件!");
+        }
+
+        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 outputPathDir = new File(inputPath.toString());
+        if (!outputPathDir.exists()) {
+            return CommonResult.fail("数据集文件夹不存在!");
+        }
+
+        Path path1 = inputPath.resolve("trainA");
+        Path path2 = inputPath.resolve("trainB");
+
+
+        String urlPrefix = Constants.RESOURCE_PREFIX;
+        return getSortCompareImage(urlPrefix, path1.toString(), path2.toString());
+    }
+
+    public CommonResult getSortCompareImage(String urlPrefix, String inputPath, String outputPath) {
+        try {
+            List<String> inputImageList = calculateImagePath(urlPrefix, inputPath);
+            List<String> outputImageList = calculateImagePath(urlPrefix, outputPath);
+            List<Map<String, String>> resultList = new ArrayList<>();
+
+            if(ObjectUtil.isNull(inputImageList) || ObjectUtil.isNull(outputImageList)) {
+                return CommonResult.success(resultList, "success");
+            }
+
+            inputImageList.sort(Comparator.naturalOrder());
+            outputImageList.sort(Comparator.naturalOrder());
+
+
+            for(int i = 0; i < min(inputImageList.size(), outputImageList.size()); i++) {
+                Map<String, String> map = new HashMap<>();
+                map.put("inputUrl", inputImageList.get(i));
+                map.put("outputUrl", outputImageList.get(i));
+                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 static final String[] IMAGE_EXTENSIONS = {".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".tif", ".webp"};
 

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

@@ -91,28 +91,17 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
 
     private QueryWrapper buildQueryWrapper(ToInfraredBo toInfraredBo) {
         QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
-        queryWrapper.and(TO_INFRARED.NAME.like
-            (toInfraredBo.getName()));
-        queryWrapper.and(TO_INFRARED.STATUS.eq
-            (toInfraredBo.getStatus()));
-        queryWrapper.and(TO_INFRARED.START_TIME.eq
-            (toInfraredBo.getStartTime()));
-        queryWrapper.and(TO_INFRARED.END_TIME.eq
-            (toInfraredBo.getEndTime()));
-        queryWrapper.and(TO_INFRARED.COST_SECOND.eq
-            (toInfraredBo.getCostSecond()));
-        queryWrapper.and(TO_INFRARED.LOG.eq
-            (toInfraredBo.getLog()));
-        queryWrapper.and(TO_INFRARED.REMARKS.eq
-            (toInfraredBo.getRemarks()));
-        queryWrapper.and(TO_INFRARED.URL.eq
-            (toInfraredBo.getUrl()));
-        queryWrapper.and(TO_INFRARED.INPUT_OSS_ID.eq
-            (toInfraredBo.getInputOssId()));
-        queryWrapper.and(TO_INFRARED.INPUT_PATH.eq
-            (toInfraredBo.getInputPath()));
-        queryWrapper.and(TO_INFRARED.OUTPUT_PATH.eq
-            (toInfraredBo.getOutputPath()));
+        queryWrapper.and(TO_INFRARED.NAME.like(toInfraredBo.getName()));
+        queryWrapper.and(TO_INFRARED.STATUS.eq(toInfraredBo.getStatus()));
+        queryWrapper.and(TO_INFRARED.START_TIME.eq(toInfraredBo.getStartTime()));
+        queryWrapper.and(TO_INFRARED.END_TIME.eq(toInfraredBo.getEndTime()));
+        queryWrapper.and(TO_INFRARED.COST_SECOND.eq(toInfraredBo.getCostSecond()));
+        queryWrapper.and(TO_INFRARED.LOG.eq(toInfraredBo.getLog()));
+        queryWrapper.and(TO_INFRARED.REMARKS.eq(toInfraredBo.getRemarks()));
+        queryWrapper.and(TO_INFRARED.URL.eq(toInfraredBo.getUrl()));
+        queryWrapper.and(TO_INFRARED.INPUT_OSS_ID.eq(toInfraredBo.getInputOssId()));
+        queryWrapper.and(TO_INFRARED.INPUT_PATH.eq(toInfraredBo.getInputPath()));
+        queryWrapper.and(TO_INFRARED.OUTPUT_PATH.eq(toInfraredBo.getOutputPath()));
 
         return queryWrapper;
     }
@@ -490,7 +479,7 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         Path statisticsResultPath = outputPath.resolve(BizConstant.RESULT_JSON_NAME);
 
         List<Dict> resultMap = parseJsonMapList(statisticsResultPath);
-        if(ObjectUtil.isEmpty(resultMap)) {
+        if (ObjectUtil.isEmpty(resultMap)) {
             return CommonResult.fail("获取结果文件失败");
         }
 
@@ -502,7 +491,7 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
             String jsonString = new String(Files.readAllBytes(path));
             List<Dict> dicts = JsonUtils.parseArrayMap(jsonString);
             return dicts;
-        }catch (Exception e) {
+        } catch (Exception e) {
             e.printStackTrace();
             return null;
         }
@@ -514,17 +503,23 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
             List<String> inputImageList = calculateImagePath(urlPrefix, inputPath);
             List<String> outputImageList = calculateImagePath(urlPrefix, outputPath);
 
-            HashMap<String,String> nameToUrl1 = new HashMap<>();
+            HashMap<String, String> nameToUrl1 = new HashMap<>();
 
-            for (String imageUrl : inputImageList) {
-                String name = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
-                nameToUrl1.put(name, imageUrl);
+            if (ObjectUtil.isNotNull(inputImageList)) {
+                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);
+
+            HashMap<String, String> nameToUrl2 = new HashMap<>();
+            if (ObjectUtil.isNotNull(outputImageList)) {
+                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());
@@ -565,10 +560,7 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         }
 
         org.springframework.core.io.Resource resource = new FileSystemResource(file);
-        return ResponseEntity.ok()
-            .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getName() + "\"")
-            .header(HttpHeaders.CONTENT_TYPE, "application/octet-stream")
-            .body(resource);
+        return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getName() + "\"").header(HttpHeaders.CONTENT_TYPE, "application/octet-stream").body(resource);
     }
 
     public ResponseEntity<org.springframework.core.io.Resource> getLastModelFile(ToInfrared toInfrared) {
@@ -591,10 +583,7 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         File returnFile = modelFiles[modelFiles.length - 1];
 
         org.springframework.core.io.Resource resource = new FileSystemResource(returnFile);
-        return ResponseEntity.ok()
-            .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + returnFile.getName() + "\"")
-            .header(HttpHeaders.CONTENT_TYPE, "application/octet-stream")
-            .body(resource);
+        return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + returnFile.getName() + "\"").header(HttpHeaders.CONTENT_TYPE, "application/octet-stream").body(resource);
     }
 
 //    @Override