Browse Source

增加数组查询功能

menglu 3 years ago
parent
commit
d41a3da1f4

+ 1 - 1
ibms-data-sdk/pom.xml

@@ -216,7 +216,7 @@
 		<dependency>
 			<groupId>com.persagy</groupId>
 			<artifactId>sailfish</artifactId>
-			<version>0.0.24</version>
+			<version>0.0.25</version>
 		</dependency>
 	</dependencies>
 

+ 50 - 46
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestUtil.java

@@ -36,6 +36,11 @@ public class RestUtil {
 		Object Content;
 		try {
 			JSONObject sql_json = JSON.parseObject(param);
+			List<ExceptionItem> errorList = new ArrayList<ExceptionItem>();
+			ExamineUtil.check_sql(Repository, null, "query", null, false, false, false, sql_json, errorList);
+			if (errorList.size() > 0) {
+				throw new ExceptionWrapper(errorList);
+			}
 			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());
@@ -697,44 +702,43 @@ public class RestUtil {
 		return result;
 	}
 
-
-	public static String getAdmUrl(String param){
+	public static String getAdmUrl(String param) {
 		JSONObject result = new JSONObject();
-		result.put("status","success");
-		result.put("statusCode","0");
-		if(Objects.isNull(param)){
-			result.put("status","fail");
-			result.put("msg","参数不能为空");
-			result.put("statusCode","250");
+		result.put("status", "success");
+		result.put("statusCode", "0");
+		if (Objects.isNull(param)) {
+			result.put("status", "fail");
+			result.put("msg", "参数不能为空");
+			result.put("statusCode", "250");
 			return result.toJSONString();
 		}
 		try {
-			//1.解析参数转为JSONObject对像
+			// 1.解析参数转为JSONObject对像
 			JSONObject paramObject = JSON.parseObject(param);
-			//2.组装ADM请求对像
+			// 2.组装ADM请求对像
 			JSONObject postJSON = new JSONObject();
-			//"label contain 'Sy440307000395af770eea9646b0b68e80748d596f19'"
+			// "label contain 'Sy440307000395af770eea9646b0b68e80748d596f19'"
 			postJSON.put("filters", paramObject.get("filters"));
-			Map<String,String> head = new HashMap<>();
+			Map<String, String> head = new HashMap<>();
 			head.put("projectId", RepositoryContainer.RepositoryBase.projectId);
-			//3.发送请求
-			//http://39.102.40.239:28888/labsl/graph/pub/query
-			String post_url ="http://39.102.40.239:28888"+ "/labsl/graph/pub/query";
-			String post_result = HttpClientUtil.post(post_url, postJSON.toJSONString(),head);
-			//4.解析返回结果
+			// 3.发送请求
+			// http://39.102.40.239:28888/labsl/graph/pub/query
+			String post_url = "http://39.102.40.239:28888" + "/labsl/graph/pub/query";
+			String post_result = HttpClientUtil.post(post_url, postJSON.toJSONString(), head);
+			// 4.解析返回结果
 			JSONObject resultJSON = JSON.parseObject(post_result);
-			Map<String,String> map = new HashMap<>();
-			JSONArray content = (JSONArray)resultJSON.get("content");
+			Map<String, String> map = new HashMap<>();
+			JSONArray content = (JSONArray) resultJSON.get("content");
 			JSONObject rd = new JSONObject();
-			if(content == null || content.isEmpty()){
-				//TODO 如果失败返回失败信息
+			if (content == null || content.isEmpty()) {
+				// TODO 如果失败返回失败信息
 				result.put("Result", "failure");
 				result.put("ResultMsg", "暂无数据");
 				result.put("ResultCode", 250);
 				return result.toJSONString();
-			}else{
-				//有数据返回
-				//http://192.168.0.34:8081/#/Home
+			} else {
+				// 有数据返回
+				// http://192.168.0.34:8081/#/Home
 				// ?graphId=cd08520e0e6d4fb4b06ed0b400feb9f0
 				// &id=69f4fc84cf8d4027b02325d2fc6da703
 				// &projectId=Pj4403050019
@@ -742,27 +746,27 @@ public class RestUtil {
 				// &img_baseurl=http://39.102.40.239
 				// &topo_baseurl=http://39.102.40.239:28888
 				JSONObject obj = (JSONObject) content.get(0);
-				map.put("graphId",obj.get("graphId").toString());
-				map.put("id",obj.get("id").toString());
-				map.put("projectId",obj.get("projectId").toString());
-				map.put("serviceUrl","http://192.168.0.53:8811");
-				map.put("img_baseurl","http://39.102.40.239");
-				map.put("topo_baseurl","http://39.102.40.239:28888");
-				rd.put("projectId",obj.get("projectId").toString());
-				rd.put("graphId",obj.get("graphId").toString());
+				map.put("graphId", obj.get("graphId").toString());
+				map.put("id", obj.get("id").toString());
+				map.put("projectId", obj.get("projectId").toString());
+				map.put("serviceUrl", "http://192.168.0.53:8811");
+				map.put("img_baseurl", "http://39.102.40.239");
+				map.put("topo_baseurl", "http://39.102.40.239:28888");
+				rd.put("projectId", obj.get("projectId").toString());
+				rd.put("graphId", obj.get("graphId").toString());
 			}
 
-			//http://192.168.0.34:8081/#/?graphId=740364c0a1c849da948fd07d7ab3c0a8&id=72835645a33c4f70b9a2d6a851e7070c
+			// http://192.168.0.34:8081/#/?graphId=740364c0a1c849da948fd07d7ab3c0a8&id=72835645a33c4f70b9a2d6a851e7070c
 			// &categoryName=%25E4%25B8%25AD%25E5%25A4%25AE%25E4%25BE%259B%25E5%2586%25B7%25E7%25B3%25BB%25E7%25BB%259F%25EF%25BC%2588%25E5%2586%25B7%25E6%25BA%2590%25EF%25BC%2589
 			// &isPub=0&groupCode=&projectId=Pj5001120003
 			String path = "http://192.168.0.34:8081/#/";
-			//5.组装URL返回对像
+			// 5.组装URL返回对像
 
-			rd.put("url",toUrl(path,map));
+			rd.put("url", toUrl(path, map));
 
-			result.put("Content",rd);
-		}catch (Exception e){
-			log.error("获取图形数据失败",e);
+			result.put("Content", rd);
+		} catch (Exception e) {
+			log.error("获取图形数据失败", e);
 			result.put("Result", "failure");
 			String message = LogUtil.GetExceptionStackTrace(e);
 			result.put("ResultMsg", message);
@@ -771,17 +775,17 @@ public class RestUtil {
 		return result.toJSONString();
 	}
 
-	//组装URL
-	private static String toUrl(String path,Map<String,String> param){
+	// 组装URL
+	private static String toUrl(String path, Map<String, String> param) {
 
 		for (Map.Entry<String, String> entry : param.entrySet()) {
-			if(!path.contains("?")){
-				//说明地址中已有参数
-				path +="?";
-			}else{
-				path +="&";
+			if (!path.contains("?")) {
+				// 说明地址中已有参数
+				path += "?";
+			} else {
+				path += "&";
 			}
-			path += entry.getKey()+"="+entry.getValue();
+			path += entry.getKey() + "=" + entry.getValue();
 		}
 		return path;
 	}

+ 2 - 2
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/test/CheckTest.java

@@ -20,7 +20,7 @@ import lombok.extern.slf4j.Slf4j;
 public class CheckTest {
 
 	public static void test(String[] args) throws Exception {
-		Constant.debug = true;// 调试模式设为true
+		Constant.debug = false;// 调试模式设为true
 		RepositoryImpl Repository = RepositoryContainer.instance;
 		Repository.use_thread = !Constant.debug;
 		Repository.RepositoryBase = RepositoryContainer.RepositoryBase;
@@ -50,7 +50,7 @@ public class CheckTest {
 			}
 			if (Constant.alarm_enable) {
 				log.warn("LoadAlarm");
-				RWDLoadUtil.LoadAlarm(Repository, false);
+				RWDLoadUtil.LoadAlarm(Repository, true);
 			}
 			log.warn("computeAll");
 			ComputeUtil.computeAll(Repository, spListList);