Jelajahi Sumber

fix: 可见光装红外任务修正

WANGKANG 5 bulan lalu
induk
melakukan
38d9728b06

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

@@ -60,7 +60,7 @@ import static com.taais.biz.service.impl.VideoStableServiceImpl.*;
  * 可见光转红外Service业务层处理
  *
  * @author 0
- * 2024-09-20
+ *         2024-09-20
  */
 @Service
 @Log4j2
@@ -243,7 +243,28 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         return entity;
     }
 
-    public static Map<String, Object> getAlgorithmParameters(String algorithmConfigStr, Map<String, Object> otherParams) {
+    public static Object strToTargetType(Object val_) {
+        if (ObjectUtil.isEmpty(val_)) {
+            return null;
+        }
+        String val = val_.toString();
+        try {
+            return Integer.parseInt(val);
+        } catch (Exception e1) {
+            try {
+                return Double.parseDouble(val);
+            } catch (Exception e2) {
+                try {
+                    return Boolean.parseBoolean(val);
+                } catch (Exception e3) {
+                    return val;
+                }
+            }
+        }
+    }
+
+    public static Map<String, Object> getAlgorithmParameters(String algorithmConfigStr,
+            Map<String, Object> otherParams) {
         Map<String, Object> algorithmParameters = new HashMap<>();
         List<Dict> config_list = JsonUtils.parseArrayMap(algorithmConfigStr);
 
@@ -251,7 +272,7 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         if (ObjectUtil.isEmpty(config_list)) {
             System.out.println("算法配置参数为空");
             return algorithmParameters;
-//            throw new RuntimeException("算法配置参数为空");
+            // throw new RuntimeException("算法配置参数为空");
         }
         for (Dict config : config_list) {
             String key = (String) config.get("agName");
@@ -263,7 +284,7 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         // 步骤 3. 然后根据前端传入的参数,覆盖默认参数
         for (String key : algorithmParameters.keySet()) {
             if (otherParams.containsKey(key) && ObjectUtil.isNotEmpty(otherParams.get(key))) {
-                algorithmParameters.put(key, otherParams.get(key));
+                algorithmParameters.put(key, strToTargetType(otherParams.get(key)));
             }
         }
         return algorithmParameters;
@@ -277,13 +298,14 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
             throw new RuntimeException("算法配置参数为空");
         }
 
-        Map<String, Object> algorithmParameters = getAlgorithmParameters(algorithmConfig.getParameters(), entityBo.getOtherParams());
+        Map<String, Object> algorithmParameters = getAlgorithmParameters(algorithmConfig.getParameters(),
+                entityBo.getOtherParams());
 
         // 步骤4. 构造可以直接传给前端的map数据结构
         Map<String, Object> result = new HashMap<>();
 
-        result.put("biz_id", entity.getId());
-        result.put("biz_type", BizConstant.BizType.TO_INFRARED);
+        result.put("bizId", entity.getId());
+        result.put("bizType", BizConstant.BizType.TO_INFRARED);
 
         if (algorithmConfig.getType().equals(BizConstant.AlgorithmType.TRAIN)) {
             String source_dir = getTrainInputPath(ossEntity);
@@ -375,10 +397,9 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
 
         Path path = Paths.get(resourcePath);
         File file = new File(path.toString());
-        if(file.isDirectory()) {
+        if (file.isDirectory()) {
             return path.toString();
-        }
-        else {
+        } else {
             Path dirPath = path.resolveSibling(fileName_without_suffix + BizConstant.UNZIP_SUFFIX);
             return dirPath.toString();
         }
@@ -403,7 +424,6 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         return getUnZipDirPath(ossEntity) + File.separator + BizConstant.TO_INFRARED_PREDICT_OUTPUT_DIR;
     }
 
-
     public static String getLogFilePath(String outputPath, Long id, String suffix) {
         return outputPath + File.separator + id.toString() + suffix + ".log";
     }
@@ -484,8 +504,7 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
             return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
         }
 
-        AlgorithmModelTrackVo model = algorithmModelTrackService.selectById(toInfrared.getAlgorithmModelId());
-        AlgorithmConfigTrackVo config = algorithmConfigTrackService.selectById(model.getAlgorithmId());
+        AlgorithmConfigTrackVo config = algorithmConfigTrackService.selectById(toInfrared.getAlgorithmId());
 
         if (BizConstant.AlgorithmType.TRAIN.equals(config.getType())) { // 如果是训练类型,返回模型
             return getLastModelFile(toInfrared);
@@ -593,7 +612,6 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         }
     }
 
-
     public static CommonResult getCompareImage(String urlPrefix, String inputPath, String outputPath) {
         try {
             List<String> inputImageList = calculateImagePath(urlPrefix, inputPath);
@@ -604,7 +622,7 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
             if (ObjectUtil.isNotNull(inputImageList)) {
                 for (String imageUrl : inputImageList) {
                     String name = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
-                    nameToUrl1.put(name, imageUrl);
+                    nameToUrl1.put(name.split("\\.")[0], imageUrl);
                 }
             }
 
@@ -612,7 +630,7 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
             if (ObjectUtil.isNotNull(outputImageList)) {
                 for (String imageUrl : outputImageList) {
                     String name = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
-                    nameToUrl2.put(name, imageUrl);
+                    nameToUrl2.put(name.split("\\.")[0], imageUrl);
                 }
             }
 
@@ -649,13 +667,14 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
             }
         }
 
-
         if (!file.exists() || !file.isFile()) {
             return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
         }
 
         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) {
@@ -678,6 +697,8 @@ 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);
     }
 }