Переглянути джерело

设备运行诊断计算程序,只获取设备运行诊断的报警规则

lixing 3 роки тому
батько
коміт
2bc1058c63

+ 15 - 12
src/main/java/com/persagy/apm/diagnose/indicatorrecord/service/impl/MonitorIndicatorRecordServiceImpl.java

@@ -1,7 +1,6 @@
 package com.persagy.apm.diagnose.indicatorrecord.service.impl;
 
 import cn.hutool.json.JSONUtil;
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.persagy.apm.diagnose.config.ComputePropertiesConfig;
@@ -23,7 +22,6 @@ import com.persagy.apm.diagnose.service.dto.TimeDataDTO;
 import com.persagy.apm.diagnose.timerecord.model.CalculateTimeRecord;
 import com.persagy.apm.diagnose.timerecord.service.ICalculateTimeRecordService;
 import com.persagy.apm.diagnose.utils.*;
-import com.persagy.apm.energyalarmstarter.alarmdata.service.AlarmConfigServiceImpl;
 import com.persagy.framework.ems.data.core.enumeration.EMSOrder;
 import com.persagy.framework.ems.data.core.enumeration.SpecialOperator;
 import com.persagy.framework.ems.data.mvc.dao.CoreDao;
@@ -60,10 +58,6 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
     @Autowired
     private ICalculateTimeRecordService calculateTimeRecordService;
 
-
-    @Autowired
-    private AlarmConfigServiceImpl alarmConfigService;
-
     @Autowired
     private RedisUtil redisUtil;
 
@@ -73,7 +67,6 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
     @Autowired
     private ComputePropertiesConfig computePropertiesConfig;
 
-
     @Autowired
     private CenterDataService centerDataService;
 
@@ -148,7 +141,13 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
             }
         }
         //通过报警服务查询报警规则
-        List<AlarmRuleDTO> projectAlarmRules = energyAlarmService.getProjectAlarmRules(projectDTO.getProjectId());
+        // 查询设备运行诊断的报警类型
+        List<String> eqdxAlarmItemCodeList = energyAlarmService.queryEqdxAlarmItemCodes();
+
+        if (CollectionUtils.isEmpty(eqdxAlarmItemCodeList)) {
+            return new AsyncResult<>("【监测指标数据计算线程】未查询到设备运行诊断的报警类型");
+        }
+        List<AlarmRuleDTO> projectAlarmRules = energyAlarmService.getProjectAlarmRules(projectDTO.getProjectId(), eqdxAlarmItemCodeList);
         if (CollectionUtils.isEmpty(projectAlarmRules)) {
             return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "未设置报警规则");
         }
@@ -180,6 +179,10 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
             }
             Date computeEndTime = DateUtils.addDays(lastComputeTime, computePropertiesConfig.getRoundDays());
             String formula = calculateMethodDTO.getFormula();
+            if (StringUtils.isBlank(formula)) {
+                log.error("【监测指标数据计算线程】:项目监控指标设置公式为null:" + projectDTO.getProjectId() + ";" + objId + ";" + indicatorId);
+                continue;
+            }
             Date computeTime = computeIndicatorData(projectDTO, objId, lastComputeTime, computeEndTime, indicatorId, formula);
             saveOrUpdateComputeTime(projectDTO.getProjectId(), objId, indicatorId, computeTime);
         }
