Bläddra i källkod

修正eer计算逻辑

wangchenghong 3 år sedan
förälder
incheckning
df7bb9c7d0

+ 24 - 20
src/main/java/com/persagy/apm/energy/report/centermiddleware/service/impl/ICenterMiddlewareWebServiceImp.java

@@ -98,12 +98,16 @@ public class ICenterMiddlewareWebServiceImp implements ICenterMiddlewareWebServi
                     Double coolingCapacity = date_coolingCapacityMap.get(date);
                     Double powerConsumption = date_powerConsumptionMap.get(date);
                     Double eer = null;
-                    if (coolingCapacity != null && powerConsumption != null) {
+                    if (coolingCapacity != null && powerConsumption != null && powerConsumption != 0.0) {
                         eer = coolingCapacity / powerConsumption;
+                    }
+                    if (coolingCapacity != null) {
                         if (null == allCoolingCapacity) {
                             allCoolingCapacity = 0.0;
                         }
                         allCoolingCapacity = allCoolingCapacity + coolingCapacity;
+                    }
+                    if (powerConsumption != null) {
                         if (null == allPowerConsumption) {
                             allPowerConsumption = 0.0;
                         }
@@ -113,7 +117,7 @@ public class ICenterMiddlewareWebServiceImp implements ICenterMiddlewareWebServi
                     dateGraphItemVOList.add(dateGraphItemVO);
                 }
                 Double allEer = null;
-                if (allCoolingCapacity != null && allPowerConsumption != null) {
+                if (allCoolingCapacity != null && allPowerConsumption != null && allPowerConsumption != 0.0) {
                     allEer = allCoolingCapacity / allPowerConsumption;
                 }
                 projectEERDataVo.setProjectId(pjId);
@@ -153,18 +157,7 @@ public class ICenterMiddlewareWebServiceImp implements ICenterMiddlewareWebServi
     private TreeMap<Date, Double> getDayCountData(String pjId, String groupCode, Date reportDate, String infoCode, List<String> classCodeList, List<Date> dateList) {
         List<String> objectIdList = getObjectIdList(pjId, groupCode, classCodeList);
         if (!CollectionUtils.isEmpty(objectIdList)) {
-            TreeMap<Date, Double> date_dataMap = new TreeMap<>();
-            TreeMap<Date, Double> day_coolDataMap = getInfoCodePeriodDataCountMap(pjId, groupCode, objectIdList, reportDate, infoCode, "1d");
-            for (Date date : dateList) {
-                Double currentDayCoolData = day_coolDataMap.get(date);
-                Double nextDayCoolData = day_coolDataMap.get(DateUtils.getDayOff(date, 1));
-                if (currentDayCoolData != null && nextDayCoolData != null) {
-                    date_dataMap.put(date, nextDayCoolData - currentDayCoolData);
-                } else {
-                    date_dataMap.put(date, null);
-                }
-            }
-            return date_dataMap;
+            return getInfoCodePeriodDataCountMap(pjId, groupCode, objectIdList, reportDate, infoCode, "1d",dateList);
         }
         return new TreeMap<>();
     }
@@ -195,7 +188,7 @@ public class ICenterMiddlewareWebServiceImp implements ICenterMiddlewareWebServi
         return resultList;
     }
 
-    private TreeMap<Date, Double> getInfoCodePeriodDataCountMap(String pjId, String groupCode, List<String> objectIdList, Date reportDate, String infoCode, String period) {
+    private TreeMap<Date, Double> getInfoCodePeriodDataCountMap(String pjId, String groupCode, List<String> objectIdList, Date reportDate, String infoCode, String period, List<Date> dateList) {
         if (StringUtils.isEmpty(pjId) || StringUtils.isEmpty(groupCode) || CollectionUtils.isEmpty(objectIdList) || null == reportDate) {
             log.info("查询历史数据时参数为空,故不进行查询");
             return new TreeMap<>();
@@ -229,16 +222,27 @@ public class ICenterMiddlewareWebServiceImp implements ICenterMiddlewareWebServi
                     if (CollectionUtils.isEmpty(periodDataInfoVOList)) {
                         continue;
                     }
+                    // 每个设备每天的数据
+                    Map<Date, Double> day_coolDataMap = new TreeMap<>();
                     for (PeriodDataInfoVO vo : periodDataInfoVOList) {
                         if (null == vo.getData_value() || StringUtils.isEmpty(vo.getData_time())) {
                             continue;
                         }
-                        Double data = dataMap.get(DateUtils.str2Date(vo.getData_time(), DateUtils.SDFSECOND));
-                        if (null == data) {
-                            data = 0.0;
+                        day_coolDataMap.put(DateUtils.str2Date(vo.getData_time(), DateUtils.SDFSECOND), vo.getData_value());
+                    }
+                    for (Date date : dateList) {
+                        Double currentDayCoolData = day_coolDataMap.get(date);
+                        Double nextDayCoolData = day_coolDataMap.get(DateUtils.getDayOff(date, 1));
+                        Double allCool = dataMap.get(date);
+                        if (allCool == null) {
+                            allCool = 0.0;
+                        }
+                        Double cool = 0.0;
+                        if (currentDayCoolData != null && nextDayCoolData != null) {
+                            cool = nextDayCoolData - currentDayCoolData;
                         }
-                        data = data + vo.getData_value();
-                        dataMap.put(DateUtils.str2Date(vo.getData_time(), DateUtils.SDFSECOND), data);
+                        allCool = allCool + cool;
+                        dataMap.put(date, allCool);
                     }
                 }
             }