Pārlūkot izejas kodu

按照3小时统计

yq 3 gadi atpakaļ
vecāks
revīzija
d7bdace4e4

+ 1 - 1
mhfire-mapping/src/main/resources/mapper/mysql/DeviceMapper.xml

@@ -65,7 +65,7 @@
     </select>
     <select id="selectCollectOne" resultType="com.bizmatics.mhfire.persistence.mapper.vo.DeviceCollectVO">
         select
-
+        count(d.id) as deviceCount,
         ROUND(COUNT(CASE WHEN aj.aj_flag=3 THEN aj.aj_flag END)/COUNT(aj.id),2)
         as checkRate
 

+ 24 - 2
mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/JcjAjxxServiceImpl.java

@@ -23,10 +23,12 @@ import com.bizmatics.mhfire.service.util.Arith;
 import com.bizmatics.mhfire.service.util.GouldUtil;
 import com.bizmatics.mhfire.service.vo.AlertMapVO;
 import com.bizmatics.mhfire.service.vo.AlertStatisticsVO;
+import com.google.common.collect.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 /**
@@ -60,11 +62,31 @@ public class JcjAjxxServiceImpl extends AbstractCrudService<JcjAjxxMapper, JcjAj
         Map<String, List<AlertStatisticsVO>> typeMap = enhanceList(this.listMaps(queryWrapper));
         Date maxDate = getMaxDate();
         Date minDate = getMinDate();
-        int distanceOfTwoDate = DateUtils.getDistanceOfTwoDateNew(minDate, maxDate);
-        perfect(typeMap,24,distanceOfTwoDate,0);
+        AtomicInteger distanceOfTwoDate = new AtomicInteger(1);
+        Optional.ofNullable(maxDate)
+                .ifPresent(md -> distanceOfTwoDate.set(DateUtils.getDistanceOfTwoDateNew(minDate, maxDate)));
+        perfect(typeMap,24, distanceOfTwoDate.get(),0);
+        collectByThree(typeMap,distanceOfTwoDate.get());
         return typeMap;
     }
 
+    public void collectByThree(Map<String, List<AlertStatisticsVO>> map,Integer distanceOfTwoDate){
+        for (String type:map.keySet()) {
+            List<AlertStatisticsVO> list = map.get(type);
+            List<List<AlertStatisticsVO>> partition = Lists.partition(list, 3);
+            List<AlertStatisticsVO> thList = new ArrayList<>();
+            for (List<AlertStatisticsVO> threeList:partition) {
+                double sum = threeList.stream().mapToDouble(AlertStatisticsVO::getNumber).sum();
+                AlertStatisticsVO alertStatisticsVO = new AlertStatisticsVO();
+                alertStatisticsVO.setType(type);
+                alertStatisticsVO.setMonth(String.valueOf(partition.indexOf(threeList)));
+                alertStatisticsVO.setAvg(Arith.div(sum, distanceOfTwoDate));
+                thList.add(alertStatisticsVO);
+            }
+            map.put(type,thList);
+        }
+    }
+
 
     public Date getMaxDate(){
         IPage<JcjAjxx> page = new Page<>(1, 1);