Browse Source

feat: 可见光转红外添加模型选择

WANGKANG 8 months ago
parent
commit
1bda44677c

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

@@ -130,4 +130,9 @@ public class ToInfraredController extends BaseController {
     public CommonResult getLog(@PathVariable("id") Long id) {
         return toInfraredService.getLog(id);
     }
+
+    @GetMapping("/model/{id}")
+    public CommonResult getModelList(@PathVariable("id") Long id) {
+        return toInfraredService.getModelList(id);
+    }
 }

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

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

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

@@ -7,9 +7,8 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import java.text.DecimalFormat;
+import java.util.*;
 
 import cn.hutool.core.util.ObjectUtil;
 import com.mybatisflex.core.paginate.Page;
@@ -59,6 +58,12 @@ import static com.taais.biz.service.impl.VideoStableServiceImpl.*;
 @Service
 @Log4j2
 public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToInfrared> implements IToInfraredService {
+    @Value("${server.port}")
+    String port;
+
+    @Value("${taais.profile}")
+    String profile;
+
     @Value("${server.task_stop_url}")
     private String task_stop_url;
 
@@ -394,6 +399,40 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         }
     }
 
+    @Override
+    public CommonResult getModelList(Long id) {
+        ToInfrared entity = getById(id);
+        String outPutPath = entity.getOutputPath();
+        String logPath = outPutPath + File.separator + "model";
+        File modelDir = new File(logPath);
+        if (!modelDir.exists()) {
+            return CommonResult.fail("模型输出目录不存在!");
+        }
+        File[] files = modelDir.listFiles();
+        Integer idx = 0;
+        ArrayList<Map<String, String>> res = new ArrayList<>();
+        for (File file : files) {
+            idx += 1;
+            Map<String, String> tmp = new HashMap<>();
+            tmp.put("id", idx.toString());
+            tmp.put("name", file.getName());
+            String filePath = file.getPath();
+            tmp.put("path", filePath);
+            // todo 获取真正的url
+            // http://localhost:9090/profile/upload/2024/10/27/1_1729404909511_20241027153840A001.zip
+            String url = "http://localhost:" + port + Constants.RESOURCE_PREFIX + filePath.substring(profile.length());
+            url = url.replaceAll("\\\\", "/"); // windows
+            tmp.put("url", url);
+
+            double fileSize = (file.length() / (1024.0 * 1024.0));
+            DecimalFormat decimalFormat = new DecimalFormat("#.##");
+            String formatFileSize = decimalFormat.format(fileSize);
+            tmp.put("size", formatFileSize + "MB");
+            res.add(tmp);
+        }
+        return CommonResult.success(res, "success");
+    }
+
     private ResponseEntity<org.springframework.core.io.Resource> getPredictImages(ToInfrared toInfrared) {
         String outputPath = toInfrared.getOutputPath();
         String predictDir = outputPath + File.separator + BizConstant.PREDICT_PATH;