|
@@ -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 {
|