Просмотр исходного кода

完善指定路径历史数据查询

menglu 4 лет назад
Родитель
Сommit
b07ae08016

+ 58 - 8
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestUtil.java

@@ -1,10 +1,13 @@
 package com.persagy.ibms.data.sdk.service.rest;
 
 import java.io.File;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -21,6 +24,7 @@ import com.persagy.ibms.data.sdk.util.ControlUtil;
 import com.persagy.ibms.data.sdk.util.FastJsonReaderUtil;
 import com.persagy.ibms.data.sdk.util.FastJsonUtil;
 import com.persagy.ibms.data.sdk.util.HttpClientUtil;
+import com.persagy.ibms.data.sdk.util.IntWrapper;
 import com.persagy.ibms.data.sdk.util.LogUtil;
 import com.persagy.ibms.data.sdk.util.QueryAssist;
 import com.persagy.ibms.data.sdk.util.QueryUtil;
@@ -625,26 +629,72 @@ public class RestUtil {
 	}
 
 	public static String path_array_history_fjd_query(String param) {
-		JSONArray result = new JSONArray();
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
 		JSONObject parseObject = JSON.parseObject(param);
 		String time_from = parseObject.getString("time_from");
 		String time_to = parseObject.getString("time_to");
 		JSONArray Items = parseObject.getJSONArray("Items");
+		List<Object> drawObjectList = new ArrayList<Object>();
+		Map<String, String> ObjInfo2Point = new HashMap<String, String>();
 		for (int i = 0; i < Items.size(); i++) {
 			JSONObject item = (JSONObject) Items.get(i);
-			String name = (String) item.get("name");
 			JSONArray path = (JSONArray) item.get("path");
 			String[] valuePath = new String[path.size()];
 			for (int ii = 0; ii < path.size(); ii++) {
 				valuePath[ii] = path.getString(ii);
 			}
 			Object valueObject = ComputeUtil.getValueObject(RepositoryBase.instance, valuePath);
-			Object draw_object = RecursiveUtil.drawObject(RepositoryBase.instance, valueObject);
-			JSONObject resultItem = new JSONObject();
-			resultItem.put("name", name);
-			resultItem.put("path", path);
-			resultItem.put("Content", draw_object);
-			result.add(resultItem);
+			Object drawObject = RecursiveUtil.drawObject(RepositoryBase.instance, valueObject, ObjInfo2Point);
+			drawObjectList.add(drawObject);
+		}
+		Map<String, JSONArray> Point2datas = new HashMap<String, JSONArray>();
+		Map<String, IntWrapper> Point2index = new HashMap<String, IntWrapper>();
+		for (String objInfo : ObjInfo2Point.keySet()) {
+			String point = ObjInfo2Point.get(objInfo);
+			int index_ = point.lastIndexOf('-');
+			String meter = point.substring(0, index_);
+			int funcid = Integer.parseInt(point.substring(index_ + 1));
+			JSONArray datas = null;
+			try {
+				datas = fjd_query_inner(meter, funcid, time_from, time_to);
+			} catch (Exception e) {
+				// e.printStackTrace();
+				try {
+					datas = fjd_query_inner(meter, funcid, time_from, time_to);
+				} catch (Exception e1) {
+					// e.printStackTrace();
+				}
+			}
+			if (datas == null) {
+				datas = new JSONArray();
+			}
+			Point2datas.put(point, datas);
+			Point2index.put(point, new IntWrapper());
+		}
+		JSONArray result = new JSONArray();
+		try {
+			Date timeFrom = sdf.parse(time_from);
+			Date timeTo = sdf.parse(time_to);
+			for (Date tmpDate = timeFrom; tmpDate.getTime() < timeTo.getTime(); tmpDate = new Date(tmpDate.getTime() + 1000L * 60 * 15)) {
+				String tmp = sdf.format(tmpDate);
+				JSONObject timeJSON = new JSONObject();
+				timeJSON.put("time", tmp);
+				JSONArray time_datas = new JSONArray();
+				for (int i = 0; i < Items.size(); i++) {
+					JSONObject item = (JSONObject) Items.get(i);
+					Object drawObject = drawObjectList.get(i);
+					Object valueObject = RecursiveUtil.fillTimeValueObject(drawObject, Point2datas, Point2index, tmp);
+					String name = (String) item.get("name");
+					JSONObject resultItem = new JSONObject();
+					resultItem.put("name", name);
+					resultItem.put("Content", valueObject);
+					time_datas.add(resultItem);
+				}
+				timeJSON.put("pathArray", time_datas);
+				result.add(timeJSON);
+			}
+		} catch (ParseException e) {
+			// e.printStackTrace();
 		}
 		return result.toJSONString();
 	}

