浏览代码

add
苹果手机报警推送

18339543638 1 年之前
父节点
当前提交
4b3dd9d5f1

+ 15 - 15
nb-service/web-service/src/main/java/com/nb/web/service/bus/alarmPush/YanShiKeAlarmPushServiceImpl.java

@@ -57,26 +57,26 @@ public class YanShiKeAlarmPushServiceImpl implements IAlarmPushService{
             //mq配置错误
             return;
         }
-        //todo 开始推送
         Channel channel = null;
         try {
             channel = connection.createChannel();
+            for (String staffCode : staffCodeList) {
+                // 构建报警消息
+                AlarmMessageEntity alarmMessageEntity= new AlarmMessageEntity(msg,
+                        3,
+                        staffCode,
+                        new BusinessTemplateDTO(null, Instant.now().toString(), "驼人镇痛泵报警", "type",msg),
+                        new SmsEventcs("15105777745","xxx")
+                );
+                // 将报警消息序列化为 JSON 字符串
+                String message = JSONUtil.toJsonStr(alarmMessageEntity);
+                // 推送报警消息
+                channel.basicPublish(MqConstants.EXCHANGE_NAME, MqConstants.QUEUE_NAME, null, message.getBytes("UTF-8"));
+                log.info("SentMQ>>>>>>:{}",message);
+            }
 
-            // 构建报警消息
-            AlarmMessageEntity alarmMessageEntity= new AlarmMessageEntity(msg,
-                    3,
-                    staffCodeList,
-                    new BusinessTemplateDTO("remark", Instant.now().toString(), "设备报警", "type","http://www.baidu.com"),
-                    new SmsEventcs("15105777745","xxx")
-            );
-            // 将报警消息序列化为 JSON 字符串
-            ObjectMapper objectMapper = new ObjectMapper();
-            String message = objectMapper.writeValueAsString(alarmMessageEntity);
-            // 推送报警消息
-            channel.basicPublish(MqConstants.EXCHANGE_NAME, MqConstants.QUEUE_NAME, null, message.getBytes("UTF-8"));
-            System.out.println("Sent: " + message);
         }catch (Exception e) {
-            e.printStackTrace();
+            log.info("SentMQ confront a error,",e);
         }finally {
             // 确保通道和连接被关闭
             try {

+ 3 - 3
nb-service/web-service/src/main/java/com/nb/web/service/bus/entity/AlarmMessageEntity.java

@@ -31,7 +31,7 @@ public class AlarmMessageEntity {
     private int msgTo;
 
     @ApiModelProperty(value = "接收者工号")
-    private List<String> receiveUserCode;
+    private String receiveUserCode;
 
     @ApiModelProperty(value = "发送者工号")
     private String sendeUserCode;
@@ -46,11 +46,11 @@ public class AlarmMessageEntity {
     private BusinessTemplateDTO smsInfo;
 
 
-    public AlarmMessageEntity(String msg, int msgTo, List<String> receiveUserCode, BusinessTemplateDTO smsInfo, SmsEventcs staffInfo) {
+    public AlarmMessageEntity(String msg, int msgTo, String receiveUserCode, BusinessTemplateDTO smsInfo, SmsEventcs staffInfo) {
         this.msg = msg;
         this.msgTo = msgTo;
         this.receiveUserCode = receiveUserCode;
         this.smsInfo = smsInfo;
-        this.staffInfo = staffInfo;
+//        this.staffInfo = staffInfo;
     }
 }

+ 2 - 2
nb-service/web-service/src/main/java/com/nb/web/service/bus/entity/BusinessTemplateDTO.java

@@ -35,11 +35,11 @@ public class BusinessTemplateDTO {
     @ApiModelProperty(value = "消息超链接")
     private String url;
 
-    public BusinessTemplateDTO(String remark, String sendTime, String title, String type, String url) {
+    public BusinessTemplateDTO(String remark, String sendTime, String title, String type, String content) {
         this.remark = remark;
         this.sendTime = sendTime;
         this.title = title;
         this.type = type;
-        this.url = url;
+        this.content = content;
     }
 }