|
@@ -1,17 +1,19 @@
|
|
|
package com.persagy.ibms.data.sdk.util;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.locks.ReentrantLock;
|
|
|
+
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.persagy.ibms.data.sdk.data.SceneDataBase;
|
|
|
import com.persagy.ibms.data.sdk.data.SceneDataObject;
|
|
|
import com.persagy.ibms.data.sdk.data.SceneDataValue;
|
|
|
import com.persagy.ibms.data.sdk.data.SceneProperty;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.concurrent.locks.ReentrantLock;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
@Slf4j
|
|
|
public class RecursiveUtil {
|
|
@@ -21,6 +23,99 @@ public class RecursiveUtil {
|
|
|
* @param tmpData
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
+ public static Object drawObject(Repository Repository, Object tmpData) {
|
|
|
+ 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);
|
|
|
+ } 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);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static JSONObject draw(Repository Repository, SceneDataObject sdo, int depth, Date currTime) {
|
|
|
+ if (sdo == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ int depthInner = depth == -1 ? -1 : (depth > 0 ? depth - 1 : 0);
|
|
|
+ if (sdo.containsKey("id")) {
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ String id = (String) sdo.get("id").value_primitive;
|
|
|
+ result.put("id", id);
|
|
|
+ JSONObject obj = Repository.id2object.get(id);
|
|
|
+ String classCode = (String) obj.get("classCode");
|
|
|
+ List<SceneDataValue> infoArray = Repository.infoArrayDic.get(classCode);
|
|
|
+ for (String Key : obj.keySet()) {
|
|
|
+ if (obj.get(Key) != null && obj.get(Key) instanceof String) {
|
|
|
+ if (RWDUtil.isRunParam(infoArray, Key)) {
|
|
|
+ String infoValue = (String) obj.get(Key);
|
|
|
+ if (RWDLoadUtil.infoValue_is_point(infoValue)) {
|
|
|
+ result.put(Key, "point:" + obj.get(Key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ } 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);
|
|
|
+ result.put("清单", list);
|
|
|
+ return result;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Object draw(Repository Repository, SceneDataValue sdv, int depth, Date currTime) {
|
|
|
+ if (sdv == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ int curr_depth = depth;
|
|
|
+ if (sdv.rel_property != null && curr_depth != -1) {
|
|
|
+ curr_depth -= Integer.parseInt(sdv.rel_property.offset_level);
|
|
|
+ if (curr_depth < 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (depth > 0 || depth == -1) {
|
|
|
+ if (sdv.value_object != null) {
|
|
|
+ JSONObject result = draw(Repository, sdv.value_object, curr_depth, currTime);
|
|
|
+ return result;
|
|
|
+ } else if (sdv.value_array != null) {
|
|
|
+ JSONArray result = new JSONArray();
|
|
|
+ for (int i = 0; i < sdv.value_array.size(); i++) {
|
|
|
+ SceneDataBase sdb = sdv.value_array.get(i);
|
|
|
+ if (sdb instanceof SceneDataObject) {
|
|
|
+ SceneDataObject sod = (SceneDataObject) sdb;
|
|
|
+ JSONObject resultItem = draw(Repository, sod, curr_depth, currTime);
|
|
|
+ result.add(resultItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 刷新数据节点,根据read_level
|
|
|
+ *
|
|
|
+ * @param tmpData
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
public static void refreshObject(Repository Repository, Object tmpData) throws Exception {
|
|
|
Date currTime = new Date();
|
|
|
if (tmpData instanceof SceneDataValue) {
|
|
@@ -164,7 +259,7 @@ public class RecursiveUtil {
|
|
|
compute(Repository, sdv);
|
|
|
}
|
|
|
|
|
|
-// LogUtil.info(getPath(sv));
|
|
|
+ // LogUtil.info(getPath(sv));
|
|
|
ReentrantLock lock = Repository.property2lock.get(sv.rel_property);
|
|
|
try {
|
|
|
lock.lock();
|