From 1b4c6718db46841cbfff33b26336f3d1e5cb19d4 Mon Sep 17 00:00:00 2001
From: 于紫祥_1901 <email@yuzixiang_1910>
Date: Sat, 10 Oct 2020 11:31:50 +0800
Subject: [PATCH] update
---
src/main/java/com/moral/service/impl/WeatherServiceImpl.java | 130 +++++++++++++++++++++++--------------------
1 files changed, 70 insertions(+), 60 deletions(-)
diff --git a/src/main/java/com/moral/service/impl/WeatherServiceImpl.java b/src/main/java/com/moral/service/impl/WeatherServiceImpl.java
index 4010f85..a370f6e 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);
}
@@ -387,7 +387,18 @@
}
parameters.put("cityCode", code);
parameters.put("name", name);
- String time = parameters.get("time").toString();
+ String string = parameters.get("time").toString();
+ String year = string.substring(0, 4);
+ String[] split = string.substring(5).split("-");
+ String month = split[0];
+ String day = split[1];
+ if (split[0].length() < 2) {
+ month = 0 + split[0];
+ }
+ if (split[1].length() < 2) {
+ day = 0 + split[1];
+ }
+ String time = year + "-" + month + "-" + day;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date now = new Date();
@@ -490,7 +501,6 @@
}
}
}
-
DecimalFormat df = new DecimalFormat(".####");
DecimalFormat df1 = new DecimalFormat("#.#");
List<Map<String, Object>> realAqilist = new ArrayList<>();
@@ -591,7 +601,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 {
@@ -602,22 +612,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();
@@ -627,55 +661,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<>();
@@ -733,9 +737,15 @@
map.put("COC", map.get("CO").toString());
map.remove("CO");
}
- if ((!map.containsKey("PM25C")) && map.containsKey("PM2_5")) {
- map.put("PM25C", map.get("PM2_5").toString().replace("\\.", ""));
- map.remove("PM2_5");
+ 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) {
+ map.put("PM25C", map.get("PM25").toString().replace("\\.", ""));
+ map.remove("PM25");
+ }
}
if ((!map.containsKey("PM10C")) && map.containsKey("PM10")) {
map.put("PM10C", map.get("PM10").toString().replace("\\.", ""));
--
Gitblit v1.8.0