menglu пре 3 година
родитељ
комит
42ac47eaa1

+ 79 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RedirectApi.java

@@ -0,0 +1,79 @@
+package com.persagy.ibms.data.sdk.service.rest;
+
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.persagy.ibms.core.util.LogUtil;
+import com.persagy.ibms.data.sdk.util.ConfigRedirect;
+import com.persagy.ibms.data.sdk.util.Constant;
+import com.persagy.ibms.data.sdk.util.HttpClientUtil;
+
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+
+@ApiOperation(value = "重定向接口")
+@RestController
+@Slf4j
+public class RedirectApi {
+
+	@PostMapping(path = { "/redirect", "/zkt-sdk/redirect" }, produces = "application/json;charset=UTF-8")
+	public String redirect(@RequestBody String param) {
+		String result;
+		JSONObject sql_json = JSON.parseObject(param);
+		String code = sql_json.getString("code");
+		ConfigRedirect ConfigRedirect = Constant.ConfigRedirectMap.get(code);
+		if (ConfigRedirect == null) {
+			JSONObject resultJSON = new JSONObject();
+			resultJSON.put("Result", "failure");
+			resultJSON.put("ResultMsg", "code: " + code + " not exist");
+			resultJSON.put("ResultCode", 250);
+			return JSONObject.toJSONString(resultJSON, SerializerFeature.WriteMapNullValue);
+		}
+		String url = ConfigRedirect.url;
+		JSONObject urlParams = sql_json.getJSONObject("urlParams");
+		if (urlParams != null) {
+			StringBuffer sb = new StringBuffer();
+			for (String key : urlParams.keySet()) {
+				if (sb.length() > 0) {
+					sb.append("&");
+				}
+				sb.append(key + "=" + urlParams.get(key));
+			}
+			url = url + "?" + sb.toString();
+		}
+		String urlSuffix = sql_json.getString("urlSuffix");
+		if (urlSuffix != null) {
+			url = url + urlSuffix;
+		}
+		try {
+			if (ConfigRedirect.http_request_type.equals("get")) {
+				result = HttpClientUtil.get(url);
+			} else {
+				Object postBody = sql_json.get("postBody");
+				String postString;
+				if (postBody instanceof JSONObject) {
+					postString = JSONObject.toJSONString((JSONObject) postBody, SerializerFeature.WriteMapNullValue);
+				} else if (postBody instanceof JSONArray) {
+					postString = JSONArray.toJSONString((JSONArray) postBody, SerializerFeature.WriteMapNullValue);
+				} else {
+					postString = postBody.toString();
+				}
+				result = HttpClientUtil.post(url, postString);
+			}
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			JSONObject resultJSON = new JSONObject();
+			resultJSON.put("Result", "failure");
+			String message = LogUtil.GetExceptionStackTrace(e);
+			resultJSON.put("ResultMsg", message);
+			resultJSON.put("ResultCode", 250);
+			result = JSONObject.toJSONString(resultJSON, SerializerFeature.WriteMapNullValue);
+		}
+		return result;
+	}
+}

+ 7 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/ConfigRedirect.java

@@ -0,0 +1,7 @@
+package com.persagy.ibms.data.sdk.util;
+
+public class ConfigRedirect {
+	public String code;
+	public String http_request_type;
+	public String url;
+}

+ 12 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/Constant.java