+ 9 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/IntWrapper.java

@@ -0,0 +1,9 @@
+package com.persagy.ibms.data.sdk.util;
+
+public class IntWrapper {
+	public int value;
+
+	public IntWrapper() {
+		this.value = 0;
+	}
+}

+ 99 - 9
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RecursiveUtil.java

@@ -3,6 +3,7 @@ package com.persagy.ibms.data.sdk.util;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.locks.ReentrantLock;
 
 import com.alibaba.fastjson.JSON;
@@ -23,25 +24,113 @@ public class RecursiveUtil {
 	 * @param tmpData
 	 * @throws Exception
 	 */
-	public static Object drawObject(Repository Repository, Object tmpData) {
+	public static Object fillTimeValueObject(Object tmpData, Map<String, JSONArray> Point2datas, Map<String, IntWrapper> Point2index, String time) {
+		Object result = null;
+		if (tmpData instanceof JSONObject) {
+			JSONObject currData = (JSONObject) tmpData;
+			result = fillTimeValue(currData, Point2datas, Point2index, time);
+		} else if (tmpData instanceof JSONArray) {
+			JSONArray currData = (JSONArray) tmpData;
+			result = fillTimeValue(currData, Point2datas, Point2index, time);
+		}
+		return result;
+	}
+
+	private static Object fillTimeValueAssist(JSONArray datas, IntWrapper intWrapper, String time) {
+		Object result = null;
+		while (intWrapper.value < datas.size()) {
+			JSONObject data = (JSONObject) datas.get(intWrapper.value);
+			String timeInner = (String) data.get("data_time");
+			if (timeInner.compareTo(time) < 0) {
+				intWrapper.value++;
+			} else {
+				break;
+			}
+		}
+		if (intWrapper.value < datas.size()) {
+			JSONObject data = (JSONObject) datas.get(intWrapper.value);
+			result = data.get("data_value");
+		}
+		return result;
+	}
+
+	private static JSONObject fillTimeValue(JSONObject sdo, Map<String, JSONArray> Point2datas, Map<String, IntWrapper> Point2index, String time) {
+		if (sdo == null) {
+			return null;
+		}
+
+		if (sdo.containsKey("id")) {
+			JSONObject result = new JSONObject();
+			String id = (String) sdo.get("id");
+			result.put("id", id);
+			for (String Key : sdo.keySet()) {
+				String infoValue = (String) sdo.get(Key);
+				if (infoValue.startsWith("point:")) {
+					String point = infoValue.substring("point:".length());
+					JSONArray datas = Point2datas.get(point);
+					IntWrapper intWrapper = Point2index.get(point);
+					Object data_value = fillTimeValueAssist(datas, intWrapper, time);
+					result.put(Key, data_value);
+				}
+			}
+			return result;
+		} else {
+			JSONObject result = new JSONObject();
+			for (String Key : sdo.keySet()) {
+				Object value = sdo.get(Key);
+				if (value instanceof String) {
+					result.put(Key, value);
+				} else {
+					result.put(Key, fillTimeValueObject(value, Point2datas, Point2index, time));
+				}
+			}
+			return result;
+		}
+	}
+
+	private static Object fillTimeValue(JSONArray sdv, Map<String, JSONArray> Point2datas, Map<String, IntWrapper> Point2index, String time) {
+		if (sdv == null) {
+			return null;
+		}
+
+		JSONArray result = new JSONArray();
+		for (int i = 0; i < sdv.size(); i++) {
+			Object sdb = sdv.get(i);
+			if (sdb instanceof JSONObject) {
+				JSONObject sdbObject = (JSONObject) sdb;
+				result.add(fillTimeValue(sdbObject, Point2datas, Point2index, time));
+			} else {
+				result.add(fillTimeValueObject(sdb, Point2datas, Point2index, time));
+			}
+		}
+		return result;
+	}
+
+	/**
+	 * 刷新数据节点,根据read_level
+	 * 
+	 * @param tmpData
+	 * @throws Exception
+	 */
+	public static Object drawObject(Repository Repository, Object tmpData, Map<String, String> ObjInfo2Point) {
 		Object result = null;
 		Date currTime = new Date();
 		if (tmpData instanceof SceneDataValue) {
 			SceneDataValue currData = (SceneDataValue) tmpData;
 			int read_level = currData.rel_property == null ? 1 : Integer.parseInt(currData.rel_property.read_level);
 			read_level = read_level == 0 ? -1 : read_level;
-			result = draw(Repository, currData, read_level, currTime);
+			result = draw(Repository, currData, read_level, currTime, ObjInfo2Point);
 		} else if (tmpData instanceof SceneDataObject) {
 			SceneDataObject currData = (SceneDataObject) tmpData;
 			int read_level = (currData.parentArrayData != null && currData.parentArrayData.rel_property != null)
 					? Integer.parseInt(currData.parentArrayData.rel_property.read_level) : 1;
 			read_level = read_level == 0 ? -1 : read_level;
-			result = draw(Repository, currData, read_level, currTime);
+			result = draw(Repository, currData, read_level, currTime, ObjInfo2Point);
 		}
 		return result;
 	}
 
-	private static JSONObject draw(Repository Repository, SceneDataObject sdo, int depth, Date currTime) {
+	private static JSONObject draw(Repository Repository, SceneDataObject sdo, int depth, Date currTime, Map<String, String> ObjInfo2Point) {
 		if (sdo == null) {
 			return null;
 		}
@@ -59,7 +148,8 @@ public class RecursiveUtil {
 					if (RWDUtil.isRunParam(infoArray, Key)) {
 						String infoValue = (String) obj.get(Key);
 						if (RWDLoadUtil.infoValue_is_point(infoValue)) {
-							result.put(Key, "point:" + obj.get(Key));
+							result.put(Key, "point:" + infoValue);
+							ObjInfo2Point.put(id + "-" + Key, infoValue);
 						}
 					}
 				}
@@ -68,7 +158,7 @@ public class RecursiveUtil {
 		} else if (sdo.containsKey("名称") && sdo.containsKey("清单")) {
 			JSONObject result = new JSONObject();
 			result.put("名称", sdo.get("名称").value_primitive);
-			Object list = draw(Repository, (SceneDataValue) sdo.get("清单"), depthInner, currTime);
+			Object list = draw(Repository, (SceneDataValue) sdo.get("清单"), depthInner, currTime, ObjInfo2Point);
 			result.put("清单", list);
 			return result;
 		} else {
@@ -76,7 +166,7 @@ public class RecursiveUtil {
 		}
 	}
 
-	private static Object draw(Repository Repository, SceneDataValue sdv, int depth, Date currTime) {
+	private static Object draw(Repository Repository, SceneDataValue sdv, int depth, Date currTime, Map<String, String> ObjInfo2Point) {
 		if (sdv == null) {
 			return null;
 		}
@@ -91,7 +181,7 @@ public class RecursiveUtil {
 
 		if (depth > 0 || depth == -1) {
 			if (sdv.value_object != null) {
-				JSONObject result = draw(Repository, sdv.value_object, curr_depth, currTime);
+				JSONObject result = draw(Repository, sdv.value_object, curr_depth, currTime, ObjInfo2Point);
 				return result;
 			} else if (sdv.value_array != null) {
 				JSONArray result = new JSONArray();
@@ -99,7 +189,7 @@ public class RecursiveUtil {
 					SceneDataBase sdb = sdv.value_array.get(i);
 					if (sdb instanceof SceneDataObject) {
 						SceneDataObject sod = (SceneDataObject) sdb;
-						JSONObject resultItem = draw(Repository, sod, curr_depth, currTime);
+						JSONObject resultItem = draw(Repository, sod, curr_depth, currTime, ObjInfo2Point);
 						result.add(resultItem);
 					}
 				}