瀏覽代碼

新post获取报警方式

lirong 3 年之前
父節點
當前提交
ae4b0c5dad

+ 148 - 142
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RedirectUtil.java

@@ -19,149 +19,155 @@ import javax.servlet.http.HttpServletResponse;
 
 @Slf4j
 public class RedirectUtil {
-	public static String redirect(String param, boolean wrapper) {
-		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 resultString;
-		try {
-			Map<String, String> otherMap = new ConcurrentHashMap<String, String>();
-			Object result = RedirectUtil.redirectInner(ConfigRedirect, sql_json, otherMap);
-			if (wrapper) {
-				JSONObject resultJSON = new JSONObject();
-				resultJSON.put("Result", "success");
-				resultJSON.put("Content", result);
-				resultJSON.put("Url", otherMap.get("Url"));
-				resultString = JSONObject.toJSONString(resultJSON, SerializerFeature.WriteMapNullValue);
-			} else {
-				if (result instanceof JSONObject) {
-					JSONObject resultJSON = (JSONObject) result;
-					resultString = JSONObject.toJSONString(resultJSON, SerializerFeature.WriteMapNullValue);
-				} else if (result instanceof JSONArray) {
-					JSONArray resultJSON = (JSONArray) result;
-					resultString = JSONArray.toJSONString(resultJSON, SerializerFeature.WriteMapNullValue);
-				} else {
-					resultString = result.toString();
-				}
-			}
-		} 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);
-			resultString = JSONObject.toJSONString(resultJSON, SerializerFeature.WriteMapNullValue);
-		}
-		return resultString;
-	}
+    public static String redirect(String param, boolean wrapper) {
+        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 resultString;
+        try {
+            Map<String, String> otherMap = new ConcurrentHashMap<String, String>();
+            Object result = RedirectUtil.redirectInner(ConfigRedirect, sql_json, otherMap);
+            if (wrapper) {
+                JSONObject resultJSON = new JSONObject();
+                resultJSON.put("Result", "success");
+                resultJSON.put("Content", result);
+                resultJSON.put("Url", otherMap.get("Url"));
+                resultString = JSONObject.toJSONString(resultJSON, SerializerFeature.WriteMapNullValue);
+            } else {
+                if (result instanceof JSONObject) {
+                    JSONObject resultJSON = (JSONObject) result;
+                    resultString = JSONObject.toJSONString(resultJSON, SerializerFeature.WriteMapNullValue);
+                } else if (result instanceof JSONArray) {
+                    JSONArray resultJSON = (JSONArray) result;
+                    resultString = JSONArray.toJSONString(resultJSON, SerializerFeature.WriteMapNullValue);
+                } else {
+                    resultString = result.toString();
+                }
+            }
+        } 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);
+            resultString = JSONObject.toJSONString(resultJSON, SerializerFeature.WriteMapNullValue);
+        }
+        return resultString;
+    }
 
-	public static Object redirectInner(ConfigRedirect ConfigRedirect, JSONObject sql_json, Map<String, String> otherMap) throws Exception {
-		String resultString;
-		String url = ConfigRedirect.url;
-		String url_ori = url;
-		JSONObject urlParams = sql_json.getJSONObject("urlParams");
-		if (urlParams != null) {
-			StringBuffer sb = new StringBuffer();
-			StringBuffer sb_ori = new StringBuffer();
-			for (String key : urlParams.keySet()) {
-				if (sb.length() > 0) {
-					sb.append("&");
-					sb_ori.append("&");
-				}
-				sb.append(key + "=" + URLEncoder.encode(urlParams.get(key).toString(), "UTF-8"));
-				sb_ori.append(key + "=" + urlParams.get(key));
-			}
-			if (sb.length() > 0) {
-				url = url + "?" + sb.toString();
-				url_ori = url_ori + "?" + sb_ori.toString();
-			}
-		}
-		String urlSuffix = sql_json.getString("urlSuffix");
-		if (urlSuffix != null) {
-			url = url + urlSuffix;
-			url_ori = url_ori + "?" + urlSuffix;
-		}
-		otherMap.put("Url", url_ori);
-		log.warn(url_ori);
-		if (ConfigRedirect.http_request_type.equals("get")) {
-			resultString = HttpClientUtil.instance("redirect").get(url, null, ConfigRedirect.headerMap);
-		} 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();
-			}
-			resultString = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap);
-		}
-		Object result;
-		try {
-			result = JSON.parse(resultString);
-		} catch (Exception e) {
-			result = resultString;
-		}
-		return result;
-	}
+    public static Object redirectInner(ConfigRedirect ConfigRedirect, JSONObject sql_json, Map<String, String> otherMap) throws Exception {
+        String resultString;
+        String url = ConfigRedirect.url;
+        String url_ori = url;
+        JSONObject urlParams = sql_json.getJSONObject("urlParams");
+        if (urlParams != null) {
+            StringBuffer sb = new StringBuffer();
+            StringBuffer sb_ori = new StringBuffer();
+            for (String key : urlParams.keySet()) {
+                if (sb.length() > 0) {
+                    sb.append("&");
+                    sb_ori.append("&");
+                }
+                sb.append(key + "=" + URLEncoder.encode(urlParams.get(key).toString(), "UTF-8"));
+                sb_ori.append(key + "=" + urlParams.get(key));
+            }
+            if (sb.length() > 0) {
+                url = url + "?" + sb.toString();
+                url_ori = url_ori + "?" + sb_ori.toString();
+            }
+        }
+        String urlSuffix = sql_json.getString("urlSuffix");
+        if (urlSuffix != null) {
+            url = url + urlSuffix;
+            url_ori = url_ori + "?" + urlSuffix;
+        }
+        otherMap.put("Url", url_ori);
+        log.warn(url_ori);
+        if (ConfigRedirect.http_request_type.equals("get")) {
+            resultString = HttpClientUtil.instance("redirect").get(url, null, ConfigRedirect.headerMap);
+        } 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();
+            }
+            //这里添加日志,重试手动,并设置成短链接
+            try {
+                resultString = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap);
+            } catch (Exception e) {
+                log.error("redirect异常", e);
+                resultString = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap);
+            }
+        }
+        Object result;
+        try {
+            result = JSON.parse(resultString);
+        } catch (Exception e) {
+            result = resultString;
+        }
+        return result;
+    }
 
