|
@@ -1,13 +1,22 @@
|
|
|
package com.persagy.dmp.starter.alarm.service;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.persagy.dmp.starter.alarm.communication.mq.DmpMessage;
|
|
|
import com.persagy.dmp.starter.alarm.feign.AlarmUrlParam;
|
|
|
import com.persagy.dmp.starter.alarm.feign.DmpResult;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* @description: 处理netty消息中调用数据中台的逻辑
|
|
|
* @author: lixing
|
|
@@ -15,6 +24,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
* @since: 2020/11/30 2:38 下午
|
|
|
* @version: V1.0
|
|
|
**/
|
|
|
+@Slf4j
|
|
|
public abstract class NettyAlarmService {
|
|
|
@Autowired
|
|
|
AlarmService alarmService;
|
|
@@ -93,12 +103,14 @@ public abstract class NettyAlarmService {
|
|
|
criteria.remove("onlyCount");
|
|
|
}
|
|
|
|
|
|
- Integer page = criteria.getInteger("page");
|
|
|
- Integer size = criteria.getInteger("size");
|
|
|
- requestBody.put("page", page);
|
|
|
- requestBody.put("size", size);
|
|
|
- criteria.remove("page");
|
|
|
- criteria.remove("size");
|
|
|
+ if (criteria.containsKey("page") && criteria.containsKey("size")) {
|
|
|
+ Integer page = criteria.getInteger("page");
|
|
|
+ Integer size = criteria.getInteger("size");
|
|
|
+ requestBody.put("page", page);
|
|
|
+ requestBody.put("size", size);
|
|
|
+ criteria.remove("page");
|
|
|
+ criteria.remove("size");
|
|
|
+ }
|
|
|
|
|
|
requestBody.put("criteria", criteria);
|
|
|
return requestBody;
|
|
@@ -118,26 +130,68 @@ public abstract class NettyAlarmService {
|
|
|
DmpResult<JSONArray> queryResult = alarmService.queryAlarmConfig(getAlarmUrlParam(data), getRequestBody(data));
|
|
|
JSONArray alarmConfigs = queryResult.getData();
|
|
|
// 报警定义中的信息点转换为表号、功能号
|
|
|
+ initAlarmConfigInfoCodes(alarmConfigs);
|
|
|
+ return alarmConfigs;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 报警定义中的信息点转换为表号、功能号
|
|
|
+ * @param: alarmConfigs
|
|
|
+ * @return: void
|
|
|
+ * @exception:
|
|
|
+ * @author: lixing
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/12/1 2:32 下午
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ private void initAlarmConfigInfoCodes(JSONArray alarmConfigs) throws Exception {
|
|
|
+ if (alarmConfigs == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
for (Object alarmConfig : alarmConfigs) {
|
|
|
- JSONObject config = (JSONObject)alarmConfig;
|
|
|
+ JSONObject config = (JSONObject) alarmConfig;
|
|
|
+ String classCode = config.getString("classCode");
|
|
|
JSONObject condition = config.getJSONObject("condition");
|
|
|
JSONArray infoCodeArray = condition.getJSONArray("infoCode");
|
|
|
|
|
|
JSONArray infoCodes = new JSONArray();
|
|
|
JSONObject infoCode = new JSONObject();
|
|
|
for (Object infoCodeObj : infoCodeArray) {
|
|
|
- String infoCodeStr = (String)infoCodeObj;
|
|
|
- String[] tmp = infoCodeStr.split("_");
|
|
|
+ String infoCodeStr = (String) infoCodeObj;
|
|
|
infoCode.put("infoCode", infoCodeStr);
|
|
|
- infoCode.put("meterId", tmp[0]);
|
|
|
- infoCode.put("funcId", tmp[1]);
|
|
|
+ infoCode.put("meterId", getMeterId(infoCodeStr, classCode));
|
|
|
+ infoCode.put("funcId", getFuncId(infoCodeStr, classCode));
|
|
|
infoCodes.add(infoCode);
|
|
|
}
|
|
|
config.put("infoCodes", infoCodes);
|
|
|
}
|
|
|
- return alarmConfigs;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @description: 获取表号
|
|
|
+ * @param: infoCode
|
|
|
+ * @param: classCode
|
|
|
+ * @return: java.lang.String
|
|
|
+ * @exception:
|
|
|
+ * @author: lixing
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/12/1 9:40 上午
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ public abstract String getMeterId(String infoCode, String classCode) throws Exception;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 获取功能号
|
|
|
+ * @param: infoCode
|
|
|
+ * @param: classCode
|
|
|
+ * @return: java.lang.String
|
|
|
+ * @exception:
|
|
|
+ * @author: lixing
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/12/1 9:40 上午
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ public abstract String getFuncId(String infoCode, String classCode) throws Exception;
|
|
|
|
|
|
/**
|
|
|
* @description: 获取报警名称
|
|
@@ -200,4 +254,74 @@ public abstract class NettyAlarmService {
|
|
|
public void updateAlarmRecord(JSONObject data) throws Exception {
|
|
|
alarmService.updateAlarmRecord(getAlarmUrlParam(data), data);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 报警定义增量变化时,查询发生变化的报警定义
|
|
|
+ * @param: dmpMessage
|
|
|
+ * @return: java.util.Map<java.lang.String, com.alibaba.fastjson.JSONArray>
|
|
|
+ * @exception:
|
|
|
+ * @author: lixing
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/12/1 12:06 下午
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ public Map<String, JSONArray> queryChangedAlarmConfigs(DmpMessage dmpMessage) throws Exception {
|
|
|
+ String projectId = dmpMessage.getProjectId();
|
|
|
+ JSONObject exts = dmpMessage.getExts();
|
|
|
+ //删除报警定义
|
|
|
+ JSONArray deletedConfigUniques = exts.getJSONArray("deletedConfigUniques");
|
|
|
+ //新增报警定义
|
|
|
+ JSONArray createdConfigUniques = exts.getJSONArray("createdConfigUniques");
|
|
|
+ //修改报警定义
|
|
|
+ JSONArray updatedConfigUniques = exts.getJSONArray("updatedConfigUniques");
|
|
|
+ createdConfigUniques = CollectionUtil.isEmpty(createdConfigUniques) ? new JSONArray() : createdConfigUniques;
|
|
|
+ deletedConfigUniques = CollectionUtil.isEmpty(deletedConfigUniques) ? new JSONArray() : deletedConfigUniques;
|
|
|
+ updatedConfigUniques = CollectionUtil.isEmpty(updatedConfigUniques) ? new JSONArray() : updatedConfigUniques;
|
|
|
+ createdConfigUniques.addAll(updatedConfigUniques);
|
|
|
+ List<String> defineList = createdConfigUniques.stream().map(
|
|
|
+ p -> JSONObject.parseObject(JSONObject.toJSONString(p))
|
|
|
+ ).map(this::getAlarmConfigDefineId).collect(Collectors.toList());
|
|
|
+ deletedConfigUniques = deletedConfigUniques.stream().map(
|
|
|
+ p -> JSONObject.parseObject(JSONObject.toJSONString(p))
|
|
|
+ ).filter(
|
|
|
+ t -> !defineList.contains(getAlarmConfigDefineId(t))
|
|
|
+ ).collect(Collectors.toCollection(JSONArray::new));
|
|
|
+
|
|
|
+ JSONArray alarmConfigArr = new JSONArray();
|
|
|
+ for (Object p : createdConfigUniques) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(p));
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("projectId", projectId);
|
|
|
+ data.put("groupCode", dmpMessage.getGroupCode());
|
|
|
+ data.put("itemCode", jsonObject.getString("itemCode"));
|
|
|
+ data.put("objId", jsonObject.getString("objId"));
|
|
|
+ data.put("userId", "system");
|
|
|
+ DmpResult<JSONArray> alarmConfigQueryResult = alarmService.queryAlarmConfig(getAlarmUrlParam(data), getRequestBody(data));
|
|
|
+ JSONArray tmpAlarmConfigArr = alarmConfigQueryResult.getData();
|
|
|
+ if (CollectionUtil.isNotEmpty(tmpAlarmConfigArr)) {
|
|
|
+ // 报警定义中的信息点转换为表号、功能号
|
|
|
+ initAlarmConfigInfoCodes(tmpAlarmConfigArr);
|
|
|
+ alarmConfigArr.addAll(tmpAlarmConfigArr);
|
|
|
+ }
|
|
|
+ log.info("新增和更新的报警定义-------------------:{}", tmpAlarmConfigArr);
|
|
|
+ }
|
|
|
+ Map<String, JSONArray> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("createdConfigUniques", alarmConfigArr);
|
|
|
+ resultMap.put("deletedConfigUniques", deletedConfigUniques);
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 获取报警定义唯一标识
|
|
|
+ * @param: obj
|
|
|
+ * @return: java.lang.String
|
|
|
+ * @exception:
|
|
|
+ * @author: lixing
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/12/1 11:54 上午
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ private String getAlarmConfigDefineId(JSONObject obj) {
|
|
|
+ return obj.getString("itemCode") + "" + obj.getString("objId");
|
|
|
+ }
|
|
|
}
|