|
@@ -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);
|
|
|
}
|
|
|
}
|