소스 검색

feat: 可见光转红外配置完成

WANGKANG 7 달 전
부모
커밋
836daa9333
1개의 변경된 파일87개의 추가작업 그리고 41개의 파일을 삭제
  1. 87 41
      taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/ToInfraredServiceImpl.java

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

@@ -71,9 +71,6 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
     @Value("${taais.profile}")
     String profile;
 
-    @Value("${server.task_stop_url}")
-    private String task_stop_url;
-
     @Autowired
     private ISysOssService ossService;
 
@@ -142,13 +139,18 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         Page<ToInfraredVo> page = this.pageAs(PageQuery.build(), queryWrapper, ToInfraredVo.class);
         page.getRecords().forEach(entity -> {
             Long modelId = entity.getAlgorithmModelId();
-            AlgorithmModelTrackVo model = algorithmModelTrackService.selectById(modelId);
-            if (ObjectUtil.isNotNull(model)) {
-                AlgorithmConfigTrackVo config = algorithmConfigTrackService.selectById(model.getAlgorithmId());
+            if (ObjectUtil.isNotNull(modelId)) {
+                AlgorithmModelTrack model = algorithmModelTrackService.getById(modelId);
+                entity.setModelName(model.getModelName());
+
+            }
+
+            Long algorithmId = entity.getAlgorithmId();
+            if (ObjectUtil.isNotNull(algorithmId)) {
+                AlgorithmConfigTrackVo config = algorithmConfigTrackService.selectById(algorithmId);
                 entity.setType(config.getType());
                 entity.setSubsystem(config.getSubsystem());
                 entity.setAlgorithmName(config.getAlgorithmName());
-                entity.setModelName(model.getModelName());
             }
         });
         page.getRecords().sort(Comparator.comparing(ToInfraredVo::getCreateTime).reversed());
@@ -181,29 +183,80 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         entity.setStatus(NOT_START);
         entity.setRemarks(toInfraredBo.getRemarks());
         entity.setAlgorithmModelId(toInfraredBo.getAlgorithmModelId());
-
+        entity.setAlgorithmId(toInfraredBo.getAlgorithmId());
         boolean flag = this.save(entity);
 
-        if(!flag) {
+        if (!flag) {
             return false;
         }
 
-        AlgorithmModelTrack algorithmModelTrack = algorithmModelTrackService.getById(entity.getAlgorithmModelId());
-        AlgorithmConfigTrack algorithmConfigTrack = algorithmConfigTrackService.getById(algorithmModelTrack.getAlgorithmId());
-
-        if (algorithmConfigTrack.getType().equals(BizConstant.AlgorithmType.TRAIN)) {
-            String inputPath = getTrainInputPath(ossEntity);
-            String outputPath = getTrainOutputPath(entity, ossEntity);
-            entity.setInputPath(inputPath);
-            entity.setOutputPath(outputPath);
-        } else if (algorithmConfigTrack.getType().equals(BizConstant.AlgorithmType.REASONING)) {
-            String inputPath = getPredictInputPath(ossEntity);
-            String outputPath = getPredictOutputPath(entity, ossEntity);
-            entity.setInputPath(inputPath);
-            entity.setOutputPath(outputPath);
+        // 从这里开始,配置任务的algorithm_parameters参数
+        // 步骤 1. 首先根据算法id获取算法配置
+        AlgorithmConfigTrack algorithmConfig = algorithmConfigTrackService.getById(entity.getAlgorithmId());
+        if (ObjectUtil.isNull(algorithmConfig)) {
+            throw new RuntimeException("算法配置参数为空");
+        }
+
+        Map<String, Object> algorithmParameters = new HashMap<>();
+        List<Dict> config_list = JsonUtils.parseArrayMap(algorithmConfig.getParameters());
+
+        // 步骤 2. 根据算法配置,生成默认参数的map数据结构,同时需要解析default_value字段,生成对应的结果
+        if (ObjectUtil.isEmpty(config_list)) {
+            throw new RuntimeException("算法配置参数为空");
+        }
+        for (Dict config : config_list) {
+            String key = (String) config.get("agName");
+            Object value = config.get("defaultValue");
+            if (ObjectUtil.isNotNull(key) && ObjectUtil.isNotNull(value)) {
+                algorithmParameters.put(key, value);
+            }
+        }
+        // 步骤 3. 然后根据前端传入的参数,覆盖默认参数
+        for (String key : algorithmParameters.keySet()) {
+            if (toInfraredBo.getOtherParams().containsKey(key)) {
+                algorithmParameters.put(key, toInfraredBo.getOtherParams().get(key));
+            }
+        }
+        // 步骤4. 构造可以直接传给前端的map数据结构
+        Map<String, Object> result = new HashMap<>();
+
+        if (algorithmConfig.getType().equals(BizConstant.AlgorithmType.TRAIN)) {
+            String source_dir = getTrainInputPath(ossEntity);
+            String result_dir = getTrainOutputPath(entity, ossEntity);
+
+            entity.setInputPath(source_dir);
+            entity.setOutputPath(result_dir);
+
+            String log_path = getLogFilePath(entity);
+            entity.setLogPath(log_path);
+
+            result.put("source_dir", source_dir);
+            result.put("result_dir", result_dir);
+            result.put("log_path", log_path);
+
+        } else if (algorithmConfig.getType().equals(BizConstant.AlgorithmType.REASONING)) {
+            String source_dir = getPredictInputPath(ossEntity);
+            String result_dir = getPredictOutputPath(entity, ossEntity);
+            String model_path = getModelPath(entity);
+
+            entity.setInputPath(source_dir);
+            entity.setOutputPath(result_dir);
+
+            String log_path = getLogFilePath(entity);
+            entity.setLogPath(log_path);
+
+            result.put("result_dir", result_dir);
+            result.put("source_dir", source_dir);
+            result.put("model_path", model_path);
+            result.put("log_path", log_path);
+
         } else {
             throw new RuntimeException("算法类型不支持");
         }
+        result.put("otherParams", algorithmParameters);
+        // 步骤 5. 将算法参数map序列化为json字符串,保存到数据库中
+        entity.setAlgorithmParameters(JsonUtils.toJsonString(result));
+
 
         String resourcePath = getResourcePath(ossService.getById(entity.getInputOssId()));
         makeDir(entity.getInputPath());
@@ -213,7 +266,7 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         if (!file.exists()) {
             ZipUtils.unzip(resourcePath, entity.getInputPath());
         }
-
+        // 步骤 6. 保存算法参数到数据库
         return this.updateById(entity);// 使用全局配置的雪花算法主键生成器生成ID值
     }
 
@@ -293,29 +346,20 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         return getUnZipDirPath(ossEntity) + File.separator + BizConstant.RESULT_JSON_NAME;
     }
 
+    private String getModelPath(ToInfrared entity) {
+        AlgorithmModelTrack algorithmModelTrack = algorithmModelTrackService.getById(entity.getAlgorithmModelId());
+        return algorithmModelTrack.getModelAddress();
+    }
+
     @Override
     public CommonResult start(Long id) {
         ToInfrared entity = getById(id);
         entity.setStartTime(new Date());
 
-        AlgorithmModelTrack algorithmModelTrack = algorithmModelTrackService.getById(entity.getAlgorithmModelId());
-        AlgorithmConfigTrack algorithmConfigTrack = algorithmConfigTrackService.getById(algorithmModelTrack.getAlgorithmId());
-
-        StartTaskConfig startTaskConfig = new StartTaskConfig();
-        startTaskConfig.setBizType(BizConstant.BizType.TO_INFRARED);
-        startTaskConfig.setBizId(entity.getId());
-
-        startTaskConfig.setOtherParams(algorithmConfigTrack.getParameterConfig());
+        AlgorithmConfigTrack algorithmConfigTrack = algorithmConfigTrackService.getById(entity.getAlgorithmId());
+        Map<String, Object> startTaskConfig = JsonUtils.parseMap(entity.getAlgorithmParameters());
 
-        startTaskConfig.setSource_dir(entity.getInputPath());
-        startTaskConfig.setResult_dir(entity.getOutputPath());
-        startTaskConfig.setLog_path(getLogFilePath(entity));
-
-        if (BizConstant.AlgorithmType.REASONING.equals(algorithmConfigTrack.getType())) {
-            startTaskConfig.setModel_path(algorithmModelTrack.getModelAddress());
-        }
-
-        HttpResponseEntity responseEntity = sendPostMsg(algorithmConfigTrack.getAlgorithmAddress(), startTaskConfig);
+        HttpResponseEntity responseEntity = sendPostMsg(algorithmConfigTrack.getStartApi(), startTaskConfig);
         if (ObjectUtil.isNotNull(responseEntity) && responseEntity.getStatus() == 200) {
             entity.setStatus(BizConstant.VideoStatus.RUNNING);
             updateById(entity);
@@ -335,7 +379,9 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         startTaskConfig.setBizType(BizConstant.BizType.TO_INFRARED);
         startTaskConfig.setBizId(toInfrared.getId());
 
-        HttpResponseEntity responseEntity = sendPostMsg(task_stop_url, startTaskConfig);
+        AlgorithmConfigTrack algorithmConfigTrack = algorithmConfigTrackService.getById(toInfrared.getAlgorithmId());
+
+        HttpResponseEntity responseEntity = sendPostMsg(algorithmConfigTrack.getTerminateApi(), startTaskConfig);
         if (ObjectUtil.isNotNull(responseEntity) && responseEntity.getStatus() == 200) {
             toInfrared.setStatus(BizConstant.VideoStatus.INTERRUPTED);
             updateById(toInfrared);