@@ -526,10 +529,10 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
      */
     private ConfigItemDataSendTimeDTO getConfigItemSendTimeDTO(ProjectDTO projectDTO, String objIdAndAlarmItemCode) throws Exception {
         ConfigItemDataSendTimeDTO sendTimeDTO = null;
-        Object obj = redisUtil.get(getRedisSendDataKey(projectDTO.getProjectId(),objIdAndAlarmItemCode));
-        if (null != obj){
-            sendTimeDTO =  JSONUtil.toBean(obj.toString(), ConfigItemDataSendTimeDTO.class);
-        }else{
+        Object obj = redisUtil.get(getRedisSendDataKey(projectDTO.getProjectId(), objIdAndAlarmItemCode));
+        if (null != obj) {
+            sendTimeDTO = JSONUtil.toBean(obj.toString(), ConfigItemDataSendTimeDTO.class);
+        } else {
             sendTimeDTO = ConfigItemDataSendTimeDTO.builder().lastSendTime(getDefultStartTime()).build();
         }
         return sendTimeDTO;

+ 27 - 1
src/main/java/com/persagy/apm/diagnose/service/EnergyAlarmServiceImpl.java

@@ -2,18 +2,24 @@ package com.persagy.apm.diagnose.service;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.mysql.cj.xdevapi.JsonArray;
 import com.persagy.apm.common.model.vo.SimpleObjVO;
 import com.persagy.apm.diagnose.feign.AlarmResult;
 import com.persagy.apm.diagnose.feign.client.AlarmServiceClient;
 import com.persagy.apm.diagnose.indicatorrecord.service.impl.MonitorIndicatorRecordServiceImpl;
+import com.persagy.apm.diagnose.maintenance.constant.EnumAlarmCategory;
 import com.persagy.apm.diagnose.maintenance.model.dto.AlarmCondition;
 import com.persagy.apm.diagnose.maintenance.model.dto.AlarmProjectDTO;
 import com.persagy.apm.diagnose.maintenance.model.dto.QueryAlarmProjectDTO;
 import com.persagy.apm.diagnose.service.dto.*;
 import com.persagy.apm.diagnose.service.vo.MonitorIndicatorConfigVO;
 import com.persagy.apm.diagnose.utils.AlarmResultUtil;
+import com.persagy.apm.diagnose.utils.DmpResultUtil;
 import com.persagy.apm.diagnose.utils.RedisUtil;
+import com.persagy.apm.energyalarmstarter.alarmdata.feign.DmpResult;
+import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmitem.QueryAlarmItemDTO;
+import com.persagy.apm.energyalarmstarter.alarmdata.model.vo.AlarmItem;
+import com.persagy.apm.energyalarmstarter.alarmdata.service.AlarmItemServiceImpl;
+import org.assertj.core.util.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -39,6 +45,8 @@ public class EnergyAlarmServiceImpl {
     AlarmServiceClient alarmServiceClient;
     @Autowired
     RedisUtil redisUtil;
+    @Autowired
+    private AlarmItemServiceImpl alarmItemService;
 
     /**
      * @throws
@@ -193,6 +201,24 @@ public class EnergyAlarmServiceImpl {
         return allAlarmRuleDTOList;
     }
 
+    /**
+     * 获取设备运行诊断下所有报警类型编码
+     *
+     * @return 设备运行诊断下所有报警类型编码
+     * @author lixing
+     * @version V1.0 2021/12/16 3:25 下午
+     */
+    public List<String> queryEqdxAlarmItemCodes() throws Exception {
+        QueryAlarmItemDTO queryAlarmItemDTO = new QueryAlarmItemDTO();
+        queryAlarmItemDTO.setCategory(Lists.newArrayList(EnumAlarmCategory.EQDX.getCode()));
+        DmpResult<List<AlarmItem>> queryResult = alarmItemService.query(queryAlarmItemDTO);
+        List<AlarmItem> eqdxAlarmItems = DmpResultUtil.getData(queryResult);
+        if (CollectionUtils.isEmpty(eqdxAlarmItems)) {
+            return null;
+        }
+        return eqdxAlarmItems.stream().map(AlarmItem::getCode).collect(Collectors.toList());
+    }
+
     public List<AlarmCondition> getProjectAlarmCondition(String projectId,String objId,String itemCode)throws Exception{
         QueryAlarmConditionByObjDTO selDTO = new QueryAlarmConditionByObjDTO();
         selDTO.setObjId(objId);