| | |
| | | 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", |
| | |
| | | ); |
| | | 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()); |