From 2ad979f912a1883c7a46048fa371d213f8406ba9 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Mon, 08 Nov 2021 11:26:22 +0800
Subject: [PATCH] update
---
screen-api/src/main/java/com/moral/api/service/impl/GovMonitorPointServiceImpl.java | 356 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 317 insertions(+), 39 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 3e954ae..7ddf17e 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
@@ -1,6 +1,5 @@
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;
@@ -15,6 +14,8 @@
import com.moral.api.service.OrganizationService;
import com.moral.constant.Constants;
import com.moral.constant.RedisConstants;
+import com.moral.pojo.AQI;
+import com.moral.util.AQIUtils;
import com.moral.util.RegionCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
@@ -100,6 +101,11 @@
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<>();
@@ -126,31 +132,6 @@
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<>();
@@ -177,6 +158,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���������������������������������������������������������������������������
@@ -218,12 +200,30 @@
}
}
}
- 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 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);
@@ -232,44 +232,61 @@
}
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);
}
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){
+ 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){
@@ -325,7 +342,266 @@
break;
}
}
+ 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);
+ 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);
+ 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);
+ }
+ AQI aqi = new AQI();
+ if (AQIMap.size()!=0){
+ aqi = AQIUtils.hourlyAQI(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(aqi.getAQIValue())){
+ avgMap.put("aqi",aqi.getAQIValue());
+ }else {
+ avgMap.put("aqi","");
+ }
+ if (!ObjectUtils.isEmpty(aqi.getPrimaryPollutantNames())){
+ if (Integer.parseInt(aqi.getAQIValue().toString())>50){
+ String pollutant = aqi.getPrimaryPollutantNames().toString();
+ pollutant = pollutant.replace("[","");
+ pollutant = pollutant.replace("]","");
+ avgMap.put("pollutant",pollutant);
+ }else {
+ avgMap.put("pollutant","-");
+ }
+ }else {
+ avgMap.put("aqi","");
+ }
+ 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;
+ case 24:hour_AVG.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","������");
data.add(hour_1);
data.add(hour_2);
data.add(hour_3);
@@ -350,9 +626,11 @@
data.add(hour_22);
data.add(hour_23);
data.add(hour_24);
+ data.add(hour_AVG);
resultMap.put("title",date+"������");
resultMap.put("data",data);
- resultMap.put("gocMonitorPoint",govMonitorPointList);
+ govMonitorPointList.add(govMonitorPoint_avg);
+ resultMap.put("govMonitorPoint",govMonitorPointList);
return resultMap;
}catch (Exception e){
e.printStackTrace();
--
Gitblit v1.8.0