瀏覽代碼

添加场站监视页面上网电量和购网电量数据

shilin 3 年之前
父節點
當前提交
090b6a8643

+ 20 - 0
src/main/java/com/gyee/frame/common/conf/V2Config.java

@@ -44,6 +44,26 @@ public class V2Config
     private  static  String swaggerip;
     /** 小数位数 **/
     private  static  Integer digit;
+    /** 气象采集指定IP **/
+    private  static  String weatherurl;
+    /** 区域公司key指定IP **/
+    private  static  String weatherqygs;
+
+    public static String getWeatherurl() {
+        return weatherurl;
+    }
+
+    public  void setWeatherurl(String weatherurl) {
+        V2Config.weatherurl = weatherurl;
+    }
+
+    public static String getWeatherqygs() {
+        return weatherqygs;
+    }
+
+    public  void setWeatherqygs(String weatherqygs) {
+        V2Config.weatherqygs = weatherqygs;
+    }
 
     public static  Integer getDigit() {
         return digit;

+ 105 - 62
src/main/java/com/gyee/frame/service/weather/WeatherDay5Service.java

@@ -3,6 +3,7 @@ package com.gyee.frame.service.weather;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
 import com.gyee.frame.common.cache.RedisUtils;
+import com.gyee.frame.common.conf.V2Config;
 import com.gyee.frame.common.spring.InitialRunner;
 import com.gyee.frame.model.auto.Line;
 import com.gyee.frame.model.auto.Project;
@@ -10,7 +11,10 @@ import com.gyee.frame.model.auto.Windpowerstation;
 import com.gyee.frame.model.custom.weather.*;
 import com.gyee.frame.util.MathUtil;
 import com.gyee.frame.util.StringUtils;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
@@ -23,6 +27,7 @@ import java.util.Map;
 @Service
 public class WeatherDay5Service {
 
+    private RestTemplate restTemplate=new RestTemplate();
 	private final Integer DATABASE=2;
 	@Resource
 	private RedisUtils redisUtils;
@@ -54,74 +59,112 @@ public class WeatherDay5Service {
 				id=wp.getId();
 			}
 
-			String weatherStr =null;
-
-			switch(id) {
-				case "0" :
-					result.put("name","银川");
-					weatherStr = redisUtils.get("NX_QYGS_WEATHER_FORECAST",DATABASE);
-					break;
-				case "-1" :
-					result.put("name","银川");
-					weatherStr = redisUtils.get("NX_QYGS_WEATHER_FORECAST",DATABASE);
-					break;
-				case "-2" :
-					result.put("name","银川");
-					weatherStr = redisUtils.get("NX_QYGS_WEATHER_FORECAST",DATABASE);
-					break;
-				case "MHS_FDC" :
-					result.put("name","麻黄山");
-					weatherStr = redisUtils.get("MHS_FDC_WEATHER_FORECAST",DATABASE);
-					break;
-				case "NSS_FDC" :
-					result.put("name","牛首山");
-					weatherStr = redisUtils.get("NSS_FDC_WEATHER_FORECAST",DATABASE);
-					break;
-				case "QS_FDC" :
-					result.put("name","青山");
-					weatherStr = redisUtils.get("QS_FDC_WEATHER_FORECAST",DATABASE);
-					break;
-				case "SBQ_FDC" :
-					result.put("name","石板泉");
-					weatherStr = redisUtils.get("SBQ_FDC_WEATHER_FORECAST",DATABASE);
-					break;
-				case "XS_FDC" :
-					result.put("name","香山");
-					weatherStr = redisUtils.get("XS_FDC_WEATHER_FORECAST",DATABASE);
-					break;
-				case "DWK_GDC" :
-					result.put("name","大武口");
-					weatherStr = redisUtils.get("DWK_GDC_WEATHER_FORECAST",DATABASE);
-					break;
-				case "PL_GDC" :
-					result.put("name","平罗");
-					weatherStr = redisUtils.get("PL_GDC_WEATHER_FORECAST",DATABASE);
-					break;
-				case "XH_GDC" :
-					result.put("name","宣和");
-					weatherStr = redisUtils.get("XH_GDC_WEATHER_FORECAST",DATABASE);
-					break;
-				case "MCH_GDC" :
-					result.put("name","马场湖");
-					weatherStr = redisUtils.get("MCH_GDC_WEATHER_FORECAST",DATABASE);
-					break;
-				case "HZJ_GDC" :
-					result.put("name","海子井");
-					weatherStr = redisUtils.get("HZJ_GDC_WEATHER_FORECAST",DATABASE);
-					break;
-				default:
-					break;
-			}
 
-			if(StringUtils.notEmp(weatherStr))
+            String weatherStr =null;
+            JsonRootBean jsonRootBean   = null;
+            // weather,forecast,onecall
+            try {
+
+
+
+                StringBuilder sb=new StringBuilder();
+                sb.append(V2Config.getWeatherurl()).append("/meteorological/datas?");
+
+                if(id.equals("0") || id.equals("-1")  || id.equals("-2"))
+                {
+                    sb.append("&wpid=").append(V2Config.getWeatherqygs());
+                }else {
+                    sb.append("&wpid=").append(id);
+                }
+
+                sb.append("&model=forecast");
+
+                String url=String.valueOf(sb);
+
+                ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
+
+                if(StringUtils.notEmp(resp.getBody()))
+                {
+                    weatherStr = resp.getBody().toJSONString();
+                }else
+                {
+                    weatherStr = "";
+                }
+
+
+                jsonRootBean = JSONObject.parseObject(weatherStr, new TypeReference<JsonRootBean>(){});
+
+
+            } catch (HttpClientErrorException exception) {
+
+            }
+
+//			switch(id) {
+//				case "0" :
+//					result.put("name","银川");
+//					weatherStr = redisUtils.get("NX_QYGS_WEATHER_FORECAST",DATABASE);
+//					break;
+//				case "-1" :
+//					result.put("name","银川");
+//					weatherStr = redisUtils.get("NX_QYGS_WEATHER_FORECAST",DATABASE);
+//					break;
+//				case "-2" :
+//					result.put("name","银川");
+//					weatherStr = redisUtils.get("NX_QYGS_WEATHER_FORECAST",DATABASE);
+//					break;
+//				case "MHS_FDC" :
+//					result.put("name","麻黄山");
+//					weatherStr = redisUtils.get("MHS_FDC_WEATHER_FORECAST",DATABASE);
+//					break;
+//				case "NSS_FDC" :
+//					result.put("name","牛首山");
+//					weatherStr = redisUtils.get("NSS_FDC_WEATHER_FORECAST",DATABASE);
+//					break;
+//				case "QS_FDC" :
+//					result.put("name","青山");
+//					weatherStr = redisUtils.get("QS_FDC_WEATHER_FORECAST",DATABASE);
+//					break;
+//				case "SBQ_FDC" :
+//					result.put("name","石板泉");
+//					weatherStr = redisUtils.get("SBQ_FDC_WEATHER_FORECAST",DATABASE);
+//					break;
+//				case "XS_FDC" :
+//					result.put("name","香山");
+//					weatherStr = redisUtils.get("XS_FDC_WEATHER_FORECAST",DATABASE);
+//					break;
+//				case "DWK_GDC" :
+//					result.put("name","大武口");
+//					weatherStr = redisUtils.get("DWK_GDC_WEATHER_FORECAST",DATABASE);
+//					break;
+//				case "PL_GDC" :
+//					result.put("name","平罗");
+//					weatherStr = redisUtils.get("PL_GDC_WEATHER_FORECAST",DATABASE);
+//					break;
+//				case "XH_GDC" :
+//					result.put("name","宣和");
+//					weatherStr = redisUtils.get("XH_GDC_WEATHER_FORECAST",DATABASE);
+//					break;
+//				case "MCH_GDC" :
+//					result.put("name","马场湖");
+//					weatherStr = redisUtils.get("MCH_GDC_WEATHER_FORECAST",DATABASE);
+//					break;
+//				case "HZJ_GDC" :
+//					result.put("name","海子井");
+//					weatherStr = redisUtils.get("HZJ_GDC_WEATHER_FORECAST",DATABASE);
+//					break;
+//				default:
+//					break;
+//			}
+
+			if(StringUtils.notEmp(jsonRootBean))
 			{
-				JsonRootBean jsonRootBean = JSONObject.parseObject(weatherStr, new TypeReference<JsonRootBean>() {
-				});
+//				JsonRootBean jsonRootBean = JSONObject.parseObject(weatherStr, new TypeReference<JsonRootBean>() {
+//				});
 
 				if(null!=jsonRootBean && null!=jsonRootBean.getList() && !jsonRootBean.getList().isEmpty())
 				{
 
-					for(com.gyee.frame.model.custom.weather.List weatherReal:jsonRootBean.getList())
+					for(List weatherReal:jsonRootBean.getList())
 					{
 						Map<String,Object> map=new HashMap<>();
 

+ 126 - 67
src/main/java/com/gyee/frame/service/weather/WeatherService.java

@@ -5,26 +5,35 @@ import com.alibaba.fastjson.TypeReference;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.gyee.frame.common.cache.RedisUtils;
+import com.gyee.frame.common.conf.V2Config;
 import com.gyee.frame.common.spring.InitialRunner;
-import com.gyee.frame.mapper.auto.WeatherfdMapper;
 import com.gyee.frame.model.auto.*;
 import com.gyee.frame.model.custom.Tablepar;
 import com.gyee.frame.model.custom.weather.*;
 import com.gyee.frame.service.WeatherfdService;
 import com.gyee.frame.util.MathUtil;
 import com.gyee.frame.util.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 
 @Service
 public class WeatherService  {
 
-	private final Integer DATABASE=2;
+
+    private RestTemplate restTemplate=new RestTemplate();
+    @Value("${spring.redis.database}")
+    private Integer database;
 	@Resource
 	private RedisUtils redisUtils;
 	@Resource
@@ -57,71 +66,121 @@ public class WeatherService  {
 			}
 
 			String weatherStr =null;
-
-			switch(id) {
-				case "0" :
-					map.put("name","银川");
-					weatherStr = redisUtils.get("NX_QYGS_WEATHER_WEATHER",DATABASE);
-					break;
-				case "-1" :
-					map.put("name","银川");
-					weatherStr = redisUtils.get("NX_QYGS_WEATHER_WEATHER",DATABASE);
-					break;
-				case "-2" :
-					map.put("name","银川");
-					weatherStr = redisUtils.get("NX_QYGS_WEATHER_WEATHER",DATABASE);
-					break;
-				case "MHS_FDC" :
-					map.put("name","麻黄山");
-					weatherStr = redisUtils.get("MHS_FDC_WEATHER_WEATHER",DATABASE);
-					break;
-				case "NSS_FDC" :
-					map.put("name","牛首山");
-					weatherStr = redisUtils.get("NSS_FDC_WEATHER_WEATHER",DATABASE);
-					break;
-				case "QS_FDC" :
-					map.put("name","青山");
-					weatherStr = redisUtils.get("QS_FDC_WEATHER_WEATHER",DATABASE);
-					break;
-				case "SBQ_FDC" :
-					map.put("name","石板泉");
-					weatherStr = redisUtils.get("SBQ_FDC_WEATHER_WEATHER",DATABASE);
-					break;
-				case "XS_FDC" :
-					map.put("name","香山");
-					weatherStr = redisUtils.get("XS_FDC_WEATHER_WEATHER",DATABASE);
-					break;
-				case "DWK_GDC" :
-					map.put("name","大武口");
-					weatherStr = redisUtils.get("DWK_GDC_WEATHER_WEATHER",DATABASE);
-					break;
-				case "PL_GDC" :
-					map.put("name","平罗");
-					weatherStr = redisUtils.get("PL_GDC_WEATHER_WEATHER",DATABASE);
-					break;
-				case "XH_GDC" :
-					map.put("name","宣和");
-					weatherStr = redisUtils.get("XH_GDC_WEATHER_WEATHER",DATABASE);
-					break;
-				case "MCH_GDC" :
-					map.put("name","马场湖");
-					weatherStr = redisUtils.get("MCH_GDC_WEATHER_WEATHER",DATABASE);
-					break;
-				case "HZJ_GDC" :
-					map.put("name","海子井");
-					weatherStr = redisUtils.get("HZJ_GDC_WEATHER_WEATHER",DATABASE);
-					break;
-				default:
-					break;
-			}
-
-			if(StringUtils.notEmp(weatherStr))
+            WeatherReal weatherReal   = null;
+           // weather,forecast,onecall
+            try {
+
+
+
+                StringBuilder sb=new StringBuilder();
+                sb.append(V2Config.getWeatherurl()).append("/meteorological/datas?");
+                if(id.equals("0") || id.equals("-1")  || id.equals("-2"))
+                {
+                    sb.append("&wpid=").append(V2Config.getWeatherqygs());
+                }else {
+                    sb.append("&wpid=").append(id);
+                }
+                sb.append("&model=weather");
+
+                String url=String.valueOf(sb);
+
+                ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
+                if(StringUtils.notEmp(resp.getBody()))
+                {
+                    weatherStr = resp.getBody().toJSONString();
+                }else
+                {
+                    weatherStr = "";
+                }
+
+                weatherReal = JSONObject.parseObject(weatherStr, new TypeReference<WeatherReal>(){});
+
+
+            } catch (HttpClientErrorException exception) {
+
+            }
+
+            if(InitialRunner.wpmap.containsKey(id))
+            {
+                Windpowerstation wp=InitialRunner.wpmap.get(id);
+                if(wp.getName().indexOf("风电场")!=-1)
+                {
+                    String name=wp.getName().substring(0,wp.getName().indexOf("风电场"));
+                    map.put("name",name);
+                }else  if(wp.getName().indexOf("光电场")!=-1)
+                {
+                    String name=wp.getName().substring(0,wp.getName().indexOf("光电场"));
+                    map.put("name",name);
+                }
+
+            }else
+            {
+                map.put("name","区域公司");
+            }
+//			switch(id) {
+//				case "0" :
+//					map.put("name","银川");
+//					weatherStr = redisUtils.get("NX_QYGS_WEATHER_WEATHER",database);
+//					break;
+//				case "-1" :
+//					map.put("name","银川");
+//					weatherStr = redisUtils.get("NX_QYGS_WEATHER_WEATHER",database);
+//					break;
+//				case "-2" :
+//					map.put("name","银川");
+//					weatherStr = redisUtils.get("NX_QYGS_WEATHER_WEATHER",database);
+//					break;
+//				case "MHS_FDC" :
+//					map.put("name","麻黄山");
+//					weatherStr = redisUtils.get("MHS_FDC_WEATHER_WEATHER",database);
+//					break;
+//				case "NSS_FDC" :
+//					map.put("name","牛首山");
+//					weatherStr = redisUtils.get("NSS_FDC_WEATHER_WEATHER",database);
+//					break;
+//				case "QS_FDC" :
+//					map.put("name","青山");
+//					weatherStr = redisUtils.get("QS_FDC_WEATHER_WEATHER",database);
+//					break;
+//				case "SBQ_FDC" :
+//					map.put("name","石板泉");
+//					weatherStr = redisUtils.get("SBQ_FDC_WEATHER_WEATHER",database);
+//					break;
+//				case "XS_FDC" :
+//					map.put("name","香山");
+//					weatherStr = redisUtils.get("XS_FDC_WEATHER_WEATHER",database);
+//					break;
+//				case "DWK_GDC" :
+//					map.put("name","大武口");
+//					weatherStr = redisUtils.get("DWK_GDC_WEATHER_WEATHER",database);
+//					break;
+//				case "PL_GDC" :
+//					map.put("name","平罗");
+//					weatherStr = redisUtils.get("PL_GDC_WEATHER_WEATHER",database);
+//					break;
+//				case "XH_GDC" :
+//					map.put("name","宣和");
+//					weatherStr = redisUtils.get("XH_GDC_WEATHER_WEATHER",database);
+//					break;
+//				case "MCH_GDC" :
+//					map.put("name","马场湖");
+//					weatherStr = redisUtils.get("MCH_GDC_WEATHER_WEATHER",database);
+//					break;
+//				case "HZJ_GDC" :
+//					map.put("name","海子井");
+//					weatherStr = redisUtils.get("HZJ_GDC_WEATHER_WEATHER",database);
+//					break;
+//				default:
+//					break;
+//			}
+
+			if(StringUtils.notEmp(weatherReal))
 			{
-				WeatherReal weatherReal = JSONObject.parseObject(weatherStr, new TypeReference<WeatherReal>() {
-				});
+//				WeatherReal weatherReal = JSONObject.parseObject(weatherStr, new TypeReference<WeatherReal>() {
+//				});
 
-				if(null!=weatherReal)
-				{
+//				if(null!=weatherReal)
+//				{
 					double qxd=weatherReal.getVisibility();
 					//清晰度
 					map.put("qxd", MathUtil.twoBit(qxd/1000));
@@ -271,7 +330,7 @@ public class WeatherService  {
 				}
 			}
 
-		}
+//		}
 		return  map;
 	}
 

+ 2 - 0
src/main/resources/application.yml

@@ -34,6 +34,8 @@ gyee:
   #默认小数位数
   digit: 2
   realtimedataBase: golden #数据查询模式 golden、hwy
+  weatherurl: http://123.60.213.70:7011
+  weatherqygs: nx_qygs
 #tomcat config
 server :
   port : 8082