From 903d3c3954b73c3518aaa1528a95a24a4896e058 Mon Sep 17 00:00:00 2001
From: cjl <276999030@qq.com>
Date: Fri, 18 Aug 2023 15:09:43 +0800
Subject: [PATCH] fix:实测补偿修复

---
 screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java |  100 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 83 insertions(+), 17 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java
index b9b8e75..da9ea5e 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java
@@ -24,6 +24,7 @@
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import springfox.documentation.schema.Entry;
 
 import java.math.BigDecimal;
 import java.util.*;
@@ -480,17 +481,40 @@
         }
         return resultList;
     }
-
-
     @Override
     public List<MonitoringStationDTO> listMonitoringStationDTO(Map<String, Object> params, int reportType, String startTime, String endTime) {
        // List<String> macs = Arrays.asList(mac.split(","));
         List<String> macs = (List<String>) params.remove("mac");
-        Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_EN);
-        Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_EN);
-        List<HistoryDaily> historyDailyByMacAndTimeSlot = historyDailyService.getHistoryDailyByMacAndTimeSlot(macs, startDate, endDate);
+        List<MonitoringStationDTO> resultList = new ArrayList<>();
 
-        return resultList(historyDailyByMacAndTimeSlot);
+        if(reportType == 1||reportType == 4){
+            Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_EN);
+            Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_EN);
+            List<HistoryDaily> historyDailyByMacAndTimeSlot = historyDailyService.getHistoryDailyByMacAndTimeSlot(macs, startDate, endDate);
+            resultList = resultList(historyDailyByMacAndTimeSlot);
+        }else if(reportType == 2){
+            Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_EN);
+            Date endDate = DateUtils.addDays(startDate,6);
+            List<HistoryDaily> historyDailyByMacAndTimeSlot = historyDailyService.getHistoryDailyByMacAndTimeSlot(macs, startDate, endDate);
+            resultList = resultList(historyDailyByMacAndTimeSlot);
+        }else if(reportType == 3){
+            Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_EN);
+            Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_EN);
+            QueryWrapper<HistoryMonthly> HistoryMonthlyWrapper = new QueryWrapper<>();
+            HistoryMonthlyWrapper.in("mac",macs);
+            HistoryMonthlyWrapper.between("time",startDate,endDate);
+            List<HistoryMonthly> historyMonthlyList = historyMonthlyMapper.selectList(HistoryMonthlyWrapper);
+            List<HistoryDaily> historyDailies = new ArrayList<>();
+            for(HistoryMonthly h : historyMonthlyList) {
+                HistoryDaily historyDaily = new HistoryDaily();
+                historyDaily.setMac(h.getMac());
+                historyDaily.setTime(h.getTime());
+                historyDaily.setValue(h.getValue());
+                historyDailies.add(historyDaily);
+            }
+            resultList = resultList(historyDailies);
+        }
+        return resultList;
     }
 
 
@@ -551,7 +575,7 @@
             Map<String, Object> data = new HashMap<>();
             if(mapValue.containsKey("PM2_5")){
                 Double ListAvg = mapValue.get("PM2_5").stream().collect(Collectors.averagingDouble(Double::doubleValue));
-                double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
+                double rsAvg = new BigDecimal(ListAvg).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                 data.put("PM2_5",rsAvg);
             }else {
                 data.put("PM2_5",0);
@@ -586,7 +610,7 @@
             }
             if(mapValue.containsKey("O3")){
                 Double ListAvg = percentile(mapValue.get("O3"),90d);
-                double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
+                double rsAvg = new BigDecimal(ListAvg).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
                 data.put("O3",rsAvg);
             }else {
                 data.put("O3",0);
@@ -607,10 +631,10 @@
             monitoringStationDTO.setMac(mapKey);
             list.add(monitoringStationDTO);
         }
-        List<MonitoringStationDTO> compositeList = list.stream().sorted(Comparator.comparing(MonitoringStationDTO::getComposite).reversed()).collect(Collectors.toList());
-        List<MonitoringStationDTO> pM25List = list.stream().sorted(Comparator.comparing(MonitoringStationDTO::getPM25).reversed()).collect(Collectors.toList());
-        List<MonitoringStationDTO> o3List = list.stream().sorted(Comparator.comparing(MonitoringStationDTO::getO3).reversed()).collect(Collectors.toList());
-        List<MonitoringStationDTO> tovcList = list.stream().sorted(Comparator.comparing(MonitoringStationDTO::getTovc).reversed()).collect(Collectors.toList());
+        List<MonitoringStationDTO> compositeList = fun3(list,1);
+        List<MonitoringStationDTO> pM25List = fun3(list,2);
+        List<MonitoringStationDTO> o3List = fun3(list,3);
+        List<MonitoringStationDTO> tovcList = fun3(list,4);
         List<MonitoringStationDTO> resultList = new ArrayList<>();
         LambdaQueryChainWrapper<Device> wrapper = deviceService.lambdaQuery();
         wrapper.eq(Device::getIsDelete,0);
