From e97c393e23f4c015a44b5fef5fd26ae288bc6c0f Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Wed, 10 Jul 2019 11:31:35 +0800
Subject: [PATCH] 天气预报
---
src/main/java/com/moral/controller/ScreenController.java | 65 ++++++++++++++++++++++++++++++--
1 files changed, 61 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/moral/controller/ScreenController.java b/src/main/java/com/moral/controller/ScreenController.java
index 86f7a10..61c46c2 100644
--- a/src/main/java/com/moral/controller/ScreenController.java
+++ b/src/main/java/com/moral/controller/ScreenController.java
@@ -7,6 +7,9 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -23,6 +26,7 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.net.ftp.FTPClient;
+import org.apache.http.HttpResponse;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.Element;
@@ -90,6 +94,7 @@
import com.moral.service.SensorService;
import com.moral.service.SensorUnitService;
import com.moral.service.WeatherService;
+import com.moral.util.TempAllocationUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -975,6 +980,7 @@
public ResultBean<List<Map<String, Object>>> AIForecast (HttpServletRequest request) throws Exception {
Map<String, Object> parameters = getParametersStartingWith(request, null);
//System.out.println(parameters);
+ String monitorPoint = (String) parameters.get("monitorPoint");
String intoTime = parameters.get("time").toString();
String[] timeArray = intoTime.split("-");
//System.out.println(timeArray);
@@ -997,6 +1003,15 @@
// monitorPointService.isCompensateCalculation(parameters);
List<Map<String, Object>> list = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters);
+ Map<String, Object> mpMap = new HashMap<>();
+ mpMap = monitorPointService.selectAllById(monitorPoint);
+ //������������map���������������������������������������������������
+ Map<String, Object> weatherParameters = new HashMap<>();
+ weatherParameters.put("organizationId", mpMap.get("organization_id"));
+ weatherParameters.put("time", intoTime);
+ //������������������
+ Map<String, Object> weatherMap = weatherService.get15DayWeatherDataByRegion(weatherParameters);
+ Map<String, Object> tempMap = TempAllocationUtils.tempAllocation(weatherMap);
//������������������
Map<String, Map<String, Object>> sensorUnitMap = sensorUnitService.getSensorsByMonitPointId(monitor_point_id);
@@ -1004,17 +1019,16 @@
String time = map.get("time").toString();
time = time.substring(time.length() - 2);
map.put("time", Integer.valueOf(time));
+ map.put("temp", tempMap.get(map.get("time").toString()));
List<Number> values = new ArrayList<Number>();
List<String> units = new ArrayList<String>();
for (String string : sensorKeys) {
if(sensorUnitMap!=null && !sensorUnitMap.isEmpty()) {
if(sensorUnitMap.get(string)!=null) {
units.add(sensorUnitMap.get(string).get("name").toString());
- System.out.println("ScreenController-----AIForecast-----map2:"+string+":"+map.get(string));
String rules = sensorUnitMap.get(string).get("rules").toString();
rules = rules.replace("{0}", "a");
rules = rules.replace("d", "");
- System.out.println(rules);
Expression expression = AviatorEvaluator.compile(rules);
Double value;
Map<String, Object> ev = new HashMap<>();
@@ -1023,8 +1037,6 @@
//������������������
DecimalFormat df = new DecimalFormat("#.00");
value = Double.parseDouble(df.format(value));
- System.out.println(map.get(string));
- System.out.println(value);
values.add(value);
}else {
Map<String, Object> sensorMap = sensorService.getSensorBySensorKey(string);
@@ -1043,5 +1055,50 @@
}
return new ResultBean<List<Map<String, Object>>>(list);
}
+
+ @GetMapping("getWeather")
+ @ApiOperation(value = "������������������", notes = "������������������")
+ @ApiImplicitParams(value = {
+ @ApiImplicitParam(name = "organizationId", defaultValue = "5", value = "���������������������id", required = true, paramType = "query", dataType = "String"),
+ @ApiImplicitParam(name = "time", value = "������,���(���������2018-03-06)", required = true, paramType = "query", dataType = "String"),
+ })
+ public ResultBean<Map<String, Object>> getWeather(HttpServletRequest request) throws Exception {
+ Map<String, Object> parameters = getParametersStartingWith(request, null);
+ Map<String, Object> map = weatherService.get15DayWeatherDataByRegion(parameters);
+ /*Map<String, Object> tempMap = new HashMap<>();
+ Double tempDay = Double.parseDouble(map.get("tempDay").toString());
+ Double tempNight = Double.parseDouble(map.get("tempNight").toString());
+ Double time5 = tempNight;
+ Double time13 = tempDay;
+ Double difference = tempDay-tempNight;
+ Double dif_8 = difference/8;
+ Double dif_16 = difference/16;
+ tempMap.put("5", time5);
+ tempMap.put("13", time13);
+ String time = null;
+ Double t = time5;
+ for(int i=4;i>=0;i--) {
+ time = ""+i;
+ t = t+dif_16;
+ String tempLast = ""+Math.round(t);
+ tempMap.put(time, tempLast);
+ }
+ Double y = time5;
+ for(int i=6;i<13;i++) {
+ time = ""+i;
+ y = y+dif_8;
+ String tempLast = ""+Math.round(y);
+ tempMap.put(time, tempLast);
+ }
+ Double z = time13;
+ for(int i=14;i<=23;i++) {
+ time = ""+i;
+ z = z-dif_16;
+ String tempLast = ""+Math.round(z);
+ tempMap.put(time, tempLast);
+ }*/
+ Map<String, Object> tempMap = TempAllocationUtils.tempAllocation(map);
+ return new ResultBean<Map<String, Object>>(tempMap);
+ }
}
--
Gitblit v1.8.0