|
|
@@ -1,5 +1,6 @@
|
|
|
package com.sckw.slope.detection.consumer;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
@@ -7,6 +8,7 @@ import com.sckw.core.model.constant.Global;
|
|
|
import com.sckw.core.model.constant.NumberConstant;
|
|
|
import com.sckw.core.model.enums.AlarmTitleEnum;
|
|
|
import com.sckw.core.model.enums.AlarmTypeEnum;
|
|
|
+import com.sckw.core.model.enums.DictEnum;
|
|
|
import com.sckw.core.model.enums.DictItemEnum;
|
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.DateUtils;
|
|
|
@@ -14,6 +16,7 @@ import com.sckw.core.utils.IdWorker;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.log.TraceLog.TraceLog;
|
|
|
import com.sckw.redis.utils.RedissonUtils;
|
|
|
+import com.sckw.slope.detection.common.config.SmsTemplateConfig;
|
|
|
import com.sckw.slope.detection.dao.mysql.*;
|
|
|
import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
|
|
|
import com.sckw.slope.detection.model.dos.mysql.*;
|
|
|
@@ -22,7 +25,7 @@ import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
|
|
|
import com.sckw.slope.detection.model.dto.AlarmList;
|
|
|
import com.sckw.slope.detection.model.dto.DevicesAlarm;
|
|
|
import com.sckw.slope.detection.model.dto.DevicesItem;
|
|
|
-import com.sckw.slope.detection.model.param.SmsMessageParam;
|
|
|
+import com.sckw.slope.detection.model.dto.SystemDict;
|
|
|
import com.sckw.slope.detection.model.vo.DeviceIntegrationVo;
|
|
|
import com.sckw.slope.detection.service.CommonService;
|
|
|
import com.sckw.slope.detection.service.TdengineService;
|
|
|
@@ -32,7 +35,6 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.dubbo.common.utils.MD5Utils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -78,6 +80,9 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
@Autowired
|
|
|
KwsIntegrationMapper integrationMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ SmsTemplateConfig smsTemplateConfig;
|
|
|
+
|
|
|
@TraceLog(description = "处理system/iot/device_data_slope")
|
|
|
@DSTransactional
|
|
|
public HttpResult handle(String topic, String payload) {
|
|
|
@@ -85,7 +90,7 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
log.info("MqttDeviceCallbackHandler:" + topic + "|" + payload);
|
|
|
|
|
|
DevicesAlarm devicesAlarm = JSONObject.parseObject(payload, DevicesAlarm.class);
|
|
|
-// Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
|
|
|
+ Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.MODEL_PART);
|
|
|
// JSONObject objects = JSONObject.parseObject(payload);
|
|
|
// String deviceTs = objects.getString("ts");
|
|
|
// String deviceGuid = objects.getString("guid");
|
|
|
@@ -146,14 +151,47 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
Long level = Long.valueOf(map.get("level"));
|
|
|
Long thresholdId = Long.valueOf(map.get("thresholdId"));
|
|
|
//阈值表以及明细表存储
|
|
|
- long id = insertAlarmAndDetail(level, device, thresholdId, itemValue, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
|
|
|
+ String url = dictByDictCode.get(itemName) == null ? null : dictByDictCode.get(itemName).getUrl();
|
|
|
+ String itemValueAndUnit = StringUtils.isBlank(url) ? itemValue : (itemValue + url);
|
|
|
+ long id = insertAlarmAndDetail(level, device, thresholdId, itemValueAndUnit, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
|
|
|
//todo 不适用redis存统计 使用新字段处理
|
|
|
/**阈值次数存redis*/
|
|
|
// redisPutAlarmCount(id);
|
|
|
/*【露天矿山边坡监测系统】尊敬的管理员,2023-10-01 12:23:34监测到一级告警。
|
|
|
设备名称:位移监测设备-gnss一号机,监测数值:55。123456789N,请尽快处理问题。*/
|
|
|
Map<String, Object> messageMap = new HashMap<>();
|
|
|
- pushSmsMessage(messageUrl, device, level, thresholdId, messageMap);
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
@@ -190,11 +228,11 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(deviceIntegrations)) {
|
|
|
integrationIds = deviceIntegrations.stream().map(KwsDeviceIntegration::getIntegrationId).collect(Collectors.toList());
|
|
|
}
|
|
|
- List<KwsIntegration> integrations = integrationMapper.selectList(
|
|
|
- new LambdaQueryWrapper<KwsIntegration>()
|
|
|
- .in(KwsIntegration::getId, integrationIds)
|
|
|
- .eq(KwsIntegration::getDelFlag, NumberConstant.ZERO)
|
|
|
- );
|
|
|
+// List<KwsIntegration> integrations = integrationMapper.selectList(
|
|
|
+// new LambdaQueryWrapper<KwsIntegration>()
|
|
|
+// .in(KwsIntegration::getId, integrationIds)
|
|
|
+// .eq(KwsIntegration::getDelFlag, NumberConstant.ZERO)
|
|
|
+// );
|
|
|
// Map<String, Long> integrationMap = new HashMap<>(NumberConstant.SIXTEEN);
|
|
|
// if (!org.springframework.util.CollectionUtils.isEmpty(integrations)) {
|
|
|
// integrationMap = integrations.stream().collect(Collectors.toMap(KwsIntegration::getPartNames, KwsIntegration::getId));
|
|
|
@@ -218,54 +256,50 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
Long level = Long.valueOf(map.get("level"));
|
|
|
Long thresholdId = Long.valueOf(map.get("thresholdId"));
|
|
|
//阈值表以及明细表存储
|
|
|
- long id = insertAlarmAndDetail(level, device, thresholdId, deviceIntegration.getPartNames(), ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
|
|
|
+ String url = deviceIntegration.getUnit() == null ? null : 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());
|
|
|
Map<String, Object> messageMap = new HashMap<>();
|
|
|
- pushSmsMessage(messageUrl, device, level, thresholdId, messageMap);
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Async
|
|
|
- public void pushSmsMessage(String messageUrl, KwsDevice device, Long level, Long thresholdId, Map<String, Object> messageMap) {
|
|
|
- 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());
|
|
|
- }
|
|
|
- }
|
|
|
- SmsMessageParam param = new SmsMessageParam();
|
|
|
- param.setCode("123456");
|
|
|
- param.setType("2");
|
|
|
- List<String> stringList = new ArrayList<>();
|
|
|
- stringList.add("18215677925");
|
|
|
- param.setPushTo(stringList);
|
|
|
- SmsMessageParam.Content content = new SmsMessageParam.Content();
|
|
|
- content.setTemplateCode("SMS_262585113");
|
|
|
- content.setSignName("矿拉拉");
|
|
|
- SmsMessageParam.TemplateParam templateParam = new SmsMessageParam.TemplateParam();
|
|
|
- templateParam.setName("123");
|
|
|
- templateParam.setStart("123");
|
|
|
- content.setTemplateParam(templateParam);
|
|
|
- param.setContent(content);
|
|
|
- detectionApiService.pushSmsMessage(messageUrl, JSONObject.toJSONString(param));
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
private void checkDeviceAlarm(String deviceCode, KwsDevice device, String itemValue, Long ts) {
|
|
|
try {
|