@@ -623,22 +647,64 @@
             monit.setMac(mac);
             monit.setName(deviceMap.get(mac));
             monit.setComposite(m.getComposite());
-            monit.setCompositeNum(num);
+            monit.setCompositeNum(m.getCompositeNum());
             List<String> listPM25 = pM25List.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
             List<String> listO3 = o3List.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
             List<String> listTovc = tovcList.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
             monit.setO3(o3List.get(listO3.indexOf(mac)).getO3());
-            monit.setO3Num(listO3.indexOf(mac)+1);
+            monit.setO3Num(o3List.get(listO3.indexOf(mac)).getO3Num());
             monit.setPM25(pM25List.get(listPM25.indexOf(mac)).getPM25());
-            monit.setPM25Num(listPM25.indexOf(mac)+1);
+            monit.setPM25Num(pM25List.get(listPM25.indexOf(mac)).getPM25Num());
             monit.setTovc(tovcList.get(listTovc.indexOf(mac)).getTovc());
-            monit.setTOVCNum(listTovc.indexOf(mac)+1);
-            num++;
+            monit.setTOVCNum(tovcList.get(listTovc.indexOf(mac)).getTOVCNum());
+            //num++;
             resultList.add(monit);
         }
         return resultList;
     }
 
+    public List<MonitoringStationDTO> fun3(List<MonitoringStationDTO> monList,int type) {
+        List<MonitoringStationDTO> resultList = new ArrayList<>();
+        List<MonitoringStationDTO> compositeList = new ArrayList<>();
+        Map<BigDecimal,List<MonitoringStationDTO>> map1 = new HashMap<>();
+        if(type == 1){
+            compositeList = monList.stream().sorted(Comparator.comparing(MonitoringStationDTO::getComposite)).collect(Collectors.toList());
+            map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getComposite,LinkedHashMap::new,Collectors.toList()));
+        }else if(type == 2){
+            compositeList = monList.stream().sorted(Comparator.comparing(MonitoringStationDTO::getPM25)).collect(Collectors.toList());
+            map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getPM25,LinkedHashMap::new,Collectors.toList()));
+        }else if(type == 3){
+            compositeList = monList.stream().sorted(Comparator.comparing(MonitoringStationDTO::getO3)).collect(Collectors.toList());
+            map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getO3,LinkedHashMap::new,Collectors.toList()));
+        }else if(type == 4){
+            compositeList = monList.stream().sorted(Comparator.comparing(MonitoringStationDTO::getTovc)).collect(Collectors.toList());
+            map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getTovc,LinkedHashMap::new,Collectors.toList()));
+        }
+        int index = 1;
+        for (Map.Entry entry : map1.entrySet()) {
+            List<MonitoringStationDTO> mapValue = (List<MonitoringStationDTO>)entry.getValue();
+            for(MonitoringStationDTO m : mapValue){
+                MonitoringStationDTO stationDTO = new MonitoringStationDTO();
+                stationDTO.setMac(m.getMac());
+                if(type == 1){
+                    stationDTO.setComposite(m.getComposite());
+                    stationDTO.setCompositeNum(index);
+                }else if(type == 2){
+                    stationDTO.setPM25(m.getPM25());
+                    stationDTO.setPM25Num(index);
+                }else if(type == 3){
+                    stationDTO.setO3(m.getO3());
+                    stationDTO.setO3Num(index);
+                }else if(type == 4){
+                    stationDTO.setTovc(m.getTovc());
+                    stationDTO.setTOVCNum(index);
+                }
+                resultList.add(stationDTO);
+            }
+            index = index +mapValue.size();
+        }
+        return resultList;
+    }
 
     private Map<String,Map<String,Object>> resultMap(List<HistoryDaily> list , List<HistoryMonthly> historyMonthlyList){
         Map<String,Map<String,Object>> map = new HashMap<>();

--
Gitblit v1.8.0