@@ -47,6 +47,8 @@ public class Constant {
 
 	public static Map<String, Boolean> objType_hasRelation = new HashMap<String, Boolean>();
 	public static List<ConfigRelation> ConfigRelationList = new ArrayList<ConfigRelation>();
+	public static Map<String, ConfigRedirect> ConfigRedirectMap = new HashMap<String, ConfigRedirect>();
+
 	public static Map<String, Boolean> keyWordMap = new HashMap<String, Boolean>();
 	public static Map<String, Boolean> prefixMap;
 	public static Map<String, Boolean> suffixMap;
@@ -190,6 +192,16 @@ public class Constant {
 					objType_hasRelation.put(ConfigRelation.objFrom, true);
 					objType_hasRelation.put(ConfigRelation.objTo, true);
 				}
+
+				iter = document.selectNodes("/root/Redirect").iterator();
+				while (iter.hasNext()) {
+					element = (Element) iter.next();
+					ConfigRedirect ConfigRedirect = new ConfigRedirect();
+					ConfigRedirect.code = element.attribute("code").getValue();
+					ConfigRedirect.http_request_type = element.attribute("http_request_type").getValue();
+					ConfigRedirect.url = element.attribute("url").getValue();
+					ConfigRedirectMap.put(ConfigRedirect.code, ConfigRedirect);
+				}
 			}
 		} catch (Exception e) {
 			log.error(e.getMessage(), e);

+ 5 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/HttpClientUtil.java

@@ -75,6 +75,11 @@ public class HttpClientUtil {
 		return result;
 	}
 
+	public synchronized static String get(String url) throws Exception {
+		String result = get(url, 300000);
+		return result;
+	}
+
 	public synchronized static String get(String url, Integer timeout) throws Exception {
 		HttpGet httpget = new HttpGet(url);
 		if (timeout != null) {

+ 14 - 7
ibms-data-sdk/src/main/resources/config.xml

@@ -24,13 +24,9 @@
 	<!-- adm-project的服务地址 -->
 	<adm_project url="http://39.102.40.239:28888/" />
 	<!-- 报警的websocket地址和服务地址 -->
-	<!--
-	<alarm enable="true" websocket="ws://192.168.100.33:9909/webSocketServer" rest="http://192.168.100.33:9909/zkt-alarm/" rest_get="false" />
-	-->
-	<alarm enable="true" websocket="ws://192.168.100.33:8835/webSocketServer" rest="http://192.168.100.33:9909/ibms-alarm/" rest_get="true" />
-	<!--
-	<alarm enable="true" websocket="http://39.102.43.179:9993/webSocketServer" rest="http://39.102.43.179:9993/" rest_get="true" />
-	-->
+	<!-- <alarm enable="true" websocket="ws://192.168.100.33:9909/webSocketServer" rest="http://192.168.100.33:9909/zkt-alarm/" rest_get="false" /> -->
+	<alarm enable="true" websocket="ws://192.168.100.76:8835/webSocketServer" rest="http://192.168.100.33:9909/ibms-alarm/" rest_get="true" />
+	<!-- <alarm enable="true" websocket="http://39.102.43.179:9993/webSocketServer" rest="http://39.102.43.179:9993/" rest_get="true" /> -->
 
 	<ConfigRelation graphCode="ArchSubset" relCode="Bd2Fl" objFrom="building" objTo="floor" nameInTo="所属建筑" multiplicityTo="1" />
 	<ConfigRelation graphCode="ArchSubset" relCode="Bd2Sp" objFrom="building" objTo="space" nameInTo="所属建筑" multiplicityTo="1" />
@@ -45,4 +41,15 @@
 	<ConfigRelation graphCode="ValveRelationship" relCode="Vv2Eq" objFrom="equipment" objTo="equipment" nameInFrom="限制设备" multiplicityFrom="n" nameInTo="被设备限制" multiplicityTo="n" />
 	<ConfigRelation graphCode="ArchForArch" relCode="Sp2Sp" objFrom="space" objTo="space" nameInFrom="服务于空间" multiplicityFrom="n" nameInTo="被空间服务" multiplicityTo="n" />
 
+	<Redirect code="获取报警时长" http_request_type="get" url="http://39.102.43.179:9982/alarmTime/query" />
+	<Redirect code="查询项目概括" http_request_type="get" url="http://39.102.43.179:9982/projectSummary/query" />
+	<Redirect code="获取数据质量总览" http_request_type="get" url="http://39.102.43.179:9982/qualityTotal/query" />
+	<Redirect code="查询温控平台数据" http_request_type="post" url="http://39.102.43.179:9982/temperatureControl/query" />
+	<Redirect code="查询温控平台数据v2" http_request_type="post" url="http://39.102.43.179:9982/temperatureControl/query/v2" />
+	<Redirect code="查询温控平台数据v3" http_request_type="post" url="http://39.102.43.179:9982/temperatureControl/query/v3" />
+	<Redirect code="查询定额管理" http_request_type="get" url="http://39.102.43.179:9982/weekNeedMatter/query" />
+
+	<Redirect code="test-get1" http_request_type="get" url="http://192.168.18.21:9993/alarm-record/page?appId=0&amp;userId=systemId&amp;projectId=Pj3702020002&amp;groupCode=GX" />
+	<Redirect code="test-get2" http_request_type="get" url="http://192.168.18.21:9993/alarm-record/page" />
+	<Redirect code="test-post1" http_request_type="post" url="http://192.168.4.69:8806/zkt-sdk/post" />
 </root>