Browse Source

完善query

menglu 3 years ago
parent
commit
953a63ffb6

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

@@ -39,31 +39,31 @@ public class RestApi {
 		return "alarm_websocket_close";
 	}
 
-	@PostMapping(path = { "/query", "/zkt-sdk/query" }, produces = "application/json;charset=UTF-8")
+	@PostMapping(path = { "/query" }, produces = "application/json;charset=UTF-8")
 	public String query(@RequestBody String param) {
 		String result = RestUtil.query(param);
 		return result;
 	}
 
-	@GetMapping(path = { "/showTree", "/zkt-sdk/showTree" }, produces = "application/json;charset=UTF-8")
+	@GetMapping(path = { "/showTree" }, produces = "application/json;charset=UTF-8")
 	String showTree() {
 		String result = RestUtil.showTree();
 		return result;
 	}
 
-	@GetMapping(path = { "/check", "/zkt-sdk/check" }, produces = "application/json;charset=UTF-8")
+	@GetMapping(path = { "/check" }, produces = "application/json;charset=UTF-8")
 	String check() {
 		String result = RestUtil.check();
 		return result;
 	}
 
-	@PostMapping(path = { "/desc", "/zkt-sdk/desc" }, produces = "application/json;charset=UTF-8")
+	@PostMapping(path = { "/desc" }, produces = "application/json;charset=UTF-8")
 	public String desc(@RequestBody String param) {
 		String result = RestUtil.desc(param);
 		return result;
 	}
 
