From 3d685203e77cd8deb2982856ee70f4d51d7ce8db Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Fri, 20 May 2022 11:33:42 +0800
Subject: [PATCH] 千灯转发数据添加恶臭两台微站数据
---
src/main/java/com/moral/service/impl/AQIServiceImpl.java | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/moral/service/impl/AQIServiceImpl.java b/src/main/java/com/moral/service/impl/AQIServiceImpl.java
index 3ae2ebc..231f3f6 100644
--- a/src/main/java/com/moral/service/impl/AQIServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/AQIServiceImpl.java
@@ -1,16 +1,31 @@
package com.moral.service.impl;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
import com.moral.mapper.AQIMapper;
import com.moral.service.AQIService;
+import com.moral.util.HttpUtils;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;
+import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
@Service
public class AQIServiceImpl implements AQIService {
@Resource
private AQIMapper aqiMapper;
+
@Override
public List<Map<String, Object>> getCityAqiConfig() {
return aqiMapper.getCityAqiConfig();
@@ -20,4 +35,48 @@
public int insertAQIData(Map<String, Object> parameters) {
return aqiMapper.insertAQIData(parameters);
}
+
+ @Override
+ public int insertStationData() {
+ int state = 500;
+ List<Map<String, Object>> stationCodes = aqiMapper.getStationConfig();
+ String host = "https://api.epmap.org";
+ String path = "/api/v1/air/station";
+ String method = "GET";
+ String appcode = "31b6ea8f804a4472be3b633cfee44849";
+ Map<String, String> headers = new HashMap<String, String>();
+ headers.put("Authorization", "APPCODE " + appcode);
+ Map<String, String> querys = new HashMap<String, String>();
+ Date date = new Date();
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH");
+ String pubtime = df.format(date) + ":00:00";
+ querys.put("pubtime", pubtime);
+ List<Map<String, Object>> insertList = new ArrayList<>();
+ for (Map<String, Object> stationMap : stationCodes) {
+ String stationCode = stationMap.get("station_code").toString();
+ String cityCode = stationMap.get("city_code").toString();
+ Map<String, Object> map = new HashMap<>();
+ querys.put("station_code", stationCode);
+ try {
+ HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
+ JSONObject json = JSON.parseObject(EntityUtils.toString(response.getEntity()));
+ Map<String, Object> data = (Map<String, Object>) json.get("data");
+ if (!ObjectUtils.isEmpty(data)) {
+ pubtime = data.get("pubtime").toString();
+ map.put("time", pubtime);
+ map.put("json", JSON.toJSONString(data));
+ map.put("stationCode", stationCode);
+ map.put("cityCode", cityCode);
+ insertList.add(map);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ if (!insertList.isEmpty()) {
+ aqiMapper.insertStationData(insertList);
+ state = 200;
+ }
+ return state;
+ }
}
--
Gitblit v1.8.0