Browse Source

增加天气服务

menglu 3 years ago
parent
commit
1983287da1

+ 8 - 2
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/DaemonThread.java

@@ -225,14 +225,20 @@ public class DaemonThread extends Thread {
 			}
 
 			RepositoryImpl Repository = RepositoryContainer.instance;
+			log.warn("refresh calendar weather start");
 			try {
-				log.warn("refresh calendar start");
 				RWDLoadUtil.LoadCalendar(Repository);
-				log.warn("refresh calendar finish");
 			} catch (Exception e) {
 				log.error(e.getMessage(), e);
 			}
 			try {
+				RWDLoadUtil.LoadWeather(Repository);
+			} catch (Exception e) {
+				log.error(e.getMessage(), e);
+			}
+			log.warn("refresh calendar weather finish");
+			
+			try {
 				log.warn("deamon start");
 				DeamonUtil.Process_deamon(Repository);
 				log.warn("deamon finish");

+ 47 - 3
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/Constant.java

@@ -35,8 +35,8 @@ public class Constant {
 	public static long compute_thread_sdv_interval;
 
 	public static String sdk_version;
-	public static String control_mode;	
-	
+	public static String control_mode;
+
 	public static String zkt_dmp_url;
 	public static boolean zkt_dmp_compress = false;
 	public static String zkt_monitor_url;
@@ -59,6 +59,10 @@ public class Constant {
 	public static String alarm_url;
 	public static String alarm_service_name;
 	public static String person_center_url;
+	public static String weather_url;
+
+	public static Map<String, Map<String, String>> weather_nowMap = new ConcurrentHashMap<String, Map<String, String>>();
+	public static Map<String, Map<String, String>> weather_forecastMap = new ConcurrentHashMap<String, Map<String, String>>();
 
 	public static Map<String, ConfigRefresh> ConfigRefreshMap = new ConcurrentHashMap<String, ConfigRefresh>();
 
@@ -121,7 +125,7 @@ public class Constant {
 					element = (Element) iter.next();
 					control_mode = element.getText();
 				}
-				
+
 				iter = document.selectNodes("/root/zkt_dmp").iterator();
 				if (iter.hasNext()) {
 					element = (Element) iter.next();
@@ -150,6 +154,13 @@ public class Constant {
 					person_center_url = element.attribute("url").getValue();
 					person_center_url = StrUtil.removeSuffix(person_center_url, "/");
 				}
+				iter = document.selectNodes("/root/weather").iterator();
+				if (iter.hasNext()) {
+					element = (Element) iter.next();
+					weather_url = element.attribute("url").getValue();
+					weather_url = StrUtil.removeSuffix(weather_url, "/");
+				}
+
 				iter = document.selectNodes("/root/config").iterator();
 				if (iter.hasNext()) {
 					element = (Element) iter.next();
@@ -265,6 +276,39 @@ public class Constant {
 					subsystem_connect_status_excludeMap.put(ibmsSceneCode, true);
 				}
 
+				iter = document.selectNodes("/root/weather_now").iterator();
+				while (iter.hasNext()) {
+					element = (Element) iter.next();
+					String dataType = element.attribute("dataType").getValue();
+					String key = element.attribute("key").getValue();
+					String info_code = element.attribute("info_code").getValue();
+					String name = element.attribute("name").getValue();
+					String unit = element.attribute("unit").getValue();
+					Map<String, String> oneMap = new ConcurrentHashMap<String, String>();
+					oneMap.put("dataType", dataType);
+					oneMap.put("key", key);
+					oneMap.put("info_code", info_code);
+					oneMap.put("name", name);
+					oneMap.put("unit", unit);
+					weather_nowMap.put(key, oneMap);
+				}
+				iter = document.selectNodes("/root/weather_forecast").iterator();
+				while (iter.hasNext()) {
+					element = (Element) iter.next();
+					String dataType = element.attribute("dataType").getValue();
+					String key = element.attribute("key").getValue();
+					String info_code = element.attribute("info_code").getValue();
+					String name = element.attribute("name").getValue();
+					String unit = element.attribute("unit").getValue();
+					Map<String, String> oneMap = new ConcurrentHashMap<String, String>();
+					oneMap.put("dataType", dataType);
+					oneMap.put("key", key);
+					oneMap.put("info_code", info_code);
+					oneMap.put("name", name);
+					oneMap.put("unit", unit);
+					weather_forecastMap.put(key, oneMap);
+				}
+
 				iter = document.selectNodes("/root/ConfigRelation").iterator();
 				while (iter.hasNext()) {
 					element = (Element) iter.next();

+ 105 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RWDLoadUtil.java

@@ -1100,4 +1100,109 @@ public class RWDLoadUtil {
 			Repository.IBMSCalendarBinding.set = RWDUtil.array2SDOList(arrayToday);
 		}
 	}
+
+	public static void LoadWeather(RepositoryImpl Repository) throws Exception {
+		{
+			JSONArray array = new JSONArray();
+			for (String key : Constant.weather_nowMap.keySet()) {
+				Map<String, String> oneMap = Constant.weather_nowMap.get(key);
+				String dataType = oneMap.get("dataType");
+				String info_code = oneMap.get("info_code");
+				String name = oneMap.get("name");
+				String unit = oneMap.get("unit");
+				JSONObject info = new JSONObject();
+				info.put("code", info_code);
+				info.put("name", name);
+				info.put("category", "SEQUENTIAL");
+				info.put("firstTag", "运行参数");
+				info.put("dataType", dataType);
+				info.put("unit", unit);
+				array.add(info);
+			}
+			for (String key : Constant.weather_forecastMap.keySet()) {
+				Map<String, String> oneMap = Constant.weather_forecastMap.get(key);
+				String dataType = oneMap.get("dataType");
+				String info_code = oneMap.get("info_code");
+				String name = oneMap.get("name");
+				String unit = oneMap.get("unit");
+				JSONObject info = new JSONObject();
+				info.put("code", info_code);
+				info.put("name", name);
+				info.put("category", "SEQUENTIAL");
+				info.put("firstTag", "运行参数");
+				info.put("dataType", dataType);
+				info.put("unit", unit);
+				array.add(info);
+			}
+			SceneDataSet SceneDataSet = new SceneDataSet(false);
+			SceneDataSet.set = RWDUtil.array2SDOList(array);
+			Repository.infoArrayDic.put("weather", SceneDataSet);
+		}
+
+		String cityCode = RepositoryContainer.RepositoryProject.projectId.substring(2, 8);
+		{
+			JSONObject arrayItem = new JSONObject();
+			{
+				JSONObject param = new JSONObject();
+				param.put("cityCode", cityCode);
+				param.put("dataType", "all");
+				String post_result = HttpClientUtil.instance("weather")
+						.post(Constant.weather_url + "/Spring/MVC/entrance/unifierJson/NowWeatherQuery", param.toJSONString());
+				JSONObject resultJSON = JSON.parseObject(post_result);
+				JSONArray content = (JSONArray) resultJSON.get("content");
+				if (content.size() > 0) {
+					JSONObject contentItem = content.getJSONObject(0);
+					for (String key : Constant.weather_nowMap.keySet()) {
+						Object value = contentItem.get(key);
+						if (value instanceof String) {
+							String valueString = (String) value;
+							Map<String, String> oneMap = Constant.weather_nowMap.get(key);
+							String dataType = oneMap.get("dataType");
+							if (dataType.equals("INTEGER")) {
+								arrayItem.put(key, Long.parseLong(valueString));
+							} else if (dataType.equals("DOUBLE")) {
+								arrayItem.put(key, Double.parseDouble(valueString));
+							} else {
+								arrayItem.put(key, valueString);
+							}
+						} else {
+							arrayItem.put(key, value);
+						}
+					}
+				}
+			}
+			{
+				JSONObject param = new JSONObject();
+				param.put("cityCode", cityCode);
+				param.put("dataType", "all");
+				String post_result = HttpClientUtil.instance("weather").post(Constant.weather_url + "/Spring/MVC/entrance/unifierJson/DayForecast",
+						param.toJSONString());
+				JSONObject resultJSON = JSON.parseObject(post_result);
+				JSONArray content = (JSONArray) resultJSON.get("content");
+				if (content.size() > 0) {
+					JSONObject contentItem = content.getJSONObject(0);
+					for (String key : Constant.weather_forecastMap.keySet()) {
+						Object value = contentItem.get(key);
+						if (value instanceof String) {
+							String valueString = (String) value;
+							Map<String, String> oneMap = Constant.weather_forecastMap.get(key);
+							String dataType = oneMap.get("dataType");
+							if (dataType.equals("INTEGER")) {
+								arrayItem.put(key, Long.parseLong(valueString));
+							} else if (dataType.equals("DOUBLE")) {
+								arrayItem.put(key, Double.parseDouble(valueString));
+							} else {
+								arrayItem.put(key, valueString);
+							}
+						} else {
+							arrayItem.put(key, value);
+						}
+					}
+				}
+			}
+			JSONArray array = new JSONArray();
+			array.add(arrayItem);
+			Repository.weather.set = RWDUtil.array2SDOList(array);
+		}
+	}
 }

+ 10 - 2
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RWDRepositoryUtil.java

@@ -121,20 +121,28 @@ public class RWDRepositoryUtil {
 		List<List<SceneProperty>> spListList = ComputeUtil.computePrepare(Repository);
 		log.warn("computeAll");
 		ComputeUtil.computeAll(Repository, spListList);
+
+		log.warn("refresh calendar weather start");
 		try {
-			log.warn("refresh calendar start");
 			RWDLoadUtil.LoadCalendar(Repository);
-			log.warn("refresh calendar finish");
 		} catch (Exception e) {
 			log.error(e.getMessage(), e);
 		}
 		try {
+			RWDLoadUtil.LoadWeather(Repository);
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+		}
+		log.warn("refresh calendar weather finish");
+
+		try {
 			log.warn("deamon start");
 			DeamonUtil.Process_deamon(Repository);
 			log.warn("deamon finish");
 		} catch (Exception e) {
 			log.error(e.getMessage(), e);
 		}
+
 		Repository.property2SDV_enable = false;
 		Repository.property2SDV.clear();
 	}

+ 3 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RepositoryImpl.java

@@ -68,6 +68,7 @@ public class RepositoryImpl extends RepositoryBase {
 	// 日历模式:周期性刷新,不需要拷贝
 	public SceneDataSet IBMSCalendarModel = new SceneDataSet(false, true);
 	public SceneDataSet IBMSCalendarBinding = new SceneDataSet(false, true);
+	public SceneDataSet weather = new SceneDataSet(false, true);
 
 	// 信息点
 	public SceneDataSet InfoPointListArray = new SceneDataSet(false);
@@ -178,6 +179,8 @@ public class RepositoryImpl extends RepositoryBase {
 			result = this.IBMSCalendarBinding;
 		} else if (Source.equals("ibms-alarm-type")) {
 			result = this.ZKTAlarmTypeArray;
+		} else if (Source.equals("weather")) {
+			result = this.weather;
 		} else if (Source.equals("alarm")) {
 			result = this.RepositoryProject.alarmArray;
 		} else if (Source.equals("info-point-list")) {

+ 17 - 5
ibms-data-sdk/src/main/resources/config.xml

@@ -33,6 +33,7 @@
     <alarm enable="true" websocket="ws://192.168.100.76:8870/webSocketServer"
            url="http://192.168.100.33:9909/ibms-alarm/" service_name="ibms-alarm"/>
     <person_center url="http://39.102.40.239:9970/person-center/"/>
+    <weather url="http://114.215.64.204:9090/EMS_Weather/"/>
 
     <!-- 场景/产品模块编码与后台tab页名称的对应关系 -->
     <SceneCode2TabName sceneCode="ggzm" tabName="公共照明"/>
@@ -48,11 +49,10 @@
     <!--	<info_replace objType="equipment" from="localId" to="ibmsxianshibianma" />-->
     <!--	<info_replace objType="equipment" from="localName" to="ibmsxianshimingcheng" />-->
     <!-- 万达用下面四行 -->
-    <info_replace objType="space" from="wD_huiyunbendibianma" to="ibmsxianshibianma"/>
-    <info_replace objType="space" from="wD_huiyunbendimingcheng" to="ibmsxianshimingcheng"/>
-    <info_replace objType="equipment" from="wD_huiyunbendibianma" to="ibmsxianshibianma"/>
-    <info_replace objType="equipment" from="wD_huiyunbendimingcheng" to="ibmsxianshimingcheng"/>
-
+	<info_replace objType="space" from="wD_huiyunbendibianma" to="ibmsxianshibianma" />
+	<info_replace objType="space" from="wD_huiyunbendimingcheng" to="ibmsxianshimingcheng" />
+	<info_replace objType="equipment" from="wD_huiyunbendibianma" to="ibmsxianshibianma" />
+	<info_replace objType="equipment" from="wD_huiyunbendimingcheng" to="ibmsxianshimingcheng" />
 
     <!-- 子系统连接状态里面,产品模块黑名单 -->
     <!--
@@ -62,6 +62,18 @@
     <subsystem_connect_status_exclude ibmsSceneCode="rdsb" />
     -->
 
+	<weather_now dataType="STRING" key="code" info_code="now_weather_code" name="实时天气编码" unit="" />
+	<weather_now dataType="STRING" key="text" info_code="now_weather_name" name="实时天气名称" unit="" />
+	<weather_now dataType="DOUBLE" key="temperature" info_code="now_temp" name="温度" unit="℃" />
+	<weather_now dataType="INTEGER" key="humidity" info_code="now_rh" name="湿度" unit="%" />
+	<weather_now dataType="STRING" key="quality" info_code="now_quality" name="空气质量" unit="" />
+	<weather_forecast dataType="STRING" key="codeDay" info_code="day_code" name="日间天气编码" unit="" />
+	<weather_forecast dataType="STRING" key="textDay" info_code="day_name" name="日间天气名称" unit="" />
+	<weather_forecast dataType="STRING" key="codeNight" info_code="night_code" name="夜间天气编码" unit="" />
+	<weather_forecast dataType="STRING" key="textNight" info_code="night_name" name="夜间天气名称" unit="" />
+	<weather_forecast dataType="DOUBLE" key="maxTemperature" info_code="maxTemperature" name="最高温度" unit="℃" />
+	<weather_forecast dataType="DOUBLE" key="minTemperature" info_code="maxTemperature" name="最低温度" unit="℃" />
+
     <!-- 数据中台物理世界对象初始加载的关系,供SDK配置中使用 -->
     <ConfigRelation graphCode="ArchSubset" relCode="Bd2Fl" objFrom="building" objTo="floor" nameInTo="所属建筑"
                     multiplicityTo="1"/>