|  |  |  | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  | import org.springframework.web.client.RestTemplate; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | 
|---|
|  |  |  | List<GovMonitorPoint> govMonitorPoints = govMonitorPointService.list(queryWrapper); | 
|---|
|  |  |  | Date time = DateUtils.dataToTimeStampTime(new Date(), DateUtils.yyyy_MM_dd_HH_EN); | 
|---|
|  |  |  | String timeStr = DateUtils.dateToDateString(time, DateUtils.yyyy_MM_dd_HH_mm_ss_EN); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<HistoryAqi> historyAqis = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (GovMonitorPoint govMonitorPoint : govMonitorPoints) { | 
|---|
|  |  |  | HistoryAqi historyAqi = new HistoryAqi(); | 
|---|
|  |  |  | String guid = govMonitorPoint.getGuid(); | 
|---|
|  |  |  | ResponseEntity<String> response; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(map)) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | HistoryAqi historyAqi = new HistoryAqi(); | 
|---|
|  |  |  | historyAqi.setGuid(guid); | 
|---|
|  |  |  | historyAqi.setTime(DateUtils.addHours(time, -1)); | 
|---|
|  |  |  | //存入数据库 | 
|---|
|  |  |  | historyAqi.setValue(JSONObject.toJSONString(map)); | 
|---|
|  |  |  | historyAqiMapper.insert(historyAqi); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | historyAqis.add(historyAqi); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> value = new HashMap<>(); | 
|---|
|  |  |  | Object pm2_5 = map.get("pm2_5"); | 
|---|
|  |  |  | 
|---|
|  |  |  | //aqi数据存入redis | 
|---|
|  |  |  | redisTemplate.opsForHash().put(RedisConstants.AQI_DATA, guid, value); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //存入数据库 | 
|---|
|  |  |  | historyAqiMapper.insertHistoryAqi(historyAqis); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return historyAqi; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<HistoryAqi> getHistoryAqi() { | 
|---|
|  |  |  | String time = DateUtils.getDateStringOfHour(-1, DateUtils.yyyy_MM_dd_HH_EN) + ":00:00"; | 
|---|
|  |  |  | QueryWrapper<HistoryAqi> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("time", time); | 
|---|
|  |  |  | return historyAqiMapper.selectList(queryWrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|