瀏覽代碼

处理数据质量无报警信息时的统计数

wangchenghong 3 年之前
父節點
當前提交
812b2d49e9

+ 1 - 0
src/main/java/com/persagy/apm/energy/report/common/service/impl/CommonServiceImpl.java

@@ -279,6 +279,7 @@ public class CommonServiceImpl implements CommonService {
         List<AlarmInfoVo> alarmInfoVoList = iDataAnalysisWebService.getAlarmInfoVo(groupCode, projectIdList, reportDate);
         Map<String, Integer> sortMap = new HashMap<>();
         sortMap.put("alarmCount", -1);
+        sortMap.put("projectId", 1);
         DataUtils.sort(alarmInfoVoList, sortMap);
         for (int i = 0; i < alarmInfoVoList.size(); i++) {
             AlarmInfoVo vo = alarmInfoVoList.get(i);

+ 9 - 11
src/main/java/com/persagy/apm/energy/report/iotdataanalysis/service/impl/IDataAnalysisWebServiceImpl.java

@@ -116,11 +116,11 @@ public class IDataAnalysisWebServiceImpl implements IDataAnalysisWebService {
             String url = iotDataAnalysisUrl + "/alarm/alarmList";
             String response = HttpUtils.postJson(url, paramObject.toString());
             JSONObject responseObject = JSONObject.parseObject(response);
+            Map<String, Integer> pjId_alarmCountMap = new HashMap<>();
+            Map<String, Double> pjId_alarmDurationMap = new HashMap<>();
             if (DataConstants.SUCCESS.equals(responseObject.getString("respMsg"))) {
                 List<Map> content = (List<Map>) responseObject.get("content");
                 if (CollectionUtils.isNotEmpty(content)) {
-                    Map<String, Integer> pjId_alarmCountMap = new HashMap<>();
-                    Map<String, Double> pjId_alarmDurationMap = new HashMap<>();
                     for (Map map : content) {
                         String pjId = (String) map.get("projectId");
                         Long alarmBeginTime = (Long) map.get("alarmStartTime");
@@ -145,17 +145,15 @@ public class IDataAnalysisWebServiceImpl implements IDataAnalysisWebService {
                         alarmDuration = alarmDuration + duration;
                         pjId_alarmDurationMap.put(pjId, alarmDuration);
                     }
-                    if (pjId_alarmCountMap.size() != 0) {
-                        for (Map.Entry<String, Integer> entry : pjId_alarmCountMap.entrySet()) {
-                            AlarmInfoVo alarmInfoVo = new AlarmInfoVo();
-                            alarmInfoVo.setProjectId(entry.getKey());
-                            alarmInfoVo.setAlarmCount(entry.getValue());
-                            alarmInfoVo.setTotalDuration(pjId_alarmDurationMap.get(entry.getKey()));
-                            resultList.add(alarmInfoVo);
-                        }
-                    }
                 }
             }
+            for (String projectId : projectIdList) {
+                AlarmInfoVo alarmInfoVo = new AlarmInfoVo();
+                alarmInfoVo.setProjectId(projectId);
+                alarmInfoVo.setAlarmCount(pjId_alarmCountMap.get(projectId) == null ? 0 : pjId_alarmCountMap.get(projectId));
+                alarmInfoVo.setTotalDuration(pjId_alarmDurationMap.get(projectId) == null ? 0.0 : pjId_alarmDurationMap.get(projectId));
+                resultList.add(alarmInfoVo);
+            }
         } catch (Exception e) {
             log.error("获取数据质量报警数据异常:", e);
         }