|
@@ -30,11 +30,11 @@ import com.sckw.slope.detection.model.vo.DeviceIntegrationVo;
|
|
|
import com.sckw.slope.detection.service.CommonService;
|
|
import com.sckw.slope.detection.service.CommonService;
|
|
|
import com.sckw.slope.detection.service.TdengineService;
|
|
import com.sckw.slope.detection.service.TdengineService;
|
|
|
import com.sckw.slope.detection.service.api.DetectionApiService;
|
|
import com.sckw.slope.detection.service.api.DetectionApiService;
|
|
|
|
|
+import com.sckw.slope.detection.service.repository.KwsAlarmInfoRepository;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.dubbo.common.utils.MD5Utils;
|
|
import org.apache.dubbo.common.utils.MD5Utils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
@@ -53,8 +53,6 @@ import java.util.stream.Collectors;
|
|
|
@Service("system/iot/device_data_slope")
|
|
@Service("system/iot/device_data_slope")
|
|
|
public class MqttCallbackHandler extends AbstractHandler {
|
|
public class MqttCallbackHandler extends AbstractHandler {
|
|
|
|
|
|
|
|
- @Value("${sms.url}")
|
|
|
|
|
- private String messageUrl;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
CommonService commonService;
|
|
CommonService commonService;
|
|
@@ -80,6 +78,9 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
KwsIntegrationMapper integrationMapper;
|
|
KwsIntegrationMapper integrationMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ KwsAlarmInfoRepository alarmInfoRepository;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
SmsTemplateConfig smsTemplateConfig;
|
|
SmsTemplateConfig smsTemplateConfig;
|
|
|
|
|
|
|
@@ -159,39 +160,35 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
// redisPutAlarmCount(id);
|
|
// redisPutAlarmCount(id);
|
|
|
/*【露天矿山边坡监测系统】尊敬的管理员,2023-10-01 12:23:34监测到一级告警。
|
|
/*【露天矿山边坡监测系统】尊敬的管理员,2023-10-01 12:23:34监测到一级告警。
|
|
|
设备名称:位移监测设备-gnss一号机,监测数值:55。123456789N,请尽快处理问题。*/
|
|
设备名称:位移监测设备-gnss一号机,监测数值:55。123456789N,请尽快处理问题。*/
|
|
|
- Map<String, Object> messageMap = new HashMap<>();
|
|
|
|
|
- Long deviceId = device.getId();
|
|
|
|
|
- KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
|
|
|
|
|
- .eq(KwsProjectDevice::getDeviceId, deviceId)
|
|
|
|
|
- .eq(KwsProjectDevice::getDelFlag, 0)
|
|
|
|
|
- .eq(KwsProjectDevice::getStatus, 0)
|
|
|
|
|
- .orderByDesc(KwsProjectDevice::getCreateTime)
|
|
|
|
|
- .last(" limit 1")
|
|
|
|
|
|
|
+ String mountainId = device.getMountainId();
|
|
|
|
|
+ List<KwsAlarmInfo> list = alarmInfoRepository.list(new LambdaQueryWrapper<KwsAlarmInfo>()
|
|
|
|
|
+ .eq(KwsAlarmInfo::getMountainId, mountainId)
|
|
|
|
|
+ .eq(KwsAlarmInfo::getLevel, level.intValue())
|
|
|
|
|
+ .eq(KwsAlarmInfo::getType, NumberConstant.ONE)
|
|
|
|
|
+ .eq(KwsAlarmInfo::getDelFlag, NumberConstant.ZERO)
|
|
|
);
|
|
);
|
|
|
- LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
|
|
|
|
|
- .eq(KwsAlarm::getLevel, level.intValue())
|
|
|
|
|
- .eq(KwsAlarm::getDeviceId, deviceId)
|
|
|
|
|
- .eq(KwsAlarm::getType, NumberConstant.ONE)
|
|
|
|
|
- .orderByDesc(KwsAlarm::getCreateTime);
|
|
|
|
|
- if (projectDevice != null) {
|
|
|
|
|
- wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
|
|
|
|
|
- .eq(KwsAlarm::getMountainId, projectDevice.getMountainId());
|
|
|
|
|
- if (projectDevice.getProjectId() != null) {
|
|
|
|
|
- wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
|
|
|
|
|
|
|
+ List<String> pushToPhone = new ArrayList<>();
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
|
+ pushToPhone = list.stream().map(KwsAlarmInfo::getValueDesc).distinct().collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(pushToPhone)) {
|
|
|
|
|
+// KwsThreshold kwsThreshold = thresholdMapper.selectById(thresholdId);
|
|
|
|
|
+// String phones = kwsThreshold.getPhones();
|
|
|
|
|
+// List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
|
|
|
|
|
+ Map<String, String> templateParam = new HashMap<>();
|
|
|
|
|
+ if (StringUtils.isBlank(time)) {
|
|
|
|
|
+ LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
|
|
+ time = com.sckw.excel.utils.DateUtil.format(localDateTime);
|
|
|
}
|
|
}
|
|
|
|
|
+ templateParam.put("time", time);
|
|
|
|
|
+ templateParam.put("level", level.toString());
|
|
|
|
|
+ templateParam.put("name", device.getName());
|
|
|
|
|
+ templateParam.put("value", itemValue);
|
|
|
|
|
+ commonService.pushSmsMessage(pushToPhone
|
|
|
|
|
+ , smsTemplateConfig.getDataAlarm().getSmsCode()
|
|
|
|
|
+ , smsTemplateConfig.getDataAlarm().getSignName()
|
|
|
|
|
+ , templateParam);
|
|
|
}
|
|
}
|
|
|
- KwsThreshold kwsThreshold = thresholdMapper.selectById(thresholdId);
|
|
|
|
|
- String phones = kwsThreshold.getPhones();
|
|
|
|
|
- List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
|
|
|
|
|
- Map<String, String> templateParam = new HashMap<>();
|
|
|
|
|
- templateParam.put("time", time);
|
|
|
|
|
- templateParam.put("level", level.toString());
|
|
|
|
|
- templateParam.put("name", device.getName());
|
|
|
|
|
- templateParam.put("value", itemValue);
|
|
|
|
|
- commonService.pushSmsMessage(pushToPhone
|
|
|
|
|
- , smsTemplateConfig.getDataAlarm().getSmsCode()
|
|
|
|
|
- , smsTemplateConfig.getDataAlarm().getSignName()
|
|
|
|
|
- , templateParam);
|
|
|
|
|
}
|
|
}
|
|
|
//集成要素阈值告警
|
|
//集成要素阈值告警
|
|
|
deviceIntegrationsAlarm(device, ts);
|
|
deviceIntegrationsAlarm(device, ts);
|
|
@@ -219,15 +216,15 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void deviceIntegrationsAlarm(KwsDevice device, Long ts) {
|
|
private void deviceIntegrationsAlarm(KwsDevice device, Long ts) {
|
|
|
- List<KwsDeviceIntegration> deviceIntegrations = deviceIntegrationMapper.selectList(
|
|
|
|
|
- new LambdaQueryWrapper<KwsDeviceIntegration>()
|
|
|
|
|
- .eq(KwsDeviceIntegration::getDeviceId, device.getId())
|
|
|
|
|
- .eq(KwsDeviceIntegration::getDelFlag, 0)
|
|
|
|
|
- );
|
|
|
|
|
- List<Long> integrationIds = null;
|
|
|
|
|
- if (!org.springframework.util.CollectionUtils.isEmpty(deviceIntegrations)) {
|
|
|
|
|
- integrationIds = deviceIntegrations.stream().map(KwsDeviceIntegration::getIntegrationId).collect(Collectors.toList());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// List<KwsDeviceIntegration> deviceIntegrations = deviceIntegrationMapper.selectList(
|
|
|
|
|
+// new LambdaQueryWrapper<KwsDeviceIntegration>()
|
|
|
|
|
+// .eq(KwsDeviceIntegration::getDeviceId, device.getId())
|
|
|
|
|
+// .eq(KwsDeviceIntegration::getDelFlag, 0)
|
|
|
|
|
+// );
|
|
|
|
|
+// List<Long> integrationIds = null;
|
|
|
|
|
+// if (!org.springframework.util.CollectionUtils.isEmpty(deviceIntegrations)) {
|
|
|
|
|
+// integrationIds = deviceIntegrations.stream().map(KwsDeviceIntegration::getIntegrationId).collect(Collectors.toList());
|
|
|
|
|
+// }
|
|
|
// List<KwsIntegration> integrations = integrationMapper.selectList(
|
|
// List<KwsIntegration> integrations = integrationMapper.selectList(
|
|
|
// new LambdaQueryWrapper<KwsIntegration>()
|
|
// new LambdaQueryWrapper<KwsIntegration>()
|
|
|
// .in(KwsIntegration::getId, integrationIds)
|
|
// .in(KwsIntegration::getId, integrationIds)
|
|
@@ -259,47 +256,70 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
String url = deviceIntegration.getUnit() == null ? null : deviceIntegration.getUnit();
|
|
String url = deviceIntegration.getUnit() == null ? null : deviceIntegration.getUnit();
|
|
|
String itemValueAndUnit = StringUtils.isBlank(url) ? String.valueOf(offset) : (offset + deviceIntegration.getUnit());
|
|
String itemValueAndUnit = StringUtils.isBlank(url) ? String.valueOf(offset) : (offset + deviceIntegration.getUnit());
|
|
|
long id = insertAlarmAndDetail(level, device, thresholdId, itemValueAndUnit, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
|
|
long id = insertAlarmAndDetail(level, device, thresholdId, itemValueAndUnit, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
|
|
|
- Map<String, Object> messageMap = new HashMap<>();
|
|
|
|
|
- Long deviceId = device.getId();
|
|
|
|
|
- KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
|
|
|
|
|
- .eq(KwsProjectDevice::getDeviceId, deviceId)
|
|
|
|
|
- .eq(KwsProjectDevice::getDelFlag, 0)
|
|
|
|
|
- .eq(KwsProjectDevice::getStatus, 0)
|
|
|
|
|
- .orderByDesc(KwsProjectDevice::getCreateTime)
|
|
|
|
|
- .last(" limit 1")
|
|
|
|
|
|
|
+ /**最初发送短信模式*/
|
|
|
|
|
+// oldPushSms(device,level,thresholdId);
|
|
|
|
|
+ /**目前发送短信模式*/
|
|
|
|
|
+ String mountainId = device.getMountainId();
|
|
|
|
|
+ List<KwsAlarmInfo> list = alarmInfoRepository.list(new LambdaQueryWrapper<KwsAlarmInfo>()
|
|
|
|
|
+ .eq(KwsAlarmInfo::getMountainId, mountainId)
|
|
|
|
|
+ .eq(KwsAlarmInfo::getLevel, level.intValue())
|
|
|
|
|
+ .eq(KwsAlarmInfo::getType, NumberConstant.ONE)
|
|
|
|
|
+ .eq(KwsAlarmInfo::getDelFlag, NumberConstant.ZERO)
|
|
|
);
|
|
);
|
|
|
- LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
|
|
|
|
|
- .eq(KwsAlarm::getLevel, level.intValue())
|
|
|
|
|
- .eq(KwsAlarm::getDeviceId, deviceId)
|
|
|
|
|
- .eq(KwsAlarm::getType, NumberConstant.ONE)
|
|
|
|
|
- .orderByDesc(KwsAlarm::getCreateTime);
|
|
|
|
|
- if (projectDevice != null) {
|
|
|
|
|
- wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
|
|
|
|
|
- .eq(KwsAlarm::getMountainId, projectDevice.getMountainId());
|
|
|
|
|
- if (projectDevice.getProjectId() != null) {
|
|
|
|
|
- wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
|
|
|
|
|
|
|
+ List<String> pushToPhone = new ArrayList<>();
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
|
+ pushToPhone = list.stream().map(KwsAlarmInfo::getValueDesc).distinct().collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(pushToPhone)) {
|
|
|
|
|
+ LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
|
|
+ String time = DateUtil.format(localDateTime, "yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ Map<String, String> templateParam = new HashMap<>();
|
|
|
|
|
+ if (StringUtils.isBlank(time)) {
|
|
|
|
|
+ LocalDateTime localDateTimes = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
|
|
+ time = com.sckw.excel.utils.DateUtil.format(localDateTimes);
|
|
|
}
|
|
}
|
|
|
|
|
+ templateParam.put("time", time);
|
|
|
|
|
+ templateParam.put("level", level.toString());
|
|
|
|
|
+ templateParam.put("name", device.getName());
|
|
|
|
|
+ templateParam.put("value", itemValueAndUnit);
|
|
|
|
|
+ commonService.pushSmsMessage(pushToPhone
|
|
|
|
|
+ , smsTemplateConfig.getDataAlarm().getSmsCode()
|
|
|
|
|
+ , smsTemplateConfig.getDataAlarm().getSignName()
|
|
|
|
|
+ , templateParam);
|
|
|
}
|
|
}
|
|
|
- KwsThreshold kwsThreshold = thresholdMapper.selectById(thresholdId);
|
|
|
|
|
- String phones = kwsThreshold.getPhones();
|
|
|
|
|
- List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
|
|
|
|
|
- LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
|
|
- String time = DateUtil.format(localDateTime, "yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
- Map<String, String> templateParam = new HashMap<>();
|
|
|
|
|
- templateParam.put("time", time);
|
|
|
|
|
- templateParam.put("level", level.toString());
|
|
|
|
|
- templateParam.put("name", device.getName());
|
|
|
|
|
- templateParam.put("value", itemValueAndUnit);
|
|
|
|
|
- commonService.pushSmsMessage(pushToPhone
|
|
|
|
|
- , smsTemplateConfig.getDataAlarm().getSmsCode()
|
|
|
|
|
- , smsTemplateConfig.getDataAlarm().getSignName()
|
|
|
|
|
- , templateParam);
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void oldPushSms(KwsDevice device, Long level, Long thresholdId) {
|
|
|
|
|
+ Map<String, Object> messageMap = new HashMap<>();
|
|
|
|
|
+ Long deviceId = device.getId();
|
|
|
|
|
+ KwsProjectDevice projectDevice = projectDeviceMapper.selectOne(new LambdaQueryWrapper<KwsProjectDevice>()
|
|
|
|
|
+ .eq(KwsProjectDevice::getDeviceId, deviceId)
|
|
|
|
|
+ .eq(KwsProjectDevice::getDelFlag, 0)
|
|
|
|
|
+ .eq(KwsProjectDevice::getStatus, 0)
|
|
|
|
|
+ .orderByDesc(KwsProjectDevice::getCreateTime)
|
|
|
|
|
+ .last(" limit 1")
|
|
|
|
|
+ );
|
|
|
|
|
+ LambdaQueryWrapper<KwsAlarm> wrapper = new LambdaQueryWrapper<KwsAlarm>()
|
|
|
|
|
+ .eq(KwsAlarm::getLevel, level.intValue())
|
|
|
|
|
+ .eq(KwsAlarm::getDeviceId, deviceId)
|
|
|
|
|
+ .eq(KwsAlarm::getType, NumberConstant.ONE)
|
|
|
|
|
+ .orderByDesc(KwsAlarm::getCreateTime);
|
|
|
|
|
+ if (projectDevice != null) {
|
|
|
|
|
+ wrapper.eq(KwsAlarm::getProjectId, projectDevice.getProjectId())
|
|
|
|
|
+ .eq(KwsAlarm::getMountainId, projectDevice.getMountainId());
|
|
|
|
|
+ if (projectDevice.getProjectId() != null) {
|
|
|
|
|
+ wrapper.eq(KwsAlarm::getCompanyId, projectDevice.getCompanyId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ KwsThreshold kwsThreshold = thresholdMapper.selectById(thresholdId);
|
|
|
|
|
+ String phones = kwsThreshold.getPhones();
|
|
|
|
|
+ List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
private void checkDeviceAlarm(String deviceCode, KwsDevice device, String itemValue, Long ts) {
|
|
private void checkDeviceAlarm(String deviceCode, KwsDevice device, String itemValue, Long ts) {
|
|
|
try {
|
|
try {
|