lizijie
2022-08-15 d0857416b2d72cac3b5b3cac449907c66feac737
src/main/java/com/moral/service/impl/WeatherServiceImpl.java
@@ -67,13 +67,17 @@
        ks.put("cityCode", 320583);
        ks.put("cityId", 101190404);
        cityList.add(ks);
        int count = 0;
        Map<String, Object> hq = new HashMap<>();
        hq.put("cityCode", 320505);
        hq.put("cityId", 101190406);
        cityList.add(hq);
        int state = 200;
        for (Map<String, Object> map : cityList) {
            String cityCode = map.get("cityCode").toString();
            String id = map.get("cityId").toString();
            Map<String, Object> dataMap = restTemplate.getForObject("https://api.heweather.net/v7/weather/72h?key=da05c6c4852d4f7aa3364a9236ee9e26&gzip=n&location={1}", Map.class, id);
            if (dataMap == null) {
                return count;
            if (!dataMap.get("code").equals("200")) {
                return 500;
            }
            String json = JSONObject.toJSONString(dataMap);
            dataMap = (Map<String, Object>) JSONObject.parse(json);
@@ -261,9 +265,9 @@
            parameters.put("end", c.getTime());
            parameters.put("cityCode", cityCode);
            weatherMapper.deleteByTime(parameters);
            count = count + weatherMapper.insertForecastWeather(resultList);
            weatherMapper.insertForecastWeather(resultList);
        }
        return count;
        return state;
    }
    private List<Map<String, Object>> getSample(Map<String, Object> params, List<Integer> years) {
@@ -348,15 +352,15 @@
        RestTemplate restTemplate = new RestTemplate();
        c.setTime(new Date());
        Date endTime = sdf.parse(sdf.format(c.getTime()));
        c.add(Calendar.MONTH, -2);
        c.add(Calendar.MONTH, -1);
        Date startTime = sdf.parse(sdf.format(c.getTime()));
        int count = 0;
        int state = 200;
        List<Map<String, Object>> cityList = weatherMapper.getCityWeatherConfig();
        for (Map<String, Object> map : cityList) {
            String id = map.get("cityId").toString();
            Map<String, Object> dataMap = restTemplate.getForObject("https://api.heweather.net/v7/weather/72h?key=da05c6c4852d4f7aa3364a9236ee9e26&gzip=n&location={1}", Map.class, id);
            if (dataMap == null) {
                return count;
            if (!dataMap.get("code").equals("200")) {
                return 500;
            }
            String json = JSONObject.toJSONString(dataMap);
            dataMap = (Map<String, Object>) JSONObject.parse(json);
@@ -514,8 +518,8 @@
                        sum2 = sum2 + temp * temp;
                    }
                    //光照
                    double cloud = Double.valueOf(listMap.get("cloud").toString().replace("\"", "").split("\\.")[0]);
                    if (listMap.get("beam") != null) {
                    if (listMap.get("beam") != null&&listMap.get("cloud") != null) {
                        double cloud = Double.valueOf(listMap.get("cloud").toString().replace("\"", "").split("\\.")[0]);
                        double beam = Double.valueOf(listMap.get("beam").toString().replace("\"", "").split("\\.")[0]);
                        cloudSum = cloudSum + cloud;
                        beamSum = beamSum + beam;
@@ -569,9 +573,9 @@
            parameters.put("end", end);
            parameters.put("cityCode", cityCode);
            weatherMapper.deleteByTime(parameters);
            count = count + weatherMapper.insertForecastWeather(resultList);
            weatherMapper.insertForecastWeather(resultList);
        }
        return count;
        return state;
    }
    @Override
@@ -583,12 +587,12 @@
        Date now = sdf1.parse(sdf.format(c.getTime()) + ":00:00");
        RestTemplate restTemplate = new RestTemplate();
        List<Map<String, Object>> cityList = weatherMapper.getCityWeatherConfig();
        int count = 0;
        int state = 200;
        for (Map<String, Object> map : cityList) {
            String id = map.get("cityId").toString();
            Map<String, Object> dataMap = restTemplate.getForObject("https://api.heweather.net/v7/weather/now?key=da05c6c4852d4f7aa3364a9236ee9e26&gzip=n&location={1}", Map.class, id);
            if (dataMap == null) {
                return count;
            if (!dataMap.get("code").equals("200")) {
                return 500;
            }
            String json = JSONObject.toJSONString(dataMap);
            dataMap = (Map<String, Object>) JSONObject.parse(json);
@@ -614,7 +618,8 @@
            resultList.add(resultMap);
        }
        weatherMapper.deleteRealWeather(sdf1.format(now));
        return weatherMapper.insertRealWeather(resultList);
        weatherMapper.insertRealWeather(resultList);
        return state;
    }
    private int getWindScale(Double windSpeed) {