Browse Source

1、增加重定向报警处理、导出历史、实时报警接口
2、远程控制保存日志改为批量保存操作日志

lirong 2 years ago
parent
commit
c6d69a3566

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

@@ -194,7 +194,7 @@ public class RestUtil {
 				}
 			}
 
-			JSONArray points = ControlUtil.set(userId, userName, Repository, path, infoValueSet);
+			JSONArray points = ControlUtil.set(userId, userName, Repository, path, infoValueSet,controlReason);
 			JSONArray success_points = new JSONArray();
 			JSONArray failure_points = new JSONArray();
 			for (int i = 0; i < points.size(); i++) {

+ 89 - 2
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/ControlUtil.java

@@ -32,7 +32,7 @@ public class ControlUtil {
 		return result;
 	}
 
-	public static JSONArray set(String userId, String userName, RepositoryImpl Repository, JSONArray path, JSONObject infoValueSet) throws Exception {
+	public static JSONArray set(String userId, String userName, RepositoryImpl Repository, JSONArray path, JSONObject infoValueSet,String controlReason) throws Exception {
 		JSONArray result;
 		Object valueObject = ComputeUtil.getValueObject(Repository, path);
 		List<SceneDataObject> sdoList = new CopyOnWriteArrayList<SceneDataObject>();
@@ -65,7 +65,8 @@ public class ControlUtil {
 			setControlValue(path, infoValueSet);
 		}
 
-		ControlUtil.saveOperationLog(userId, userName, sdoList, infoValueSet, result);
+		ControlUtil.saveBatchOperationLog(userId, userName, sdoList, infoValueSet, result,controlReason,Repository);
+//		ControlUtil.saveOperationLog(userId, userName, sdoList, infoValueSet, result);
 
 		return result;
 	}
@@ -149,6 +150,85 @@ public class ControlUtil {
 			log.error(e.getMessage(), e);
 		}
 	}
+	public static void saveBatchOperationLog(String userId, String userName, List<SceneDataObject> sdoList, JSONObject infoValueSet, JSONArray points,String controlReason,RepositoryImpl Repository) {
+		try {
+			JSONArray postParamArray=new JSONArray();
+			JSONObject postParam = new JSONObject();
+			for (int i = 0; i < sdoList.size();i++) {
+				postParam.put("groupCode", RepositoryContainer.RepositoryProject.groupCode);
+				postParam.put("projectId", RepositoryContainer.RepositoryProject.projectId);
+				if (userId == null || userId.length() == 0) {
+					postParam.put("userId", "systemId");
+				} else {
+					postParam.put("userId", userId);
+				}
+				if (userName == null || userName.length() == 0) {
+					postParam.put("userName", "系统");
+				} else {
+					postParam.put("userName", userName);
+				}
+				{
+					SceneDataObject sdo=sdoList.get(i);
+					postParam.put("objId", sdo.get("id").value_prim.value);
+					Object objType = sdo.get("objType").value_prim.value;
+					Object objName = sdo.get("ibmsxianshimingcheng").value_prim.value;
+					Object systemCode = null;
+					String classCode = (String) sdo.get("classCode").value_prim.value;
+					Object belongSystem = sdo.get("所属场景").value_prim.value;
+					List<SceneDataObject> infoList = RepositoryContainer.instance.infoArrayDic.get(classCode).set;
+					postParam.put("objType", objType);
+					postParam.put("objName", objName);
+					postParam.put("systemCode", systemCode);
+					postParam.put("classCode", classCode);
+					postParam.put("functionType", "remoteControl");
+					StringBuffer sb = new StringBuffer();
+					for (String key : infoValueSet.keySet()) {
+						Object infoValue = infoValueSet.get(key);
+						SceneDataObject infoDef = null;
+						for (SceneDataObject infoDefInner : infoList) {
+							String code = (String) infoDefInner.get("code").value_prim.value;
+							if (code.equals(key)) {
+								infoDef = infoDefInner;
+								break;
+							}
+						}
+						String infoName = key;
+						if (infoDef != null) {
+							infoName = (String) infoDef.get("name").value_prim.value;
+							infoValue = ControlUtil.value2CanRead(infoDef, infoValue);
+						}
+						sb.append("[" + infoName + "]" + "设为:" + "[" + infoValue + "]");
+						sb.append(";");
+						if(infoDef.get("code").value_prim.value.equals("manualAutoSet"))
+						{
+							sb.append("原因:"+controlReason+";");
+						}
+						String id = (String) sdo.get("id").value_prim.value;
+						JSONObject obj = Repository.id2object.get(id);
+						String objInfoValue = (String) obj.get(key);
+						if (objInfoValue != null && objInfoValue.length() > 0) {
+							int index_ = objInfoValue.lastIndexOf("-");
+							String meter = objInfoValue.substring(0, index_);
+							int funcid = Integer.parseInt(objInfoValue.substring(index_ + 1));
+							JSONObject point= (JSONObject) points.stream().filter(x->JSONObject.parseObject(x.toString()).get("meter").equals(meter)&&JSONObject.parseObject(x.toString()).get("funcid").equals(funcid)).findFirst().get();
+							String status = (String) point.get("status");
+							if (status.equals("finish:success")) {
+								sb.append("控制结果:成功;");
+							} else {
+								sb.append("控制结果:失败;");
+							}
+						}
+					}
+					postParam.put("operateDetail", "【" + belongSystem + "】:" + objName + "-" + sb.toString());
+					postParam.put("sourceType", 1);
+					postParamArray.add(postParam);
+				}
+			}
+			saveBatchOperationLog(postParamArray);
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+		}
+	}
 
 	public static Object value2CanRead(SceneDataObject infoDef, Object infoValue) {
 		if (infoDef.containsKey("dataSource")) {
@@ -176,6 +256,13 @@ public class ControlUtil {
 		log.debug(result.toJSONString());
 	}
 
+	private static void saveBatchOperationLog(JSONArray postParam) throws Exception {
+		String post_url = Constant.zkt_control_url + "/operationLog/saveBatchOperationLog";
+		String post_result = HttpClientUtil.instance("zkt_control").post(post_url, postParam.toJSONString());
+		JSONObject result = JSON.parseObject(post_result);
+		log.debug(result.toJSONString());
+	}
+
 	private static JSONArray set(RepositoryImpl Repository, SceneDataObject object, JSONObject infoValueSet, List<SceneDataObject> sdoList)
 			throws Exception {
 		JSONArray result;

+ 8 - 0
ibms-data-sdk/src/main/resources/config.xml

@@ -272,6 +272,14 @@
 	<Redirect code="导出历史报警" http_request_type="post" url="http://ibmsdev.persagy.com/ibms-alarm/alarm-record/downLoadHistory">
 		<header key="Content-Type" value="application/json"/>
 	</Redirect>
+	<!--报警处理-->
+	<Redirect code="报警处理" http_request_type="post" url="http://ibmsdev.persagy.com/ibms-alarm/alarm-record/handleAlarm">
+		<header key="Content-Type" value="application/json"/>
+	</Redirect>
+	<!--导出实时报警记录,需配置alarm的地址和端口-->
+	<Redirect code="导出实时报警" http_request_type="post" url="http://ibmsdev.persagy.com/ibms-alarm/alarm-record/downLoadActual">
+		<header key="Content-Type" value="application/json"/>
+	</Redirect>
 	<Redirect code="test-get1" http_request_type="get" url="http://39.102.43.179:9993/alarm-record/list" />
 	<Redirect code="test-post1" http_request_type="post" url="http://192.168.4.69:8806/zkt-sdk/post" />
 	<Redirect code="test-get2" http_request_type="get" url="http://39.102.43.179:9993/alarm-record/list?projectId=Pj4403070003&amp;groupCode=WD" />