|
@@ -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<>();
|
|
|
|