Jelajahi Sumber

mqtt邮箱取值查询

lengfaqiang 2 tahun lalu
induk
melakukan
a7e1050dfa

+ 36 - 5
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/consumer/MqttCallbackHandler.java

@@ -191,7 +191,7 @@ public class MqttCallbackHandler extends AbstractHandler {
                                     , templateParam);
                         }
                         ProjectVo vo = projectDeviceMapper.selectProjectByDeviceId(device.getId());
-                        /**邮推送*/
+                        /**邮推送*/
                         List<KwsAlarmInfo> emailList = alarmInfoRepository.list(new LambdaQueryWrapper<KwsAlarmInfo>()
                                 .eq(KwsAlarmInfo::getMountainId, mountainId)
                                 .eq(KwsAlarmInfo::getLevel, level.intValue())
@@ -200,7 +200,7 @@ public class MqttCallbackHandler extends AbstractHandler {
                         );
                         List<String> emailAddress = new ArrayList<>();
                         if (!CollectionUtils.isEmpty(emailList)) {
-                            emailAddress = list.stream().map(KwsAlarmInfo::getValueDesc).distinct().collect(Collectors.toList());
+                            emailAddress = emailList.stream().map(KwsAlarmInfo::getValueDesc).distinct().collect(Collectors.toList());
                         }
                         if (!CollectionUtils.isEmpty(emailAddress)) {
                             Map<String, Object> templateParam = new HashMap<>();
@@ -219,7 +219,7 @@ public class MqttCallbackHandler extends AbstractHandler {
                         }
                     }
                     //集成要素阈值告警
-                    deviceIntegrationsAlarm(device, ts);
+                    deviceIntegrationsAlarm(device, ts, time);
                 }
             }
         } catch (Exception e) {
@@ -243,7 +243,7 @@ public class MqttCallbackHandler extends AbstractHandler {
         }
     }
 
-    private void deviceIntegrationsAlarm(KwsDevice device, Long ts) {
+    private void deviceIntegrationsAlarm(KwsDevice device, Long ts, String time) {
 //        List<KwsDeviceIntegration> deviceIntegrations = deviceIntegrationMapper.selectList(
 //                new LambdaQueryWrapper<KwsDeviceIntegration>()
 //                        .eq(KwsDeviceIntegration::getDeviceId, device.getId())
@@ -263,6 +263,10 @@ public class MqttCallbackHandler extends AbstractHandler {
 //            integrationMap = integrations.stream().collect(Collectors.toMap(KwsIntegration::getPartNames, KwsIntegration::getId));
 //        }
         //获取集成要素
+        if (StringUtils.isBlank(time)) {
+            LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
+            time = com.sckw.excel.utils.DateUtil.format(localDateTime);
+        }
         List<DeviceIntegrationVo> intergData = new ArrayList<>();
         String snCode = device.getSnCode();
         intergData = deviceIntegrationMapper.selectListParamsAndInterNameByDeviceId(device.getId());
@@ -300,7 +304,7 @@ public class MqttCallbackHandler extends AbstractHandler {
                         }
                         if (!CollectionUtils.isEmpty(pushToPhone)) {
                             LocalDateTime localDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.systemDefault()).toLocalDateTime();
-                            String time = DateUtil.format(localDateTime, "yyyy-MM-dd HH:mm:ss");
+                            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();
@@ -315,6 +319,33 @@ public class MqttCallbackHandler extends AbstractHandler {
                                     , 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("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", itemValueAndUnit);
+                            commonService.pushEmailMessage(emailAddress
+                                    , templateParam);
+                        }
                     }
                 }
             }

+ 2 - 2
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsProjectDeviceMapper.xml

@@ -234,7 +234,7 @@ WHERE
             kws_project a
                 LEFT JOIN kws_project_device b ON a.id = b.project_id
         WHERE
-            b.id = #{deviceId}
+            b.device_id = #{deviceId}
         order by  b.create_time desc  limit 1
     </select>
 
@@ -243,7 +243,7 @@ WHERE
                a.`name` AS projectName
         FROM kws_project a
                  LEFT JOIN kws_project_device b ON a.id = b.project_id
-        WHERE b.id = #{deviceId}
+        WHERE b.device_id = #{deviceId}
           and a.del_flag = 0
         order by b.create_time desc limit 1
     </select>