Procházet zdrojové kódy

增加处理报警转工单的接口

menglu před 3 roky
rodič
revize
2aef00e43f

+ 17 - 4
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestApi.java

@@ -6,7 +6,6 @@ import java.util.concurrent.ConcurrentHashMap;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import io.swagger.annotations.ApiModelProperty;
 import org.springframework.core.io.FileSystemResource;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -22,11 +21,13 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.persagy.ibms.data.sdk.util.ExportUtil;
+import com.persagy.ibms.data.sdk.util.RWDAlarmUtil;
 import com.persagy.ibms.data.sdk.util.RepositoryContainer;
 import com.persagy.ibms.data.sdk.util.ToolUtil;
 import com.persagy.ibms.data.sdk.websocket.AlarmWebSocketClient;
 import com.persagy.ibms.data.sdk.websocket.IOTWebSocketClient;
 
+import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 
@@ -54,7 +55,7 @@ public class RestApi {
 			long millisecond = Long.parseLong(sleep);
 			Thread.sleep(millisecond);
 		} catch (Exception e) {
-			log.error(e.getMessage(),e);
+			log.error(e.getMessage(), e);
 		}
 		return body;
 	}
@@ -182,6 +183,18 @@ public class RestApi {
 		return result;
 	}
 
+	@PostMapping(path = { "/handleAlarm", "/zkt-sdk/handleAlarm" }, produces = "application/json;charset=UTF-8")
+	public String handleAlarm(@RequestBody String param, HttpServletRequest request) {
+		String result = RWDAlarmUtil.handleAlarm(param);
+		return result;
+	}
+
+	@PostMapping(path = { "/alarmToWorkOrder", "/zkt-sdk/alarmToWorkOrder" }, produces = "application/json;charset=UTF-8")
+	public String alarmToWorkOrder(@RequestBody String param, HttpServletRequest request) {
+		String result = RWDAlarmUtil.alarmToWorkOrder(param);
+		return result;
+	}
+
 	@PostMapping(path = { "/fjd_query", "/zkt-sdk/fjd_query" }, produces = "application/json;charset=UTF-8")
 	public String fjd_query(@RequestBody String param, HttpServletRequest request) {
 		String result = RestUtil.fjd_query(param);
@@ -224,15 +237,15 @@ public class RestApi {
 		return result;
 	}
 
-
 	/**
 	 * 根据参数获取图形URL路径
+	 * 
 	 * @param param
 	 * @param request
 	 * @return
 	 */
 	@ApiModelProperty("获取图形URL路径")
-	@PostMapping(path = { "/getUrl"}, produces = "application/json;charset=UTF-8")
+	@PostMapping(path = { "/getUrl" }, produces = "application/json;charset=UTF-8")
 	public String getUrl(@RequestBody String param, HttpServletRequest request) {
 		String result = RestUtil.getAdmUrl(param);
 		return result;

+ 41 - 11
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestUtil.java

@@ -1,21 +1,51 @@
 package com.persagy.ibms.data.sdk.service.rest;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.http.ResponseEntity;
+
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
-import com.persagy.ibms.core.data.*;
-import com.persagy.ibms.core.util.*;
-import com.persagy.ibms.data.sdk.util.*;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.http.ResponseEntity;
+import com.persagy.ibms.core.data.SceneDataObject;
+import com.persagy.ibms.core.data.SceneDataPrimitive;
+import com.persagy.ibms.core.data.SceneDataSet;
+import com.persagy.ibms.core.data.SceneDataValue;
+import com.persagy.ibms.core.data.SceneProperty;
+import com.persagy.ibms.core.util.ComputeUtil;
+import com.persagy.ibms.core.util.ExamineUtil;
+import com.persagy.ibms.core.util.ExceptionItem;
+import com.persagy.ibms.core.util.ExceptionWrapper;
+import com.persagy.ibms.core.util.FastJsonCompareUtil;
+import com.persagy.ibms.core.util.FilterUtil;
+import com.persagy.ibms.core.util.IntWrapper;
+import com.persagy.ibms.core.util.LogUtil;
+import com.persagy.ibms.core.util.QueryAssist;
+import com.persagy.ibms.core.util.QueryUtil;
+import com.persagy.ibms.core.util.RecursiveUtil;
+import com.persagy.ibms.data.sdk.util.Constant;
+import com.persagy.ibms.data.sdk.util.ControlUtil;
+import com.persagy.ibms.data.sdk.util.DrawUtil;
+import com.persagy.ibms.data.sdk.util.ExeclReadEquipStaticInfoUtil;
+import com.persagy.ibms.data.sdk.util.ExportUtil;
+import com.persagy.ibms.data.sdk.util.HttpClientUtil;
+import com.persagy.ibms.data.sdk.util.RWDAlarmUtil;
+import com.persagy.ibms.data.sdk.util.RepositoryContainer;
+import com.persagy.ibms.data.sdk.util.RepositoryImpl;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
+import lombok.extern.slf4j.Slf4j;
 
 @Slf4j
 public class RestUtil {

+ 37 - 7
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/HttpClientUtil.java

@@ -9,6 +9,7 @@ import org.apache.http.client.HttpClient;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.HttpClients;
 
@@ -16,6 +17,35 @@ public class HttpClientUtil {
 
 	private static final HttpClient client = HttpClients.createDefault();
 
+	public synchronized static String put(String url, String content) throws Exception {
+		String result = put(url, content, 300000);
+		return result;
+	}
+
+	public synchronized static String put(String url, String content, Integer timeout) throws Exception {
+		HttpPut httpost = new HttpPut(url);
+		if (timeout != null) {
+			RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout).setConnectionRequestTimeout(timeout)
+					.setSocketTimeout(timeout).build();
+			httpost.setConfig(requestConfig);
+		}
+		StringEntity entity = new StringEntity(content, "UTF-8");
+		httpost.setEntity(entity);
+		entity.setContentType("application/json");
+		HttpResponse httpResponse = client.execute(httpost);
+		InputStream is = httpResponse.getEntity().getContent();
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		int b = -1;
+		while ((b = is.read()) != -1) {
+			baos.write(b);
+		}
+		baos.close();
+		is.close();
+
+		String result = baos.toString("UTF-8");
+		return result;
+	}
+
 	public synchronized static String post(String url, String content) throws Exception {
 		String result = post(url, content, 300000);
 		return result;
@@ -68,11 +98,11 @@ public class HttpClientUtil {
 		return result;
 	}
 
-
-	public synchronized static String post(String url, String content, Map<String,String> headParam) throws Exception{
-		return post(url,content,headParam,300000);
+	public synchronized static String post(String url, String content, Map<String, String> headParam) throws Exception {
+		return post(url, content, headParam, 300000);
 	}
-	public synchronized static String post(String url, String content, Map<String,String> headParam,Integer timeout) throws Exception {
+
+	public synchronized static String post(String url, String content, Map<String, String> headParam, Integer timeout) throws Exception {
 		HttpPost httpost = new HttpPost(url);
 		if (timeout != null) {
 			RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout).setConnectionRequestTimeout(timeout)
@@ -80,9 +110,9 @@ public class HttpClientUtil {
 			httpost.setConfig(requestConfig);
 		}
 		StringEntity entity = new StringEntity(content, "UTF-8");
-		if(headParam != null && headParam.size()>0){
-			headParam.forEach((key,value) ->{
-				httpost.addHeader(key,value);
+		if (headParam != null && headParam.size() > 0) {
+			headParam.forEach((key, value) -> {
+				httpost.addHeader(key, value);
 			});
 		}
 		httpost.setEntity(entity);

+ 108 - 6
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RWDAlarmUtil.java

@@ -205,6 +205,9 @@ public class RWDAlarmUtil {
 		if (alarm.containsKey("level")) {
 			alarm.put("level_name", levelMap.get(alarm.get("level")));
 		}
+		if (alarm.containsKey("objType")) {
+			alarm.put("category", alarm.get("objType"));
+		}
 		if (alarm.containsKey("category")) {
 			alarm.put("category_name", categoryMap.get(alarm.get("category")));
 		}
@@ -217,7 +220,11 @@ public class RWDAlarmUtil {
 					alarm.put("triggerTime", sdf.format(new Date(timeLong)));
 				} else if (object instanceof String) {
 					String timeString = (String) object;
-					alarm.put("triggerTime", sdf.format(sdf_.parse(timeString)));
+					try {
+						alarm.put("triggerTime", sdf.format(sdf_.parse(timeString)));
+					} catch (Exception e) {
+						// e.printStackTrace();
+					}
 				}
 			}
 		}
@@ -379,11 +386,17 @@ public class RWDAlarmUtil {
 
 		JSONArray Content;
 		if (Constant.alarm_rest_get) {
-			String get_url = Constant.alarm_rest_url + "/alarm-record/list" + "?appId=" + "0" + "&userId=" + "systemId" + "&projectId="
-					+ RepositoryContainer.RepositoryBase.projectId + "&groupCode=" + RepositoryContainer.RepositoryBase.groupCode;
-			String getResultString = HttpClientUtil.get(get_url, null);
-			JSONObject getResult = JSON.parseObject(getResultString);
-			Content = (JSONArray) getResult.get("Item");
+			Content = new JSONArray();
+			int[] treatState_array = { 1, 2 };
+			for (int treatState : treatState_array) {
+				String get_url = Constant.alarm_rest_url + "/alarm-record/page" + "?appId=" + "0" + "&userId=" + "systemId" + "&projectId="
+						+ RepositoryContainer.RepositoryBase.projectId + "&groupCode=" + RepositoryContainer.RepositoryBase.groupCode
+						+ "&size=65535&current=1&treatState=" + treatState;
+				String getResultString = HttpClientUtil.get(get_url, null);
+				JSONObject getResult = JSON.parseObject(getResultString);
+				JSONArray ContentInner = (JSONArray) getResult.get("Content");
+				Content.addAll(ContentInner);
+			}
 		} else {
 			String post_url = Constant.alarm_rest_url + "/alarm/queryAlarmList";
 			JSONObject postParam = new JSONObject();
@@ -411,6 +424,95 @@ public class RWDAlarmUtil {
 		return Content.size();
 	}
 
+	public static String handleAlarm(String param) {
+		JSONObject result = new JSONObject();
+		try {
+			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+			Date currTime = new Date();
+			JSONObject paramJSON = JSON.parseObject(param);
+			if (Constant.alarm_rest_get) {
+				{
+					JSONObject handleJSON = new JSONObject();
+					handleJSON.put("id", paramJSON.get("id"));
+					handleJSON.put("treatMode", paramJSON.get("treatMode"));
+					handleJSON.put("treatState", paramJSON.get("treatState"));
+					String post_result = HttpClientUtil.put(Constant.alarm_rest_url + "/alarm-record/handleAlarm", handleJSON.toJSONString());
+					result = JSON.parseObject(post_result);
+				}
+				if (paramJSON.containsKey("comment") && paramJSON.containsKey("userId")) {
+					JSONObject commentJSON = new JSONObject();
+					JSONObject dtoJSON = new JSONObject();
+					dtoJSON.put("userId", paramJSON.get("userId"));
+					dtoJSON.put("content", paramJSON.get("comment"));
+					dtoJSON.put("commentTime", sdf.format(currTime));
+					commentJSON.put("id", paramJSON.get("id"));
+					commentJSON.put("alarmRecordCommentDto", dtoJSON);
+					HttpClientUtil.put(Constant.alarm_rest_url + "/alarm-record/updateComment", commentJSON.toJSONString());
+				}
+			} else {
+				// TODO
+			}
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			String message = LogUtil.GetExceptionStackTrace(e);
+			log.error(message);
+			result.put("Result", "failure");
+			result.put("ResultCode", -1);
+			result.put("ResultMsg", message);
+		}
+		return result.toJSONString();
+	}
+
+	public static String alarmToWorkOrder(String param) {
+		JSONObject result = new JSONObject();
+		try {
+			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+			Date currTime = new Date();
+			JSONObject paramJSON = JSON.parseObject(param);
+			if (Constant.alarm_rest_get) {
+				{
+					JSONObject handleJSON = new JSONObject();
+					handleJSON.put("groupCode", RepositoryContainer.RepositoryBase.groupCode);
+					handleJSON.put("projectId", RepositoryContainer.RepositoryBase.projectId);
+					handleJSON.put("appId", "systemId");
+					handleJSON.put("userId", paramJSON.get("userId"));
+					handleJSON.put("id", paramJSON.get("id"));
+					handleJSON.put("alarmDescribe", "null");
+					String post_result = HttpClientUtil.post(Constant.alarm_rest_url + "/alarmToWorkOrder/transfer", handleJSON.toJSONString());
+					result = JSON.parseObject(post_result);
+				}
+				{
+					JSONObject handleJSON = new JSONObject();
+					handleJSON.put("id", paramJSON.get("id"));
+					handleJSON.put("treatMode", 2);
+					handleJSON.put("treatState", 2);
+					String post_result = HttpClientUtil.put(Constant.alarm_rest_url + "/alarm-record/handleAlarm", handleJSON.toJSONString());
+					result = JSON.parseObject(post_result);
+				}
+				if (paramJSON.containsKey("comment") && paramJSON.containsKey("userId")) {
+					JSONObject commentJSON = new JSONObject();
+					JSONObject dtoJSON = new JSONObject();
+					dtoJSON.put("userId", paramJSON.get("userId"));
+					dtoJSON.put("content", paramJSON.get("comment"));
+					dtoJSON.put("commentTime", sdf.format(currTime));
+					commentJSON.put("id", paramJSON.get("id"));
+					commentJSON.put("alarmRecordCommentDto", dtoJSON);
+					HttpClientUtil.put(Constant.alarm_rest_url + "/alarm-record/updateComment", commentJSON.toJSONString());
+				}
+			} else {
+				// TODO
+			}
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			String message = LogUtil.GetExceptionStackTrace(e);
+			log.error(message);
+			result.put("Result", "failure");
+			result.put("ResultCode", -1);
+			result.put("ResultMsg", message);
+		}
+		return result.toJSONString();
+	}
+
 	// 获取时间差方法
 	public static String getTimeDiff(Date startDate, Date endDate) {
 		long diffMS = endDate.getTime() - startDate.getTime();

+ 1 - 1
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/websocket/AlarmWebSocketClient.java

@@ -59,7 +59,7 @@ public class AlarmWebSocketClient extends WebSocketClient {
 			try {
 				RWDAlarmUtil.modify_alarm(alarm);
 			} catch (Exception e) {
-				log.error(e.getMessage(),e);
+				log.error(e.getMessage(), e);
 				log.error(LogUtil.GetExceptionStackTrace(e));
 			}
 			RWDAlarmUtil.ProcessAlarm(alarm);