| | |
| | | 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.entity.Device; |
| | | import com.moral.api.entity.GovMonitorPoint; |
| | | import com.moral.api.entity.HistoryHourly; |
| | | import com.moral.api.entity.Organization; |
| | | import com.moral.api.mapper.DeviceMapper; |
| | | import com.moral.api.mapper.GovMonitorPointMapper; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired(required = false) |
| | | private DeviceMapper deviceMapper; |
| | | |
| | | @Resource |
| | | private HistoryHourlyServiceImpl historyHourlyService; |
| | | |
| | | @Override |
| | | public List<GovMonitorPoint> queryGovMonitorPointAndDataByRegionCode(Integer regionCode,String sensorCode) { |
| | |
| | | List<GovMonitorPoint> govMonitorPointList = govMonitorPointMapper.selectList(wrapper_govMonitorPoint); |
| | | return govMonitorPointList; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> queryGovMonitorPointHoutlyDatyByGuidsAndOrgid(Map map) { |
| | | String[] guids = map.get("guids").toString().split(","); |
| | | Integer orgId = Integer.parseInt(map.get("organization_id").toString()); |
| | | String date = map.get("date").toString(); |
| | | String startTime = date+" 00:00:00"; |
| | | String endTime = date+" 23:00:01"; |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//注意月份是MM |
| | | try { |
| | | Date startDate = simpleDateFormat.parse(startTime); |
| | | Date endDate = simpleDateFormat.parse(endTime); |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | List govMonitorPointList = new ArrayList(); |
| | | 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_3 = new HashMap<>(); |
| | | Map<String,Object> hour_4 = new HashMap<>(); |
| | | Map<String,Object> hour_5 = new HashMap<>(); |
| | | Map<String,Object> hour_6 = new HashMap<>(); |
| | | Map<String,Object> hour_7 = new HashMap<>(); |
| | | Map<String,Object> hour_8 = new HashMap<>(); |
| | | Map<String,Object> hour_9 = new HashMap<>(); |
| | | Map<String,Object> hour_10 = new HashMap<>(); |
| | | Map<String,Object> hour_11 = new HashMap<>(); |
| | | Map<String,Object> hour_12 = new HashMap<>(); |
| | | Map<String,Object> hour_13 = new HashMap<>(); |
| | | Map<String,Object> hour_14 = new HashMap<>(); |
| | | Map<String,Object> hour_15 = new HashMap<>(); |
| | | Map<String,Object> hour_16 = new HashMap<>(); |
| | | Map<String,Object> hour_17 = new HashMap<>(); |
| | | Map<String,Object> hour_18 = new HashMap<>(); |
| | | Map<String,Object> hour_19 = new HashMap<>(); |
| | | Map<String,Object> hour_20 = new HashMap<>(); |
| | | Map<String,Object> hour_21 = new HashMap<>(); |
| | | Map<String,Object> hour_22 = 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<>(); |
| | | wrapper_govMonitorPoint.eq("is_delete",Constants.NOT_DELETE).eq("guid",guid); |
| | | GovMonitorPoint govMonitorPoint = govMonitorPointMapper.selectOne(wrapper_govMonitorPoint); |
| | | if (!ObjectUtils.isEmpty(govMonitorPoint)){ |
| | | govMonitorPointList.add(govMonitorPoint); |
| | | }else { |
| | | continue; |
| | | } |
| | | int govMonitorPointId = govMonitorPoint.getId(); |
| | | QueryWrapper<Device> wrapper_device = new QueryWrapper<>(); |
| | | wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgId).eq("guid",guid); |
| | | List<Device> devices = deviceMapper.selectList(wrapper_device); |
| | | List<String> macs = devices.stream().map(device -> device.getMac()).collect(Collectors.toList()); |
| | | List<List<HistoryHourly>> oneGovMonitorPointDevicesValue = new ArrayList(); |
| | | for (String mac:macs) { |
| | | List<HistoryHourly> valueByMacAndTime = historyHourlyService.getValueByMacAndTime(mac, startDate, endDate); |
| | | oneGovMonitorPointDevicesValue.add(valueByMacAndTime); |
| | | } |
| | | List<Double> PM2_5List_daliy = new ArrayList<>(); |
| | | List<Double> PM10List_daliy = new ArrayList<>(); |
| | | List<Double> SO2List_daliy = new ArrayList<>(); |
| | | List<Double> NO2List_daliy = new ArrayList<>(); |
| | | List<Double> COList_daliy = new ArrayList<>(); |
| | | List<Double> O3_1hList_daliy = new ArrayList<>(); |
| | | Map<Integer,Double> O3_1hMap = new HashMap<>(); |
| | | for (int i=0; i<24; i++){ |
| | | //声明一个Map,存放当前政府站点的六参和臭氧八小时滑动平均值数据 |
| | | Map<String,Object> oneGovMonitorPointOneHourData = new HashMap<>(); |
| | | String time_hourly = ""; |
| | | if (i<10){ |
| | | time_hourly = date+" 0"+i+":00:00"; |
| | | }else { |
| | | time_hourly = date+" "+i+":00:00"; |
| | | } |
| | | List<Double> PM2_5List = new ArrayList<>(); |
| | | List<Double> PM10List = new ArrayList<>(); |
| | | List<Double> SO2List = new ArrayList<>(); |
| | | List<Double> NO2List = new ArrayList<>(); |
| | | List<Double> COList = new ArrayList<>(); |
| | | List<Double> O3_1hList = new ArrayList<>(); |
| | | for (List<HistoryHourly> valueByMacAndTime:oneGovMonitorPointDevicesValue) { |
| | | for (HistoryHourly historyHourly:valueByMacAndTime) { |
| | | if (simpleDateFormat.format(historyHourly.getTime()).equals(time_hourly)){ |
| | | JSONObject value = JSONObject.parseObject(historyHourly.getValue()); |
| | | if (!ObjectUtils.isEmpty(value.get("a34004"))){ |
| | | PM2_5List.add(Double.parseDouble(value.get("a34004").toString())); |
| | | } |
| | | if (!ObjectUtils.isEmpty(value.get("a34002"))){ |
| | | PM10List.add(Double.parseDouble(value.get("a34002").toString())); |
| | | } |
| | | if (!ObjectUtils.isEmpty(value.get("a21026"))){ |
| | | SO2List.add(Double.parseDouble(value.get("a21026").toString())); |
| | | } |
| | | if (!ObjectUtils.isEmpty(value.get("a21004"))){ |
| | | NO2List.add(Double.parseDouble(value.get("a21004").toString())); |
| | | } |
| | | if (!ObjectUtils.isEmpty(value.get("a21005"))){ |
| | | COList.add(Double.parseDouble(value.get("a21005").toString())); |
| | | } |
| | | if (!ObjectUtils.isEmpty(value.get("a05024"))){ |
| | | O3_1hList.add(Double.parseDouble(value.get("a05024").toString())); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | 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()); |
| | | if (!ObjectUtils.isEmpty(PM2_5Avg)){ |
| | | PM2_5List_daliy.add(PM2_5Avg); |
| | | oneGovMonitorPointOneHourData.put("a34004_"+govMonitorPointId,PM2_5Avg); |
| | | }else { |
| | | oneGovMonitorPointOneHourData.put("a34004_"+govMonitorPointId,null); |
| | | } |
| | | if (!ObjectUtils.isEmpty(PM10Avg)){ |
| | | PM10List_daliy.add(PM10Avg); |
| | | oneGovMonitorPointOneHourData.put("a34002_"+govMonitorPointId,PM2_5Avg); |
| | | }else { |
| | | oneGovMonitorPointOneHourData.put("a34002_"+govMonitorPointId,null); |
| | | } |
| | | if (!ObjectUtils.isEmpty(SO2Avg)){ |
| | | SO2List_daliy.add(SO2Avg); |
| | | oneGovMonitorPointOneHourData.put("a21026_"+govMonitorPointId,PM2_5Avg); |
| | | }else { |
| | | oneGovMonitorPointOneHourData.put("a21026_"+govMonitorPointId,null); |
| | | } |
| | | if (!ObjectUtils.isEmpty(NO2Avg)){ |
| | | NO2List_daliy.add(NO2Avg); |
| | | oneGovMonitorPointOneHourData.put("a21004_"+govMonitorPointId,PM2_5Avg); |
| | | }else { |
| | | oneGovMonitorPointOneHourData.put("a21004_"+govMonitorPointId,null); |
| | | } |
| | | if (!ObjectUtils.isEmpty(COAvg)){ |
| | | COList_daliy.add(COAvg); |
| | | oneGovMonitorPointOneHourData.put("a21005_"+govMonitorPointId,PM2_5Avg); |
| | | }else { |
| | | oneGovMonitorPointOneHourData.put("a21005_"+govMonitorPointId,null); |
| | | } |
| | | if (!ObjectUtils.isEmpty(O3_1hAvg)){ |
| | | O3_1hList_daliy.add(O3_1hAvg); |
| | | oneGovMonitorPointOneHourData.put("a05024_"+govMonitorPointId,PM2_5Avg); |
| | | O3_1hMap.put(i,O3_1hAvg); |
| | | }else { |
| | | oneGovMonitorPointOneHourData.put("a05024_"+govMonitorPointId,null); |
| | | } |
| | | Double O3_8h = null; |
| | | 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_8h = (double)Math.round(O3_8hList.stream().mapToDouble(aDouble ->aDouble).summaryStatistics().getAverage()); |
| | | } |
| | | oneGovMonitorPointOneHourData.put("O3_8h_"+govMonitorPointId,O3_8h); |
| | | switch (i){ |
| | | case 0:hour_1.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 1:hour_2.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 2:hour_3.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 3:hour_4.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 4:hour_5.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 5:hour_6.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 6:hour_7.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 7:hour_8.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 8:hour_9.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 9:hour_10.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 10:hour_11.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 11:hour_12.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 12:hour_13.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 13:hour_14.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 14:hour_15.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 15:hour_16.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 16:hour_17.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 17:hour_18.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 18:hour_19.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 19:hour_20.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 20:hour_21.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 21:hour_22.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 22:hour_23.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | case 23:hour_24.putAll(oneGovMonitorPointOneHourData); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | data.add(hour_1); |
| | | data.add(hour_2); |
| | | data.add(hour_3); |
| | | data.add(hour_4); |
| | | data.add(hour_5); |
| | | data.add(hour_6); |
| | | data.add(hour_7); |
| | | data.add(hour_8); |
| | | data.add(hour_9); |
| | | data.add(hour_10); |
| | | data.add(hour_11); |
| | | data.add(hour_12); |
| | | data.add(hour_13); |
| | | data.add(hour_14); |
| | | data.add(hour_15); |
| | | data.add(hour_16); |
| | | data.add(hour_17); |
| | | data.add(hour_18); |
| | | data.add(hour_19); |
| | | data.add(hour_20); |
| | | data.add(hour_21); |
| | | data.add(hour_22); |
| | | data.add(hour_23); |
| | | data.add(hour_24); |
| | | resultMap.put("title",data+"月报"); |
| | | resultMap.put("data",data); |
| | | resultMap.put("gocMonitorPoint",govMonitorPointList); |
| | | return resultMap; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | } |