From bb77c5e3089fc3e9ccb520625b7798d81c99bfa2 Mon Sep 17 00:00:00 2001
From: 于紫祥_1901 <email@yuzixiang_1910>
Date: Fri, 06 Nov 2020 13:55:15 +0800
Subject: [PATCH] update
---
src/main/java/com/moral/service/impl/WeatherServiceImpl.java | 147 +++++++++++++++++++++++++++----------------------
1 files changed, 81 insertions(+), 66 deletions(-)
diff --git a/src/main/java/com/moral/service/impl/WeatherServiceImpl.java b/src/main/java/com/moral/service/impl/WeatherServiceImpl.java
index 5c6d0e4..2a64f27 100644
--- a/src/main/java/com/moral/service/impl/WeatherServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/WeatherServiceImpl.java
@@ -205,14 +205,14 @@
List<Map<String, Object>> aqiList = hangzhouAqiMapper.getAqiDataByAreaCode(parameters);
List<Map<String, Object>> forecastList = forecastWeatherMapper.getForecastHour(parameters);
- String timeUnits=time.substring(5,7);
- if(aqiList.size() == 0){
+ String timeUnits = time.substring(5, 7);
+ if (aqiList.size() == 0) {
parameters.put("timeUnits", timeUnits);
aqiList = hangzhouAqiMapper.getHistoryO3(parameters);
if (aqiList.size() == 0) {
parameters.put("cityCode", monitorPoint.getCityCode());
aqiList = hangzhouAqiMapper.getAqiDataByAreaCode(parameters);
- if(aqiList.size() == 0){
+ if (aqiList.size() == 0) {
parameters.put("cityCode", monitorPoint.getAreaCode());
aqiList = hangzhouAqiMapper.getHistoryO3(parameters);
}
@@ -501,7 +501,6 @@
}
}
}
-
DecimalFormat df = new DecimalFormat(".####");
DecimalFormat df1 = new DecimalFormat("#.#");
List<Map<String, Object>> realAqilist = new ArrayList<>();
@@ -570,6 +569,7 @@
//������������
int x = 0;
+ parameters.put("cityCode", code);
List<Map<String, Object>> realList = realWeatherMapper.getRealWeather(parameters);
if (realList.size() == 0) {
//1-23���������������������������������������������������������������������
@@ -602,7 +602,7 @@
for (Map<String, Object> realMap : realList) {
Map<String, Object> hashMap = new HashMap<>();
hashMap.put("time", realMap.get("time"));
- Map<String, Object> jsonMap = new HashMap<>();
+ Map<String, Object> jsonMap;
if (x == 0) {
jsonMap = (Map<String, Object>) JSONObject.parse(realMap.get("json").toString());
} else {
@@ -613,22 +613,46 @@
realWeatherList.add(hashMap);
}
- for (Map<String, Object> realMap : realWeatherList) {
- String rtime = realMap.get("time").toString();
- //������������
- for (Map<String, Object> beamMap : beamList) {
- if (beamMap.get("time").equals(rtime)) {
- realMap.put("beam", beamMap.get("beam").toString());
- }
- }
- //TVOC
+ //Tvoc,������������
+ for (Map<String, Object> beamMap : beamList) {
for (Map<String, Object> tvocMap : tvocList) {
- if (tvocMap.get("time").equals(rtime)) {
- realMap.put("TVOC", tvocMap.get("TVOC").toString());
+ Object bTime = beamMap.get("time");
+ Object Ttime = tvocMap.get("time");
+ if (bTime.equals(Ttime)) {
+ beamMap.putAll(tvocMap);
}
}
+ }
+
+ List<Map<String, Object>> list = new ArrayList<>();
+ for (int i = 0; i < 24; i++) {
+ Map<String, Object> map = new HashMap<>();
+ String tt = time + " " + (i + 1) + ":00:00";
+ if ((i + 1) < 10) {
+ tt = time + " 0" + (i + 1) + ":00:00";
+ } else if (i == 23) {
+ tt = sdf.format(end) + " 00:00:00";
+ }
+ map.put("time", tt);
+ list.add(map);
+ }
+
+ for (Map<String, Object> map1 : list) {
+ String time1 = map1.get("time").toString();
+ for (Map<String, Object> map2 : beamList) {
+ if (time1.equals(map2.get("time"))) {
+ map1.putAll(map2);
+ }
+ }
+
+ for (Map<String, Object> realMap : realWeatherList) {
+ if (time1.equals(realMap.get("time"))) {
+ map1.putAll(realMap);
+ }
+ }
+
//������6���������������(������)
- Date endTime = sdf1.parse(rtime);
+ Date endTime = sdf1.parse(time1);
cal.setTime(endTime);
cal.add(Calendar.HOUR, -6);
Date startTime = cal.getTime();
@@ -638,55 +662,25 @@
hashMap.put("end", endTime);
Map<String, Object> precip6HourMap = realWeatherMapper.getPrecip6Hour(hashMap);
if (precip6HourMap != null) {
- realMap.put("precip6", precip6HourMap.get("precip6").toString());
+ map1.put("precip6", precip6HourMap.get("precip6").toString());
}
}
- List<Map<String, Object>> list = new ArrayList<>();
- for (int i = 0; i < 24; i++) {
- list.add(null);
- }
-
- for (Map<String, Object> map : realWeatherList) {
- Integer t1 = Integer.valueOf(map.get("time").toString().split(" ")[1].split(":")[0]);
- if (t1 == 0) {
- list.set(list.size() - 1, map);
- } else {
- list.set(t1 - 1, map);
- }
- }
-
- for (Map<String, Object> map : realAqilist) {
- Integer t1 = Integer.valueOf(map.get("time").toString().split(" ")[1].split(":")[0]);
- if (t1 == 0) {
- Map<String, Object> map1 = list.get(list.size() - 1);
- if (map1 == null) {
- list.set(list.size() - 1, map);
- } else {
- map1.putAll(map);
- list.set(list.size() - 1, map1);
- }
- } else {
- Map<String, Object> map1 = list.get(t1 - 1);
- if (map1 == null) {
- list.set(t1 - 1, map);
- } else {
- map1.putAll(map);
- list.set(t1 - 1, map1);
+ for (Map<String, Object> listMap : list) {
+ listMap.put("type", "������");
+ listMap.put("city", name);
+ String time1 = listMap.get("time").toString();
+ for (Map<String, Object> aqiMap : realAqilist) {
+ if (time1.equals(aqiMap.get("time"))) {
+ listMap.putAll(aqiMap);
}
}
- }
- list.removeAll(Collections.singleton(null));
- for (Map<String, Object> map : list) {
- map.put("type", "������");
- map.put("city", name);
}
List<Map<String, Object>> resultList = new ArrayList<>();
-
if (foreList.size() == 0) {
cal.setTime(selectTime);
- for (long d = cal.getTimeInMillis(); d <= end.getTime();
+ for (long d = cal.getTimeInMillis(); d < end.getTime();
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) + 1),
d = cal.getTimeInMillis()) {
Map<String, Object> hashMap = new LinkedHashMap<>();
@@ -744,12 +738,12 @@
map.put("COC", map.get("CO").toString());
map.remove("CO");
}
- if ((!map.containsKey("PM25C")) && (map.containsKey("PM2_5")||map.containsKey("PM25"))) {
+ if ((!map.containsKey("PM25C")) && (map.containsKey("PM2_5") || map.containsKey("PM25"))) {
if (map.get("PM2_5") != null) {
map.put("PM25C", map.get("PM2_5").toString().replace("\\.", ""));
map.remove("PM2_5");
}
- if(map.get("PM25") != null){
+ if (map.get("PM25") != null) {
map.put("PM25C", map.get("PM25").toString().replace("\\.", ""));
map.remove("PM25");
}
@@ -804,20 +798,28 @@
if (rhour == nowHour) {
Map<String, Object> sumO3Map = hangzhouAqiMapper.getSumO3(hashMap);
- double v = value - Double.valueOf(sumO3Map.get("O3Sum").toString());
- resultMap.put("goodValue", v);
+ if (sumO3Map != null) {
+ double v = value - Double.valueOf(sumO3Map.get("O3Sum").toString());
+ resultMap.put("goodValue", v);
+ }
} else if (rhour == nowHour + 1) {
Map<String, Object> sumO3Map = hangzhouAqiMapper.getSumO3(hashMap);
- double v = (value - Double.valueOf(sumO3Map.get("O3Sum").toString())) / 2;
- resultMap.put("goodValue", String.valueOf(Math.round(v)));
+ if (sumO3Map != null) {
+ double v = (value - Double.valueOf(sumO3Map.get("O3Sum").toString())) / 2;
+ resultMap.put("goodValue", String.valueOf(Math.round(v)));
+ }
} else if (rhour == nowHour + 2) {
Map<String, Object> sumO3Map = hangzhouAqiMapper.getSumO3(hashMap);
- double v = (value - Double.valueOf(sumO3Map.get("O3Sum").toString())) / 3;
- resultMap.put("goodValue", String.valueOf(Math.round(v)));
+ if (sumO3Map != null) {
+ double v = (value - Double.valueOf(sumO3Map.get("O3Sum").toString())) / 3;
+ resultMap.put("goodValue", String.valueOf(Math.round(v)));
+ }
} else if (rhour == nowHour + 3) {
Map<String, Object> sumO3Map = hangzhouAqiMapper.getSumO3(hashMap);
- double v = (value - Double.valueOf(sumO3Map.get("O3Sum").toString())) / 4;
- resultMap.put("goodValue", String.valueOf(Math.round(v)));
+ if (sumO3Map != null) {
+ double v = (value - Double.valueOf(sumO3Map.get("O3Sum").toString())) / 4;
+ resultMap.put("goodValue", String.valueOf(Math.round(v)));
+ }
}
}
}
@@ -840,6 +842,19 @@
map.put("river", geographyMap.get("river").toString());
}
}
+ for (int i = 0; i < resultList.size(); i = i + 2) {
+ Map<String, Object> foreMap = resultList.get(i);
+ Map<String, Object> realMap = resultList.get(i + 1);
+ if (foreMap.get("O3C") != null && realMap.get("O3C") != null) {
+ Double foreO3 = Double.valueOf(foreMap.get("O3C").toString());
+ Double realO3 = Double.valueOf(realMap.get("O3C").toString());
+ int round = (int) Math.round((realO3 - foreO3) / realO3 * 100);
+ if (round < 0) {
+ round = -round;
+ }
+ realMap.put("errorRate", round + "%");
+ }
+ }
return resultList;
}
}
--
Gitblit v1.8.0