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