From 36844dfeea0914de1138be9ebdf27c92d745d73a Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Thu, 07 Mar 2024 15:58:54 +0800
Subject: [PATCH] fix:断线统计补充提交

---
 screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 55 insertions(+), 4 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
index 2d779fd..8763d27 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
@@ -350,7 +350,7 @@
             Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_HH_mm_ss_EN);
             Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_HH_mm_ss_EN);
             List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(startDate, endDate, SeparateTableType.MONTH);
-            for (String mac:macs) {
+/*            for (String mac:macs) {
                 Map<String, Object> mapParams = new HashMap<>();
                 mapParams.put("startDate",startDate);
                 mapParams.put("endDate",endDate);
@@ -384,6 +384,56 @@
                     historyHourlyMap.put("time",timeStr);
                     list.add(historyHourlyMap);
                 }
+            }*/
+
+
+            for (String mac:macs) {
+                Map<String, Object> mapParams = new HashMap<>();
+                mapParams.put("startDate",startDate);
+                mapParams.put("endDate",endDate);
+                mapParams.put("mac",mac);
+                List<HistoryFiveMinutely> HistoryFiveMinutelys = FiveMinuteTableQuery(mapParams, tableNames);
+                HistoryFiveMinutelys = HistoryFiveMinutelys.stream().distinct().collect(Collectors.toList());
+                List<HistoryFiveMinutely> distinctHistoryHourlies = new ArrayList<>();
+                Map<String, Object> disMap = new HashMap<>();
+                for (HistoryFiveMinutely historyFiveMinutely:HistoryFiveMinutelys) {
+                    Date time = historyFiveMinutely.getTime();
+                    String timeStr = DateUtils.dateToDateString(time,DateUtils.yyyy_MM_dd_HH_mm_EN);
+                    if (!disMap.containsKey(timeStr)){
+                        distinctHistoryHourlies.add(historyFiveMinutely);
+                        disMap.put(timeStr,true);
+                    }
+                }
+                for (HistoryFiveMinutely historyFiveMinutely:distinctHistoryHourlies) {
+                    Map<String,Object> historyHourlyMap = new HashMap<>();
+                    historyHourlyMap.put("mac",mac);
+                    JSONObject  value= JSONObject.parseObject(historyFiveMinutely.getValue());
+                    Double sensorValue = Objects.nonNull(value)&&Objects.nonNull(value.get(sensorCode))?Double.parseDouble(value.get(sensorCode).toString()):0d;
+                    historyHourlyMap.put(sensorCode,sensorValue);
+                    Date time = historyFiveMinutely.getTime();
+                    String timeStr = DateUtils.dateToDateString(time, DateUtils.yyyy_MM_dd_HH_mm_EN);
+                    historyHourlyMap.put("time",timeStr);
+                    list.add(historyHourlyMap);
+                }
+            }
+            Date middleDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_HH_mm_EN);
+            while (DateUtils.compareDateStr(endTime,DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_HH_mm_EN),DateUtils.yyyy_MM_dd_HH_mm_EN)<=0){
+                for (String mac:macs) {
+                    boolean flag = true;
+                    for (Map map:list) {
+                        if (map.get("time").equals(DateUtils.dateToDateString(middleDate, DateUtils.yyyy_MM_dd_HH_mm_EN)) && map.get("mac").toString().equals(mac.toString())){
+                            flag = false;
+                        }
+                    }
+                    if (flag){
+                        Map<String,Object> historyHourlyMap = new HashMap<>();
+                        historyHourlyMap.put("mac",mac);
+                        historyHourlyMap.put(sensorCode,"0.0");
+                        historyHourlyMap.put("time",DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_dd_HH_mm_EN));
+                        list.add(historyHourlyMap);
+                    }
+                }
+                middleDate = DateUtils.getDateOfMin(middleDate,5);
             }
         }
         for (Map map:list) {
@@ -558,7 +608,8 @@
         long hour = (diff / nh)+1; //������������������������
 
         Map<String, List<OnlineRateVo>> collectList=new HashMap<>();
-        List<OnlineRateVo> OnlineRateVoList = deviceMapper.getLists(onlineRatePageCond.getOrganizationId(),onlineRatePageCond.getState());
+//        List<OnlineRateVo> OnlineRateVoList = deviceMapper.getLists(onlineRatePageCond.getOrganizationId(),onlineRatePageCond.getState());
+        List<OnlineRateVo> OnlineRateVoList = deviceMapper.getLists(onlineRatePageCond.getMacs(),onlineRatePageCond.getState());
         if (!ObjectUtils.isEmpty(OnlineRateVoList)){
 
             for (OnlineRateVo onlineRateVo : OnlineRateVoList) {
@@ -972,9 +1023,9 @@
     }
 
     @Override
-    public Map<String,Object> getStart(Integer organizationId) {
+    public Map<String,Object> getStart(List<String> macs) {
         HashMap<String, Object> map = new HashMap<>();
-        List<OnlineRateVo> lists = deviceMapper.getLists(organizationId, null);
+        List<OnlineRateVo> lists = deviceMapper.getLists(macs, null);
         if (!ObjectUtils.isEmpty(lists)){
             Map<String, List<OnlineRateVo>> collect = lists.stream().collect(Collectors.groupingBy(OnlineRateVo::getState));
             int size1 = lists.size();

--
Gitblit v1.8.0