Quellcode durchsuchen

增加根据路径查询下属所有历史分精度数据接口(未完成)
屏蔽部分错误信息点

menglu vor 4 Jahren
Ursprung
Commit
a29446f006

+ 4 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/data/SceneDataObject.java

@@ -104,6 +104,10 @@ public class SceneDataObject extends SceneDataBase {
 		this.value_object.put(key, value);
 	}
 
+	public void remove(String key) {
+		this.value_object.remove(key);
+	}
+
 	public int size() {
 		int result = 0;
 		if (this.father != null) {

+ 6 - 5
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/WebSocketCheckThread.java

@@ -5,15 +5,15 @@ import java.net.URISyntaxException;
 
 import javax.annotation.PostConstruct;
 
-import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
 import com.persagy.ibms.data.sdk.util.Constant;
-import com.persagy.ibms.data.sdk.util.LogUtil;
 import com.persagy.ibms.data.sdk.util.RepositoryBase;
 import com.persagy.ibms.data.sdk.websocket.AlarmWebSocketClient;
 import com.persagy.ibms.data.sdk.websocket.IOTWebSocketClient;
 
+import lombok.extern.slf4j.Slf4j;
+
 @Slf4j
 @Component
 public class WebSocketCheckThread extends Thread {
@@ -33,11 +33,12 @@ public class WebSocketCheckThread extends Thread {
 			if (IOTWebSocketClient.client != null) {
 				try {
 					if (!IOTWebSocketClient.client.isOpen()) {
-						IOTWebSocketClient.client = new IOTWebSocketClient(new URI(Constant.iot_websocket_url + "?projectId=" + RepositoryBase.projectId.substring(2) + "&type=iot,pointset"));
+						IOTWebSocketClient.client = new IOTWebSocketClient(
+								new URI(Constant.iot_websocket_url + "?projectId=" + RepositoryBase.projectId.substring(2) + "&type=iot,pointset"));
 						IOTWebSocketClient.client.connect();
 					}
 				} catch (URISyntaxException e) {
-					log.warn(e.getMessage(),e);
+					log.warn(e.getMessage(), e);
 					e.printStackTrace();
 				}
 			}
@@ -48,7 +49,7 @@ public class WebSocketCheckThread extends Thread {
 						AlarmWebSocketClient.client.connect();
 					}
 				} catch (URISyntaxException e) {
-					log.warn(e.getMessage(),e);
+					log.warn(e.getMessage(), e);
 					e.printStackTrace();
 				}
 			}

+ 1 - 1
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestApi.java

@@ -120,7 +120,7 @@ public class RestApi {
 		return result;
 	}
 	
-	@PostMapping(path = { "/path_array_history_fjd_query", "/zkt-sdk/history_fjd_query" }, produces = "application/json;charset=UTF-8")
+	@PostMapping(path = { "/path_array_history_fjd_query", "/zkt-sdk/path_array_history_fjd_query" }, produces = "application/json;charset=UTF-8")
 	public String path_array_history_fjd_query(@RequestBody String param) {
 		String result = RestUtil.path_array_history_fjd_query(param);
 		return result;

+ 14 - 11
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestUtil.java

@@ -6,6 +6,8 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
+import javax.servlet.http.HttpServletRequest;
+
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -25,9 +27,8 @@ import com.persagy.ibms.data.sdk.util.QueryUtil;
 import com.persagy.ibms.data.sdk.util.RecursiveUtil;
 import com.persagy.ibms.data.sdk.util.Repository;
 import com.persagy.ibms.data.sdk.util.RepositoryBase;
-import lombok.extern.slf4j.Slf4j;
 
-import javax.servlet.http.HttpServletRequest;
+import lombok.extern.slf4j.Slf4j;
 
 @Slf4j
 public class RestUtil {
@@ -631,21 +632,23 @@ public class RestUtil {
 		JSONArray Items = parseObject.getJSONArray("Items");
 		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", item.get("name"));
-			resultItem.put("path", item.get("path"));
-			resultItem.put("Content", path_query_inner(time_from, time_to, item));
+			resultItem.put("name", name);
+			resultItem.put("path", path);
+			resultItem.put("Content", draw_object);
 			result.add(resultItem);
 		}
 		return result.toJSONString();
 	}
 
-	private static JSONArray path_query_inner(String time_from, String time_to, JSONObject parseObject) {
-		JSONArray result = new JSONArray();
-		// TODO
-		return result;
-	}
-
 	private static JSONArray fjd_query_inner(String meter, int funcid, String time_from, String time_to) throws Exception {
 		JSONObject pointObject = new JSONObject();
 		pointObject.put("meter", meter);

+ 45 - 21
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RWDLoadUtil.java

@@ -20,6 +20,22 @@ public class RWDLoadUtil {
 	public static String[] concentrate_codes = { "CO2", "PM2.5" };
 	public static String[] concentrate_names = { "CO2", "PM2.5" };
 
+	public static boolean infoValue_is_point(String infoValue) {
+		int index_ = infoValue.lastIndexOf('-');
+		if (index_ == -1 || index_ == 0 || index_ == infoValue.length() - 1) {
+			return false;
+		}
+
+		String funcid = infoValue.substring(index_ + 1);
+		try {
+			Integer.parseInt(funcid);
+			return true;
+		} catch (NumberFormatException e) {
+			// e.printStackTrace();
+			return false;
+		}
+	}
+
 	public static void LoadPhysicalWorld(Repository Repository) throws Exception {
 		String validPath = Constant.getLatestPath(Constant.physical_world, true);
 
@@ -190,20 +206,24 @@ public class RWDLoadUtil {
 						}
 						String point = (String) value_primitive;
 						if (point != null) {
-							RepositoryBase.info2point.put(obj_id, new ConcurrentHashMap<String, String>());
-							ConcurrentHashMap<String, String> pointMap = RepositoryBase.info2point.get(obj_id);
-							pointMap.putIfAbsent(Key, point);
-							// 表号功能号改为null
-							{
-								SceneDataValue sdv = new SceneDataValue(Repository, obj, Key, null, true);
-								sdv.value_primitive = 0.0;
-								SceneDataValue exist_sdv = RepositoryBase.point2sdv.putIfAbsent(point, sdv);
-								if (exist_sdv == null) {
-									RepositoryBase.sdv2point.putIfAbsent(sdv, point);
+							if (RWDLoadUtil.infoValue_is_point(point)) {
+								RepositoryBase.info2point.put(obj_id, new ConcurrentHashMap<String, String>());
+								ConcurrentHashMap<String, String> pointMap = RepositoryBase.info2point.get(obj_id);
+								pointMap.putIfAbsent(Key, point);
+								// 表号功能号改为null
+								{
+									SceneDataValue sdv = new SceneDataValue(Repository, obj, Key, null, true);
+									sdv.value_primitive = 0.0;
+									SceneDataValue exist_sdv = RepositoryBase.point2sdv.putIfAbsent(point, sdv);
+									if (exist_sdv == null) {
+										RepositoryBase.sdv2point.putIfAbsent(sdv, point);
+									}
 								}
+								SceneDataValue data = RepositoryBase.point2sdv.get(point);
+								obj.put(Key, data);
+							} else {
+								obj.remove(Key);
 							}
-							SceneDataValue data = RepositoryBase.point2sdv.get(point);
-							obj.put(Key, data);
 						}
 					} else if (RWDUtil.isSetParam(infoArray, Key)) {
 						if (!(value_primitive instanceof String)) {
@@ -211,17 +231,21 @@ public class RWDLoadUtil {
 						}
 						String point = (String) value_primitive;
 						if (point != null) {
-							// 表号功能号改为null
-							{
-								SceneDataValue sdv = new SceneDataValue(Repository, obj, Key, null, true);
-								sdv.value_primitive = 0;
-								SceneDataValue exist_sdv = RepositoryBase.set2sdv.putIfAbsent(point, sdv);
-								if (exist_sdv == null) {
-									RepositoryBase.sdv2set.putIfAbsent(sdv, point);
+							if (RWDLoadUtil.infoValue_is_point(point)) {
+								// 表号功能号改为null
+								{
+									SceneDataValue sdv = new SceneDataValue(Repository, obj, Key, null, true);
+									sdv.value_primitive = 0;
+									SceneDataValue exist_sdv = RepositoryBase.set2sdv.putIfAbsent(point, sdv);
+									if (exist_sdv == null) {
+										RepositoryBase.sdv2set.putIfAbsent(sdv, point);
+									}
 								}
+								SceneDataValue data = RepositoryBase.set2sdv.get(point);
+								obj.put(Key, data);
+							} else {
+								obj.remove(Key);
 							}
-							SceneDataValue data = RepositoryBase.set2sdv.get(point);
-							obj.put(Key, data);
 						}
 					}
 				}

+ 101 - 6
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RecursiveUtil.java

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