| | |
| | | package com.moral.task; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Calendar; |
| | | import java.util.Collection; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.moral.service.AQIService; |
| | | import com.moral.util.HttpUtils; |
| | | import com.moral.util.WxMappingJackson2HttpMessageConverter; |
| | | |
| | | import com.xxl.job.core.biz.model.ReturnT; |
| | | import com.xxl.job.core.handler.annotation.XxlJob; |
| | | |
| | | import org.apache.commons.lang3.time.DateUtils; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.util.EntityUtils; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | @Component |
| | | public class AQIDataInsertTask { |
| | |
| | | @Resource |
| | | private RedisTemplate redisTemplate; |
| | | @XxlJob("insertData") |
| | | public ReturnT insertData(){ |
| | | public ReturnT insertData(String param){ |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | RestTemplate restTemplate = new RestTemplate(); |
| | | restTemplate.getMessageConverters().add(new WxMappingJackson2HttpMessageConverter()); |
| | |
| | | if (!ObjectUtils.isEmpty(data)) { |
| | | values = data.values(); |
| | | pubtime = format.parse(data.get("pubtime").toString()); |
| | | int hours = pubtime.getHours(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | int hour = calendar.get(Calendar.HOUR_OF_DAY); |
| | | if (hour != hours){ |
| | | pubtime = null; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if (ObjectUtils.isEmpty(entity) || ObjectUtils.isEmpty(values) || values.contains("None")) { |
| | | if (ObjectUtils.isEmpty(entity) || ObjectUtils.isEmpty(values) || values.contains("None") || pubtime == null) { |
| | | 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; |