diff --git a/src/main/java/com/cm/tenlion/pollutantdata/controller/app/resource/instrument/InstrumentAppResourceController.java b/src/main/java/com/cm/tenlion/pollutantdata/controller/app/resource/instrument/InstrumentAppResourceController.java index fba0560..1f319f4 100644 --- a/src/main/java/com/cm/tenlion/pollutantdata/controller/app/resource/instrument/InstrumentAppResourceController.java +++ b/src/main/java/com/cm/tenlion/pollutantdata/controller/app/resource/instrument/InstrumentAppResourceController.java @@ -9,6 +9,7 @@ import com.cm.common.result.SuccessResultList; import com.cm.tenlion.pollutantdata.controller.app.resource.BigDataResult; import com.cm.tenlion.pollutantdata.pojo.dtos.instrument.InstrumentDTO; import com.cm.tenlion.pollutantdata.service.instrument.IInstrumentService; +import com.cm.tenlion.pollutantdata.utils.WeatherUtil; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -82,7 +83,17 @@ public class InstrumentAppResourceController extends AbstractController { - + @ApiOperation(value = "天气查询", notes = "天气查询接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "区域ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("queryweather") + public BigDataResult queryWeather(String id) throws Exception { + BigDataResult result = new BigDataResult(); + result.setData(WeatherUtil.getWeather(id)); + return result; + } diff --git a/src/main/java/com/cm/tenlion/pollutantdata/utils/HttpUtil.java b/src/main/java/com/cm/tenlion/pollutantdata/utils/HttpUtil.java new file mode 100644 index 0000000..406dae1 --- /dev/null +++ b/src/main/java/com/cm/tenlion/pollutantdata/utils/HttpUtil.java @@ -0,0 +1,156 @@ +package com.cm.tenlion.pollutantdata.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; +import java.util.Map; +import java.util.Map.Entry; + +/** + * 网络请求发送 + * ClassName: HttpUtil + * @Description: TODO + * 创建工具: IDEA + * 运行环境: [Tomcat7以上,MySql5.6以上,JDK7以上] + * @author 崔宝铖 + * @date 2019年6月19日 + */ +public class HttpUtil { + + /** 请求超时时间 */ + private static Integer TIMEOUT = 3000; + + /** + * Post请求 + * @Description: TODO + * @param @param postUrl + * @param @param param + * @param @return + * @return String + * @throws IOException + * @throws + * @author 崔宝铖 + * @date 2019年6月19日 + */ + public static String doPost(String postUrl, Map param) throws IOException { + // 封装发送的请求参数 + StringBuffer buffer = new StringBuffer(); + int x = 0; + for(Entry map : param.entrySet()) { + buffer.append(map.getKey()).append("=").append(map.getValue().toString()); + if(x != param.size()-1) { + buffer.append("&"); + } + x++; + } + URL url = new URL(postUrl); + URLConnection urlConnection = url.openConnection(); + HttpURLConnection httpUrlConnection = (HttpURLConnection) urlConnection; + httpUrlConnection.setConnectTimeout(TIMEOUT); + // 设置请求头属性参数 + httpUrlConnection.setRequestProperty("charset", "UTF-8"); + httpUrlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + httpUrlConnection.setRequestProperty("accept", "application/json"); + // 发送POST请求必须设置如下两行 + httpUrlConnection.setDoOutput(true); + httpUrlConnection.setDoInput(true); + String response = "";// 响应内容 + String status = "";// 响应状态 + PrintWriter out = null; + BufferedReader in = null; + try{ + // 获取URLConnection对象对应的输出流 + out = new PrintWriter(httpUrlConnection.getOutputStream()); + // 发送请求参数 + out.write(buffer.toString()); + // flush输出流的缓冲 + out.flush(); + httpUrlConnection.connect(); + // 定义BufferedReader输入流来读取URL的响应数据 + in = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream(), "UTF-8")); + String line; + while ((line = in.readLine()) != null) { + response += line; + } + // 获得URL的响应状态码 + status = new Integer(httpUrlConnection.getResponseCode()).toString(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + try { + if (out != null) { out.close();} + if (in != null) {in.close();} + } catch (Exception ex) { + ex.printStackTrace(); + } + } + if(!"200".equals(status)) { + return null; + } + return response; + } + + /** + * Get请求 + * @Description: TODO + * @param @param getUrl 请求地址 + * @param @param param 请求参数 + * @param @return + * @param @throws Exception + * @return RetBody + * @throws + * @author 崔宝铖 + * @date 2019年6月19日 + */ + public static String doGet(String getUrl, Map param) throws Exception { + // 封装发送的请求参数 + StringBuffer buffer = new StringBuffer(); + int x = 0; + for(Entry map : param.entrySet()) { + buffer.append(map.getKey()).append("=").append(map.getValue().toString()); + if(x != param.size()-1) { + buffer.append("&"); + } + x++; + } + URL url = new URL(getUrl+"?"+buffer.toString()); + URLConnection urlConnection = url.openConnection(); + HttpURLConnection httpUrlConnection = (HttpURLConnection) urlConnection; + httpUrlConnection.setConnectTimeout(TIMEOUT); + // 设置请求头属性参数 + httpUrlConnection.setRequestProperty("charset", "UTF-8"); + httpUrlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + httpUrlConnection.setRequestProperty("accept", "application/json"); + String response = "";// 响应内容 + String status = "";// 响应状态6 + PrintWriter out = null; + BufferedReader in = null; + try{ + httpUrlConnection.connect(); + // 定义BufferedReader输入流来读取URL的响应数据 + in = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream(), "UTF-8")); + String line; + while ((line = in.readLine()) != null) { + response += line; + } + // 获得URL的响应状态码 + status = new Integer(httpUrlConnection.getResponseCode()).toString(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + try { + if (out != null) { out.close();} + if (in != null) {in.close();} + } catch (Exception ex) { + } + } + if(!"200".equals(status)) { + return null; + } + return response; + } +} diff --git a/src/main/java/com/cm/tenlion/pollutantdata/utils/WeatherUtil.java b/src/main/java/com/cm/tenlion/pollutantdata/utils/WeatherUtil.java new file mode 100644 index 0000000..e4a6a36 --- /dev/null +++ b/src/main/java/com/cm/tenlion/pollutantdata/utils/WeatherUtil.java @@ -0,0 +1,55 @@ +package com.cm.tenlion.pollutantdata.utils; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class WeatherUtil { + + private final static String url = "https://api.seniverse.com/v3/weather/now.json"; + + private final static ConcurrentHashMap> weather = new ConcurrentHashMap(); + + public final static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyyMMddHH"); + + public static Map getWeather(String id) throws Exception { + String date = sdfTime.format(new Date()); + if (weather.get(id + "_" + date) != null) { + return weather.get(id + "_" + date); + } + Map params = new HashMap(); + params.put("key", "Sk1Gt66B1Z-ZsEJP5"); + params.put("location", id); + params.put("language", "zh-Hans"); + params.put("unit", "c"); + String result = HttpUtil.doGet(url, params); + System.out.println("天气预报返回 : " + result); + JSONObject jsonObject = JSONObject.parseObject(result); + JSONArray array = jsonObject.getJSONArray("results"); + Map resultMap = new HashMap(); + if(array.size() > 0) { + JSONObject object = array.getJSONObject(0).getJSONObject("now"); + JSONObject location = array.getJSONObject(0).getJSONObject("location"); + String text = object.getString("text"); + String temperature = object.getString("temperature"); + String code = object.getString("code"); + resultMap.put("text", text); + resultMap.put("temperature", temperature); + resultMap.put("code", code); + resultMap.put("city", location.getString("name")); + weather.put(id + "_" + date, resultMap); + System.out.println(resultMap.toString()); + } + return resultMap; + } + + public static void main(String[] args) throws Exception { + WeatherUtil.getWeather("WRR2Q2Z7CXWM"); + } + +} diff --git a/src/main/resources/static/route/bigdatamain/bendanweirenwu.html b/src/main/resources/static/route/bigdatamain/bendanweirenwu.html index 95217a8..9c4af59 100644 --- a/src/main/resources/static/route/bigdatamain/bendanweirenwu.html +++ b/src/main/resources/static/route/bigdatamain/bendanweirenwu.html @@ -4,24 +4,24 @@ 本单位任务信息二级页(2) - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -437,30 +437,30 @@ // return mapData; // } // 请求参数拼接 - function getSqlData(module, areaId, params) { - var serverData = { - state:'400', - msg:'执行失败', - list:[], - data:{} - }; - $.ajax({ - url: 'http://117.161.31.148:8098/dataview/app/bigdatatemplate/querydatarelease/' + areaId, - cache: false, - data: params, - type: "GET", - async: false, - dataType: "json", - success: function(response){ - console.log(module + "网络接口请求结果"); - console.log(response); - serverData = response; - },error: function(response) { - console.error(module + '网络接口请求失败'); - console.log(response); - } - }); - return serverData; + // function getSqlData(module, areaId, params) { + // var serverData = { + // state:'400', + // msg:'执行失败', + // list:[], + // data:{} + // }; + // $.ajax({ + // url: 'http://117.161.31.148:8098/dataview/app/bigdatatemplate/querydatarelease/' + areaId, + // cache: false, + // data: params, + // type: "GET", + // async: false, + // dataType: "json", + // success: function(response){ + // console.log(module + "网络接口请求结果"); + // console.log(response); + // serverData = response; + // },error: function(response) { + // console.error(module + '网络接口请求失败'); + // console.log(response); + // } + // }); + // return serverData; } // Ajax接口数据获取 function getJsonData(module, url, params) { @@ -704,7 +704,7 @@ z-index: 9999 !important; } .C0002_button:hover{ - color: rgba(255, 184, 0, 0.39) !important; + background-color: rgba(240, 240, 240, 0.39) !important; } - + \ No newline at end of file diff --git a/src/main/resources/static/route/bigdatamain/enterpriseof.html b/src/main/resources/static/route/bigdatamain/enterpriseof.html index 67f243e..d809689 100644 --- a/src/main/resources/static/route/bigdatamain/enterpriseof.html +++ b/src/main/resources/static/route/bigdatamain/enterpriseof.html @@ -4,24 +4,24 @@ 网格化监管人员信息(2) - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -565,7 +565,7 @@ z-index: 9999 !important; } .C0002_button:hover{ - color: rgba(255, 184, 0, 0.39) !important; + background-color: rgba(240, 240, 240, 0.39) !important; } - + \ No newline at end of file diff --git a/src/main/resources/static/route/bigdatamain/inspection/enterprise/update-enterprise-pollution.html b/src/main/resources/static/route/bigdatamain/inspection/enterprise/update-enterprise-pollution.html index e9e687c..49e2a0c 100644 --- a/src/main/resources/static/route/bigdatamain/inspection/enterprise/update-enterprise-pollution.html +++ b/src/main/resources/static/route/bigdatamain/inspection/enterprise/update-enterprise-pollution.html @@ -32,7 +32,7 @@ - + diff --git a/src/main/resources/static/route/bigdatamain/main.html b/src/main/resources/static/route/bigdatamain/main.html index 8f1763a..a47ce40 100644 --- a/src/main/resources/static/route/bigdatamain/main.html +++ b/src/main/resources/static/route/bigdatamain/main.html @@ -5,25 +5,24 @@ 乌兰察布市生态委数据总览 - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -410,7 +416,7 @@ var initParticlesJs = function() {
- +
@@ -421,6 +427,7 @@ var initParticlesJs = function() {
+
- + \ No newline at end of file diff --git a/src/main/resources/static/route/bigdatamain/qiyexinxi.html b/src/main/resources/static/route/bigdatamain/qiyexinxi.html index d0440bb..0e12894 100644 --- a/src/main/resources/static/route/bigdatamain/qiyexinxi.html +++ b/src/main/resources/static/route/bigdatamain/qiyexinxi.html @@ -5,24 +5,24 @@ 企业信息二级页 - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -719,7 +719,7 @@ var initParticlesJs = function() { z-index: 9999 !important; } .C0002_button:hover{ - color: rgba(255, 184, 0, 0.39) !important; + background-color: rgba(240, 240, 240, 0.39) !important; } - + \ No newline at end of file diff --git a/src/main/resources/static/route/bigdatamain/reportCaseV2.html b/src/main/resources/static/route/bigdatamain/reportCaseV2.html index 9b3f489..740f42c 100644 --- a/src/main/resources/static/route/bigdatamain/reportCaseV2.html +++ b/src/main/resources/static/route/bigdatamain/reportCaseV2.html @@ -5,24 +5,24 @@ 环保责任落实进度表(2) - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -731,7 +731,7 @@ z-index: 9999 !important; } .C0002_button:hover{ - color: rgba(255, 184, 0, 0.39) !important; + background-color: rgba(240, 240, 240, 0.39) !important; } - + \ No newline at end of file diff --git a/src/main/resources/static/route/bigdatamain/servicecity/userlocation/map_summary.html b/src/main/resources/static/route/bigdatamain/servicecity/userlocation/map_summary.html index 79fbbc2..203ebb7 100644 --- a/src/main/resources/static/route/bigdatamain/servicecity/userlocation/map_summary.html +++ b/src/main/resources/static/route/bigdatamain/servicecity/userlocation/map_summary.html @@ -5,14 +5,14 @@ - - - - - - - - + + + + + + + + @@ -102,13 +102,13 @@ - - - - - - - + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -817,7 +817,7 @@ z-index: 9999 !important; } .C0002_button:hover{ - color: rgba(255, 184, 0, 0.39) !important; + background-color: rgba(240, 240, 240, 0.39) !important; } - + \ No newline at end of file diff --git a/src/main/resources/static/route/bigdatamain/shengtaiweirenwu.html b/src/main/resources/static/route/bigdatamain/shengtaiweirenwu.html index 88a3a8b..1d7c851 100644 --- a/src/main/resources/static/route/bigdatamain/shengtaiweirenwu.html +++ b/src/main/resources/static/route/bigdatamain/shengtaiweirenwu.html @@ -4,24 +4,24 @@ 生态委任务信息二级页(2) - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -704,7 +704,7 @@ z-index: 9999 !important; } .C0002_button:hover{ - color: rgba(255, 184, 0, 0.39) !important; + background-color: rgba(240, 240, 240, 0.39) !important; } - + \ No newline at end of file diff --git a/src/main/resources/static/route/bigdatamain/shucaiyi.html b/src/main/resources/static/route/bigdatamain/shucaiyi.html index ff22c7f..0ce2660 100644 --- a/src/main/resources/static/route/bigdatamain/shucaiyi.html +++ b/src/main/resources/static/route/bigdatamain/shucaiyi.html @@ -4,25 +4,25 @@ 企业在线信息二级页(2) - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + @@ -663,7 +663,7 @@ z-index: 9999 !important; } .C0002_button:hover{ - color: rgba(255, 184, 0, 0.39) !important; + background-color: rgba(240, 240, 240, 0.39) !important; } - + \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 8bb3e2f..edc5eef 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -36,7 +36,10 @@