|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.moral.api.entity.CityAqi; | 
|---|
|  |  |  | import com.moral.api.entity.GovMonitorPoint; | 
|---|
|  |  |  | import com.moral.api.entity.HistoryAqi; | 
|---|
|  |  |  | import com.moral.api.mapper.CityAqiMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.HistoryAqiMapper; | 
|---|
|  |  |  | import com.moral.api.service.GovMonitorPointService; | 
|---|
|  |  |  | import com.moral.api.service.HistoryAqiService; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.constant.RedisConstants; | 
|---|
|  |  |  | import com.moral.util.DateUtils; | 
|---|
|  |  |  | import com.xxl.job.core.context.XxlJobHelper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private HistoryAqiMapper historyAqiMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CityAqiMapper cityAqiMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RestTemplate restTemplate; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | //        String timeStr = DateUtils.dateToDateString(DateUtils.addHours(time, -1), DateUtils.yyyy_MM_dd_HH_mm_ss_EN); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        List<HistoryAqi> historyAqis = new ArrayList<>(); | 
|---|
|  |  |  | List<HistoryAqi> historyAqis = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (GovMonitorPoint govMonitorPoint : govMonitorPoints) { | 
|---|
|  |  |  | HistoryAqi historyAqi = new HistoryAqi(); | 
|---|
|  |  |  | 
|---|
|  |  |  | //存入数据库 | 
|---|
|  |  |  | historyAqi.setValue(JSONObject.toJSONString(map)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                historyAqis.add(historyAqi); | 
|---|
|  |  |  | historyAqis.add(historyAqi); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> value = new HashMap<>(); | 
|---|
|  |  |  | Object pm2_5 = map.get("pm2_5"); | 
|---|
|  |  |  | 
|---|
|  |  |  | value.put(Constants.SENSOR_CODE_O3, o3); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //aqi数据存入redis | 
|---|
|  |  |  | redisTemplate.opsForHash().put(RedisConstants.AQI_DATA, guid, value); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | historyAqiMapper.insert(historyAqi); | 
|---|
|  |  |  | CityAqi cityAqi = new CityAqi(); | 
|---|
|  |  |  | cityAqi.setCityCode(11111); | 
|---|
|  |  |  | cityAqi.setTime(DateUtils.addHours(time, -1)); | 
|---|
|  |  |  | cityAqi.setValue(JSONObject.toJSONString(map)); | 
|---|
|  |  |  | cityAqiMapper.insert(cityAqi); | 
|---|
|  |  |  | //                historyAqiMapper.insert(historyAqi); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | ResponseEntity<String> response; | 
|---|
|  |  |  | 
|---|
|  |  |  | //存入数据库 | 
|---|
|  |  |  | historyAqi.setValue(JSONObject.toJSONString(map)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                historyAqis.add(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.insert(historyAqi); | 
|---|
|  |  |  | //                historyAqiMapper.insert(historyAqi); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | CityAqi cityAqi = new CityAqi(); | 
|---|
|  |  |  | cityAqi.setCityCode(11111); | 
|---|
|  |  |  | cityAqi.setTime(DateUtils.addHours(time, -1)); | 
|---|
|  |  |  | cityAqi.setValue(JSONObject.toJSONString(map)); | 
|---|
|  |  |  | cityAqiMapper.insert(cityAqi); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(historyAqis)){ | 
|---|
|  |  |  | XxlJobHelper.log("数据不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //存入数据库 | 
|---|
|  |  |  | //        historyAqiMapper.insertHistoryAqi(historyAqis); | 
|---|
|  |  |  | historyAqiMapper.insertHistoryAqi(historyAqis); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|