yuzixiang
2020-05-25 677819231dd95da18e645fbaca6b9557e576a3a3
src/main/java/com/moral/task/AQIDataInsertTask.java
@@ -32,8 +32,10 @@
        Date pubtime = DateUtils.truncate(new Date(),Calendar.HOUR);
        List<Map<String,Object>> CityAqiConfigs =aqiService.getCityAqiConfig();
        ReturnT returnT = null;
        for (Map<String, Object> cityAqiConfig : CityAqiConfigs) {
            String entity = null ;
            Collection<Object> values = null;
            Map<String, Object> data = null;
            try {
                HttpResponse response = HttpUtils.doGet("https://api.epmap.org", "/api/v1/air/city", "GET",
@@ -42,15 +44,28 @@
                );
                entity = EntityUtils.toString(response.getEntity());
                JSONObject json = JSON.parseObject(entity);
                data = (Map<String, Object>) json.get("data");
                if (!ObjectUtils.isEmpty(data)) {
                    values = data.values();
                    pubtime = format.parse(data.get("pubtime").toString());
                }else {
                    continue;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (ObjectUtils.isEmpty(entity) || ObjectUtils.isEmpty(values) || values.contains("None")) {
                Map<String, Object> mjMap = restTemplate.getForObject("http://sapi.7drlb.com/api/mj?cityID={1}&apiKey=aqi", Map.class, cityAqiConfig.get("city_id"));
                if (ObjectUtils.isEmpty(mjMap)) {
                    continue;
                } else {
                    data = (Map<String, Object>) ((Map) mjMap.get("data")).get("aqi");
                    data.put("aqi", data.remove("value"));
                    data.put("PM2_5", data.remove("pm25"));
                    pubtime = new Date(Long.valueOf(data.get("pubtime").toString()));
                    String string = JSONObject.toJSONString(data).toUpperCase();
                    data = (Map<String, Object>) JSON.parse(string);
                }
            }
            Map<String, Object> parameters = new HashMap<>();
            parameters.put("time",pubtime);
            parameters.put("data",data.toString());