kaiyu
2021-10-09 2dee01ae6f13a72b1d2ba9ca3d1ffbea72ab513b
screen-api/src/main/java/com/moral/api/service/impl/GovMonitorPointServiceImpl.java
@@ -157,6 +157,7 @@
                List<Double> NO2List_daliy = new ArrayList<>();
                List<Double> COList_daliy = new ArrayList<>();
                List<Double> O3_1hList_daliy = new ArrayList<>();
                List<Double> O3_8hList_daliy = new ArrayList<>();
                Map<Integer,Double> O3_1hMap = new HashMap<>();
                for (int i=0; i<24; i++){
                    //声明一个Map,存放当前政府站点的六参和臭氧八小时滑动平均值数据
@@ -198,12 +199,30 @@
                            }
                        }
                    }
                    Double PM2_5Avg = (double)Math.round(PM2_5List.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                    Double PM10Avg = (double)Math.round(PM10List.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                    Double SO2Avg = (double)Math.round(SO2List.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                    Double NO2Avg = (double)Math.round(NO2List.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                    Double COAvg = new BigDecimal(COList.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
                    Double O3_1hAvg = (double)Math.round(O3_1hList.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                    Double PM2_5Avg = null;
                    Double PM10Avg = null;
                    Double SO2Avg = null;
                    Double NO2Avg = null;
                    Double COAvg = null;
                    Double O3_1hAvg = null;
                    if (PM2_5List.size()>0){
                        PM2_5Avg = (double)Math.round(PM2_5List.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                    }
                    if (PM10List.size()>0){
                        PM10Avg = (double)Math.round(PM10List.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                    }
                    if (SO2List.size()>0){
                        SO2Avg = (double)Math.round(SO2List.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                    }
                    if (NO2List.size()>0){
                        NO2Avg = (double)Math.round(NO2List.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                    }
                    if (COList.size()>0){
                        COAvg = new BigDecimal(COList.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
                    }
                    if (O3_1hList.size()>0){
                        O3_1hAvg = (double)Math.round(O3_1hList.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                    }
                    if (!ObjectUtils.isEmpty(PM2_5Avg)){
                        PM2_5List_daliy.add(PM2_5Avg);
                        oneGovMonitorPointOneHourData.put("a34004_"+govMonitorPointId,PM2_5Avg);
@@ -242,14 +261,29 @@
                        oneGovMonitorPointOneHourData.put("a05024_"+govMonitorPointId,null);
                    }
                    Double O3_8h = null;
                    //当前时间
                    Date now = new Date();
                    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
                    //获取今天的日期
                    String nowDay = sf.format(now);
                    //对比的时间
                    //String day = sf.format(date);
                    int curHour24 = 25;
                    if (date.equals(nowDay)){
                        Calendar calendar = Calendar.getInstance();
                        curHour24 = calendar.get(calendar.HOUR_OF_DAY);
                    }
                    if (i>=7){
                        List<Double> O3_8hList = new ArrayList<>();
                        for (Integer key:O3_1hMap.keySet()){
                            if (i-8<key && key<i+1){
                                O3_8hList.add(O3_1hMap.get(key));
                                O3_8hList_daliy.add(O3_1hMap.get(key));
                            }
                        }
                        O3_8h = (double)Math.round(O3_8hList.stream().mapToDouble(aDouble ->aDouble).summaryStatistics().getAverage());
                        if (i<curHour24){
                            O3_8h = (double)Math.round(O3_8hList.stream().mapToDouble(aDouble ->aDouble).summaryStatistics().getAverage());
                        }
                    }
                    oneGovMonitorPointOneHourData.put("O3_8h_"+govMonitorPointId,O3_8h);
                    switch (i){
@@ -305,6 +339,20 @@
                            break;
                    }
                }
                Double PM2_5Avg_daliy = (double)Math.round(PM2_5List_daliy.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                Double PM10Avg_daliy = (double)Math.round(PM10List_daliy.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                Double SO2Avg_daliy = (double)Math.round(SO2List_daliy.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                Double NO2Avg_daliy = (double)Math.round(NO2List_daliy.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                Double COAvg_daliy = new BigDecimal(COList_daliy.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
                Double O3_1hAvg_daliy = (double)Math.round(O3_1hList_daliy.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                Double O3_8hAvg_daliy = (double)Math.round(O3_8hList_daliy.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage());
                hour_AVG.put("a34004_"+govMonitorPointId,PM2_5Avg_daliy);
                hour_AVG.put("a34002_"+govMonitorPointId,PM10Avg_daliy);
                hour_AVG.put("a21026_"+govMonitorPointId,SO2Avg_daliy);
                hour_AVG.put("a21004_"+govMonitorPointId,NO2Avg_daliy);
                hour_AVG.put("a21005_"+govMonitorPointId,COAvg_daliy);
                hour_AVG.put("a05024_"+govMonitorPointId,O3_1hAvg_daliy);
                hour_AVG.put("O3_8h_"+govMonitorPointId,O3_8hAvg_daliy);
            }
            Map<Integer,Map<String,Object>> replaceDataMap = new HashMap<>();
            replaceDataMap.put(0,hour_1);
@@ -438,16 +486,18 @@
                }else {
                    avgMap.put("aqi","");
                }
                if (!ObjectUtils.isEmpty(AQIResultMap.get("aqi"))){
                    String pollutant = AQIResultMap.get("pollutant").toString();
                    pollutant = pollutant.replace("[","");
                    pollutant = pollutant.replace("]","");
                    avgMap.put("pollutant",pollutant);
                if (!ObjectUtils.isEmpty(AQIResultMap.get("pollutant"))){
                    if (Integer.parseInt(AQIResultMap.get("aqi").toString())>50){
                        String pollutant = AQIResultMap.get("pollutant").toString();
                        pollutant = pollutant.replace("[","");
                        pollutant = pollutant.replace("]","");
                        avgMap.put("pollutant",pollutant);
                    }else {
                        avgMap.put("pollutant","-");
                    }
                }else {
                    avgMap.put("aqi","");
                }
                //System.out.println("==============="+pollutant);
                //avgMap.put("pullutant",StringUtils.join(aqi_pollutantMap.get("pollutant").toArray(), separator));
                switch (i){
                    case 0:hour_1.putAll(avgMap);
                        break;
@@ -497,6 +547,8 @@
                        break;
                    case 23:hour_24.putAll(avgMap);
                        break;
                    case 24:hour_AVG.putAll(avgMap);
                        break;
                    default:
                        break;
                }
@@ -525,7 +577,7 @@
            hour_22.put("time","22时");
            hour_23.put("time","23时");
            hour_24.put("time","0时");
            hour_AVG.put("time","avg");
            hour_AVG.put("time","均值");
            data.add(hour_1);
            data.add(hour_2);
            data.add(hour_3);
@@ -550,8 +602,10 @@
            data.add(hour_22);
            data.add(hour_23);
            data.add(hour_24);
            data.add(hour_AVG);
            resultMap.put("title",date+"月报");
            resultMap.put("data",data);
            govMonitorPointList.add(govMonitorPoint_avg);
            resultMap.put("govMonitorPoint",govMonitorPointList);
            return resultMap;
        }catch (Exception e){