浏览代码

add
苹果手机报警推送

18339543638 1 年之前
父节点
当前提交
352a5fc50e

+ 1 - 0
nb-im/src/main/java/com/nb/im/controller/ImRoomMsgController.java

@@ -41,6 +41,7 @@ public class ImRoomMsgController  {
 
     @PostMapping("/edit")
     @ApiOperation("修改消息扩展字段")
+    @Deprecated
     public R<Boolean> edit(@RequestBody@Validated MsgExtendVo vo){
         return R.success(chatRoomMsgService.update(new UpdateWrapper<ImMsgEntity>()
                 .lambda()

+ 2 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/alarmPush/RabbitMqConfigPropertyDTO.java

@@ -25,6 +25,8 @@ public class RabbitMqConfigPropertyDTO {
      */
     private String exchangeName;
 
+    private String router;
+
     /**
      * 用户名称
      */

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

@@ -1,23 +1,21 @@
 package com.nb.web.service.bus.alarmPush;
 
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.lang.UUID;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import com.nb.web.api.entity.BusDeviceAlarmEntity;
 import com.nb.web.service.bus.entity.AlarmMessageEntity;
 import com.nb.web.service.bus.entity.BusinessTemplateDTO;
 import com.nb.web.service.bus.entity.SmsEventcs;
 import com.nb.web.service.system.service.ISysConfigService;
-import com.rabbitmq.client.Channel;
-import com.rabbitmq.client.Connection;
-import com.rabbitmq.client.ConnectionFactory;
+import com.rabbitmq.client.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
-import com.nb.web.service.bus.constant.MqConstants;
 
 import java.io.IOException;
 import java.time.Instant;
@@ -39,22 +37,26 @@ public class YanShiKeAlarmPushServiceImpl implements IAlarmPushService{
     private ISysConfigService configService;
 
     @Override
+    @Async
     public void pushAlarmMsg(BusDeviceAlarmEntity entity) {
         String msg=errorMsg(entity);
         List<String> staffCodeList = getStaffCodeList();
         if(CollectionUtil.isEmpty(staffCodeList)){
             //没有设置值班人员工号
+            log.warn("没有设置值班人员工号");
             return;
         }
 
         RabbitMqConfigPropertyDTO mqConfigProperty = getMqConfigProperty();
         if (ObjectUtil.isNull(mqConfigProperty)) {
             //没有设置mq配置
+            log.warn("没有设置mq配置");
             return;
         }
         Connection connection = fetchOneMqConnection(mqConfigProperty);
         if(ObjectUtil.isNull(connection)){
             //mq配置错误
+            log.warn("mq配置错误");
             return;
         }
         Channel channel = null;
@@ -70,8 +72,16 @@ public class YanShiKeAlarmPushServiceImpl implements IAlarmPushService{
                 );
                 // 将报警消息序列化为 JSON 字符串
                 String message = JSONUtil.toJsonStr(alarmMessageEntity);
+
+                HashMap<String, Object> headers = new HashMap<String, Object>();
+
+                headers.put("cap-msg-id", UUID.fastUUID().toString());
+                headers.put("cap-msg-name", mqConfigProperty.getRouter());
+
+                AMQP.BasicProperties.Builder properties = MessageProperties.PERSISTENT_TEXT_PLAIN.builder();
+                properties.headers(headers);
                 // 推送报警消息
-                channel.basicPublish(MqConstants.EXCHANGE_NAME, MqConstants.QUEUE_NAME, null, message.getBytes("UTF-8"));
+                channel.basicPublish(mqConfigProperty.getExchangeName(),mqConfigProperty.getRouter(), properties.build(), message.getBytes("UTF-8"));
                 log.info("SentMQ>>>>>>:{}",message);
             }
 
@@ -116,6 +126,7 @@ public class YanShiKeAlarmPushServiceImpl implements IAlarmPushService{
         factory.setPort(mqConfigProperty.getPort());
         factory.setUsername(mqConfigProperty.getUserName());
         factory.setPassword(mqConfigProperty.getPws());
+        factory.setVirtualHost(mqConfigProperty.getVirtualHost());
         try {
             return factory.newConnection();
         }catch (Exception e){

+ 0 - 17
nb-service/web-service/src/main/java/com/nb/web/service/bus/constant/MqConstants.java

@@ -1,17 +0,0 @@
-package com.nb.web.service.bus.constant;
-
-import org.springframework.stereotype.Component;
-
-/**
- * @author npy
- * @create 2024-10-09
- */
-public class MqConstants {
-
-    //交换机
-    public final static String EXCHANGE_NAME = "alarm_queue";
-
-    //队列
-    public final static String QUEUE_NAME = "alarm_queue";
-
-}