Jelajahi Sumber

批量虚警抑制结果

Gaokun Wang 3 bulan lalu
induk
melakukan
4e682fc9d1

+ 6 - 8
als-modules/agile-assurance/src/main/java/org/eco/als/controller/AlgorithmController.java

@@ -9,7 +9,6 @@ import org.eco.als.domain.bo.ExpressBo;
 import org.eco.als.domain.bo.QaBo;
 import org.eco.als.domain.bo.TaskBo;
 import org.eco.als.service.IAlgorithmService;
-import org.eco.als.service.IFormulaService;
 import org.eco.common.core.core.domain.CommonResult;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
@@ -29,8 +28,7 @@ import java.util.List;
 public class AlgorithmController {
     @Resource
     private IAlgorithmService algorithmService;
-    @Resource
-    private IFormulaService formulaService;
+
 
     /**
      * 执行预处理
@@ -52,9 +50,9 @@ public class AlgorithmController {
      * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
      **/
     @PostMapping("/execute/falseAlarm")
-    public CommonResult<String> executeFalseAlarm(@Validated @RequestBody AlgorithmBo algorithmBo) {
-        String result = algorithmService.executeFalseAlarm(algorithmBo);
-        return StrUtil.isBlank(result) ? CommonResult.fail() : CommonResult.success(result, "");
+    public CommonResult<Void> executeFalseAlarm(@Validated @RequestBody AlgorithmBo algorithmBo) {
+        algorithmService.executeFalseAlarm(algorithmBo);
+        return CommonResult.success();
     }
 
     /**
@@ -147,7 +145,7 @@ public class AlgorithmController {
     @PostMapping("/execute/express")
     public CommonResult<Object> executeExpress(@RequestBody ExpressBo expressBo) throws Exception {
         // 执行表达式求值
-        Object result = formulaService.evaluateExpression(expressBo);
-        return CommonResult.success(result);
+//        Object result = formulaService.evaluateExpression(expressBo);
+        return CommonResult.success();
     }
 }

+ 1 - 1
als-modules/agile-assurance/src/main/java/org/eco/als/service/IAlgorithmService.java

@@ -15,7 +15,7 @@ import java.util.List;
 public interface IAlgorithmService {
     String executePro(AlgorithmBo algorithmBo);
 
-    String executeFalseAlarm(AlgorithmBo algorithmBo);
+    void executeFalseAlarm(AlgorithmBo algorithmBo);
 
     void executeFault(AlgorithmBo algorithmBo);
     String executeEvaluation(AlgorithmBo algorithmBo);

+ 1 - 1
als-modules/agile-assurance/src/main/java/org/eco/als/service/IFormulaService.java

@@ -6,5 +6,5 @@ import org.eco.als.domain.bo.ExpressBo;
  * @author wanggaokun
  */
 public interface IFormulaService {
-    Object evaluateExpression(ExpressBo expressBo) throws Exception;
+    int evaluateExpression(ExpressBo expressBo);
 }

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

@@ -9,11 +9,11 @@ import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
-import org.eco.als.domain.*;
+import org.eco.als.domain.FaultDiagnosis;
+import org.eco.als.domain.LifePrediction;
+import org.eco.als.domain.PreProcessing;
 import org.eco.als.domain.bo.*;
-import org.eco.als.domain.vo.AirConfigurationVo;
-import org.eco.als.domain.vo.ModelHttpVo;
-import org.eco.als.domain.vo.ModelVo;
+import org.eco.als.domain.vo.*;
 import org.eco.als.service.*;
 import org.eco.als.utils.CsvUtils;
 import org.eco.common.core.config.EcoConfig;
@@ -51,9 +51,6 @@ public class AlgorithmService implements IAlgorithmService {
     @Resource
     private IWarningService warningService;
 
-    @Resource
-    private IFalseAlarmService falseAlarmService;
-
     @Resource
     private IFalseAlarmResultService falseAlarmResultService;
 
@@ -70,6 +67,11 @@ public class AlgorithmService implements IAlgorithmService {
     private ITaskService taskService;
     @Resource
     private IQaHistoryService qaHistoryService;
+    @Resource
+    private IJudgeFaultLogicService judgeFaultLogicService;
+
+    @Resource
+    private IFormulaService formulaService;
 
     @Value("${kgqa.ask-url}")
     private String askUrl;
@@ -140,66 +142,24 @@ public class AlgorithmService implements IAlgorithmService {
      * executeFalseAlarm 虚警抑制
      *
      * @param algorithmBo 参数
-     * @return java.lang.String
      **/
     @Override
     @Transactional
-    public String executeFalseAlarm(AlgorithmBo algorithmBo) {
-        // 虚警抑制校验警告列表
-        if (ObjectUtil.isNull(algorithmBo.getWarningIds())) {
-            throw new BusinessException("警告信息不能为空,请检查!");
-        }
-        // 模型相关信息
-        ModelBo modelBo = new ModelBo();
-        modelBo.setPartId(algorithmBo.getPartId());
-        modelBo.setType("4");
-        List<ModelVo> list = modelService.selectList(modelBo);
-        ModelVo modelVo = list.getFirst();
-        if (ObjectUtil.isNull(modelVo)) {
-            throw new BusinessException("模型信息为空,请检查!");
-        }
-        SysOssVo sysOssVo = getSysOssVo(algorithmBo);
-        if (sysOssVo == null) {
-            return null;
-        }
-        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();
-        FalseAlarm falseAlarm = falseAlarmService.insert(falseAlarmBo);
-
+    public void executeFalseAlarm(AlgorithmBo algorithmBo) {
+        WarningBo warningBo = new WarningBo();
+        warningBo.setSortieNo(algorithmBo.getSortieNo());
         // 警告列表
-        List<Warning> warnings = warningService.listByIds(Arrays.asList(algorithmBo.getWarningIds()));
-        Warning warning = warnings.getFirst();
-        warnings.forEach(el -> {
-        });
-        // 参数
-        Map<String, Object> map = StrUtil.isBlank(algorithmBo.getParam()) ? new HashMap<>() : new HashMap<>(JSONUtil.parseObj(algorithmBo.getParam()));
-        map.put("url", sysOssVo.getUrl());
-        map.put("faultCode", warning.getCode());
-        // 请求
-        ModelHttpVo httpVo = sendHttp(modelVo, map);
-        if (httpVo != null && httpVo.getStatus() == 200) {
-            falseAlarmBo.setStatus("1");
-            falseAlarmBo.setId(falseAlarm.getId());
-            falseAlarmBo.setVersion(falseAlarm.getVersion());
-            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())
+        List<WarningVo> warningList = warningService.selectList(warningBo);
+        warningList.forEach(el -> {
+            JudgeFaultLogicVo logicVo = judgeFaultLogicService.selectByHmc(el.getCode());
+            ExpressBo expressBo = new ExpressBo();
+            expressBo.setExpression(logicVo.getRemarks());
+            expressBo.setOssId(algorithmBo.getOssId());
+            int result = formulaService.evaluateExpression(expressBo);
+            FalseAlarmResultBo falseAlarmResultBo = FalseAlarmResultBo.builder().code(el.getCode()).name(el.getName()).aircraftId(el.getAircraftId()).sortieNo(el.getSortieNo()).status(String.valueOf(result))
                 .build();
             falseAlarmResultService.insert(falseAlarmResultBo);
-        }
-        return httpVo != null ? httpVo.getData() : null;
+        });
     }
 
     /**
@@ -274,6 +234,9 @@ public class AlgorithmService implements IAlgorithmService {
             throw new BusinessException("模型信息为空,请检查!");
         }
         ModelVo modelVo = list.getFirst();
+
+//        List<SysOssVo> list = ossService.listSysOssByIds(Arrays.asList(algorithmBo.getOssIds()));
+
         List<String> urls = new ArrayList<>();
         for (Long ossId : algorithmBo.getOssIds()) {
             SysOssVo sysOss = ossService.getById(ossId);
@@ -331,24 +294,6 @@ public class AlgorithmService implements IAlgorithmService {
 
     @Override
     public String batchExecute(TaskBo taskBo) {
-        // 数据编号
-        Long dataId;
-        // 预处理编号
-        Long preId;
-        // 虚警编号
-        Long falseAlarmId;
-        // 故障诊断编号
-        Long faultId;
-        // 决策编号
-        Long decisionId;
-        List<AlgorithmBo> algorithmList = taskBo.getAlgorithmList();
-        // 批量执行
-        algorithmList.forEach(el -> {
-            executePro(el);
-            executeFalseAlarm(el);
-            executeFault(el);
-        });
-        taskService.insert(taskBo);
         return null;
     }
 

+ 33 - 15
als-modules/agile-assurance/src/main/java/org/eco/als/service/impl/FormulaService.java

@@ -6,17 +6,22 @@ import cn.hutool.json.JSONObject;
 import com.ql.util.express.DefaultContext;
 import com.ql.util.express.ExpressRunner;
 import com.ql.util.express.InstructionSet;
-import com.ql.util.express.exception.QLBizException;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
 import org.eco.als.domain.bo.ExpressBo;
-import org.eco.als.service.IAlgorithmService;
 import org.eco.als.service.IFormulaService;
 import org.eco.als.utils.CheckVibrationDuration;
+import org.eco.als.utils.CsvUtils;
+import org.eco.common.core.constant.Constants;
 import org.eco.common.core.exception.BusinessException;
+import org.eco.common.core.utils.StringUtils;
+import org.eco.system.domain.vo.SysOssVo;
+import org.eco.system.service.ISysOssService;
 import org.springframework.stereotype.Service;
 
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -26,22 +31,34 @@ import java.util.Map;
 @Slf4j
 public class FormulaService implements IFormulaService {
     @Resource
-    private IAlgorithmService algorithmService;
+    private ISysOssService ossService;
     private ExpressRunner runner;
 
     @Override
-    public Object evaluateExpression(ExpressBo expressBo) throws Exception {
-        runner = new ExpressRunner();
-        runner.addOperatorWithAlias("≠", "!=", null);
-        runner.addOperatorWithAlias("≥", ">=", null);
-        runner.addOperatorWithAlias("≤", "<=", null);
-        // // 注册自定义(持续时间计算)函数到QLExpress上下文
-        runner.addFunction("checkVibrationDuration", new CheckVibrationDuration());
-        runner.setShortCircuit(true);
-        Object result = null;
+    public int evaluateExpression(ExpressBo expressBo) {
+        // 虚警
+        int result = 0;
         try {
+            CsvUtils.getCsvHeaders("");
+            runner = new ExpressRunner();
+            runner.addOperatorWithAlias("≠", "!=", null);
+            runner.addOperatorWithAlias("≥", ">=", null);
+            runner.addOperatorWithAlias("≤", "<=", null);
+            // // 注册自定义(持续时间计算)函数到QLExpress上下文
+            runner.addFunction("checkVibrationDuration", new CheckVibrationDuration());
+            runner.setShortCircuit(true);
             runner.parseInstructionSet(expressBo.getExpression());
-            JSONArray arr = algorithmService.getArrayByOssId(expressBo.getOssId());
+            SysOssVo ossVo = ossService.getById(expressBo.getOssId());
+            String path = StringUtils.substringAfter(ossVo.getFileName(), Constants.RESOURCE_PREFIX);
+
+            // 参数列名称
+            List<String> headers = CsvUtils.getCsvHeaders(path);
+            String[] variableNames = parseVariableNames(expressBo.getExpression());
+            if (CollUtil.containsAll(Arrays.asList(variableNames), headers)) {
+                return 2;
+            }
+
+            JSONArray arr = CsvUtils.fileCsvToJsonRegex(path);
             for (Object object : arr) {
                 DefaultContext<String, Object> context = new DefaultContext<>();
                 Map<String, Object> variables = CollUtil.isEmpty(expressBo.getVariables()) ? buildVariableContext(expressBo, (JSONObject) object) : expressBo.getVariables();
@@ -49,11 +66,12 @@ public class FormulaService implements IFormulaService {
                 Boolean isMatch = (Boolean) runner.execute(expressBo.getExpression(), context, null, true, false);
                 log.info("isMatch==========================:{}", isMatch);
                 if (isMatch) {
-                    result = object;
+                    // 实警
+                    result = 1;
                     break;
                 }
             }
-        } catch (QLBizException e) {
+        } catch (Exception e) {
             throw new BusinessException(e.getMessage());
         }
         return result;