Răsfoiți Sursa

fix: 修改预处理,虚警抑制算法执行逻辑

wanggaokun 10 luni în urmă
părinte
comite
38fdc4ce1b

+ 19 - 0
als-modules/agile-assurance/src/main/java/org/eco/als/domain/FalseAlarm.java

@@ -37,6 +37,25 @@ public class FalseAlarm extends BaseEntity {
      * 机号
      */
     private Long aircraftId;
+    /**
+     * 模型类型
+     */
+    private String modelType;
+
+    /**
+     * 参数
+     */
+    private String param;
+
+    /**
+     * 数据列
+     */
+    private String columnData;
+
+    /**
+     * 文件Id
+     */
+    private Long ossId;
     /**
      * 状态
      */

+ 1 - 1
als-modules/agile-assurance/src/main/java/org/eco/als/domain/Warning.java

@@ -31,7 +31,7 @@ public class Warning extends BaseEntity {
     /**
      * 架次号
      */
-    private Long sortieNo;
+    private String sortieNo;
 
     /**
      * 机号

+ 22 - 1
als-modules/agile-assurance/src/main/java/org/eco/als/domain/bo/AlgorithmBo.java

@@ -1,9 +1,12 @@
 package org.eco.als.domain.bo;
 
+import com.alibaba.excel.annotation.ExcelProperty;
 import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotNull;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
+import org.eco.common.excel.annotation.ExcelDictFormat;
+import org.eco.common.excel.convert.ExcelDictConvert;
 import org.eco.common.orm.core.domain.BaseEntity;
 
 import java.util.List;
@@ -26,9 +29,27 @@ public class AlgorithmBo extends BaseEntity {
     /**
      * 数据Id
      */
-    @NotNull(message = "模型Id不能为空")
+    @NotNull(message = "数据不能为空")
     private Long dataId;
 
+    /**
+     * 数据Id
+     */
+    @NotNull(message = "数据Id不能为空")
+    private Long ossId;
+
+    /**
+     * 机号Id
+     */
+    @NotNull(message = "机号Id不能为空")
+    private Long aircraftId;
+
+    /**
+     * 架次号
+     */
+    @NotBlank(message = "架次号不能为空")
+    private String sortieNo;
+
     /**
      * 参数
      */

+ 25 - 0
als-modules/agile-assurance/src/main/java/org/eco/als/domain/bo/FalseAlarmBo.java

@@ -3,6 +3,7 @@ package org.eco.als.domain.bo;
 import io.github.linpeilie.annotations.AutoMapper;
 import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotNull;
+import lombok.Builder;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import org.eco.als.domain.FalseAlarm;
@@ -14,6 +15,7 @@ import org.eco.common.orm.core.domain.BaseEntity;
  * @author wgk
  * @date 2024-07-23
  */
+@Builder
 @Data
 @EqualsAndHashCode(callSuper = true)
 @AutoMapper(target = FalseAlarm.class, reverseConvertGenerate = false)
@@ -29,12 +31,35 @@ public class FalseAlarmBo extends BaseEntity {
     @NotBlank(message = "架次号不能为空")
     private String sortieNo;
 
+    /**
+     * 模型类型
+     */
+    @NotBlank(message = "模型类型不能为空")
+    private String modelType;
+
     /**
      * 机号Id
      */
     @NotNull(message = "机号不能为空")
     private Long aircraftId;
 
+    /**
+     * 参数
+     */
+    @NotBlank(message = "参数不能为空")
+    private String param;
+
+    /**
+     * 数据列
+     */
+    @NotBlank(message = "数据列不能为空")
+    private String columnData;
+
+    /**
+     * 文件Id
+     */
+    private Long ossId;
+
     /**
      * 状态
      */

+ 2 - 0
als-modules/agile-assurance/src/main/java/org/eco/als/domain/bo/FalseAlarmResultBo.java

@@ -3,6 +3,7 @@ package org.eco.als.domain.bo;
 import io.github.linpeilie.annotations.AutoMapper;
 import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotNull;
+import lombok.Builder;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import org.eco.als.domain.FalseAlarmResult;
@@ -14,6 +15,7 @@ import org.eco.common.orm.core.domain.BaseEntity;
  * @author wgk
  * @date 2024-07-23
  */
+@Builder
 @Data
 @EqualsAndHashCode(callSuper = true)
 @AutoMapper(target = FalseAlarmResult.class, reverseConvertGenerate = false)

+ 2 - 2
als-modules/agile-assurance/src/main/java/org/eco/als/domain/bo/WarningBo.java

@@ -26,8 +26,8 @@ public class WarningBo extends BaseEntity {
     /**
      * 架次号
      */
-    @NotNull(message = "架次号不能为空")
-    private Long sortieNo;
+    @NotBlank(message = "架次号不能为空")
+    private String sortieNo;
 
     /**
      * 机号Id

+ 24 - 0
als-modules/agile-assurance/src/main/java/org/eco/als/domain/vo/FalseAlarmVo.java

@@ -46,6 +46,30 @@ public class FalseAlarmVo extends BaseEntity implements Serializable {
      * 机号Id
      */
     private Long aircraftId;
+    /**
+     * 文件Id
+     */
+    @ExcelProperty(value = "文件Id")
+    private Long ossId;
+
+    /**
+     * 模型类型
+     */
+    @ExcelProperty(value = "模型类型", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(dictType = "common_type")
+    private String modelType;
+
+    /**
+     * 参数
+     */
+    @ExcelProperty(value = "参数")
+    private String param;
+
+    /**
+     * 数据列
+     */
+    @ExcelProperty(value = "数据列")
+    private String columnData;
 
     /**
      * 机号

+ 1 - 1
als-modules/agile-assurance/src/main/java/org/eco/als/domain/vo/WarningVo.java

@@ -40,7 +40,7 @@ public class WarningVo extends BaseEntity implements Serializable {
      * 架次号
      */
     @ExcelProperty(value = "架次号")
-    private Long sortieNo;
+    private String sortieNo;
 
     /**
      * 机号Id

+ 103 - 76
als-modules/agile-assurance/src/main/java/org/eco/als/service/impl/AlgorithmService.java

@@ -7,7 +7,8 @@ import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
 import org.eco.als.domain.Warning;
 import org.eco.als.domain.bo.AlgorithmBo;
-import org.eco.als.domain.bo.FaultDiagnosisBo;
+import org.eco.als.domain.bo.FalseAlarmBo;
+import org.eco.als.domain.bo.FalseAlarmResultBo;
 import org.eco.als.domain.bo.PreProcessingBo;
 import org.eco.als.domain.bo.TaskBo;
 import org.eco.als.domain.vo.DataImportVo;
@@ -15,6 +16,7 @@ import org.eco.als.domain.vo.ModelHttpVo;
 import org.eco.als.domain.vo.ModelVo;
 import org.eco.als.service.IAlgorithmService;
 import org.eco.als.service.IDataImportService;
+import org.eco.als.service.IFalseAlarmResultService;
 import org.eco.als.service.IFalseAlarmService;
 import org.eco.als.service.IFaultDiagnosisService;
 import org.eco.als.service.IModelService;
@@ -61,12 +63,29 @@ public class AlgorithmService implements IAlgorithmService {
     @Resource
     private IFalseAlarmService falseAlarmService;
 
+    @Resource
+    private IFalseAlarmResultService falseAlarmResultService;
+
     @Resource
     private IFaultDiagnosisService faultDiagnosisService;
 
     @Resource
     private ITaskService taskService;
 
+    private static ModelHttpVo sendHttp(ModelVo modelVo, Map<String, Object> map) {
+        try {
+            String result = HttpUtils.postJson(modelVo.getUrl(), map);
+            JSONObject jsonObject = JSONUtil.parseObj(result);
+            String data = jsonObject.getStr("data");
+            String status = jsonObject.getStr("status");
+            String msg = jsonObject.getStr("msg");
+            return ModelHttpVo.builder().data(data).status(Integer.valueOf(status)).msg(msg).build();
+        } catch (Exception e) {
+            log.error(e.getMessage());
+            throw new BusinessException("算法服务连接异常,请联系管理员!");
+        }
+    }
+
     /**
      * executePro 预处理
      *
@@ -75,23 +94,14 @@ public class AlgorithmService implements IAlgorithmService {
      **/
     @Override
     public String executePro(AlgorithmBo algorithmBo) {
-
         // 模型相关信息
         ModelVo modelVo = modelService.selectById(algorithmBo.getModelId());
         if (ObjectUtil.isNull(modelVo)) {
             throw new BusinessException("模型信息为空,请检查!");
         }
 
-        // 数据相关信息
-        DataImportVo dataVo = dataImportService.selectById(algorithmBo.getDataId());
-        if (ObjectUtil.isNull(dataVo)) {
-            throw new BusinessException("数据为空,请检查!");
-        }
-
-        // 参数
-        Map<String, Object> map = new HashMap<>(JSONUtil.parseObj(algorithmBo.getParam()));
         File file = null;
-        try (InputStream inputStream = ossService.getFileStream(dataVo.getOssId())) {
+        try (InputStream inputStream = ossService.getFileStream(algorithmBo.getOssId())) {
             file = CsvUtils.excelToFileCsvByColumns(inputStream, algorithmBo.getColumnData());
         } catch (Exception e) {
             log.error("文件转换异常:{}", e.getMessage());
@@ -100,13 +110,28 @@ public class AlgorithmService implements IAlgorithmService {
             return null;
         }
         SysOssVo sysOssVo = ossService.upload(file);
-        processingService.insert(PreProcessingBo.builder().ossId(sysOssVo.getOssId()).aircraftId(dataVo.getAircraftId()).sortieNo(dataVo.getSortieNo()).build());
-        // 请求
+        PreProcessingBo processingBo =
+                PreProcessingBo.builder()
+                        .ossId(sysOssVo.getOssId())
+                        .aircraftId(algorithmBo.getAircraftId())
+                        .modelType(modelVo.getType())
+                        .sortieNo(algorithmBo.getSortieNo())
+                        .param(algorithmBo.getParam())
+                        .status("0")
+                        .columnData(Arrays.toString(algorithmBo.getColumnData()))
+                        .build();
+        processingService.insert(processingBo);
+        // 参数
+        Map<String, Object> map = new HashMap<>(JSONUtil.parseObj(algorithmBo.getParam()));
         map.put("url", sysOssVo.getUrl());
+        // 请求
         ModelHttpVo httpVo = sendHttp(modelVo, map);
         if (httpVo != null && httpVo.getStatus() == 200) {
             File resultFile = CsvUtils.jsonToFileCsv(httpVo.getData(), CsvUtils.extractFilename("model_result"));
             SysOssVo sysOssVo2 = ossService.upload(resultFile);
+            processingBo.setOssId(sysOssVo2.getOssId());
+            processingBo.setStatus("1");
+            processingService.update(processingBo);
         }
         return httpVo != null ? httpVo.getData() : null;
     }
@@ -119,45 +144,60 @@ public class AlgorithmService implements IAlgorithmService {
      **/
     @Override
     public String executeFalseAlarm(AlgorithmBo algorithmBo) {
+        // 虚警抑制校验警告列表
+        if (ObjectUtil.isNull(algorithmBo.getWarningIds())) {
+            throw new BusinessException("警告信息不能为空,请检查!");
+        }
         // 模型相关信息
         ModelVo modelVo = modelService.selectById(algorithmBo.getModelId());
         if (ObjectUtil.isNull(modelVo)) {
             throw new BusinessException("模型信息为空,请检查!");
         }
-
-        // 虚警抑制校验警告列表
-        if (ObjectUtil.isNull(algorithmBo.getWarningIds())) {
-            throw new BusinessException("警告信息不能为空,请检查!");
+        File file = null;
+        try (InputStream inputStream = ossService.getFileStream(algorithmBo.getOssId())) {
+            file = CsvUtils.excelToFileCsvByColumns(inputStream, algorithmBo.getColumnData());
+        } catch (Exception e) {
+            log.error("文件转换异常:{}", e.getMessage());
+        }
+        if (ObjectUtil.isNull(file)) {
+            return null;
         }
+        SysOssVo sysOssVo = ossService.upload(file);
+        FalseAlarmBo falseAlarmBo = FalseAlarmBo.builder()
+                .ossId(sysOssVo.getOssId())
+                .aircraftId(algorithmBo.getAircraftId())
+                .modelType(modelVo.getType())
+                .sortieNo(algorithmBo.getSortieNo())
+                .param(algorithmBo.getParam())
+                .status("0")
+                .columnData(Arrays.toString(algorithmBo.getColumnData()))
+                .build();
+        falseAlarmService.insert(falseAlarmBo);
+
         // 警告列表
         List<Warning> warnings = warningService.listByIds(Arrays.asList(algorithmBo.getWarningIds()));
+        Warning warning = warnings.getFirst();
         warnings.forEach(el -> {
-
         });
-
-        // 数据相关信息
-        DataImportVo dataVo = dataImportService.selectById(algorithmBo.getDataId());
-        if (ObjectUtil.isNull(dataVo)) {
-            throw new BusinessException("数据为空,请检查!");
-        }
         // 参数
-        String param = algorithmBo.getParam();
-        Map<String, Object> map = new HashMap<>(JSONUtil.parseObj(param));
-        try (InputStream inputStream = ossService.getFileStream(dataVo.getOssId())) {
-            File file = CsvUtils.excelToFileCsvByColumns(inputStream, algorithmBo.getColumnData());
-            SysOssVo sysOssVo1 = ossService.upload(file);
-            // 请求
-            map.put("url", sysOssVo1.getUrl());
-            ModelHttpVo httpVo = sendHttp(modelVo, map);
-            if (httpVo != null && httpVo.getStatus() == 200) {
-                File resultFile = CsvUtils.jsonToFileCsv(httpVo.getData(), CsvUtils.extractFilename("model_result"));
-                SysOssVo sysOssVo2 = ossService.upload(resultFile);
-            }
-            return httpVo != null ? httpVo.getData() : null;
-        } catch (Exception e) {
-            log.error(e.getMessage());
+        Map<String, Object> map = new HashMap<>(JSONUtil.parseObj(algorithmBo.getParam()));
+        map.put("url", sysOssVo.getUrl());
+        // 请求
+        ModelHttpVo httpVo = sendHttp(modelVo, map);
+        if (httpVo != null && httpVo.getStatus() == 200) {
+            falseAlarmBo.setStatus("1");
+            falseAlarmService.update(falseAlarmBo);
+            FalseAlarmResultBo falseAlarmResultBo = FalseAlarmResultBo.builder()
+                    .falseAlarmId(falseAlarmBo.getId())
+                    .code(warning.getCode())
+                    .name(warning.getName())
+                    .aircraftId(warning.getAircraftId())
+                    .sortieNo(warning.getSortieNo())
+                    .status(httpVo.getData())
+                    .build();
+            falseAlarmResultService.insert(falseAlarmResultBo);
         }
-        return null;
+        return httpVo != null ? httpVo.getData() : null;
     }
 
     /**
@@ -174,30 +214,30 @@ public class AlgorithmService implements IAlgorithmService {
         if (ObjectUtil.isNull(modelVo)) {
             throw new BusinessException("模型信息为空,请检查!");
         }
-
-        // 数据相关信息
-        DataImportVo dataVo = dataImportService.selectById(algorithmBo.getDataId());
-        if (ObjectUtil.isNull(dataVo)) {
-            throw new BusinessException("数据为空,请检查!");
+        File file = null;
+        try (InputStream inputStream = ossService.getFileStream(algorithmBo.getOssId())) {
+            file = CsvUtils.excelToFileCsvByColumns(inputStream, algorithmBo.getColumnData());
+        } catch (Exception e) {
+            log.error("文件转换异常:{}", e.getMessage());
+        }
+        if (ObjectUtil.isNull(file)) {
+            return null;
         }
+        SysOssVo sysOssVo = ossService.upload(file);
+
+        // 警告列表
+        List<Warning> warnings = warningService.listByIds(Arrays.asList(algorithmBo.getWarningIds()));
+        Warning warning = warnings.getFirst();
+        warnings.forEach(el -> {
+        });
         // 参数
-        String param = algorithmBo.getParam();
-        Map<String, Object> map = new HashMap<>(JSONUtil.parseObj(param));
-        try (InputStream inputStream = ossService.getFileStream(dataVo.getOssId())) {
-            File file = CsvUtils.excelToFileCsvByColumns(inputStream, algorithmBo.getColumnData());
-            SysOssVo sysOssVo1 = ossService.upload(file);
-            // 请求
-            map.put("url", sysOssVo1.getUrl());
-            ModelHttpVo httpVo = sendHttp(modelVo, map);
-            if (httpVo != null && httpVo.getStatus() == 200) {
-                faultDiagnosisService.insert(FaultDiagnosisBo.builder().aircraftId(dataVo.getAircraftId()).build());
-            } else {
-            }
-            return httpVo != null ? httpVo.getData() : null;
-        } catch (Exception e) {
-            log.error(e.getMessage());
+        Map<String, Object> map = new HashMap<>(JSONUtil.parseObj(algorithmBo.getParam()));
+        map.put("url", sysOssVo.getUrl());
+        // 请求
+        ModelHttpVo httpVo = sendHttp(modelVo, map);
+        if (httpVo != null && httpVo.getStatus() == 200) {
         }
-        return null;
+        return httpVo != null ? httpVo.getData() : null;
     }
 
     @Override
@@ -228,7 +268,8 @@ public class AlgorithmService implements IAlgorithmService {
                 map.put("url", sysOssVo.getUrl());
                 ModelHttpVo httpVo = sendHttp(modelVo, map);
                 if (httpVo != null && httpVo.getStatus() == 200) {
-                    File resultFile = CsvUtils.jsonToFileCsv(httpVo.getData(), CsvUtils.extractFilename("model_result"));
+                    File resultFile = CsvUtils.jsonToFileCsv(httpVo.getData(), CsvUtils.extractFilename("model_result"
+                    ));
                     SysOssVo sysOssVo2 = ossService.upload(resultFile);
                 }
                 if (taskBo.getStepNumber() == 1) {
@@ -241,18 +282,4 @@ public class AlgorithmService implements IAlgorithmService {
         taskService.insert(taskBo);
         return null;
     }
-
-    private static ModelHttpVo sendHttp(ModelVo modelVo, Map<String, Object> map) {
-        try {
-            String result = HttpUtils.postJson(modelVo.getUrl(), map);
-            JSONObject jsonObject = JSONUtil.parseObj(result);
-            String data = jsonObject.getStr("data");
-            String status = jsonObject.getStr("status");
-            String msg = jsonObject.getStr("msg");
-            return ModelHttpVo.builder().data(data).status(Integer.valueOf(status)).msg(msg).build();
-        } catch (Exception e) {
-            log.error(e.getMessage());
-            throw new BusinessException("算法服务连接异常,请联系管理员!");
-        }
-    }
 }