yq 3 rokov pred
rodič
commit
540e6e685d

+ 23 - 11
mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/AlertServiceImpl.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.bizmatics.common.core.bean.CommonPage;
+import com.bizmatics.common.core.util.DateUtils;
 import com.bizmatics.common.core.util.StringUtils;
 import com.bizmatics.common.mvc.base.AbstractCrudService;
 import com.bizmatics.mhfire.model.Alert;
@@ -29,28 +30,38 @@ public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> im
     @Override
     public Map<String, List<AlertStatisticsVO>> getAlertStatisticsByHouse(Date startTime,Date endTime) {
         Map<String, List<AlertStatisticsVO>> typeMap = enhanceList(baseMapper.getCountByHorse(startTime, endTime));
-        perfect(typeMap,24);
+        int distanceOfTwoDate = DateUtils.getDistanceOfTwoDateNew(startTime, endTime);
+        perfect(typeMap,24,distanceOfTwoDate);
         return typeMap;
     }
 
-    public void perfect(Map<String, List<AlertStatisticsVO>> typeMap,Integer times){
+    public void perfect(Map<String, List<AlertStatisticsVO>> typeMap,Integer times,Integer subTime){
         for (String type:ALERT_TYPE) {
             if (!typeMap.containsKey(type)){
                 typeMap.put(type,new ArrayList<>());
             }
-            perfectDate(typeMap.get(type), times);
+            perfectDate(typeMap.get(type), times,subTime);
         }
     }
 
-    public void perfectDate(List<AlertStatisticsVO> list,Integer times){
+    public void perfectDate(List<AlertStatisticsVO> list,Integer times,Integer subTime){
         for (int i = 1; i <= times; i++) {
             int finalI = i;
-            if (list.stream().noneMatch(asv->Integer.parseInt(asv.getMonth()) == finalI)){
-                AlertStatisticsVO asv = new AlertStatisticsVO();
-                asv.setMonth(Integer.toString(i));
-                asv.setNumber(0);
-                list.add(asv);
-            }
+            AlertStatisticsVO alertStatisticsVO = list.stream()
+                    .filter(asv -> Integer.parseInt(asv.getMonth()) == finalI)
+                    .findFirst()
+                    .map(asv -> {
+                        asv.setAvg(Arith.div(asv.getNumber(), subTime));
+                        return asv;
+                    })
+                    .orElseGet(() -> {
+                        AlertStatisticsVO asv = new AlertStatisticsVO();
+                        asv.setMonth(Integer.toString(finalI));
+                        asv.setNumber(0);
+                        asv.setAvg(0.00);
+                        return asv;
+                    });
+            list.add(alertStatisticsVO);
         }
         list.sort(Comparator.comparingInt(x -> Integer.parseInt(x.getMonth())));
     }
@@ -74,7 +85,8 @@ public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> im
     @Override
     public Map<String, List<AlertStatisticsVO>> getAlertStatisticsByMonth(Date startTime,Date endTime) {
         Map<String, List<AlertStatisticsVO>> typeMap = enhanceList(baseMapper.getCountByMonth(startTime, endTime));
-        perfect(typeMap,12);
+        int distanceOfTwoDate =Integer.parseInt(DateUtils.getYear(endTime)) - Integer.parseInt(DateUtils.getYear(startTime)) + 1;
+        perfect(typeMap,12,distanceOfTwoDate);
         return typeMap;
     }
 

+ 5 - 0
mhfire-service/src/main/java/com/bizmatics/mhfire/service/vo/AlertStatisticsVO.java

@@ -29,4 +29,9 @@ public class AlertStatisticsVO {
      * 占比
      */
     private Double radio;
+
+    /**
+     * 平均值
+     */
+    private Double avg;
 }