|
@@ -36,6 +36,7 @@ import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @description:报警处理实现类:包含报警产生和报警恢复
|
|
@@ -92,19 +93,20 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
|
|
|
/* 将iot消息拆分成一条条iot数据,然后处理 */
|
|
|
String[] split = msg.split(";");
|
|
|
- // 每一条iot数据应该包含4个分号
|
|
|
- int groupCount = 4;
|
|
|
+ // 每一条iot数据应该包含5个分号
|
|
|
+ int groupCount = 5;
|
|
|
int dataCounts = split.length / groupCount;
|
|
|
for (int i = 0; i < dataCounts; i++) {
|
|
|
int startIndex = i * groupCount;
|
|
|
String dataTime = split[startIndex];
|
|
|
- String meterId = split[startIndex + 1];
|
|
|
- String funcId = split[startIndex + 2];
|
|
|
- String value = split[startIndex + 3];
|
|
|
+ String itemCode = split[startIndex + 1];
|
|
|
+ String meterId = split[startIndex + 2];
|
|
|
+ String funcId = split[startIndex + 3];
|
|
|
+ String value = split[startIndex + 4];
|
|
|
// 使用intern()方法,确保上锁的是同一个String对象
|
|
|
synchronized (meterId.intern()) {
|
|
|
// 处理iot数据
|
|
|
- handleIotData(dataTime, meterId, funcId, value);
|
|
|
+ handleIotData(dataTime, itemCode, meterId, funcId, value);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -118,6 +120,7 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
/**
|
|
|
* @description: 处理iot数据, iot数据可能包含一个设备多个信息点的采集值
|
|
|
* @param: dataTime 采集时间
|
|
|
+ * @param: itemCode 报警类型
|
|
|
* @param: meterId 设备id
|
|
|
* @param: funcIdStr 信息点id
|
|
|
* @param: valueStr 采集值
|
|
@@ -128,7 +131,7 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
* @since: 2021/2/1 3:44 下午
|
|
|
* @version: V1.0
|
|
|
*/
|
|
|
- private void handleIotData(String dataTime, String meterId, String funcIdStr, String valueStr) throws Exception {
|
|
|
+ private void handleIotData(String dataTime, String itemCode, String meterId, String funcIdStr, String valueStr) throws Exception {
|
|
|
/* 如果iot数据为一组数据,先更新缓存中这组iot数据值,然后将这一组iot数据拆分为一条条iot数据处理 */
|
|
|
String funcIdSeparator = ",";
|
|
|
String[] funcIdArray = funcIdStr.split(funcIdSeparator);
|
|
@@ -142,7 +145,7 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
paramMap.put(funcIdArray[i], Double.parseDouble(values[i]));
|
|
|
}
|
|
|
|
|
|
- calculateAlarmConditions(dataTime, meterId, paramMap);
|
|
|
+ calculateAlarmConditions(dataTime, meterId, itemCode, paramMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -150,18 +153,22 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
*
|
|
|
* @param dataTime 采集日期
|
|
|
* @param meterId 报警对象id
|
|
|
+ * @param itemCode 报警类型
|
|
|
* @param paramMap 采集数据
|
|
|
* @author lixing
|
|
|
* @version V1.0 2021/10/22 5:19 下午
|
|
|
*/
|
|
|
- private void calculateAlarmConditions(String dataTime, String meterId, HashMap<String, Object> paramMap) throws Exception {
|
|
|
+ private void calculateAlarmConditions(String dataTime, String meterId, String itemCode, HashMap<String, Object> paramMap) throws Exception {
|
|
|
// 获取设备的报警条件
|
|
|
ObjConditionInfo objConditionInfo = alarmInfoCache.getAlarmConditionsByObjId(meterId);
|
|
|
if (objConditionInfo == null || CollectionUtils.isEmpty(objConditionInfo.getConditions())) {
|
|
|
log.warn("未获取到设备{}的报警条件", meterId);
|
|
|
return;
|
|
|
}
|
|
|
- LinkedList<ItemCodeCondition> itemCodeConditions = objConditionInfo.getConditions();
|
|
|
+ LinkedList<ItemCodeCondition> itemCodeConditionsByObj = objConditionInfo.getConditions();
|
|
|
+
|
|
|
+ List<ItemCodeCondition> itemCodeConditions = itemCodeConditionsByObj.stream().filter(
|
|
|
+ itemCodeCondition -> itemCode.equals(itemCodeCondition.getItemCode())).collect(Collectors.toList());
|
|
|
|
|
|
// 遍历这些条件,将采集值带入条件,判断是否产生报警
|
|
|
for (ItemCodeCondition itemCodeCondition : itemCodeConditions) {
|
|
@@ -232,10 +239,10 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
// iot数据使用英文分号分隔
|
|
|
String separator = ";";
|
|
|
// 每一条iot数据应该包含4个分号
|
|
|
- int groupCount = 4;
|
|
|
+ int groupCount = 5;
|
|
|
String[] split = msg.split(separator);
|
|
|
if (split.length % groupCount != 0) {
|
|
|
- log.error("采集值有误!每一条iot数据应该包含4个英文分号");
|
|
|
+ log.error("采集值有误!每一条iot数据应该包含{}个英文分号", groupCount);
|
|
|
return false;
|
|
|
}
|
|
|
// 数据条数
|
|
@@ -243,9 +250,10 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
for (int i = 0; i < dataCounts; i++) {
|
|
|
int startIndex = i * groupCount;
|
|
|
String dataTime = split[startIndex];
|
|
|
- String meterId = split[startIndex + 1];
|
|
|
- String funcId = split[startIndex + 2];
|
|
|
- String value = split[startIndex + 3];
|
|
|
+ String itemCode = split[startIndex + 1];
|
|
|
+ String meterId = split[startIndex + 2];
|
|
|
+ String funcId = split[startIndex + 3];
|
|
|
+ String value = split[startIndex + 4];
|
|
|
|
|
|
boolean iotDataValidateResult = validateIotData(dataTime, meterId, funcId, value);
|
|
|
if (!iotDataValidateResult) {
|