|
@@ -13,8 +13,11 @@ import com.sckw.core.model.enums.DictItemEnum;
|
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.DateUtils;
|
|
import com.sckw.core.utils.DateUtils;
|
|
|
import com.sckw.core.utils.IdWorker;
|
|
import com.sckw.core.utils.IdWorker;
|
|
|
|
|
+import com.sckw.core.utils.PasswordUtils;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.log.TraceLog.TraceLog;
|
|
import com.sckw.log.TraceLog.TraceLog;
|
|
|
|
|
+import com.sckw.redis.config.RedisLockUtil;
|
|
|
|
|
+import com.sckw.redis.constant.RedisConstant;
|
|
|
import com.sckw.redis.utils.RedissonUtils;
|
|
import com.sckw.redis.utils.RedissonUtils;
|
|
|
import com.sckw.slope.detection.common.config.SmsTemplateConfig;
|
|
import com.sckw.slope.detection.common.config.SmsTemplateConfig;
|
|
|
import com.sckw.slope.detection.dao.mysql.*;
|
|
import com.sckw.slope.detection.dao.mysql.*;
|
|
@@ -86,6 +89,9 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
SmsTemplateConfig smsTemplateConfig;
|
|
SmsTemplateConfig smsTemplateConfig;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ RedisLockUtil redisLockUtil;
|
|
|
|
|
+
|
|
|
@TraceLog(description = "处理system/iot/device_data_slope")
|
|
@TraceLog(description = "处理system/iot/device_data_slope")
|
|
|
@DSTransactional
|
|
@DSTransactional
|
|
|
public HttpResult handle(String topic, String payload) {
|
|
public HttpResult handle(String topic, String payload) {
|
|
@@ -101,145 +107,134 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
// String deviceMsgId = objects.getString("msg_id");
|
|
// String deviceMsgId = objects.getString("msg_id");
|
|
|
// String deviceRawTs = objects.getString("raw_ts");
|
|
// String deviceRawTs = objects.getString("raw_ts");
|
|
|
// JSONArray checkArr = objects.getJSONArray("check_arr");
|
|
// JSONArray checkArr = objects.getJSONArray("check_arr");
|
|
|
- try {
|
|
|
|
|
|
|
+ String key = PasswordUtils.md5(topic + "alarm" + payload);
|
|
|
|
|
+ String alarmKey = String.format(RedisConstant.MQ_CONSUMER_ALARM_KEY, key);
|
|
|
|
|
+ boolean flag = redisLockUtil.tryLock(alarmKey, 5);
|
|
|
|
|
+ if (flag) {
|
|
|
|
|
+ try {
|
|
|
// DevicesAlarm devicesAlarm = JSONObject.parseObject(payload, DevicesAlarm.class);
|
|
// DevicesAlarm devicesAlarm = JSONObject.parseObject(payload, DevicesAlarm.class);
|
|
|
- String deviceCode = devicesAlarm.getGuid();
|
|
|
|
|
- List<KwsDevice> deviceList = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>()
|
|
|
|
|
- .eq(KwsDevice::getSnCodeFullName, deviceCode)
|
|
|
|
|
- .eq(KwsDevice::getDelFlag, NumberConstant.ZERO)
|
|
|
|
|
- );
|
|
|
|
|
- KwsDevice device = null;
|
|
|
|
|
- if (!org.springframework.util.CollectionUtils.isEmpty(deviceList)) {
|
|
|
|
|
- device = deviceList.get(0);
|
|
|
|
|
- }
|
|
|
|
|
- if (device == null) {
|
|
|
|
|
- log.error("接收处理数据:{}", payload);
|
|
|
|
|
- log.error("设备数据并未维护+[" + devicesAlarm.getGuid() + "],不做处理");
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- List<DevicesItem> devicesItemList = devicesAlarm.getDevicesItemList();
|
|
|
|
|
- if (!CollectionUtils.isEmpty(devicesItemList)) {
|
|
|
|
|
- HashMap<Object, Object> devicesItemMap = devicesItemList.stream().collect(HashMap::new,
|
|
|
|
|
- (m, v) -> m.put(v.getItemName(), v.getItemValue()), HashMap::putAll);
|
|
|
|
|
- String time = "";
|
|
|
|
|
- long timeDate = 0L;
|
|
|
|
|
- //2023-11-30 22:00:00
|
|
|
|
|
- if (devicesItemMap != null) {
|
|
|
|
|
- if (Objects.nonNull(devicesItemMap.get("time"))) {
|
|
|
|
|
- time = String.valueOf(devicesItemMap.get("time").toString());
|
|
|
|
|
- timeDate = DateUtils.formatDate(time).getTime() / 1000L;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ String deviceCode = devicesAlarm.getGuid();
|
|
|
|
|
+ List<KwsDevice> deviceList = deviceMapper.selectList(new LambdaQueryWrapper<KwsDevice>()
|
|
|
|
|
+ .eq(KwsDevice::getSnCodeFullName, deviceCode)
|
|
|
|
|
+ .eq(KwsDevice::getDelFlag, NumberConstant.ZERO)
|
|
|
|
|
+ );
|
|
|
|
|
+ KwsDevice device = null;
|
|
|
|
|
+ if (!org.springframework.util.CollectionUtils.isEmpty(deviceList)) {
|
|
|
|
|
+ device = deviceList.get(0);
|
|
|
}
|
|
}
|
|
|
- for (DevicesItem devicesItem : devicesItemList) {
|
|
|
|
|
- String itemName = devicesItem.getItemName();
|
|
|
|
|
- String itemValue = devicesItem.getItemValue();
|
|
|
|
|
- List<KwsThreshold> kwsThresholds = thresholdMapper.selectList(new LambdaQueryWrapper<KwsThreshold>()
|
|
|
|
|
- .eq(KwsThreshold::getDeviceId, device.getId())
|
|
|
|
|
- .eq(KwsThreshold::getDelFlag, NumberConstant.ZERO)
|
|
|
|
|
- .eq(KwsThreshold::getItemName, itemName)
|
|
|
|
|
- );
|
|
|
|
|
- if (org.springframework.util.CollectionUtils.isEmpty(kwsThresholds)) {
|
|
|
|
|
- continue;
|
|
|
|
|
|
|
+ if (device == null) {
|
|
|
|
|
+ log.error("接收处理数据:{}", payload);
|
|
|
|
|
+ log.error("设备数据并未维护+[" + devicesAlarm.getGuid() + "],不做处理");
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<DevicesItem> devicesItemList = devicesAlarm.getDevicesItemList();
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(devicesItemList)) {
|
|
|
|
|
+ HashMap<Object, Object> devicesItemMap = devicesItemList.stream().collect(HashMap::new,
|
|
|
|
|
+ (m, v) -> m.put(v.getItemName(), v.getItemValue()), HashMap::putAll);
|
|
|
|
|
+ String time = "";
|
|
|
|
|
+ long timeDate = 0L;
|
|
|
|
|
+ //2023-11-30 22:00:00
|
|
|
|
|
+ if (devicesItemMap != null) {
|
|
|
|
|
+ if (Objects.nonNull(devicesItemMap.get("time"))) {
|
|
|
|
|
+ time = String.valueOf(devicesItemMap.get("time").toString());
|
|
|
|
|
+ timeDate = DateUtils.formatDate(time).getTime() / 1000L;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- Long ts = 0L != timeDate ? timeDate : devicesAlarm.getTs();
|
|
|
|
|
-// //获取到是 十位 1700970600
|
|
|
|
|
-// if (Objects.nonNull(ts)) {
|
|
|
|
|
-// ts = ts * 1000;
|
|
|
|
|
-// }
|
|
|
|
|
- //判断是否满足设备超时离线报警
|
|
|
|
|
-// checkDeviceAlarm(deviceCode, device, itemValue, ts);
|
|
|
|
|
- //判断是否满足数值超阈值报警
|
|
|
|
|
- Map<String, String> map = checkThresholdAlarm(devicesItem, kwsThresholds, device);
|
|
|
|
|
- if ("2".equals(map.get("flag"))) {
|
|
|
|
|
- Long level = Long.valueOf(map.get("level"));
|
|
|
|
|
- Long thresholdId = Long.valueOf(map.get("thresholdId"));
|
|
|
|
|
- String offset = map.get("offset");
|
|
|
|
|
-// /**x、y、z要进行偏移量计算 其他数值保持源数据进行计算*/
|
|
|
|
|
-// List<String> checkItemName = new ArrayList<>();
|
|
|
|
|
-// checkItemName.add(DictItemEnum.ALTITUDE_Z.getValue());
|
|
|
|
|
-// checkItemName.add(DictItemEnum.LONGITUDE_X.getValue());
|
|
|
|
|
-// checkItemName.add(DictItemEnum.LATITUDE_Y.getValue());
|
|
|
|
|
-// String itemValueAndUnit = "";
|
|
|
|
|
-// String url = "";
|
|
|
|
|
-// if (checkItemName.contains(itemName)) {
|
|
|
|
|
-//
|
|
|
|
|
-// itemValueAndUnit = StringUtils.isBlank(url) ? itemValue : (itemValue + url);
|
|
|
|
|
-// } else {
|
|
|
|
|
-// url = dictByDictCode.get(itemName) == null ? null : dictByDictCode.get(itemName).getRemark();
|
|
|
|
|
-// itemValueAndUnit = StringUtils.isBlank(url) ? itemValue : (itemValue + url);
|
|
|
|
|
-// }
|
|
|
|
|
- //阈值表以及明细表存储
|
|
|
|
|
- long id = insertAlarmAndDetail(level, device, thresholdId, offset, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
|
|
|
|
|
- //todo 不适用redis存统计 使用新字段处理
|
|
|
|
|
- /**阈值次数存redis*/
|
|
|
|
|
-// redisPutAlarmCount(id);
|
|
|
|
|
- /*【露天矿山边坡监测系统】尊敬的管理员,2023-10-01 12:23:34监测到一级告警。
|
|
|
|
|
- 设备名称:位移监测设备-gnss一号机,监测数值:55。123456789N,请尽快处理问题。*/
|
|
|
|
|
- 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)
|
|
|
|
|
|
|
+ for (DevicesItem devicesItem : devicesItemList) {
|
|
|
|
|
+ String itemName = devicesItem.getItemName();
|
|
|
|
|
+ String itemValue = devicesItem.getItemValue();
|
|
|
|
|
+ List<KwsThreshold> kwsThresholds = thresholdMapper.selectList(new LambdaQueryWrapper<KwsThreshold>()
|
|
|
|
|
+ .eq(KwsThreshold::getDeviceId, device.getId())
|
|
|
|
|
+ .eq(KwsThreshold::getDelFlag, NumberConstant.ZERO)
|
|
|
|
|
+ .eq(KwsThreshold::getItemName, itemName)
|
|
|
);
|
|
);
|
|
|
- List<String> pushToPhone = new ArrayList<>();
|
|
|
|
|
- if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
|
- pushToPhone = list.stream().map(KwsAlarmInfo::getValueDesc).distinct().collect(Collectors.toList());
|
|
|
|
|
|
|
+ if (org.springframework.util.CollectionUtils.isEmpty(kwsThresholds)) {
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
- if (!CollectionUtils.isEmpty(pushToPhone)) {
|
|
|
|
|
|
|
+ Long ts = 0L != timeDate ? timeDate : devicesAlarm.getTs();
|
|
|
|
|
+ //判断是否满足设备超时离线报警
|
|
|
|
|
+// checkDeviceAlarm(deviceCode, device, itemValue, ts);
|
|
|
|
|
+ //判断是否满足数值超阈值报警
|
|
|
|
|
+ Map<String, String> map = checkThresholdAlarm(devicesItem, kwsThresholds, device);
|
|
|
|
|
+ if ("2".equals(map.get("flag"))) {
|
|
|
|
|
+ Long level = Long.valueOf(map.get("level"));
|
|
|
|
|
+ Long thresholdId = Long.valueOf(map.get("thresholdId"));
|
|
|
|
|
+ String offset = map.get("offset");
|
|
|
|
|
+ //阈值表以及明细表存储
|
|
|
|
|
+ long id = insertAlarmAndDetail(level, device, thresholdId, offset, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
|
|
|
|
|
+ //todo 不适用redis存统计 使用新字段处理
|
|
|
|
|
+ /**阈值次数存redis*/
|
|
|
|
|
+// redisPutAlarmCount(id);
|
|
|
|
|
+ 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)
|
|
|
|
|
+ );
|
|
|
|
|
+ List<String> pushToPhone = new ArrayList<>();
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
|
+ pushToPhone = list.stream().map(KwsAlarmInfo::getValueDesc).distinct().collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(pushToPhone) && pushToPhone.size() > 0) {
|
|
|
// KwsThreshold kwsThreshold = thresholdMapper.selectById(thresholdId);
|
|
// KwsThreshold kwsThreshold = thresholdMapper.selectById(thresholdId);
|
|
|
// String phones = kwsThreshold.getPhones();
|
|
// String phones = kwsThreshold.getPhones();
|
|
|
// List<String> pushToPhone = com.sckw.core.utils.StringUtils.splitStrToList(phones, String.class);
|
|
// 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());
|
|
|
|
|
|
|
+ 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);
|
|
// templateParam.put("value", itemValue);
|
|
|
- templateParam.put("value", offset);
|
|
|
|
|
- commonService.pushSmsMessage(pushToPhone
|
|
|
|
|
- , smsTemplateConfig.getDataAlarm().getSmsCode()
|
|
|
|
|
- , smsTemplateConfig.getDataAlarm().getSignName()
|
|
|
|
|
- , templateParam);
|
|
|
|
|
- }
|
|
|
|
|
- ProjectVo vo = projectDeviceMapper.selectProjectByDeviceId(device.getId());
|
|
|
|
|
- /**邮件推送*/
|
|
|
|
|
- List<KwsAlarmInfo> emailList = alarmInfoRepository.list(new LambdaQueryWrapper<KwsAlarmInfo>()
|
|
|
|
|
- .eq(KwsAlarmInfo::getMountainId, mountainId)
|
|
|
|
|
- .eq(KwsAlarmInfo::getLevel, level.intValue())
|
|
|
|
|
- .eq(KwsAlarmInfo::getType, NumberConstant.TWO)
|
|
|
|
|
- .eq(KwsAlarmInfo::getDelFlag, NumberConstant.ZERO)
|
|
|
|
|
- );
|
|
|
|
|
- List<String> emailAddress = new ArrayList<>();
|
|
|
|
|
- if (!CollectionUtils.isEmpty(emailList)) {
|
|
|
|
|
- emailAddress = emailList.stream().map(KwsAlarmInfo::getValueDesc).distinct().collect(Collectors.toList());
|
|
|
|
|
- }
|
|
|
|
|
- if (!CollectionUtils.isEmpty(emailAddress)) {
|
|
|
|
|
- Map<String, Object> 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("value", offset);
|
|
|
|
|
+ commonService.pushSmsMessage(pushToPhone
|
|
|
|
|
+ , smsTemplateConfig.getDataAlarm().getSmsCode()
|
|
|
|
|
+ , smsTemplateConfig.getDataAlarm().getSignName()
|
|
|
|
|
+ , templateParam);
|
|
|
}
|
|
}
|
|
|
- templateParam.put("company", smsTemplateConfig.getDataAlarm().getSignName());
|
|
|
|
|
- templateParam.put("level", level.toString());
|
|
|
|
|
- templateParam.put("name", device.getName());
|
|
|
|
|
- templateParam.put("time", time);
|
|
|
|
|
- templateParam.put("project", vo == null ? null : vo.getProjectName());
|
|
|
|
|
|
|
+ ProjectVo vo = projectDeviceMapper.selectProjectByDeviceId(device.getId());
|
|
|
|
|
+ /**邮件推送*/
|
|
|
|
|
+ List<KwsAlarmInfo> emailList = alarmInfoRepository.list(new LambdaQueryWrapper<KwsAlarmInfo>()
|
|
|
|
|
+ .eq(KwsAlarmInfo::getMountainId, mountainId)
|
|
|
|
|
+ .eq(KwsAlarmInfo::getLevel, level.intValue())
|
|
|
|
|
+ .eq(KwsAlarmInfo::getType, NumberConstant.TWO)
|
|
|
|
|
+ .eq(KwsAlarmInfo::getDelFlag, NumberConstant.ZERO)
|
|
|
|
|
+ );
|
|
|
|
|
+ List<String> emailAddress = new ArrayList<>();
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(emailList) && emailList.size() > 0) {
|
|
|
|
|
+ emailAddress = emailList.stream().map(KwsAlarmInfo::getValueDesc).distinct().collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(emailAddress)) {
|
|
|
|
|
+ Map<String, Object> 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("company", smsTemplateConfig.getDataAlarm().getSignName());
|
|
|
|
|
+ templateParam.put("level", level.toString());
|
|
|
|
|
+ templateParam.put("name", device.getName());
|
|
|
|
|
+ templateParam.put("time", time);
|
|
|
|
|
+ templateParam.put("project", vo == null ? null : vo.getProjectName());
|
|
|
// templateParam.put("value", itemValue);
|
|
// templateParam.put("value", itemValue);
|
|
|
- templateParam.put("value", offset);
|
|
|
|
|
- commonService.pushEmailMessage(emailAddress
|
|
|
|
|
- , templateParam);
|
|
|
|
|
|
|
+ templateParam.put("value", offset);
|
|
|
|
|
+ templateParam.put("element", dictByDictCode.get(itemName).getLabel());
|
|
|
|
|
+ templateParam.put("type", AlarmTitleEnum.ALARM_TITLE_TWO.getName() + "告警");
|
|
|
|
|
+ commonService.pushEmailMessage(emailAddress
|
|
|
|
|
+ , templateParam);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ //集成要素阈值告警
|
|
|
|
|
+ deviceIntegrationsAlarm(device, ts, time);
|
|
|
}
|
|
}
|
|
|
- //集成要素阈值告警
|
|
|
|
|
- deviceIntegrationsAlarm(device, ts, time);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("mqtt消费异常:{}", e.getMessage(), e);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ redisLockUtil.unlock(alarmKey);
|
|
|
}
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("mqtt消费异常:{}", e.getMessage(), e);
|
|
|
|
|
}
|
|
}
|
|
|
return HttpResult.ok();
|
|
return HttpResult.ok();
|
|
|
}
|
|
}
|
|
@@ -259,7 +254,15 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 集成要素阈值告警
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param device 设备
|
|
|
|
|
+ * @param ts ts
|
|
|
|
|
+ * @param time 时间
|
|
|
|
|
+ */
|
|
|
private void deviceIntegrationsAlarm(KwsDevice device, Long ts, String time) {
|
|
private void deviceIntegrationsAlarm(KwsDevice device, Long ts, String time) {
|
|
|
|
|
+ Map<String, SystemDict> dictByDictCode = commonService.getDictByDictCode(DictEnum.INTEGRATION_UNIT);
|
|
|
// List<KwsDeviceIntegration> deviceIntegrations = deviceIntegrationMapper.selectList(
|
|
// List<KwsDeviceIntegration> deviceIntegrations = deviceIntegrationMapper.selectList(
|
|
|
// new LambdaQueryWrapper<KwsDeviceIntegration>()
|
|
// new LambdaQueryWrapper<KwsDeviceIntegration>()
|
|
|
// .eq(KwsDeviceIntegration::getDeviceId, device.getId())
|
|
// .eq(KwsDeviceIntegration::getDeviceId, device.getId())
|
|
@@ -286,8 +289,9 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
List<DeviceIntegrationVo> intergData = new ArrayList<>();
|
|
List<DeviceIntegrationVo> intergData = new ArrayList<>();
|
|
|
String snCode = device.getSnCode();
|
|
String snCode = device.getSnCode();
|
|
|
intergData = deviceIntegrationMapper.selectListParamsAndInterNameByDeviceId(device.getId());
|
|
intergData = deviceIntegrationMapper.selectListParamsAndInterNameByDeviceId(device.getId());
|
|
|
- if (!Objects.isNull(intergData)) {
|
|
|
|
|
|
|
+ if (!Objects.isNull(intergData) || intergData.size() > 0) {
|
|
|
for (DeviceIntegrationVo deviceIntegration : intergData) {
|
|
for (DeviceIntegrationVo deviceIntegration : intergData) {
|
|
|
|
|
+ String unit = "";
|
|
|
//获取到当前测量值--现在只有单一值
|
|
//获取到当前测量值--现在只有单一值
|
|
|
List<SlopeData> slopeData = slopeDataMapper.selectListByTwoLine(snCode, deviceIntegration.getPartNames());
|
|
List<SlopeData> slopeData = slopeDataMapper.selectListByTwoLine(snCode, deviceIntegration.getPartNames());
|
|
|
if (!Objects.isNull(slopeData) && slopeData.size() == 2) {
|
|
if (!Objects.isNull(slopeData) && slopeData.size() == 2) {
|
|
@@ -304,7 +308,8 @@ 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());
|
|
|
- long id = insertAlarmAndDetail(level, device, thresholdId, offset + deviceIntegration.getUnit(), ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
|
|
|
|
|
|
|
+ unit = dictByDictCode.get(deviceIntegration.getUnit()) == null ? deviceIntegration.getUnit() : dictByDictCode.get(deviceIntegration.getUnit()).getDescription();
|
|
|
|
|
+ long id = insertAlarmAndDetail(level, device, thresholdId, offset + unit, ts, AlarmTitleEnum.ALARM_TITLE_TWO.getStatus(), AlarmTypeEnum.ALARM_ONE.getCode());
|
|
|
/**最初发送短信模式*/
|
|
/**最初发送短信模式*/
|
|
|
// oldPushSms(device,level,thresholdId);
|
|
// oldPushSms(device,level,thresholdId);
|
|
|
/**目前发送短信模式*/
|
|
/**目前发送短信模式*/
|
|
@@ -331,11 +336,16 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
templateParam.put("level", level.toString());
|
|
templateParam.put("level", level.toString());
|
|
|
templateParam.put("name", device.getName());
|
|
templateParam.put("name", device.getName());
|
|
|
// templateParam.put("value", itemValueAndUnit);
|
|
// templateParam.put("value", itemValueAndUnit);
|
|
|
- templateParam.put("value", String.valueOf(offset) + deviceIntegration.getUnit());
|
|
|
|
|
- commonService.pushSmsMessage(pushToPhone
|
|
|
|
|
- , smsTemplateConfig.getDataAlarm().getSmsCode()
|
|
|
|
|
- , smsTemplateConfig.getDataAlarm().getSignName()
|
|
|
|
|
- , templateParam);
|
|
|
|
|
|
|
+ unit = dictByDictCode.get(deviceIntegration.getUnit()) == null ? deviceIntegration.getUnit() : dictByDictCode.get(deviceIntegration.getUnit()).getDescription();
|
|
|
|
|
+ BigDecimal bd = new BigDecimal(offset);
|
|
|
|
|
+ bd = bd.setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ templateParam.put("value", String.valueOf(bd) + unit);
|
|
|
|
|
+ if (pushToPhone.size() > 0) {
|
|
|
|
|
+ commonService.pushSmsMessage(pushToPhone
|
|
|
|
|
+ , smsTemplateConfig.getDataAlarm().getSmsCode()
|
|
|
|
|
+ , smsTemplateConfig.getDataAlarm().getSignName()
|
|
|
|
|
+ , templateParam);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
ProjectVo vo = projectDeviceMapper.selectProjectByDeviceId(device.getId());
|
|
ProjectVo vo = projectDeviceMapper.selectProjectByDeviceId(device.getId());
|
|
|
/**邮件推送*/
|
|
/**邮件推送*/
|
|
@@ -361,7 +371,14 @@ public class MqttCallbackHandler extends AbstractHandler {
|
|
|
templateParam.put("time", time);
|
|
templateParam.put("time", time);
|
|
|
templateParam.put("project", vo == null ? null : vo.getProjectName());
|
|
templateParam.put("project", vo == null ? null : vo.getProjectName());
|
|
|
// templateParam.put("value", itemValueAndUnit);
|
|
// templateParam.put("value", itemValueAndUnit);
|
|
|
- templateParam.put("value", String.valueOf(offset) + deviceIntegration.getUnit());
|
|
|
|
|
|
|
+ unit = dictByDictCode.get(deviceIntegration.getUnit()) == null ? deviceIntegration.getUnit() : dictByDictCode.get(deviceIntegration.getUnit()).getDescription();
|
|
|
|
|
+ BigDecimal bd = new BigDecimal(offset);
|
|
|
|
|
+ bd = bd.setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+// DecimalFormat df = new DecimalFormat("#.##");
|
|
|
|
|
+// String formattedNumber = df.format(bd);
|
|
|
|
|
+ templateParam.put("value", String.valueOf(bd) + unit);
|
|
|
|
|
+ templateParam.put("type", AlarmTitleEnum.ALARM_TITLE_TWO.getName());
|
|
|
|
|
+ templateParam.put("element", deviceIntegration.getIntegrationName());
|
|
|
commonService.pushEmailMessage(emailAddress
|
|
commonService.pushEmailMessage(emailAddress
|
|
|
, templateParam);
|
|
, templateParam);
|
|
|
}
|
|
}
|