-	public static void redirect_export(String param,HttpServletResponse response) {
-		JSONObject sql_json = JSON.parseObject(param);
-		String code = sql_json.getString("code");
-		ConfigRedirect ConfigRedirect = Constant.ConfigRedirectMap.get(code);
-		try {
-			Map<String, String> otherMap = new ConcurrentHashMap<String, String>();
-			RedirectUtil.redirect_export_Inner(ConfigRedirect, sql_json, otherMap,response);
-		} catch (Exception e) {
-			log.error(e.getMessage(), e);
-		}
-	}
+    public static void redirect_export(String param, HttpServletResponse response) {
+        JSONObject sql_json = JSON.parseObject(param);
+        String code = sql_json.getString("code");
+        ConfigRedirect ConfigRedirect = Constant.ConfigRedirectMap.get(code);
+        try {
+            Map<String, String> otherMap = new ConcurrentHashMap<String, String>();
+            RedirectUtil.redirect_export_Inner(ConfigRedirect, sql_json, otherMap, response);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+    }
 
-	public static void redirect_export_Inner(ConfigRedirect ConfigRedirect, JSONObject sql_json, Map<String, String> otherMap, HttpServletResponse response) throws Exception {
-		String url = ConfigRedirect.url;
-		String url_ori = url;
-		JSONObject urlParams = sql_json.getJSONObject("urlParams");
-		if (urlParams != null) {
-			StringBuffer sb = new StringBuffer();
-			StringBuffer sb_ori = new StringBuffer();
-			for (String key : urlParams.keySet()) {
-				if (sb.length() > 0) {
-					sb.append("&");
-					sb_ori.append("&");
-				}
-				sb.append(key + "=" + URLEncoder.encode(urlParams.get(key).toString(), "UTF-8"));
-				sb_ori.append(key + "=" + urlParams.get(key));
-			}
-			if (sb.length() > 0) {
-				url = url + "?" + sb.toString();
-				url_ori = url_ori + "?" + sb_ori.toString();
-			}
-		}
-		String urlSuffix = sql_json.getString("urlSuffix");
-		if (urlSuffix != null) {
-			url = url + urlSuffix;
-			url_ori = url_ori + "?" + urlSuffix;
-		}
-		otherMap.put("Url", url_ori);
-		log.warn(url_ori);
-		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();
-		}
-		HttpClientUtil.instance("redirect").post_export(url, postString, null, ConfigRedirect.headerMap,response);
-	}
+    public static void redirect_export_Inner(ConfigRedirect ConfigRedirect, JSONObject sql_json, Map<String, String> otherMap, HttpServletResponse response) throws Exception {
+        String url = ConfigRedirect.url;
+        String url_ori = url;
+        JSONObject urlParams = sql_json.getJSONObject("urlParams");
+        if (urlParams != null) {
+            StringBuffer sb = new StringBuffer();
+            StringBuffer sb_ori = new StringBuffer();
+            for (String key : urlParams.keySet()) {
+                if (sb.length() > 0) {
+                    sb.append("&");
+                    sb_ori.append("&");
+                }
+                sb.append(key + "=" + URLEncoder.encode(urlParams.get(key).toString(), "UTF-8"));
+                sb_ori.append(key + "=" + urlParams.get(key));
+            }
+            if (sb.length() > 0) {
+                url = url + "?" + sb.toString();
+                url_ori = url_ori + "?" + sb_ori.toString();
+            }
+        }
+        String urlSuffix = sql_json.getString("urlSuffix");
+        if (urlSuffix != null) {
+            url = url + urlSuffix;
+            url_ori = url_ori + "?" + urlSuffix;
+        }
+        otherMap.put("Url", url_ori);
+        log.warn(url_ori);
+        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();
+        }
+        HttpClientUtil.instance("redirect").post_export(url, postString, null, ConfigRedirect.headerMap, response);
+    }
 }

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

