于紫祥_1901
2020-11-18 d0fe2eb9cefc7e3bfdddc5fa66633057c42697fc
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,9 +738,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("\\.", ""));
@@ -798,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)));
                        }
                    }
                }
            }
@@ -819,19 +827,39 @@
        //地理特征
        Map<String, Object> geographyMap = shAreaMapper.getGeography(name);
        for (Map<String, Object> map : resultList) {
            double longitude = Double.valueOf(geographyMap.get("lng").toString());
            double latitude = Double.valueOf(geographyMap.get("lat").toString());
            map.put("longitude", df.format(longitude));
            map.put("latitude", df.format(latitude));
            if (geographyMap.get("altitude") != null) {
                map.put("altitude", geographyMap.get("altitude").toString());
        if (geographyMap != null) {
            for (Map<String, Object> map : resultList) {
                if (geographyMap.get("lng") != null) {
                    double longitude = Double.valueOf(geographyMap.get("lng").toString());
                    map.put("longitude", df.format(longitude));
                }
                if (geographyMap.get("lat") != null) {
                    double latitude = Double.valueOf(geographyMap.get("lat").toString());
                    map.put("latitude", df.format(latitude));
                }
                if (geographyMap.get("altitude") != null) {
                    map.put("altitude", geographyMap.get("altitude").toString());
                }
                if (geographyMap.get("vegetation") != null) {
                    map.put("vegetation", geographyMap.get("vegetation").toString());
                }
                if (geographyMap.get("river") != null) {
                    map.put("river", geographyMap.get("river").toString());
                }
            }
            if (geographyMap.get("vegetation") != null) {
                map.put("vegetation", geographyMap.get("vegetation").toString());
            }
            if (geographyMap.get("river") != null) {
                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;