|
|
@ -20,6 +20,7 @@ import com.techsor.datacenter.sender.compiler.MvelExecutor; |
|
|
import com.techsor.datacenter.sender.components.GuavaRedisCache; |
|
|
import com.techsor.datacenter.sender.components.GuavaRedisCache; |
|
|
import com.techsor.datacenter.sender.config.DataSourceContextHolder; |
|
|
import com.techsor.datacenter.sender.config.DataSourceContextHolder; |
|
|
import com.techsor.datacenter.sender.constants.Constants; |
|
|
import com.techsor.datacenter.sender.constants.Constants; |
|
|
|
|
|
import com.techsor.datacenter.sender.constants.DeviceAttrCode; |
|
|
import com.techsor.datacenter.sender.dao.*; |
|
|
import com.techsor.datacenter.sender.dao.*; |
|
|
import com.techsor.datacenter.sender.disruptor.AccumulateService; |
|
|
import com.techsor.datacenter.sender.disruptor.AccumulateService; |
|
|
import com.techsor.datacenter.sender.disruptor.AlertService; |
|
|
import com.techsor.datacenter.sender.disruptor.AlertService; |
|
|
@ -105,6 +106,9 @@ public class DataProcessServiceImpl implements IDataProcessService { |
|
|
@Value("${category.status.deviceTypeIds}") |
|
|
@Value("${category.status.deviceTypeIds}") |
|
|
private List<Integer> statusTypeIds; |
|
|
private List<Integer> statusTypeIds; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${category.temperature-humidity.deviceTypeIds}") |
|
|
|
|
|
private List<Integer> temperatureHumidityTypeIds; |
|
|
|
|
|
|
|
|
// 所有设备类型ID集合
|
|
|
// 所有设备类型ID集合
|
|
|
public static final List<Integer> ALL_DEVICE_TYPE_IDS = new ArrayList<>(); |
|
|
public static final List<Integer> ALL_DEVICE_TYPE_IDS = new ArrayList<>(); |
|
|
|
|
|
|
|
|
@ -251,7 +255,7 @@ public class DataProcessServiceImpl implements IDataProcessService { |
|
|
processJson = targetJson; |
|
|
processJson = targetJson; |
|
|
Map<String,Object> innerMap=JSON.parseObject(targetJson, Map.class); |
|
|
Map<String,Object> innerMap=JSON.parseObject(targetJson, Map.class); |
|
|
if (StringUtils.isNotEmpty(MapUtils.getString(innerMap,"BUILDINRAWDATA",""))){ |
|
|
if (StringUtils.isNotEmpty(MapUtils.getString(innerMap,"BUILDINRAWDATA",""))){ |
|
|
processJson=MapUtils.getString(innerMap,"BUILDINRAWDATA"); |
|
|
processJson=MapUtils.getString(innerMap,"BUILDINRAWDATA"); |
|
|
} |
|
|
} |
|
|
//Save To DynamoDB
|
|
|
//Save To DynamoDB
|
|
|
//The normal data stored as one item. But [KINGIOSERVER] is special.
|
|
|
//The normal data stored as one item. But [KINGIOSERVER] is special.
|
|
|
@ -599,7 +603,7 @@ public class DataProcessServiceImpl implements IDataProcessService { |
|
|
Set<String> waitingTargetKeySets=new HashSet<>(); |
|
|
Set<String> waitingTargetKeySets=new HashSet<>(); |
|
|
|
|
|
|
|
|
//设备信息
|
|
|
//设备信息
|
|
|
DeviceInfoVO deviceInfoVO = alarmDataPushLambda.queryDeviceInfoByDeviceId(deviceId); |
|
|
DeviceInfoVO deviceInfoVO = alarmDataPushLambda.queryDeviceInfoByDeviceId(deviceId); |
|
|
try { |
|
|
try { |
|
|
log.debug("triggerAlertConditions:{} {} {}", content, JSON.toJSON(baseTransDataEntity), JSON.toJSON(currentDeviceAlertInfoBindTemplateLists)); |
|
|
log.debug("triggerAlertConditions:{} {} {}", content, JSON.toJSON(baseTransDataEntity), JSON.toJSON(currentDeviceAlertInfoBindTemplateLists)); |
|
|
triggerAlertConditions(companyId, content, currentDeviceAlertInfoBindTemplateLists, baseTransDataEntity,waitingTargetKeySets,currentDevice.getDeviceSN(), deviceInfoVO); |
|
|
triggerAlertConditions(companyId, content, currentDeviceAlertInfoBindTemplateLists, baseTransDataEntity,waitingTargetKeySets,currentDevice.getDeviceSN(), deviceInfoVO); |
|
|
@ -619,16 +623,16 @@ public class DataProcessServiceImpl implements IDataProcessService { |
|
|
baseTransDataEntity.setHashId(UUID.randomUUID()); |
|
|
baseTransDataEntity.setHashId(UUID.randomUUID()); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
handleDashboardAlert(baseTransDataEntity); |
|
|
handleDashboardAlert(baseTransDataEntity); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.error("dashboard alert error", e); |
|
|
log.error("dashboard alert error", e); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
minuteLevelStorage(baseTransDataEntity); |
|
|
minuteLevelStorage(baseTransDataEntity); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.error("minuteLevelStorage error", e); |
|
|
log.error("minuteLevelStorage error", e); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// try {
|
|
|
// try {
|
|
|
// if ("alert".equals(baseTransDataEntity.getStatus())) {
|
|
|
// if ("alert".equals(baseTransDataEntity.getStatus())) {
|
|
|
@ -668,106 +672,118 @@ public class DataProcessServiceImpl implements IDataProcessService { |
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void minuteLevelStorage(DynamodbEntity baseTransDataEntity) throws Exception { |
|
|
public void minuteLevelStorage(DynamodbEntity baseTransDataEntity) throws Exception { |
|
|
String uploadValue = extractFirstValue(baseTransDataEntity.getRawData()); |
|
|
List<String> uploadValueList = extractAllValues(baseTransDataEntity.getRawData()); |
|
|
if (StringUtils.isBlank(uploadValue)) { |
|
|
if (CollectionUtil.isEmpty(uploadValueList)) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
if (temperatureHumidityTypeIds.contains(baseTransDataEntity.getTypeId())) { |
|
|
|
|
|
for (int i = 0; i < uploadValueList.size(); i++) { |
|
|
|
|
|
String uploadValue = uploadValueList.get(i); |
|
|
|
|
|
//温湿度的rawdata,一定是温度在前,湿度在后
|
|
|
|
|
|
if (0 == i) { |
|
|
|
|
|
storageMeasure(DeviceAttrCode.MEASURE_TEMPERATURE, uploadValue, baseTransDataEntity); |
|
|
|
|
|
} else if (1 == i) { |
|
|
|
|
|
storageMeasure(DeviceAttrCode.MEASURE_HUMIDITY, uploadValue, baseTransDataEntity); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
String uploadValue = uploadValueList.get(0);//这里只取第一个元素
|
|
|
|
|
|
if (accumulateTypeIds.contains(baseTransDataEntity.getTypeId())) { |
|
|
|
|
|
storageAccumulate(DeviceAttrCode.COMMON, uploadValue, baseTransDataEntity); |
|
|
|
|
|
} |
|
|
|
|
|
if (measureTypeIds.contains(baseTransDataEntity.getTypeId())) { |
|
|
|
|
|
storageMeasure(DeviceAttrCode.COMMON, uploadValue, baseTransDataEntity); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void storageMeasure(String attrCode, String uploadValue, DynamodbEntity baseTransDataEntity) throws Exception { |
|
|
|
|
|
BigDecimal currentValue = new BigDecimal(uploadValue); |
|
|
|
|
|
BigDecimal minValue = currentValue; |
|
|
|
|
|
BigDecimal maxValue = currentValue; |
|
|
|
|
|
|
|
|
|
|
|
// 获取东京时间
|
|
|
|
|
|
ComplexTime complexTime = DateUtils.getComplexTime(baseTransDataEntity.getReceive_ts()); |
|
|
|
|
|
|
|
|
if (accumulateTypeIds.contains(baseTransDataEntity.getTypeId())) { |
|
|
// 获取 Redis 数据
|
|
|
storageAccumulate(uploadValue, baseTransDataEntity); |
|
|
String currentDayKey = Constants.STATISTICS_MEASURE_LATEST_PREFIX + complexTime.getDateKey(); |
|
|
} |
|
|
if (!DeviceAttrCode.COMMON.equalsIgnoreCase(attrCode)) { |
|
|
|
|
|
|
|
|
if (measureTypeIds.contains(baseTransDataEntity.getTypeId())) { |
|
|
} |
|
|
storageMeasure(uploadValue, baseTransDataEntity); |
|
|
Object currentDayInfoObj = this.redisTemplate.opsForHash().get(currentDayKey, baseTransDataEntity.getDeviceId()); |
|
|
} |
|
|
|
|
|
} |
|
|
//比较值
|
|
|
|
|
|
if (null != currentDayInfoObj) { |
|
|
private void storageMeasure(String uploadValue, DynamodbEntity baseTransDataEntity) throws Exception { |
|
|
StatisticsMeasureInfo currentDayInfo = objectMapper.readValue(currentDayInfoObj.toString(), StatisticsMeasureInfo.class); |
|
|
BigDecimal currentValue = new BigDecimal(uploadValue); |
|
|
BigDecimal oldMaxValue = new BigDecimal(currentDayInfo.getMaxValue().toString()); |
|
|
BigDecimal minValue = currentValue; |
|
|
BigDecimal oldMinValue = new BigDecimal(currentDayInfo.getMinValue().toString()); |
|
|
BigDecimal maxValue = currentValue; |
|
|
if (ArithUtil.compareTo(oldMaxValue, currentValue) > 0) { |
|
|
|
|
|
maxValue = oldMaxValue; |
|
|
// 获取东京时间
|
|
|
} |
|
|
ComplexTime complexTime = DateUtils.getComplexTime(baseTransDataEntity.getReceive_ts()); |
|
|
if (ArithUtil.compareTo(currentValue, oldMinValue) > 0) { |
|
|
|
|
|
minValue = oldMinValue; |
|
|
// 获取 Redis 数据
|
|
|
} |
|
|
String currentDayKey = Constants.STATISTICS_MEASURE_LATEST_PREFIX + complexTime.getDateKey(); |
|
|
} |
|
|
Object currentDayInfoObj = this.redisTemplate.opsForHash().get(currentDayKey, baseTransDataEntity.getDeviceId()); |
|
|
|
|
|
|
|
|
//最新数据存入redis
|
|
|
//比较值
|
|
|
StatisticsMeasureInfo currentInfo = new StatisticsMeasureInfo(); |
|
|
if (null != currentDayInfoObj) { |
|
|
BeanUtils.copyProperties(complexTime, currentInfo); |
|
|
StatisticsMeasureInfo currentDayInfo = objectMapper.readValue(currentDayInfoObj.toString(), StatisticsMeasureInfo.class); |
|
|
currentInfo.setValue(uploadValue); |
|
|
BigDecimal oldMaxValue = new BigDecimal(currentDayInfo.getMaxValue().toString()); |
|
|
currentInfo.setUploadAt(baseTransDataEntity.getReceive_ts()); |
|
|
BigDecimal oldMinValue = new BigDecimal(currentDayInfo.getMinValue().toString()); |
|
|
currentInfo.setMaxValue(maxValue); |
|
|
if (ArithUtil.compareTo(oldMaxValue, currentValue) > 0) { |
|
|
currentInfo.setMinValue(minValue); |
|
|
maxValue = oldMaxValue; |
|
|
|
|
|
} |
|
|
redisTemplate.opsForHash().put(currentDayKey, baseTransDataEntity.getDeviceId(), JSON.toJSONString(currentInfo)); |
|
|
if (ArithUtil.compareTo(currentValue, oldMinValue) > 0) { |
|
|
// 设置过期时间 7 天
|
|
|
minValue = oldMinValue; |
|
|
redisTemplate.expire(currentDayKey, 7, TimeUnit.DAYS); |
|
|
} |
|
|
|
|
|
} |
|
|
//历史表和实时表
|
|
|
|
|
|
|
|
|
//最新数据存入redis
|
|
|
|
|
|
StatisticsMeasureInfo currentInfo = new StatisticsMeasureInfo(); |
|
|
|
|
|
BeanUtils.copyProperties(complexTime, currentInfo); |
|
|
|
|
|
currentInfo.setValue(uploadValue); |
|
|
|
|
|
currentInfo.setUploadAt(baseTransDataEntity.getReceive_ts()); |
|
|
|
|
|
currentInfo.setMaxValue(maxValue); |
|
|
|
|
|
currentInfo.setMinValue(minValue); |
|
|
|
|
|
|
|
|
|
|
|
redisTemplate.opsForHash().put(currentDayKey, baseTransDataEntity.getDeviceId(), JSON.toJSONString(currentInfo)); |
|
|
|
|
|
// 设置过期时间 7 天
|
|
|
|
|
|
redisTemplate.expire(currentDayKey, 7, TimeUnit.DAYS); |
|
|
|
|
|
|
|
|
|
|
|
//历史表和实时表
|
|
|
|
|
|
// dashboardStatisticsDao.insertDeviceMeasureInfo(uploadValue, baseTransDataEntity.getDeviceId(), currentInfo);
|
|
|
// dashboardStatisticsDao.insertDeviceMeasureInfo(uploadValue, baseTransDataEntity.getDeviceId(), currentInfo);
|
|
|
// dashboardStatisticsDao.upsertDeviceRealtimeMeasure(uploadValue, baseTransDataEntity.getDeviceId(), minValue, maxValue, currentInfo);
|
|
|
// dashboardStatisticsDao.upsertDeviceRealtimeMeasure(uploadValue, baseTransDataEntity.getDeviceId(), minValue, maxValue, currentInfo);
|
|
|
measureService.write(uploadValue, baseTransDataEntity.getDeviceId(), currentInfo, minValue, maxValue); |
|
|
measureService.write(attrCode, uploadValue, baseTransDataEntity.getDeviceId(), currentInfo, minValue, maxValue); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void storageAccumulate(String uploadValue, DynamodbEntity baseTransDataEntity) throws Exception { |
|
|
private void storageAccumulate(String attrCode, String uploadValue, DynamodbEntity baseTransDataEntity) throws Exception { |
|
|
BigDecimal currentValue = new BigDecimal(uploadValue); |
|
|
BigDecimal currentValue = new BigDecimal(uploadValue); |
|
|
Double incrementToday = null; |
|
|
Double incrementToday = null; |
|
|
Double incrementMinute = null; |
|
|
Double incrementMinute = null; |
|
|
|
|
|
|
|
|
// 获取东京时间
|
|
|
// 获取东京时间
|
|
|
ComplexTime complexTime = DateUtils.getComplexTime(baseTransDataEntity.getReceive_ts()); |
|
|
ComplexTime complexTime = DateUtils.getComplexTime(baseTransDataEntity.getReceive_ts()); |
|
|
|
|
|
|
|
|
// 获取 Redis 数据
|
|
|
// 获取 Redis 数据
|
|
|
String currentDayKey = Constants.STATISTICS_ACCUMULATE_LATEST_PREFIX + complexTime.getDateKey(); |
|
|
String currentDayKey = Constants.STATISTICS_ACCUMULATE_LATEST_PREFIX + complexTime.getDateKey(); |
|
|
String lastDayKey = Constants.STATISTICS_ACCUMULATE_LATEST_PREFIX + complexTime.getPreviousDateKey(); |
|
|
String lastDayKey = Constants.STATISTICS_ACCUMULATE_LATEST_PREFIX + complexTime.getPreviousDateKey(); |
|
|
Object currentDayInfoObj = this.redisTemplate.opsForHash().get(currentDayKey, baseTransDataEntity.getDeviceId()); |
|
|
Object currentDayInfoObj = this.redisTemplate.opsForHash().get(currentDayKey, baseTransDataEntity.getDeviceId()); |
|
|
Object lastDayInfoObj = this.redisTemplate.opsForHash().get(lastDayKey, baseTransDataEntity.getDeviceId()); |
|
|
Object lastDayInfoObj = this.redisTemplate.opsForHash().get(lastDayKey, baseTransDataEntity.getDeviceId()); |
|
|
|
|
|
|
|
|
// 今日增量
|
|
|
// 今日增量
|
|
|
// 如果昨天的没有,那直接取当前数据
|
|
|
// 如果昨天的没有,那直接取当前数据
|
|
|
if (null != lastDayInfoObj) { |
|
|
if (null != lastDayInfoObj) { |
|
|
StatisticsAccumulateInfo lastDayInfo = objectMapper.readValue(lastDayInfoObj.toString(), StatisticsAccumulateInfo.class); |
|
|
StatisticsAccumulateInfo lastDayInfo = objectMapper.readValue(lastDayInfoObj.toString(), StatisticsAccumulateInfo.class); |
|
|
BigDecimal lastDayValue = new BigDecimal(lastDayInfo.getValue().toString()); |
|
|
BigDecimal lastDayValue = new BigDecimal(lastDayInfo.getValue().toString()); |
|
|
if (ArithUtil.compareTo(currentValue, lastDayValue) >= 0) { |
|
|
incrementToday = ArithUtil.sub(currentValue, lastDayValue); |
|
|
incrementToday = ArithUtil.sub(currentValue, lastDayValue); |
|
|
} else { |
|
|
} |
|
|
incrementToday = currentValue.doubleValue(); |
|
|
} else { |
|
|
} |
|
|
incrementToday = currentValue.doubleValue(); |
|
|
|
|
|
} |
|
|
// 1分钟增量
|
|
|
|
|
|
// 这个是如果这条数据的前一分钟没有数据的话,这条数据它就不计算增量,但是保留这个数据,然后下一条数据上来的时候就继续跟这条数据计算增量就行
|
|
|
// 1分钟增量
|
|
|
long diff = 3600000L; |
|
|
// 这个是如果这条数据的前一分钟没有数据的话,这条数据它就不计算增量,但是保留这个数据,然后下一条数据上来的时候就继续跟这条数据计算增量就行
|
|
|
|
|
|
long diff = 3600000L; |
|
|
|
|
|
BigDecimal lastMinuteValue = null; |
|
|
BigDecimal lastMinuteValue = null; |
|
|
long nowTs = baseTransDataEntity.getReceive_ts(); |
|
|
long nowTs = baseTransDataEntity.getReceive_ts(); |
|
|
if (currentDayInfoObj == null) { |
|
|
if (currentDayInfoObj == null) { |
|
|
if (complexTime.getHourKey() == 0 && lastDayInfoObj != null) { |
|
|
if (complexTime.getHourKey() == 0 && lastDayInfoObj != null) { |
|
|
StatisticsAccumulateInfo lastMinInfo = objectMapper.readValue(lastDayInfoObj.toString(), StatisticsAccumulateInfo.class); |
|
|
StatisticsAccumulateInfo lastMinInfo = objectMapper.readValue(lastDayInfoObj.toString(), StatisticsAccumulateInfo.class); |
|
|
if (nowTs - lastMinInfo.getUploadAt() < diff) { //需要1小时内的数据
|
|
|
if (nowTs - lastMinInfo.getUploadAt() < diff) { //需要1小时内的数据
|
|
|
lastMinuteValue = new BigDecimal(String.valueOf(lastMinInfo.getValue())); |
|
|
lastMinuteValue = new BigDecimal(String.valueOf(lastMinInfo.getValue())); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
StatisticsAccumulateInfo currentDayInfo = objectMapper.readValue(currentDayInfoObj.toString(), StatisticsAccumulateInfo.class); |
|
|
StatisticsAccumulateInfo currentDayInfo = objectMapper.readValue(currentDayInfoObj.toString(), StatisticsAccumulateInfo.class); |
|
|
if (nowTs - currentDayInfo.getUploadAt() < diff) { |
|
|
if (nowTs - currentDayInfo.getUploadAt() < diff) { |
|
|
lastMinuteValue = new BigDecimal(String.valueOf(currentDayInfo.getValue())); |
|
|
lastMinuteValue = new BigDecimal(String.valueOf(currentDayInfo.getValue())); |
|
|
} |
|
|
} |
|
|
@ -776,80 +792,107 @@ public class DataProcessServiceImpl implements IDataProcessService { |
|
|
incrementMinute = currentValue.subtract(lastMinuteValue).doubleValue(); |
|
|
incrementMinute = currentValue.subtract(lastMinuteValue).doubleValue(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//最新数据存入redis
|
|
|
//最新数据存入redis
|
|
|
StatisticsAccumulateInfo currentInfo = new StatisticsAccumulateInfo(); |
|
|
StatisticsAccumulateInfo currentInfo = new StatisticsAccumulateInfo(); |
|
|
BeanUtils.copyProperties(complexTime, currentInfo); |
|
|
BeanUtils.copyProperties(complexTime, currentInfo); |
|
|
currentInfo.setValue(uploadValue); |
|
|
currentInfo.setValue(uploadValue); |
|
|
currentInfo.setUploadAt(baseTransDataEntity.getReceive_ts()); |
|
|
currentInfo.setUploadAt(baseTransDataEntity.getReceive_ts()); |
|
|
|
|
|
|
|
|
redisTemplate.opsForHash().put(currentDayKey, baseTransDataEntity.getDeviceId(), JSON.toJSONString(currentInfo)); |
|
|
redisTemplate.opsForHash().put(currentDayKey, baseTransDataEntity.getDeviceId(), JSON.toJSONString(currentInfo)); |
|
|
// 设置过期时间 7 天
|
|
|
// 设置过期时间 7 天
|
|
|
redisTemplate.expire(currentDayKey, 7, TimeUnit.DAYS); |
|
|
redisTemplate.expire(currentDayKey, 7, TimeUnit.DAYS); |
|
|
|
|
|
|
|
|
//历史表和日期实时表
|
|
|
//历史表和日期实时表
|
|
|
// dashboardStatisticsDao.insertDeviceAccumulateInfo(uploadValue, baseTransDataEntity.getDeviceId(), incrementToday, incrementMinute, currentInfo);
|
|
|
// dashboardStatisticsDao.insertDeviceAccumulateInfo(uploadValue, baseTransDataEntity.getDeviceId(), incrementToday, incrementMinute, currentInfo);
|
|
|
// dashboardStatisticsDao.insertOrUpdateRealtimeAccumulateDay(uploadValue, baseTransDataEntity.getDeviceId(), incrementToday, currentInfo);
|
|
|
// dashboardStatisticsDao.insertOrUpdateRealtimeAccumulateDay(uploadValue, baseTransDataEntity.getDeviceId(), incrementToday, currentInfo);
|
|
|
accumulateService.write(uploadValue, baseTransDataEntity.getDeviceId(), incrementToday, incrementMinute, currentInfo); |
|
|
accumulateService.write(attrCode, uploadValue, baseTransDataEntity.getDeviceId(), incrementToday, incrementMinute, currentInfo); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public String extractFirstValue(String rawData) { |
|
|
// public String extractFirstValue(String rawData) {
|
|
|
if (StringUtils.isBlank(rawData)){ |
|
|
// if (StringUtils.isBlank(rawData)){
|
|
|
return ""; |
|
|
// return "";
|
|
|
} |
|
|
// }
|
|
|
try { |
|
|
// try {
|
|
|
JsonNode node = objectMapper.readTree(rawData); |
|
|
// JsonNode node = objectMapper.readTree(rawData);
|
|
|
Iterator<Map.Entry<String, JsonNode>> fields = node.fields(); |
|
|
// Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
|
|
|
if (fields.hasNext()) { |
|
|
// if (fields.hasNext()) {
|
|
|
return fields.next().getValue().asText(); |
|
|
// return fields.next().getValue().asText();
|
|
|
} |
|
|
// }
|
|
|
} catch (Exception e) { |
|
|
// } catch (Exception e) {
|
|
|
log.error("Failed to parse rawData JSON: " + rawData, e); |
|
|
// log.error("Failed to parse rawData JSON: " + rawData, e);
|
|
|
} |
|
|
// }
|
|
|
return ""; |
|
|
// return "";
|
|
|
} |
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
public List<String> extractAllValues(String rawData) { |
|
|
private void handleDashboardAlert(DynamodbEntity baseTransDataEntity) { |
|
|
List<String> result = new ArrayList<>(); |
|
|
|
|
|
|
|
|
if (!ALL_DEVICE_TYPE_IDS.contains(baseTransDataEntity.getTypeId())) { |
|
|
if (StringUtils.isBlank(rawData)) { |
|
|
return; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Object redisOldStatusObj = this.alramRedisTemplate.opsForHash().get(REDIS_DASHBOARD_DEVICE_STATUS_KEY, baseTransDataEntity.getDeviceId()); |
|
|
try { |
|
|
|
|
|
JsonNode node = objectMapper.readTree(rawData); |
|
|
//更新实时信息
|
|
|
|
|
|
try { |
|
|
if (!node.isObject()) { |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Iterator<Map.Entry<String, JsonNode>> fields = node.fields(); |
|
|
|
|
|
while (fields.hasNext()) { |
|
|
|
|
|
JsonNode valueNode = fields.next().getValue(); |
|
|
|
|
|
result.add(valueNode.isValueNode() ? valueNode.asText() : valueNode.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("Failed to parse rawData JSON: {}", rawData, e); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void handleDashboardAlert(DynamodbEntity baseTransDataEntity) { |
|
|
|
|
|
|
|
|
|
|
|
if (!ALL_DEVICE_TYPE_IDS.contains(baseTransDataEntity.getTypeId())) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Object redisOldStatusObj = this.alramRedisTemplate.opsForHash().get(REDIS_DASHBOARD_DEVICE_STATUS_KEY, baseTransDataEntity.getDeviceId()); |
|
|
|
|
|
|
|
|
|
|
|
//更新实时信息
|
|
|
|
|
|
try { |
|
|
// dashboardAlertDao.upsertDeviceRawData(baseTransDataEntity);
|
|
|
// dashboardAlertDao.upsertDeviceRawData(baseTransDataEntity);
|
|
|
alertService.write(baseTransDataEntity); |
|
|
alertService.write(baseTransDataEntity); |
|
|
this.alramRedisTemplate.opsForHash().put( |
|
|
this.alramRedisTemplate.opsForHash().put( |
|
|
REDIS_DASHBOARD_DEVICE_STATUS_KEY, |
|
|
REDIS_DASHBOARD_DEVICE_STATUS_KEY, |
|
|
baseTransDataEntity.getDeviceId(), |
|
|
baseTransDataEntity.getDeviceId(), |
|
|
baseTransDataEntity.getStatus()); |
|
|
baseTransDataEntity.getStatus()); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.error("upsertDeviceRawData error", e); |
|
|
log.error("upsertDeviceRawData error", e); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//告警历史处理
|
|
|
//告警历史处理
|
|
|
if (alarmTypeIds.contains(baseTransDataEntity.getTypeId())) { |
|
|
if (alarmTypeIds.contains(baseTransDataEntity.getTypeId())) { |
|
|
String status = baseTransDataEntity.getStatus(); |
|
|
String status = baseTransDataEntity.getStatus(); |
|
|
if (null == redisOldStatusObj) { |
|
|
if (null == redisOldStatusObj) { |
|
|
if ("alert".equals(status)) { |
|
|
if ("alert".equals(status)) { |
|
|
dashboardAlertDao.insertAlertHistory(baseTransDataEntity); |
|
|
dashboardAlertDao.insertAlertHistory(baseTransDataEntity); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
String redisOldStatus = (String) redisOldStatusObj; |
|
|
String redisOldStatus = (String) redisOldStatusObj; |
|
|
if ("alert".equals(status) && !"alert".equals(redisOldStatus)) { |
|
|
if ("alert".equals(status) && !"alert".equals(redisOldStatus)) { |
|
|
dashboardAlertDao.insertAlertHistory(baseTransDataEntity); |
|
|
dashboardAlertDao.insertAlertHistory(baseTransDataEntity); |
|
|
} else if (!"alert".equals(status) && "alert".equals(redisOldStatus)) { |
|
|
} else if (!"alert".equals(status) && "alert".equals(redisOldStatus)) { |
|
|
if (0 == baseTransDataEntity.getRetainAlert()) { |
|
|
if (0 == baseTransDataEntity.getRetainAlert()) { |
|
|
dashboardAlertDao.updateLatestAlertToAutoRecovered(baseTransDataEntity); |
|
|
dashboardAlertDao.updateLatestAlertToAutoRecovered(baseTransDataEntity); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 根据设备信息和内容创建一个DynamodbEntity基础实体。 |
|
|
* 根据设备信息和内容创建一个DynamodbEntity基础实体。 |
|
|
* <p> |
|
|
* <p> |
|
|
* 该方法利用给定的设备信息和内容创建并返回一个DynamodbEntity对象。 |
|
|
* 该方法利用给定的设备信息和内容创建并返回一个DynamodbEntity对象。 |
|
|
@ -1004,7 +1047,7 @@ public class DataProcessServiceImpl implements IDataProcessService { |
|
|
if (StringUtils.isEmpty(targetId)||StringUtils.equals("-1",targetId)){ |
|
|
if (StringUtils.isEmpty(targetId)||StringUtils.equals("-1",targetId)){ |
|
|
|
|
|
|
|
|
}else{ |
|
|
}else{ |
|
|
paramsMap=JSON.parseObject(targetId, new TypeReference<Map<String,Object>>(){}); |
|
|
paramsMap=JSON.parseObject(targetId, new TypeReference<Map<String,Object>>(){}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1103,22 +1146,22 @@ public class DataProcessServiceImpl implements IDataProcessService { |
|
|
DynamodbEntity baseTransDataEntity,Set<String> waitingProcessTargetSets, |
|
|
DynamodbEntity baseTransDataEntity,Set<String> waitingProcessTargetSets, |
|
|
Set<String> existingTargetSets,String deviceSN, DeviceInfoVO deviceInfoVO) { |
|
|
Set<String> existingTargetSets,String deviceSN, DeviceInfoVO deviceInfoVO) { |
|
|
|
|
|
|
|
|
JSONObject alertTemplateInfo = null; |
|
|
JSONObject alertTemplateInfo = null; |
|
|
if (StringUtils.isNotEmpty(baseTransDataEntity.getRawData()) && StringUtils.isNotEmpty(baseTransDataEntity.getAlertTemplateIds())) { |
|
|
if (StringUtils.isNotEmpty(baseTransDataEntity.getRawData()) && StringUtils.isNotEmpty(baseTransDataEntity.getAlertTemplateIds())) { |
|
|
JSONObject postJsonObject = new JSONObject(); |
|
|
JSONObject postJsonObject = new JSONObject(); |
|
|
postJsonObject.put("deviceId", baseTransDataEntity.getDeviceId()); |
|
|
postJsonObject.put("deviceId", baseTransDataEntity.getDeviceId()); |
|
|
postJsonObject.put("status", baseTransDataEntity.getStatus()); |
|
|
postJsonObject.put("status", baseTransDataEntity.getStatus()); |
|
|
postJsonObject.put("companyId", companyId); |
|
|
postJsonObject.put("companyId", companyId); |
|
|
if (StringUtils.isNotEmpty(baseTransDataEntity.getAlertTemplateIds())){ |
|
|
if (StringUtils.isNotEmpty(baseTransDataEntity.getAlertTemplateIds())){ |
|
|
postJsonObject.put("alarmTmplIds", baseTransDataEntity.getAlertTemplateIds().replace("[", "").replace("]", "")); |
|
|
postJsonObject.put("alarmTmplIds", baseTransDataEntity.getAlertTemplateIds().replace("[", "").replace("]", "")); |
|
|
} |
|
|
} |
|
|
log.debug("triggerAndSave postJsonObject:"+postJsonObject.toString()); |
|
|
log.debug("triggerAndSave postJsonObject:"+postJsonObject.toString()); |
|
|
|
|
|
|
|
|
//根据告警模板获取转发信息和告警方式
|
|
|
//根据告警模板获取转发信息和告警方式
|
|
|
String resp = HttpUtil.doPost(businessQueryPushInfo, postJsonObject.toString() , null); |
|
|
String resp = HttpUtil.doPost(businessQueryPushInfo, postJsonObject.toString() , null); |
|
|
log.info("queryByDeviceId result:{}", resp); |
|
|
log.info("queryByDeviceId result:{}", resp); |
|
|
if (StringUtils.isNotBlank(resp)) { |
|
|
if (StringUtils.isNotBlank(resp)) { |
|
|
alertTemplateInfo = JSONObject.parseObject(resp); |
|
|
alertTemplateInfo = JSONObject.parseObject(resp); |
|
|
//Process Value replace/用于替换模版中的{Value}字段,这里和下面一段都是做处理,分别对两块数据进行了处理
|
|
|
//Process Value replace/用于替换模版中的{Value}字段,这里和下面一段都是做处理,分别对两块数据进行了处理
|
|
|
JSONArray parsedAlarmInfoListArray = alertTemplateInfo.getJSONObject("data").getJSONArray("parsedAlarmInfoList"); |
|
|
JSONArray parsedAlarmInfoListArray = alertTemplateInfo.getJSONObject("data").getJSONArray("parsedAlarmInfoList"); |
|
|
JSONObject jsonObject = JSON.parseObject(baseTransDataEntity.getRawData(), JSONObject.class); |
|
|
JSONObject jsonObject = JSON.parseObject(baseTransDataEntity.getRawData(), JSONObject.class); |
|
|
@ -1140,9 +1183,9 @@ public class DataProcessServiceImpl implements IDataProcessService { |
|
|
log.info("parsedAlarmInfoListArray 1:{}", parsedAlarmInfoListArray); |
|
|
log.info("parsedAlarmInfoListArray 1:{}", parsedAlarmInfoListArray); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//处理转发
|
|
|
//处理转发
|
|
|
alarmDataPushLambda.handleTargetUrl(alertTemplateInfo, JSON.parseObject(JSON.toJSONString(baseTransDataEntity))); |
|
|
alarmDataPushLambda.handleTargetUrl(alertTemplateInfo, JSON.parseObject(JSON.toJSONString(baseTransDataEntity))); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//处理告警内容中的{Value}变量,用实际值替换
|
|
|
//处理告警内容中的{Value}变量,用实际值替换
|
|
|
|