-	@PostMapping(path = { "/show", "/zkt-sdk/show" }, produces = "application/json;charset=UTF-8")
+	@PostMapping(path = { "/show" }, produces = "application/json;charset=UTF-8")
 	public String show(@RequestBody String param) {
 		String result = RestUtil.show(param);
 		return result;
@@ -95,24 +95,6 @@ public class RestApi {
 		return result;
 	}
 
-	// @PostMapping(path = { "/wrapper_post", "/zkt-sdk/wrapper_post" }, produces = "application/json;charset=UTF-8")
-	// public String wrapper_post(@RequestBody String param) {
-	// String result = RestUtil.wrapper_post(param);
-	// return result;
-	// }
-	//
-	// @PostMapping(path = { "/wrapper_post_filter_and_page", "/zkt-sdk/wrapper_post_filter_and_page" }, produces = "application/json;charset=UTF-8")
-	// public String wrapper_post_filter_and_page(@RequestBody String param) {
-	// String result = RestUtil.wrapper_post_filter_and_page(param);
-	// return result;
-	// }
-	//
-	// @PostMapping(path = { "/wrapper_control", "/zkt-sdk/wrapper_control" }, produces = "application/json;charset=UTF-8")
-	// public String wrapper_control(@RequestBody String param) {
-	// String result = RestUtil.wrapper_control(param);
-	// return result;
-	// }
-
 	@PostMapping(path = { "/fjd_query", "/zkt-sdk/fjd_query" }, produces = "application/json;charset=UTF-8")
 	public String fjd_query(@RequestBody String param) {
 		String result = RestUtil.fjd_query(param);

+ 18 - 125
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestUtil.java

@@ -39,38 +39,36 @@ import lombok.extern.slf4j.Slf4j;
 public class RestUtil {
 	public static String query(String param) {
 		Repository Repository = RepositoryBase.instance;
+		JSONObject result = new JSONObject();
+		Object Content;
 		try {
 			JSONObject sql_json = JSON.parseObject(param);
+			Integer read_level = (Integer) sql_json.get("read_level");
+			read_level = read_level == null ? 4 : read_level;
 			Object queryResult = QueryUtil.query(Repository, null, sql_json, new QueryAssist());
-			if (queryResult instanceof List) {
+			if (queryResult instanceof SceneDataSet) {
 				SceneDataSet sdvList = (SceneDataSet) queryResult;
-				JSONArray arrayResult = new JSONArray();
 				SceneDataValue sdv = new SceneDataValue(null, null, null, null);
-				sdv.value_array = new SceneDataSet(false);
-				sdv.value_array.set = new ArrayList<SceneDataObject>();
-				for (SceneDataObject sdvInner : sdvList.set) {
-					if (sdvInner != null) {
-						sdv.value_array.set.add(sdvInner);
-					}
-				}
-				if (arrayResult.size() > 0) {
-					return arrayResult.toString();
-				} else {
-					Integer read_level = (Integer) sql_json.get("read_level");
-					read_level = read_level == null ? 4 : read_level;
-					return sdv.toJSON(true, read_level == 0 ? -1 : read_level).toString();
-				}
+				sdv.value_array = sdvList;
+				Content = sdv.toJSON(true, read_level == 0 ? -1 : read_level);
 			} else if (queryResult instanceof SceneDataValue) {
 				SceneDataValue sdv = (SceneDataValue) queryResult;
-				int read_level = 0;
-				return sdv.toJSON(true, read_level == 0 ? -1 : read_level).toString();
+				Content = sdv.toJSON(true, read_level == 0 ? -1 : read_level);
 			} else {
-				return queryResult.toString();
+				Content = queryResult;
+			}
+			result.put("Result", "success");
+			result.put("Content", Content);
+			if (Content instanceof JSONArray) {
+				JSONArray array = (JSONArray) Content;
+				result.put("Count", array.size());
 			}
 		} catch (Exception e) {
 			e.printStackTrace();
+			result.put("Result", "failure");
+			result.put("Reason", LogUtil.GetExceptionStackTrace(e));
 		}
-		return null;
+		return FastJsonUtil.toFormatString(result);
 	}
 
 	public static String showTree() {
@@ -318,41 +316,6 @@ public class RestUtil {
 		}
 	}
 
-	// public static String wrapper_post(String param) {
-	// JSONArray path = JSON.parseArray(param);
-	// String[] valuePath = new String[path.size()];
-	// for (int i = 0; i < path.size(); i++) {
-	// valuePath[i] = path.getString(i);
-	// }
-	// String result = RestUtil.wrapper_post(valuePath);
-	// return result;
-	// }
-
-	// public static String wrapper_post(String[] valuePath) {
-	// Repository Repository = RepositoryBase.instance;
-	// JSONObject result = new JSONObject();
-	// try {
-	// Object valueObject = ComputeUtil.getValueObject(Repository, valuePath);
-	// Object valueJSON = ComputeUtil.getValueJSON(valueObject);
-	// if (valueJSON instanceof JSONArray) {
-	// JSONArray array = (JSONArray) valueJSON;
-	// result.put("Content", array);
-	// result.put("Count", array.size());
-	// } else {
-	// result.put("Item", valueJSON);
-	// }
-	// result.put("Result", "success");
-	// } catch (Exception e) {
-	// e.printStackTrace();
-	// String message = LogUtil.GetExceptionStackTrace(e);
-	// log.error(message);
-	// result.put("Result", "failure");
-	// result.put("ResultMsg", message);
-	// result.put("ResultCode", 250);
-	// }
-	// return result.toJSONString();
-	// }
-
 	public static String post_filter_and_page(String param) {
 		JSONObject result = new JSONObject();
 		try {
@@ -388,44 +351,6 @@ public class RestUtil {
 		return result.toJSONString();
 	}
 
-	// public static String wrapper_post_filter_and_page(String param) {
-	// JSONObject result = new JSONObject();
-	// try {
-	// JSONObject paramObject = JSON.parseObject(param);
-	// List<SceneDataObject> array = filter_and_page(paramObject);
-	// if (paramObject.containsKey("count")) {
-	// } else {
-	// int pageSize = Integer.MAX_VALUE;
-	// int pageIndex = 0;
-	// if (paramObject.containsKey("page")) {
-	// pageSize = (Integer) paramObject.get("pageSize");
-	// pageIndex = (Integer) paramObject.get("pageIndex");
-	// }
-	// SceneDataValue sdv = new SceneDataValue(null, null, null, null);
-	// sdv.value_array = new SceneDataSet(false);
-	// sdv.value_array.set = new ArrayList<SceneDataObject>();
-	// for (int i = pageSize * pageIndex; i < pageSize * (pageIndex + 1) && i < array.size(); i++) {
-	// sdv.value_array.set.add(array.get(i));
-	// }
-	// int read_level = 0;
-	// JSONArray content = (JSONArray) sdv.toJSON(true, read_level == 0 ? -1 : read_level);
-	//
-	// result.put("Content", content);
-	// result.put("Count", content.size());
-	// }
-	// result.put("TotalCount", array.size());
-	// result.put("Result", "success");
-	// } catch (Exception e) {
-	// e.printStackTrace();
-	// String message = LogUtil.GetExceptionStackTrace(e);
-	// log.error(message);
-	// result.put("Result", "failure");
-	// result.put("ResultMsg", message);
-	// result.put("ResultCode", 250);
-	// }
-	// return result.toJSONString();
-	// }
-
 	private static List<SceneDataObject> filter_and_page(JSONObject paramObject) throws Exception {
 		Repository Repository = RepositoryBase.instance;
 		JSONArray path = (JSONArray) paramObject.get("path");
@@ -613,38 +538,6 @@ public class RestUtil {
 		return result.toJSONString();
 	}
 
-	// public static String wrapper_control(String param) {
-	// Repository Repository = RepositoryBase.instance;
-	// JSONObject result = new JSONObject();
-	// try {
-	// JSONObject paramObject = JSON.parseObject(param);
-	// JSONArray path = (JSONArray) paramObject.get("path");
-	// JSONObject infoValueSet = (JSONObject) paramObject.get("infoValueSet");
-	// String controlReason = (String) paramObject.get("controlReason");
-	// String controlRemark = (String) paramObject.get("controlRemark");
-	// log.info("path: " + path);
-	// log.info("infoValueSet: " + infoValueSet);
-	// log.info("controlReason: " + controlReason);
-	// log.info("controlRemark: " + controlRemark);
-	//
-	// String[] valuePath = new String[path.size()];
-	// for (int i = 0; i < path.size(); i++) {
-	// valuePath[i] = path.getString(i);
-	// }
-	// ControlUtil.set(Repository, path, valuePath, infoValueSet);
-	//
-	// result.put("Result", "success");
-	// } catch (Exception e) {
-	// e.printStackTrace();
-	// String message = LogUtil.GetExceptionStackTrace(e);
-	// log.error(message);
-	// result.put("Result", "failure");
-	// result.put("ResultMsg", message);
-	// result.put("ResultCode", 250);
-	// }
-	// return result.toJSONString();
-	// }
-
 	public static String get_control_value(String param) {
 		JSONObject result = new JSONObject();
 		try {