| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | |
| | | import com.moral.api.service.OrganizationService; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.RedisConstants; |
| | | import com.moral.util.AQIUtils; |
| | | import com.moral.util.RegionCodeUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | |
| | | Date endDate = simpleDateFormat.parse(endTime); |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | List govMonitorPointList = new ArrayList(); |
| | | //声明一个国控站点,存放最后的平均值信息 |
| | | GovMonitorPoint govMonitorPoint_avg = new GovMonitorPoint(); |
| | | govMonitorPoint_avg.setId(0); |
| | | govMonitorPoint_avg.setName(""); |
| | | govMonitorPoint_avg.setGuid(""); |
| | | List<Map<String,Object>> data = new ArrayList<>(); |
| | | Map<String,Object> hour_1 = new HashMap<>(); |
| | | Map<String,Object> hour_2 = new HashMap<>(); |
| | |
| | | Map<String,Object> hour_23 = new HashMap<>(); |
| | | Map<String,Object> hour_24 = new HashMap<>(); |
| | | Map<String,Object> hour_AVG = new HashMap<>(); |
| | | hour_1.put("time","1时"); |
| | | hour_2.put("time","2时"); |
| | | hour_3.put("time","3时"); |
| | | hour_4.put("time","4时"); |
| | | hour_5.put("time","5时"); |
| | | hour_6.put("time","6时"); |
| | | hour_7.put("time","7时"); |
| | | hour_8.put("time","8时"); |
| | | hour_9.put("time","9时"); |
| | | hour_10.put("time","10时"); |
| | | hour_11.put("time","11时"); |
| | | hour_12.put("time","12时"); |
| | | hour_13.put("time","13时"); |
| | | hour_14.put("time","14时"); |
| | | hour_15.put("time","15时"); |
| | | hour_16.put("time","16时"); |
| | | hour_17.put("time","17时"); |
| | | hour_18.put("time","18时"); |
| | | hour_19.put("time","19时"); |
| | | hour_20.put("time","20时"); |
| | | hour_21.put("time","21时"); |
| | | hour_22.put("time","22时"); |
| | | hour_23.put("time","23时"); |
| | | hour_24.put("time","0时"); |
| | | hour_AVG.put("time","avg"); |
| | | for (String guid:guids) { |
| | | //获取政府站点信息 |
| | | QueryWrapper<GovMonitorPoint> wrapper_govMonitorPoint = new QueryWrapper<>(); |
| | |
| | | } |
| | | } |
| | | Double PM2_5Avg = (double)Math.round(PM2_5List.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); |
| | | Double PM10Avg = (double)Math.round(PM2_5List.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); |
| | | Double SO2Avg = (double)Math.round(PM2_5List.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); |
| | | Double NO2Avg = (double)Math.round(PM2_5List.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); |
| | | Double COAvg = new BigDecimal(PM2_5List.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); |
| | | Double O3_1hAvg = (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()); |
| | | if (!ObjectUtils.isEmpty(PM2_5Avg)){ |
| | | PM2_5List_daliy.add(PM2_5Avg); |
| | | oneGovMonitorPointOneHourData.put("a34004_"+govMonitorPointId,PM2_5Avg); |
| | |
| | | } |
| | | if (!ObjectUtils.isEmpty(PM10Avg)){ |
| | | PM10List_daliy.add(PM10Avg); |
| | | oneGovMonitorPointOneHourData.put("a34002_"+govMonitorPointId,PM2_5Avg); |
| | | oneGovMonitorPointOneHourData.put("a34002_"+govMonitorPointId,PM10Avg); |
| | | }else { |
| | | oneGovMonitorPointOneHourData.put("a34002_"+govMonitorPointId,null); |
| | | } |
| | | if (!ObjectUtils.isEmpty(SO2Avg)){ |
| | | SO2List_daliy.add(SO2Avg); |
| | | oneGovMonitorPointOneHourData.put("a21026_"+govMonitorPointId,PM2_5Avg); |
| | | oneGovMonitorPointOneHourData.put("a21026_"+govMonitorPointId,SO2Avg); |
| | | }else { |
| | | oneGovMonitorPointOneHourData.put("a21026_"+govMonitorPointId,null); |
| | | } |
| | | if (!ObjectUtils.isEmpty(NO2Avg)){ |
| | | NO2List_daliy.add(NO2Avg); |
| | | oneGovMonitorPointOneHourData.put("a21004_"+govMonitorPointId,PM2_5Avg); |
| | | oneGovMonitorPointOneHourData.put("a21004_"+govMonitorPointId,NO2Avg); |
| | | }else { |
| | | oneGovMonitorPointOneHourData.put("a21004_"+govMonitorPointId,null); |
| | | } |
| | | if (!ObjectUtils.isEmpty(COAvg)){ |
| | | COList_daliy.add(COAvg); |
| | | oneGovMonitorPointOneHourData.put("a21005_"+govMonitorPointId,PM2_5Avg); |
| | | oneGovMonitorPointOneHourData.put("a21005_"+govMonitorPointId,COAvg); |
| | | }else { |
| | | oneGovMonitorPointOneHourData.put("a21005_"+govMonitorPointId,null); |
| | | } |
| | | if (!ObjectUtils.isEmpty(O3_1hAvg)){ |
| | | O3_1hList_daliy.add(O3_1hAvg); |
| | | oneGovMonitorPointOneHourData.put("a05024_"+govMonitorPointId,PM2_5Avg); |
| | | oneGovMonitorPointOneHourData.put("a05024_"+govMonitorPointId,O3_1hAvg); |
| | | O3_1hMap.put(i,O3_1hAvg); |
| | | }else { |
| | | oneGovMonitorPointOneHourData.put("a05024_"+govMonitorPointId,null); |
| | |
| | | } |
| | | } |
| | | } |
| | | Map<Integer,Map<String,Object>> replaceDataMap = new HashMap<>(); |
| | | replaceDataMap.put(0,hour_1); |
| | | replaceDataMap.put(1,hour_2); |
| | | replaceDataMap.put(2,hour_3); |
| | | replaceDataMap.put(3,hour_4); |
| | | replaceDataMap.put(4,hour_5); |
| | | replaceDataMap.put(5,hour_6); |
| | | replaceDataMap.put(6,hour_7); |
| | | replaceDataMap.put(7,hour_8); |
| | | replaceDataMap.put(8,hour_9); |
| | | replaceDataMap.put(9,hour_10); |
| | | replaceDataMap.put(10,hour_11); |
| | | replaceDataMap.put(11,hour_12); |
| | | replaceDataMap.put(12,hour_13); |
| | | replaceDataMap.put(13,hour_14); |
| | | replaceDataMap.put(14,hour_15); |
| | | replaceDataMap.put(15,hour_16); |
| | | replaceDataMap.put(16,hour_17); |
| | | replaceDataMap.put(17,hour_18); |
| | | replaceDataMap.put(18,hour_19); |
| | | replaceDataMap.put(19,hour_20); |
| | | replaceDataMap.put(20,hour_21); |
| | | replaceDataMap.put(21,hour_22); |
| | | replaceDataMap.put(22,hour_23); |
| | | replaceDataMap.put(23,hour_24); |
| | | replaceDataMap.put(24,hour_AVG); |
| | | for (int i=0;i<25;i++){ |
| | | List<Double> PM2_5AllList = new ArrayList<>(); |
| | | List<Double> PM10AllList = new ArrayList<>(); |
| | | List<Double> SO2AllList = new ArrayList<>(); |
| | | List<Double> NO2AllList = new ArrayList<>(); |
| | | List<Double> COAllList = new ArrayList<>(); |
| | | List<Double> O3_1hAllList = new ArrayList<>(); |
| | | List<Double> O3_8hAllList = new ArrayList<>(); |
| | | for (String guid:guids) { |
| | | //获取政府站点信息 |
| | | QueryWrapper<GovMonitorPoint> wrapper_govMonitorPoint = new QueryWrapper<>(); |
| | | wrapper_govMonitorPoint.eq("is_delete",Constants.NOT_DELETE).eq("guid",guid); |
| | | GovMonitorPoint govMonitorPoint = govMonitorPointMapper.selectOne(wrapper_govMonitorPoint); |
| | | if (ObjectUtils.isEmpty(govMonitorPoint)){ |
| | | continue; |
| | | } |
| | | int govMonitorPointId = govMonitorPoint.getId(); |
| | | |
| | | Map<String,Object> replaceMap = new HashMap<>(); |
| | | replaceMap = replaceDataMap.get(i); |
| | | if (!ObjectUtils.isEmpty(replaceMap.get("a34004_"+govMonitorPointId))){ |
| | | PM2_5AllList.add((double)replaceMap.get("a34004_"+govMonitorPointId)); |
| | | } |
| | | if (!ObjectUtils.isEmpty(replaceMap.get("a34002_"+govMonitorPointId))){ |
| | | PM10AllList.add((double)replaceMap.get("a34002_"+govMonitorPointId)); |
| | | } |
| | | if (!ObjectUtils.isEmpty(replaceMap.get("a21026_"+govMonitorPointId))){ |
| | | SO2AllList.add((double)replaceMap.get("a21026_"+govMonitorPointId)); |
| | | } |
| | | if (!ObjectUtils.isEmpty(replaceMap.get("a21004_"+govMonitorPointId))){ |
| | | NO2AllList.add((double)replaceMap.get("a21004_"+govMonitorPointId)); |
| | | } |
| | | if (!ObjectUtils.isEmpty(replaceMap.get("a21005_"+govMonitorPointId))){ |
| | | COAllList.add((double)replaceMap.get("a21005_"+govMonitorPointId)); |
| | | } |
| | | if (!ObjectUtils.isEmpty(replaceMap.get("a05024_"+govMonitorPointId))){ |
| | | O3_1hAllList.add((double)replaceMap.get("a05024_"+govMonitorPointId)); |
| | | } |
| | | if (!ObjectUtils.isEmpty(replaceMap.get("O3_8h_"+govMonitorPointId))){ |
| | | O3_8hAllList.add((double)replaceMap.get("O3_8h_"+govMonitorPointId)); |
| | | } |
| | | } |
| | | Double PM2_5 = null; |
| | | Double PM10 = null; |
| | | Double SO2 = null; |
| | | Double NO2 = null; |
| | | Double CO = null; |
| | | Double O3_1h = null; |
| | | Double O3_8h = null; |
| | | if (PM2_5AllList.size()>0){ |
| | | PM2_5 = (double)Math.round(PM2_5AllList.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); |
| | | } |
| | | if (PM10AllList.size()>0){ |
| | | PM10 = (double)Math.round(PM10AllList.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); |
| | | } |
| | | if (SO2AllList.size()>0){ |
| | | SO2 = (double)Math.round(SO2AllList.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); |
| | | } |
| | | if (NO2AllList.size()>0){ |
| | | NO2 = (double)Math.round(NO2AllList.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); |
| | | } |
| | | if (COAllList.size()>0){ |
| | | CO = new BigDecimal(COAllList.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); |
| | | } |
| | | if (O3_1hAllList.size()>0){ |
| | | O3_1h = (double)Math.round(O3_1hAllList.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); |
| | | } |
| | | if (O3_8hAllList.size()>0){ |
| | | O3_8h = (double)Math.round(O3_8hAllList.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage()); |
| | | } |
| | | Map<String,Object> AQIMap = new HashMap<>(); |
| | | if (!ObjectUtils.isEmpty(PM2_5)){ |
| | | AQIMap.put("a34004",PM2_5); |
| | | } |
| | | if (!ObjectUtils.isEmpty(PM2_5)){ |
| | | AQIMap.put("a34002",PM10); |
| | | } |
| | | if (!ObjectUtils.isEmpty(PM2_5)){ |
| | | AQIMap.put("a21026",SO2); |
| | | } |
| | | if (!ObjectUtils.isEmpty(PM2_5)){ |
| | | AQIMap.put("a21004",NO2); |
| | | } |
| | | if (!ObjectUtils.isEmpty(PM2_5)){ |
| | | AQIMap.put("a21005",CO); |
| | | } |
| | | if (!ObjectUtils.isEmpty(PM2_5)){ |
| | | AQIMap.put("a05024",O3_1h); |
| | | } |
| | | Map<String,Object> AQIResultMap = new HashMap<>(); |
| | | if (AQIMap.size()!=0){ |
| | | AQIResultMap = AQIUtils.hourlyAqi_pollutant(AQIMap); |
| | | } |
| | | Map<String,Object> avgMap = new HashMap<>(); |
| | | avgMap.put("a34004_"+"0",PM2_5); |
| | | avgMap.put("a34002_"+"0",PM10); |
| | | avgMap.put("a21026_"+"0",SO2); |
| | | avgMap.put("a21004_"+"0",NO2); |
| | | avgMap.put("a21005_"+"0",CO); |
| | | avgMap.put("a05024_"+"0",O3_1h); |
| | | avgMap.put("O3_8h_"+"0",O3_8h); |
| | | if (!ObjectUtils.isEmpty(AQIResultMap.get("aqi"))){ |
| | | avgMap.put("aqi",AQIResultMap.get("aqi")); |
| | | }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); |
| | | }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; |
| | | case 1:hour_2.putAll(avgMap); |
| | | break; |
| | | case 2:hour_3.putAll(avgMap); |
| | | break; |
| | | case 3:hour_4.putAll(avgMap); |
| | | break; |
| | | case 4:hour_5.putAll(avgMap); |
| | | break; |
| | | case 5:hour_6.putAll(avgMap); |
| | | break; |
| | | case 6:hour_7.putAll(avgMap); |
| | | break; |
| | | case 7:hour_8.putAll(avgMap); |
| | | break; |
| | | case 8:hour_9.putAll(avgMap); |
| | | break; |
| | | case 9:hour_10.putAll(avgMap); |
| | | break; |
| | | case 10:hour_11.putAll(avgMap); |
| | | break; |
| | | case 11:hour_12.putAll(avgMap); |
| | | break; |
| | | case 12:hour_13.putAll(avgMap); |
| | | break; |
| | | case 13:hour_14.putAll(avgMap); |
| | | break; |
| | | case 14:hour_15.putAll(avgMap); |
| | | break; |
| | | case 15:hour_16.putAll(avgMap); |
| | | break; |
| | | case 16:hour_17.putAll(avgMap); |
| | | break; |
| | | case 17:hour_18.putAll(avgMap); |
| | | break; |
| | | case 18:hour_19.putAll(avgMap); |
| | | break; |
| | | case 19:hour_20.putAll(avgMap); |
| | | break; |
| | | case 20:hour_21.putAll(avgMap); |
| | | break; |
| | | case 21:hour_22.putAll(avgMap); |
| | | break; |
| | | case 22:hour_23.putAll(avgMap); |
| | | break; |
| | | case 23:hour_24.putAll(avgMap); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | hour_1.put("time","1时"); |
| | | hour_2.put("time","2时"); |
| | | hour_3.put("time","3时"); |
| | | hour_4.put("time","4时"); |
| | | hour_5.put("time","5时"); |
| | | hour_6.put("time","6时"); |
| | | hour_7.put("time","7时"); |
| | | hour_8.put("time","8时"); |
| | | hour_9.put("time","9时"); |
| | | hour_10.put("time","10时"); |
| | | hour_11.put("time","11时"); |
| | | hour_12.put("time","12时"); |
| | | hour_13.put("time","13时"); |
| | | hour_14.put("time","14时"); |
| | | hour_15.put("time","15时"); |
| | | hour_16.put("time","16时"); |
| | | hour_17.put("time","17时"); |
| | | hour_18.put("time","18时"); |
| | | hour_19.put("time","19时"); |
| | | hour_20.put("time","20时"); |
| | | hour_21.put("time","21时"); |
| | | hour_22.put("time","22时"); |
| | | hour_23.put("time","23时"); |
| | | hour_24.put("time","0时"); |
| | | hour_AVG.put("time","avg"); |
| | | data.add(hour_1); |
| | | data.add(hour_2); |
| | | data.add(hour_3); |
| | |
| | | data.add(hour_24); |
| | | resultMap.put("title",date+"月报"); |
| | | resultMap.put("data",data); |
| | | resultMap.put("gocMonitorPoint",govMonitorPointList); |
| | | resultMap.put("govMonitorPoint",govMonitorPointList); |
| | | return resultMap; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |