|  |  | 
 |  |  |     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); | 
 |  |  |  | 
 |  |  |         return resultList(historyDailyByMacAndTimeSlot); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     private List<MonitoringStationDTO> resultList(List<HistoryDaily> historyDailyByMacAndTimeSlot){ | 
 |  |  |         List<MonitoringStationDTO> list = new ArrayList<>(); | 
 |  |  |         if(CollectionUtils.isEmpty(historyDailyByMacAndTimeSlot)){ | 
 |  |  |             return list; | 
 |  |  |         } | 
 |  |  |         Map<String,Map<String,ArrayList<Double>>> resultMap = new HashMap<>(); | 
 |  |  |         int zz = 0; | 
 |  |  |         for(HistoryDaily h : historyDailyByMacAndTimeSlot) { | 
 |  |  |             JSONObject jsonObject = JSONObject.parseObject(h.getValue()); | 
 |  |  |             Map<String, Object> map = jsonObject.getInnerMap(); | 
 |  |  |             Map<String,ArrayList<Double>> maps = Objects.nonNull(resultMap.get(h.getMac()))?resultMap.get(h.getMac()):new HashMap<>(); | 
 |  |  |             if(Objects.nonNull(map.get("a34004"))){ | 
 |  |  |                 ArrayList<Double> numResult = Objects.nonNull(maps.get("PM2_5"))?maps.get("PM2_5"):new ArrayList<>(); | 
 |  |  |                 numResult.add(Double.parseDouble(map.get("a34004").toString())); | 
 |  |  |                 maps.put("PM2_5",numResult); | 
 |  |  |             } | 
 |  |  |             if(Objects.nonNull(map.get("a05024"))){ | 
 |  |  |                 ArrayList<Double> numResult = Objects.nonNull(maps.get("O3"))?maps.get("O3"):new ArrayList<>(); | 
 |  |  |                 numResult.add(Double.parseDouble(map.get("a05024").toString())); | 
 |  |  |                 maps.put("O3",numResult); | 
 |  |  |             } | 
 |  |  |             if(Objects.nonNull(map.get("a34002"))){ | 
 |  |  |                 ArrayList<Double> numResult = Objects.nonNull(maps.get("PM10"))?maps.get("PM10"):new ArrayList<>(); | 
 |  |  |                 numResult.add(Double.parseDouble(map.get("a34002").toString())); | 
 |  |  |                 maps.put("PM10",numResult); | 
 |  |  |             } | 
 |  |  |             if(Objects.nonNull(map.get("a21026"))){ | 
 |  |  |                 ArrayList<Double> numResult = Objects.nonNull(maps.get("SO2"))?maps.get("SO2"):new ArrayList<>(); | 
 |  |  |                 numResult.add(Double.parseDouble(map.get("a21026").toString())); | 
 |  |  |                 maps.put("SO2",numResult); | 
 |  |  |             } | 
 |  |  |             if(Objects.nonNull(map.get("a21004"))){ | 
 |  |  |                 ArrayList<Double> numResult = Objects.nonNull(maps.get("NO2"))?maps.get("NO2"):new ArrayList<>(); | 
 |  |  |                 numResult.add(Double.parseDouble(map.get("a21004").toString())); | 
 |  |  |                 maps.put("NO2",numResult); | 
 |  |  |             } | 
 |  |  |             if(Objects.nonNull(map.get("a21005"))){ | 
 |  |  |                 System.out.println(">>>"+map.toString()); | 
 |  |  |                 System.out.println(">>>"+map.get("a21005").toString()); | 
 |  |  |                 ArrayList<Double> numResult = Objects.nonNull(maps.get("CO"))?maps.get("CO"):new ArrayList<>(); | 
 |  |  |                 numResult.add(Double.parseDouble(map.get("a21005").toString())); | 
 |  |  |                 maps.put("CO",numResult); | 
 |  |  |             } | 
 |  |  |             if(Objects.nonNull(map.get("a99054"))){ | 
 |  |  |                 ArrayList<Double> numResult = Objects.nonNull(maps.get("TVOC"))?maps.get("TVOC"):new ArrayList<>(); | 
 |  |  |                 numResult.add(Double.parseDouble(map.get("a99054").toString())); | 
 |  |  |                 maps.put("TVOC",numResult); | 
 |  |  |             } | 
 |  |  |             resultMap.put(h.getMac(),maps); | 
 |  |  |             zz++; | 
 |  |  |         } | 
 |  |  |         for(Map.Entry entry : resultMap.entrySet()){ | 
 |  |  |             String mapKey = (String) entry.getKey(); | 
 |  |  |             Map<String,ArrayList<Double>> mapValue = (Map<String,ArrayList<Double>>)entry.getValue(); | 
 |  |  |             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(); | 
 |  |  |                 data.put("PM2_5",rsAvg); | 
 |  |  |             }else { | 
 |  |  |                 data.put("PM2_5",0); | 
 |  |  |             } | 
 |  |  |             if(mapValue.containsKey("PM10")){ | 
 |  |  |                 Double ListAvg = mapValue.get("PM10").stream().collect(Collectors.averagingDouble(Double::doubleValue)); | 
 |  |  |                 double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue(); | 
 |  |  |                 data.put("PM10",rsAvg); | 
 |  |  |             }else { | 
 |  |  |                 data.put("PM10",0); | 
 |  |  |             } | 
 |  |  |             if(mapValue.containsKey("SO2")){ | 
 |  |  |                 Double ListAvg = mapValue.get("SO2").stream().collect(Collectors.averagingDouble(Double::doubleValue)); | 
 |  |  |                 double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue(); | 
 |  |  |                 data.put("SO2",rsAvg); | 
 |  |  |             }else { | 
 |  |  |                 data.put("SO2",0); | 
 |  |  |             } | 
 |  |  |             if(mapValue.containsKey("NO2")){ | 
 |  |  |                 Double ListAvg = mapValue.get("NO2").stream().collect(Collectors.averagingDouble(Double::doubleValue)); | 
 |  |  |                 double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue(); | 
 |  |  |                 data.put("NO2",rsAvg); | 
 |  |  |             }else { | 
 |  |  |                 data.put("NO2",0); | 
 |  |  |             } | 
 |  |  |             if(mapValue.containsKey("CO")){ | 
 |  |  |                 Double ListAvg = percentile(mapValue.get("CO"),95d); | 
 |  |  |                 double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue(); | 
 |  |  |                 data.put("CO",rsAvg); | 
 |  |  |             }else { | 
 |  |  |                 data.put("CO",0); | 
 |  |  |             } | 
 |  |  |             if(mapValue.containsKey("O3")){ | 
 |  |  |                 Double ListAvg = percentile(mapValue.get("O3"),90d); | 
 |  |  |                 double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue(); | 
 |  |  |                 data.put("O3",rsAvg); | 
 |  |  |             }else { | 
 |  |  |                 data.put("O3",0); | 
 |  |  |             } | 
 |  |  |             if(mapValue.containsKey("TVOC")){ | 
 |  |  |                 Double ListAvg = mapValue.get("TVOC").stream().collect(Collectors.averagingDouble(Double::doubleValue)); | 
 |  |  |                 double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue(); | 
 |  |  |                 data.put("TVOC",rsAvg); | 
 |  |  |             }else { | 
 |  |  |                 data.put("TVOC",0); | 
 |  |  |             } | 
 |  |  |             Double resultNum = ComprehensiveIndexUtils.dailyData(data); | 
 |  |  |             MonitoringStationDTO monitoringStationDTO = new MonitoringStationDTO(); | 
 |  |  |             monitoringStationDTO.setPM25(BigDecimal.valueOf(Double.parseDouble(data.get("PM2_5").toString()))); | 
 |  |  |             monitoringStationDTO.setO3(BigDecimal.valueOf(Double.parseDouble(data.get("O3").toString()))); | 
 |  |  |             monitoringStationDTO.setTovc(BigDecimal.valueOf(Double.parseDouble(data.get("TVOC").toString()))); | 
 |  |  |             monitoringStationDTO.setComposite(BigDecimal.valueOf(resultNum)); | 
 |  |  |             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> resultList = new ArrayList<>(); | 
 |  |  |         LambdaQueryChainWrapper<Device> wrapper = deviceService.lambdaQuery(); | 
 |  |  |         wrapper.eq(Device::getIsDelete,0); | 
 |  |  |         Map<String,String> deviceMap =  new HashMap<>(); | 
 |  |  |         wrapper.list().forEach(it->deviceMap.put(it.getMac(),it.getName())); | 
 |  |  |         int num = 1; | 
 |  |  |         for (MonitoringStationDTO m :compositeList ){ | 
 |  |  |             MonitoringStationDTO monit = new MonitoringStationDTO(); | 
 |  |  |             String mac = m.getMac(); | 
 |  |  |             monit.setMac(mac); | 
 |  |  |             monit.setName(deviceMap.get(mac)); | 
 |  |  |             monit.setComposite(m.getComposite()); | 
 |  |  |             monit.setCompositeNum(num); | 
 |  |  |             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.setPM25(pM25List.get(listPM25.indexOf(mac)).getPM25()); | 
 |  |  |             monit.setPM25Num(listPM25.indexOf(mac)+1); | 
 |  |  |             monit.setTovc(tovcList.get(listTovc.indexOf(mac)).getTovc()); | 
 |  |  |             monit.setTOVCNum(listTovc.indexOf(mac)+1); | 
 |  |  |             num++; | 
 |  |  |             resultList.add(monit); | 
 |  |  |         } | 
 |  |  |         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"); | 
 |  |  |         List<MonitoringStationDTO> resultList = new ArrayList<>(); | 
 |  |  |  | 
 |  |  |         if(reportType == 1||reportType == 4){ |