Browse Source

实时报警需要分页查询

menglu 3 years ago
parent
commit
3435e7ddae

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

@@ -637,47 +637,72 @@ public class RWDAlarmUtil {
 		JSONArray Content;
 		if (Constant.alarm_service_name.equalsIgnoreCase("ibms-alarm")) {
 			Content = new JSONArray();
-			int[] statusArray = { 0, 1, 2 };
-			for (int status : statusArray) {
-				String get_url = Constant.alarm_url + "/alarm-record/page" + "?appId=" + "0" + "&userId=" + "systemId" + "&projectId="
-						+ RepositoryContainer.RepositoryProject.projectId + "&groupCode=" + RepositoryContainer.RepositoryProject.groupCode
-						+ "&size=65535&current=1&status=" + status;
-				String getResultString = HttpClientUtil.get(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);
+			while (true) {
+				Integer Count = null;
+				int page_size = 500;
+				int page_current = 1;
+				boolean success = true;
+				JSONArray Content_this_time = new JSONArray();
+				while (true) {
+					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;
+					String getResultString = HttpClientUtil.get(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";
-					String postResultString = HttpClientUtil.post(post_url, postParamInner.toJSONString());
-					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"));
+					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";
+						String postResultString = HttpClientUtil.post(post_url, postParamInner.toJSONString());
+						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");
+					if (page_current == 1) {
+						Count = CountInner;
+					} else {
+						if (CountInner != Count) {
+							success = false;
+							break;
+						}
+					}
+					if (page_current * page_size >= Count) {
+						break;
 					}
+					page_current++;
+				}
+				if (success) {
+					Content = Content_this_time;
+					break;
 				}
-				Content.addAll(ContentInner);
 			}
 		} else {
 			String post_url = Constant.alarm_url + "/alarm/queryAlarmList";