From 0f41a81a6b28e591bfe734ccd8327a936f9c29e0 Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Mon, 01 Nov 2021 09:16:41 +0800 Subject: [PATCH] screen-api 增加获取一个城市24小时AQI接口 --- screen-api/src/main/java/com/moral/api/service/impl/GovMonitorPointServiceImpl.java | 85 +++++++++++++++++++++++++++++++++++------- 1 files changed, 70 insertions(+), 15 deletions(-) diff --git a/screen-api/src/main/java/com/moral/api/service/impl/GovMonitorPointServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/GovMonitorPointServiceImpl.java index 2a3c803..80b0a02 100644 --- a/screen-api/src/main/java/com/moral/api/service/impl/GovMonitorPointServiceImpl.java +++ b/screen-api/src/main/java/com/moral/api/service/impl/GovMonitorPointServiceImpl.java @@ -199,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); @@ -243,6 +261,18 @@ 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()){ @@ -251,7 +281,11 @@ O3_8hList_daliy.add(O3_1hMap.get(key)); } } - O3_8h = (double)Math.round(O3_8hList.stream().mapToDouble(aDouble ->aDouble).summaryStatistics().getAverage()); + if (i<curHour24){ + if (O3_8hList.size()>0){ + O3_8h = (double)Math.round(O3_8hList.stream().mapToDouble(aDouble ->aDouble).summaryStatistics().getAverage()); + } + } } oneGovMonitorPointOneHourData.put("O3_8h_"+govMonitorPointId,O3_8h); switch (i){ @@ -307,13 +341,34 @@ 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()); + Double PM2_5Avg_daliy = null; + Double PM10Avg_daliy = null; + Double SO2Avg_daliy = null; + Double NO2Avg_daliy = null; + Double COAvg_daliy = null; + Double O3_1hAvg_daliy = null; + Double O3_8hAvg_daliy = null; + if (PM2_5List_daliy.size()>0){ + PM2_5Avg_daliy = (double)Math.round(PM2_5List_daliy.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); + } + if (PM10List_daliy.size()>0){ + PM10Avg_daliy = (double)Math.round(PM10List_daliy.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); + } + if (SO2List_daliy.size()>0){ + SO2Avg_daliy = (double)Math.round(SO2List_daliy.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); + } + if (NO2List_daliy.size()>0){ + NO2Avg_daliy = (double)Math.round(NO2List_daliy.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); + } + if (COList_daliy.size()>0){ + COAvg_daliy = new BigDecimal(COList_daliy.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); + } + if (O3_1hList_daliy.size()>0){ + O3_1hAvg_daliy = (double)Math.round(O3_1hList_daliy.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); + } + if (O3_8hList_daliy.size()>0){ + 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); @@ -461,7 +516,7 @@ pollutant = pollutant.replace("]",""); avgMap.put("pollutant",pollutant); }else { - avgMap.put("pollutant",""); + avgMap.put("pollutant","-"); } }else { avgMap.put("aqi",""); -- Gitblit v1.8.0