From 90acff60761ed769014b34c5cea4c8300ac8f802 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Wed, 05 Jul 2023 14:38:32 +0800
Subject: [PATCH] 监测站点显示修改

---
 screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java |  163 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 128 insertions(+), 35 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
index 543886e..b710fdc 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
@@ -3,6 +3,7 @@
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.moral.api.entity.*;
+import com.moral.api.mapper.DeviceMapper;
 import com.moral.api.mapper.HistoryMonthlyMapper;
 import com.moral.api.pojo.dto.dataDisplay.MonitorPointDataDisplayDTO;
 import com.moral.api.pojo.dto.dataDisplay.SensorComparisonDisplayDTO;
@@ -17,6 +18,8 @@
 import org.springframework.util.ObjectUtils;
 
 import java.util.*;
+
+import static com.moral.util.DateUtils.dateToDateString;
 
 /**
  * @ClassName DataDisplayServiceImpl
@@ -41,19 +44,27 @@
     @Autowired
     HistoryMonthlyService historyMonthlyService;
 
+    @Autowired
+    DeviceMapper deviceMapper;
+
     @Override
     public List<MonitorPointDataDisplayDTO> getMonitorPointDisplayData(MonitorPointDataDisplayForm form) {
         //������
-        Integer monitorPointId = form.getMonitorPointId();
+//        Integer monitorPointId = form.getMacs();
+        List<String> macs = form.getMacs();
         String reportType = form.getReportType();
         Date startTime = form.getStartTime();
         Date endTime = form.getEndTime();
         //������������id������������������������������
-        List<Device> devices = deviceService.getDevicesByMonitorPointId(monitorPointId);
+//        List<Device> devices = deviceService.getDevicesByMonitorPointId(monitorPointId);
+        QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
+        deviceQueryWrapper.eq("is_delete",Constants.NOT_DELETE);
+        deviceQueryWrapper.in("mac", macs);
+        List<Device> devices = deviceMapper.selectList(deviceQueryWrapper);
         Map<String, Device> deviceMap = new HashMap<>();
-        List<String> macs = new ArrayList<>();
+//        List<String> ListMacs = new ArrayList<>();
         devices.forEach(value -> {
-            macs.add(value.getMac());
+//            ListMacs.add(value.getMac());
             deviceMap.put(value.getMac(), value);
         });
         List<MonitorPointDataDisplayDTO> dtos = new ArrayList<>();
@@ -73,20 +84,26 @@
         }
         //���������������������������������������������������������
         else if (reportType.equals(Constants.HOURLY_REPORT)) {
-            Map<String, HistoryHourly> macDataMap = new HashMap<>();
+            Map<String, List<HistoryHourly>> macDataMap = new HashMap<>();
             //������������
             macs.forEach(value -> {
-                List<HistoryHourly> datas = historyHourlyService.getValueByMacAndTime(value, startTime, startTime);
+                List<HistoryHourly> datas = historyHourlyService.getValueByMacAndTime(value, startTime, endTime);
                 if (datas.size() != 0)
-                    macDataMap.put(value, datas.get(0));
+                    macDataMap.put(value,datas);
             });
             if (macDataMap.size() != 0)
                 dtos = calculateReportData(macDataMap, deviceMap, reportType, startTime);
         }
         //���������������������������������������������
         else if (reportType.equals(Constants.DAILY_REPORT)) {
+            Map<String, List<HistoryDaily>> macDataMap = new HashMap<>();
             //������������
-            Map<String, HistoryDaily> macDataMap = historyDailyService.getHistoryDailyByMacsAndDate(macs, startTime);
+            macs.forEach(value -> {
+                List<HistoryDaily> datas = historyDailyService.getHistoryDailyByMacAndTimeSlot(value, startTime, endTime);
+                if (datas.size() != 0)
+                    macDataMap.put(value,datas);
+            });
+
             if (macDataMap.size() != 0)
                 dtos = calculateReportData(macDataMap, deviceMap, reportType, startTime);
         }
@@ -101,7 +118,15 @@
         else if (reportType.equals(Constants.MONTHLY_REPORT)) {
             //������������������������������������������������������������������������������������������������
             Map<String, List<HistoryDaily>> macDataDailyMap = new HashMap<>();
-            Map<String, HistoryMonthly> macDataMonthlyMap = historyMonthlyService.getHistoryMonthlyByMacsAndDate(macs, startTime);
+            Map<String, List<HistoryMonthly>> macDataMonthlyMap = new HashMap<>();
+            macs.forEach(mac -> {
+                QueryWrapper<HistoryMonthly> wrapper = new QueryWrapper<>();
+                wrapper.eq("mac",mac);
+                wrapper.between("time",startTime,endTime);
+                List<HistoryMonthly> monthlyList = historyMonthlyMapper.selectList(wrapper);
+                if (!ObjectUtils.isEmpty(monthlyList))
+                    macDataMonthlyMap.put(mac, monthlyList);
+            });
             macs.forEach(mac -> {
                 List<HistoryDaily> dailyDatas = historyDailyService.getHistoryDailyByMacAndTimeSlot(mac, startTime, endTime);
                 if (!ObjectUtils.isEmpty(dailyDatas))
@@ -533,35 +558,103 @@
      */
     private <T> List<MonitorPointDataDisplayDTO> calculateReportData(Map<String, T> macDataMap, Map<String, Device> deviceMap, String reportType, Date... date) {
         List<MonitorPointDataDisplayDTO> dtos = new ArrayList<>();
-        macDataMap.forEach((key, valueObject) -> {
-            MonitorPointDataDisplayDTO dto = new MonitorPointDataDisplayDTO();
-            dto.setMac(key);
-            //���������map
-            Map<String, Object> valueMap;
-            //���������������value���������
-            Object valueO = ClassUtils.getPropertyValue(valueObject, "value");
-            if (valueO == null)
-                return;
-            String value = (String) valueO;
-            valueMap = JSON.parseObject(value, Map.class);
+        Set<String> strings = macDataMap.keySet();
+        for (String key : strings) {
+            if (reportType.equals("0")){
+                List<HistoryHourly> t = (List<HistoryHourly>)macDataMap.get(key);
+                for (HistoryHourly historyHourly : t) {
+                    MonitorPointDataDisplayDTO dto = new MonitorPointDataDisplayDTO();
+                    String value = historyHourly.getValue();
+                    Map map = JSON.parseObject(value, Map.class);
+                    String time = DateUtils.dateToDateString(historyHourly.getTime(), "yyyy-MM-dd HH:00:00");
+                    injectDataToDto(map, false, dto, reportType);
+                    dto.setTime(time);
+                    dto.setMac(key);
+                    dto.setDeviceName(deviceMap.get(key).getName());
+                    dtos.add(dto);
+                }
+            }
+            if (reportType.equals("1")){
+                List<HistoryDaily> t = (List<HistoryDaily>)macDataMap.get(key);
+                for (HistoryDaily historyDaily : t) {
+                    MonitorPointDataDisplayDTO dto = new MonitorPointDataDisplayDTO();
+                    String value = historyDaily.getValue();
+                    Map map = JSON.parseObject(value, Map.class);
+                    String time = DateUtils.dateToDateString(historyDaily.getTime(), "yyyy-MM-dd");
+                    injectDataToDto(map, false, dto, reportType);
+                    dto.setTime(time);
+                    dto.setMac(key);
+                    dto.setDeviceName(deviceMap.get(key).getName());
+                    dtos.add(dto);
+                }
+
+            }
+            if (reportType.equals("2")){
+                HistoryWeekly historyWeekly = (HistoryWeekly)macDataMap.get(key);
+                    MonitorPointDataDisplayDTO dto = new MonitorPointDataDisplayDTO();
+                    String value = historyWeekly.getValue();
+                    Map map = JSON.parseObject(value, Map.class);
+                    String time = DateUtils.dateToDateString(historyWeekly.getTime(), "yyyy-MM-dd");
+                    injectDataToDto(map, false, dto, reportType);
+                    dto.setTime(time);
+                    dto.setMac(key);
+                    dto.setDeviceName(deviceMap.get(key).getName());
+                    dtos.add(dto);
+
+            }
+            if (reportType.equals("3")){
+                List<HistoryMonthly> t = (List<HistoryMonthly>)macDataMap.get(key);
+                for (HistoryMonthly historyMonthly : t) {
+                    MonitorPointDataDisplayDTO dto = new MonitorPointDataDisplayDTO();
+                    String value = historyMonthly.getValue();
+                    Map map = JSON.parseObject(value, Map.class);
+                    String time = DateUtils.dateToDateString(historyMonthly.getTime(), "yyyy-MM");
+                    injectDataToDto(map, false, dto, reportType);
+                    dto.setTime(time);
+                    dto.setMac(key);
+                    dto.setDeviceName(deviceMap.get(key).getName());
+                    dtos.add(dto);
+                }
+            }
+        }
+
+//        macDataMap.forEach((key, valueObject) -> {
+//            MonitorPointDataDisplayDTO dto = new MonitorPointDataDisplayDTO();
+//            dto.setMac(key);
+//            //���������map
+//            Map<String, Object> valueMap;
+//            List<Map<String, Object>> list;
+//            //���������������value���������
+//            Object valueO = ClassUtils.getPropertyValue(valueObject, "value");
+//            if (valueO == null)
+//                return;
+//            String value = (String) valueO;
+//            list = JSON.parseObject(value, List.class);
+//            for (Map<String, Object> map : list) {
+//                String o = map.get("value").toString();
+//                valueMap = JSON.parseObject(o, Map.class);
+//                injectDataToDto(valueMap, false, dto, reportType);
+//                String deviceName = deviceMap.get(key).getName();
+//                dto.setDeviceName(deviceName);
+//                String startTime = DateUtils.dateToDateString((Date) map.get("time"), "yyyy-MM-dd HH:mm:ss");
+//                dto.setTime(startTime);
+//                dtos.add(dto);
+//            }
             //������������������
-            String deviceName = deviceMap.get(key).getName();
-            dto.setDeviceName(deviceName);
+
             //������������,������������������������������������������������������������������������������������������������������
-            String startTime = "";
-            if (valueObject instanceof HistoryHourly && date.length == 1)
-                startTime = DateUtils.dateToDateString(date[0], "yyyy-MM-dd HH:mm:ss");
-            else if (valueObject instanceof HistoryDaily && date.length == 1)
-                startTime = DateUtils.dateToDateString(date[0], "yyyy-MM-dd");
-            else if (valueObject instanceof HistoryWeekly && date.length == 2)
-                startTime = DateUtils.dateToDateString(date[0], "yyyy-MM-dd") + " -- " + DateUtils.dateToDateString(date[1], "yyyy-MM-dd");
-            else if (valueObject instanceof HistoryMonthly && date.length == 1)
-                startTime = DateUtils.dateToDateString(date[0], "yyyy-MM");
-            dto.setTime(startTime);
+//            String startTime = "";
+//            if (valueObject instanceof HistoryHourly && date.length == 1)
+//                startTime = DateUtils.dateToDateString(date[0], "yyyy-MM-dd HH:mm:ss");
+//            else if (valueObject instanceof HistoryDaily && date.length == 1)
+//                startTime = DateUtils.dateToDateString(date[0], "yyyy-MM-dd");
+//            else if (valueObject instanceof HistoryWeekly && date.length == 2)
+//                startTime = DateUtils.dateToDateString(date[0], "yyyy-MM-dd") + " -- " + DateUtils.dateToDateString(date[1], "yyyy-MM-dd");
+//            else if (valueObject instanceof HistoryMonthly && date.length == 1)
+//                startTime = DateUtils.dateToDateString(date[0], "yyyy-MM");
+//            dto.setTime(startTime);
             //������������
-            injectDataToDto(valueMap, false, dto, reportType);
-            dtos.add(dto);
-        });
+//        });
         return dtos;
     }
 

--
Gitblit v1.8.0