jinpengyong
2020-09-21 cbcbb9aa45d119bced3d52d5370e14138372fcdb
windSpeed单位km/h->m/s
2 files modified
34 ■■■■ changed files
src/main/java/com/moral/service/impl/ForecastWeatherServiceImpl.java 27 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java 7 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/ForecastWeatherServiceImpl.java
@@ -1,5 +1,6 @@
package com.moral.service.impl;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -69,6 +70,7 @@
        Calendar c = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DecimalFormat df = new DecimalFormat("0.0");
        c.add(Calendar.DAY_OF_MONTH, 1);
        String nextDay = sdf.format(c.getTime());
        c.setTime(c.getTime());
@@ -121,6 +123,19 @@
            hashMap.put("parentCode", parentCode);
            hashSet.add(hashMap);
        }
        Map<String, Object> bmap = new HashMap<>();
        bmap.put("name1", "北京市");
        bmap.put("parentName", "北京市");
        bmap.put("cityCode", 110000);
        bmap.put("parentCode", 110000);
        hashSet.add(bmap);
        Map<String, Object> kunShanMap = new HashMap<>();
        kunShanMap.put("name1", "苏州市");
        kunShanMap.put("parentName", "江苏省");
        kunShanMap.put("cityCode", 320500);
        hashSet.add(kunShanMap);
        List<Element> elements = Dom4jUtils.readDocument();
        String cityID = "101190404";
        for (Map<String, Object> map : hashSet) {
@@ -174,6 +189,10 @@
            }
            nextDayList.remove(0);
            for (Map<String, Object> nextDayMap : nextDayList) {
                //风速km/h->m/s
                Double windSpeed = Double.valueOf(nextDayMap.get("windSpeed").toString());
                windSpeed = windSpeed * 1000 / 3600;
                nextDayMap.put("windSpeed",df.format(windSpeed));
                String text = nextDayMap.get("text").toString();
                String condition = "";
                if ("晴".equals(text)) {
@@ -188,7 +207,7 @@
                    condition = "20";
                } else if ("雨".equals(text)) {
                    condition = "0";
                }else {
                } else {
                    condition = "50";
                }
                nextDayMap.put("condition", condition);
@@ -235,7 +254,7 @@
                String nextDayTemp = dataMap.get("temp").toString();
                String nextDayCloud = dataMap.get("cloud").toString();
                Integer condition = Integer.valueOf(dataMap.get("condition").toString());
                Integer value=0;
                Integer value = 0;
                if (condition >= 80) {
                    value = 80;
                } else if (condition >= 40) {
@@ -340,7 +359,7 @@
                    Double b = Double.valueOf(cmap.get("b").toString());
                    double O3C = b * Double.valueOf(nextDayTemp) + a;
                    if (O3C < 1.0) {
                        O3C=1.0;
                        O3C = 1.0;
                    }
                    dataMap.put("O3C", String.valueOf(Math.round(O3C)));
                }
@@ -349,7 +368,7 @@
                    Double n = Double.valueOf(cmap.get("n").toString());
                    double beam = n * Double.valueOf(nextDayCloud) + m;
                    if (beam < 1.0) {
                        beam=0.0;
                        beam = 0.0;
                    }
                    dataMap.put("beam", String.valueOf(Math.round(beam)));
                }
src/main/java/com/moral/service/impl/RealWeatherServiceImpl.java
@@ -1,5 +1,6 @@
package com.moral.service.impl;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -51,6 +52,7 @@
    @Override
    public int insertRealWeather() throws ParseException {
        DecimalFormat df = new DecimalFormat("0.0");
        Calendar c = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -156,6 +158,11 @@
            resultMap.put("cityCode",map.get("cityCode").toString());
            resultMap.put("time",now);
            Map<String, Object> jsonMap = (Map<String, Object>) map.get("data");
            //风速km/h->m/s
            Double windSpeed = Double.valueOf(jsonMap.get("windSpeed").toString());
            windSpeed = windSpeed * 1000 / 3600;
            jsonMap.put("windSpeed",df.format(windSpeed));
            jsonMap.remove("obsTime");
            jsonMap.remove("icon");
            String text = jsonMap.get("text").toString();