Browse Source

增加fjd_query

menglu 4 năm trước cách đây
mục cha
commit
a572a3b7b7

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

@@ -90,6 +90,12 @@ public class RestApi {
 		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);
+		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);

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

@@ -1,7 +1,9 @@
 package com.persagy.ibms.data.sdk.service.rest;
 
 import java.io.File;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 import com.alibaba.fastjson.JSON;
@@ -16,6 +18,7 @@ import com.persagy.ibms.data.sdk.util.Constant;
 import com.persagy.ibms.data.sdk.util.ControlUtil;
 import com.persagy.ibms.data.sdk.util.FastJsonReaderUtil;
 import com.persagy.ibms.data.sdk.util.FastJsonUtil;
+import com.persagy.ibms.data.sdk.util.HttpClientUtil;
 import com.persagy.ibms.data.sdk.util.LogUtil;
 import com.persagy.ibms.data.sdk.util.QueryAssist;
 import com.persagy.ibms.data.sdk.util.QueryUtil;
@@ -550,22 +553,71 @@ public class RestUtil {
 		return result.toJSONString();
 	}
 
-    public static String getIp(HttpServletRequest request) {
-        // 获取请求ip地址
-        String ip = request.getHeader("x-forwarded-for");
-        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
-            ip = request.getHeader("Proxy-Client-IP");
-        }
-        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
-            ip = request.getHeader("WL-Proxy-Client-IP");
-        }
-        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
-            ip = request.getRemoteAddr();
-        }
-        if (ip.indexOf(",") != -1) {
-            String[] ips = ip.split(",");
-            ip = ips[0].trim();
-        }
-        return ip;
-    }
+	public static String getIp(HttpServletRequest request) {
+		// 获取请求ip地址
+		String ip = request.getHeader("x-forwarded-for");
+		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			ip = request.getHeader("Proxy-Client-IP");
+		}
+		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			ip = request.getHeader("WL-Proxy-Client-IP");
+		}
+		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			ip = request.getRemoteAddr();
+		}
+		if (ip.indexOf(",") != -1) {
+			String[] ips = ip.split(",");
+			ip = ips[0].trim();
+		}
+		return ip;
+	}
+
+	public static String fjd_query(String param) {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+		Date currTime = new Date((new Date()).getTime() / (1000L * 60 * 15) * (1000L * 60 * 15));
+		Date time_from = new Date(
+				(currTime.getTime() + (1000L * 60 * 60 * 8)) / (1000L * 60 * 60 * 24) * (1000L * 60 * 60 * 24) - (1000L * 60 * 60 * 8));
+		Date time_to = currTime;
+		if (time_to.getTime() - time_from.getTime() < 1000L * 60 * 60 * 6) {
+			time_from = new Date(time_from.getTime() - (1000L * 60 * 60 * 12));
+		}
+
+		JSONObject result = new JSONObject();
+		try {
+			JSONObject parseObject = JSON.parseObject(param);
+			String objId = parseObject.getString("objId");
+			String code = parseObject.getString("code");
+			String pointString = RepositoryBase.info2point.get(objId + "-" + code);
+			int index_ = pointString.lastIndexOf('-');
+			String meter = pointString.substring(0, index_);
+			int funcid = Integer.parseInt(pointString.substring(index_ + 1));
+			JSONObject pointObject = new JSONObject();
+			pointObject.put("meter", meter);
+			pointObject.put("funcid", funcid);
+			pointObject.put("time_period", "15min");
+			pointObject.put("time_from", sdf.format(time_from));
+			pointObject.put("time_to", sdf.format(time_to));
+			JSONArray points = new JSONArray();
+			points.add(pointObject);
+			JSONObject postJSON = new JSONObject();
+			postJSON.put("building", RepositoryBase.projectId.substring(2));
+			postJSON.put("points", points);
+			String post_url = Constant.iot_collect_url + "fjd_query_batch_post";
+			String post_result = HttpClientUtil.post(post_url, postJSON.toJSONString());
+			JSONObject resultJSON = JSON.parseObject(post_result);
+			JSONArray result_points = (JSONArray) resultJSON.get("points");
+			JSONObject result_point = (JSONObject) result_points.get(0);
+			JSONArray datas = (JSONArray) result_point.get("datas");
+			result.put("Content", datas);
+			result.put("Result", "success");
+		} catch (Exception e) {
+			e.printStackTrace();
+			String message = LogUtil.GetExceptionStackTrace(e);
+			log.info(message);
+			result.put("Result", "failure");
+			result.put("ResultMsg", message);
+			result.put("ResultCode", 250);
+		}
+		return result.toJSONString();
+	}
 }

+ 2 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RWDLoadUtil.java

@@ -180,6 +180,7 @@ public class RWDLoadUtil {
 			List<SceneDataValue> objectArray = Repository.objectArrayDic.get(classCode);
 			for (int index_object = 0; index_object < objectArray.size(); index_object++) {
 				SceneDataObject obj = objectArray.get(index_object).value_object;
+				String obj_id = (String) obj.get("id").value_primitive;
 				for (String Key : obj.keySet()) {
 					Object value_primitive = obj.get(Key).value_primitive;
 					if (RWDUtil.isRunParam(infoArray, Key)) {
@@ -188,6 +189,7 @@ public class RWDLoadUtil {
 						}
 						String point = (String) value_primitive;
 						if (point != null) {
+							RepositoryBase.info2point.put(obj_id + "-" + Key, point);
 							// 表号功能号改为null
 							{
 								SceneDataValue sdv = new SceneDataValue(Repository, obj, Key, null, true);

+ 1 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RepositoryBase.java

@@ -17,6 +17,7 @@ public class RepositoryBase {
 	public static String projectId;
 
 	// IOT采集数据
+	public static ConcurrentHashMap<String, String> info2point = new ConcurrentHashMap<String, String>();
 	public static ConcurrentHashMap<String, SceneDataValue> point2sdv = new ConcurrentHashMap<String, SceneDataValue>();
 	public static ConcurrentHashMap<SceneDataValue, String> sdv2point = new ConcurrentHashMap<SceneDataValue, String>();
 	public static ConcurrentHashMap<String, List<SceneDataBase>> point2curve = new ConcurrentHashMap<String, List<SceneDataBase>>();