@@ -10,6 +10,7 @@ import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.HttpGet;
@@ -17,6 +18,7 @@ import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.HttpClients;
+import org.apache.http.protocol.HTTP;
 import org.apache.http.util.EntityUtils;
 
 import cn.hutool.core.lang.Tuple;
@@ -157,6 +159,11 @@ public class HttpClientUtil {
 		if (timeout == null) {
 			timeout = 300000;
 		}
+		//登录这里设置成短连接
+		if (url.contains("getCaptchaBase64") || url.contains("login")){
+			httpost.setProtocolVersion(HttpVersion.HTTP_1_0);
+			httpost.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
+		}
 		if (timeout != null) {
 			RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout).setConnectionRequestTimeout(timeout)
 					.setSocketTimeout(timeout).build();

+ 57 - 57
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RWDAlarmUtil.java

@@ -711,67 +711,67 @@ public class RWDAlarmUtil {
 				JSONArray Content_this_time = new JSONArray();
 				while (true) {
 					//post请求报警
-//					JSONObject postParam = new JSONObject();
-//					postParam.put("appId", "0");
-//					postParam.put("userId", "systemId");
-//					postParam.put("groupCode", RepositoryContainer.RepositoryProject.groupCode);
-//					postParam.put("projectId", RepositoryContainer.RepositoryProject.projectId);
-//					postParam.put("dealType", "0");
-//					postParam.put("size", page_size);
-//					postParam.put("current", page_current);
-//					String post_url = Constant.alarm_url + "/alarm-record/page";
-//					log.warn("onOpen refresh post start: " + post_url + "\n" + postParam.toJSONString());
-//					String postResultString = HttpClientUtil.instance("alarm").post(post_url, postParam.toJSONString());
-//					log.warn("onOpen refresh post end: " + post_url + "\n" + postParam.toJSONString());
-//					JSONObject postResult = JSON.parseObject(postResultString);
-//					JSONArray ContentInner = (JSONArray) postResult.get("Content");
+					JSONObject postParam = new JSONObject();
+					postParam.put("appId", "0");
+					postParam.put("userId", "systemId");
+					postParam.put("groupCode", RepositoryContainer.RepositoryProject.groupCode);
+					postParam.put("projectId", RepositoryContainer.RepositoryProject.projectId);
+					postParam.put("dealType", "0");
+					postParam.put("size", page_size);
+					postParam.put("current", page_current);
+					String post_url = Constant.alarm_url + "/alarm-record/page";
+					log.warn("onOpen refresh post start: " + post_url + "\n" + postParam.toJSONString());
+					String postResultString = HttpClientUtil.instance("alarm").post(post_url, postParam.toJSONString());
+					log.warn("onOpen refresh post end: " + post_url + "\n" + postParam.toJSONString());
+					JSONObject postResult = JSON.parseObject(postResultString);
+					JSONArray ContentInner = (JSONArray) postResult.get("Content");
 
 					//get请求报警
-					String get_url = Constant.alarm_url + "/alarm-record/page" + "?appId=" + "0" + "&userId=" + "systemId" + "&projectId="
-							+ RepositoryContainer.RepositoryProject.projectId + "&groupCode=" + RepositoryContainer.RepositoryProject.groupCode
-							+ "&dealType=0&size=" + page_size + "&current=" + page_current;
-					log.warn("onOpen refresh get start: " + get_url);
-					String getResultString = HttpClientUtil.instance("alarm").get(get_url);
-					log.warn("onOpen refresh get end: " + get_url);
-					JSONObject getResult = JSON.parseObject(getResultString);
-					JSONArray ContentInner = (JSONArray) getResult.get("Content");
-					JSONArray ids = new JSONArray();
-					Map<String, JSONObject> alarmMap = new ConcurrentHashMap<String, JSONObject>();
-					for (int i = 0; i < ContentInner.size(); i++) {
-						JSONObject alarm = ContentInner.getJSONObject(i);
-						if (alarm.containsKey("treatMode")) {
-							String id = (String) alarm.get("id");
-							int treatMode = alarm.getIntValue("treatMode");
-							if (treatMode == 2) {
-								ids.add(id);
-								alarmMap.put(id, alarm);
-							}
-						}
-					}
-					if (ids.size() > 0) {
-						JSONObject postParamInner = new JSONObject();
-						postParamInner.put("appId", "0");
-						postParamInner.put("userId", "systemId");
-						postParamInner.put("projectId", RepositoryContainer.RepositoryProject.projectId);
-						postParamInner.put("groupCode", RepositoryContainer.RepositoryProject.groupCode);
-						postParamInner.put("ids", ids);
-						String post_url = Constant.alarm_url + "/alarmToWorkOrder/queryOrderStateByAlarmIds";
-						log.warn("onOpen refresh post start: " + post_url + "\t" + "ids: " + ids.size());
-						String postResultString = HttpClientUtil.instance("alarm").post(post_url, postParamInner.toJSONString());
-						log.warn("onOpen refresh post end: " + post_url + "\t" + "ids: " + ids.size());
-						JSONObject postResult = JSON.parseObject(postResultString);
-						JSONArray ContentOrderState = (JSONArray) postResult.get("Content");
-						for (int i = 0; i < ContentOrderState.size(); i++) {
-							JSONObject orderStateItem = ContentOrderState.getJSONObject(i);
-							String alarmId = (String) orderStateItem.get("alarmId");
-							JSONObject alarm = alarmMap.get(alarmId);
-							alarm.put("orderId", orderStateItem.get("orderId"));
-							alarm.put("orderStateDesc", orderStateItem.get("orderStateDesc"));
-						}
-					}
+//					String get_url = Constant.alarm_url + "/alarm-record/page" + "?appId=" + "0" + "&userId=" + "systemId" + "&projectId="
+//							+ RepositoryContainer.RepositoryProject.projectId + "&groupCode=" + RepositoryContainer.RepositoryProject.groupCode
+//							+ "&dealType=0&size=" + page_size + "&current=" + page_current;
+//					log.warn("onOpen refresh get start: " + get_url);
+//					String getResultString = HttpClientUtil.instance("alarm").get(get_url);
+//					log.warn("onOpen refresh get end: " + get_url);
+//					JSONObject getResult = JSON.parseObject(getResultString);
+//					JSONArray ContentInner = (JSONArray) getResult.get("Content");
+//					JSONArray ids = new JSONArray();
+//					Map<String, JSONObject> alarmMap = new ConcurrentHashMap<String, JSONObject>();
+//					for (int i = 0; i < ContentInner.size(); i++) {
+//						JSONObject alarm = ContentInner.getJSONObject(i);
+//						if (alarm.containsKey("treatMode")) {
+//							String id = (String) alarm.get("id");
+//							int treatMode = alarm.getIntValue("treatMode");
+//							if (treatMode == 2) {
+//								ids.add(id);
+//								alarmMap.put(id, alarm);
+//							}
+//						}
+//					}
+//					if (ids.size() > 0) {
+//						JSONObject postParamInner = new JSONObject();
+//						postParamInner.put("appId", "0");
+//						postParamInner.put("userId", "systemId");
+//						postParamInner.put("projectId", RepositoryContainer.RepositoryProject.projectId);
+//						postParamInner.put("groupCode", RepositoryContainer.RepositoryProject.groupCode);
+//						postParamInner.put("ids", ids);
+//						String post_url = Constant.alarm_url + "/alarmToWorkOrder/queryOrderStateByAlarmIds";
+//						log.warn("onOpen refresh post start: " + post_url + "\t" + "ids: " + ids.size());
+//						String postResultString = HttpClientUtil.instance("alarm").post(post_url, postParamInner.toJSONString());
+//						log.warn("onOpen refresh post end: " + post_url + "\t" + "ids: " + ids.size());
+//						JSONObject postResult = JSON.parseObject(postResultString);
+//						JSONArray ContentOrderState = (JSONArray) postResult.get("Content");
+//						for (int i = 0; i < ContentOrderState.size(); i++) {
+//							JSONObject orderStateItem = ContentOrderState.getJSONObject(i);
+//							String alarmId = (String) orderStateItem.get("alarmId");
+//							JSONObject alarm = alarmMap.get(alarmId);
+//							alarm.put("orderId", orderStateItem.get("orderId"));
+//							alarm.put("orderStateDesc", orderStateItem.get("orderStateDesc"));
+//						}
+//					}
 					Content_this_time.addAll(ContentInner);
 					// 检查数量
-					int CountInner = getResult.getInteger("Count");
+					int CountInner =postResult.getInteger("Count");
 					if (page_current == 1) {
 						Count = CountInner;
 					} else {