Procházet zdrojové kódy

设备报警信息推送mq

niu před 1 rokem
rodič
revize
f8c678a101

+ 1 - 1
LICENSE

@@ -25,7 +25,7 @@
 
       "Source" form shall mean the preferred form for making modifications,
       including but not limited to software source code, documentation
-      source, and configuration files.
+      source, and uration files.
 
       "Object" form shall mean any form resulting from mechanical
       transformation or translation of a Source form, including but

+ 1 - 1
nb-admin/src/main/resources/application-dev.yml

@@ -30,7 +30,7 @@ spring:
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
     driverClassName: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://192.168.100.32:3306/nbnetpump?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true
+    url: jdbc:mysql://localhost:3306/nbnetpump?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true
     username: root
     password: 123456
     druid:

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

@@ -4,15 +4,26 @@ import cn.hutool.core.collection.CollectionUtil;
 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 lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Component;
+import com.nb.web.service.bus.constant.MqConstants;
+
+import java.io.IOException;
+import java.time.Instant;
 import java.util.*;
+import java.util.concurrent.TimeoutException;
+
 /**
  * @ClassName : YanShiKeAlarmPushServiceImpl
  * @Description : 本地化部署时浙江眼视科医院报警信息推送
@@ -47,8 +58,44 @@ public class YanShiKeAlarmPushServiceImpl implements IAlarmPushService{
             return;
         }
         //todo 开始推送
+        Channel channel = null;
+        try {
+            channel = connection.createChannel();
+
+            // 构建报警消息
+            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();
+        }finally {
+            // 确保通道和连接被关闭
+            try {
+                if (channel != null) {
+                    channel.close(); // 关闭通道
+                }
+                if (connection != null) {
+                    connection.close();// 关闭连接
+                }
+            } catch (IOException e) {
+                log.error("关闭通道或连接时发生异常", e);
+            } catch (TimeoutException e) {
+                log.error("关闭连接时发生超时异常", e);
+            }
+        }
     }
 
+
+
     /**
      * 获取值班人员的工号
      * @return

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

@@ -0,0 +1,17 @@
+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";
+
+}

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

@@ -0,0 +1,56 @@
+package com.nb.web.service.bus.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.nb.core.entity.GenericEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import org.springframework.beans.factory.annotation.Value;
+
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+/**
+ * @author npy
+ * @create 2024-10-09
+ */
+@Data
+@AllArgsConstructor
+@ApiModel(value="设备警报信息类", description="设备警报信息")
+@ToString
+public class AlarmMessageEntity {
+    @ApiModelProperty(value = "消息内容")
+    @NotNull(message = "消息内容不能为空")
+    private String msg;
+
+    @ApiModelProperty(value = "消息发送途径")
+    @NotNull(message = "消息发送途径不能为空")
+    private int msgTo;
+
+    @ApiModelProperty(value = "接收者工号")
+    private List<String> receiveUserCode;
+
+    @ApiModelProperty(value = "发送者工号")
+    private String sendeUserCode;
+
+    @ApiModelProperty(value = "业务类型")
+    private String businessType;
+
+    @ApiModelProperty(value = "员工助手发送配置")
+    private SmsEventcs staffInfo;
+
+    @ApiModelProperty(value = "短信发送配置")
+    private BusinessTemplateDTO smsInfo;
+
+
+    public AlarmMessageEntity(String msg, int msgTo, List<String> receiveUserCode, BusinessTemplateDTO smsInfo, SmsEventcs staffInfo) {
+        this.msg = msg;
+        this.msgTo = msgTo;
+        this.receiveUserCode = receiveUserCode;
+        this.smsInfo = smsInfo;
+        this.staffInfo = staffInfo;
+    }
+}

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

@@ -0,0 +1,45 @@
+package com.nb.web.service.bus.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.ToString;
+
+/**
+ * @author npy
+ * @create 2024-10-09
+ */
+@Data
+@ApiModel(value="微信消息类", description="微信消息")
+@ToString
+public class BusinessTemplateDTO {
+    @ApiModelProperty(value = "员工号")
+    private String userCode;
+
+    @ApiModelProperty(value = "title")
+    private String title;
+
+    @ApiModelProperty(value = "通知业务类型")
+    private String type;
+
+    @ApiModelProperty(value = "业务内容")
+    private String content;
+
+    @ApiModelProperty(value = "业务时间")
+    private String sendTime;
+
+    @ApiModelProperty(value = "备注")
+    private String remark;
+
+    @ApiModelProperty(value = "消息超链接")
+    private String url;
+
+    public BusinessTemplateDTO(String remark, String sendTime, String title, String type, String url) {
+        this.remark = remark;
+        this.sendTime = sendTime;
+        this.title = title;
+        this.type = type;
+        this.url = url;
+    }
+}

+ 42 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/entity/SmsEventcs.java

@@ -0,0 +1,42 @@
+package com.nb.web.service.bus.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.ToString;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author npy
+ * @create 2024-10-09
+ */
+@Data
+@ApiModel(value="短信消息类", description="短信消息")
+@ToString
+public class SmsEventcs {
+    @ApiModelProperty(value = "HIS系统短信发送账户")
+    @NotNull(message = "发送账户不能为空")
+    private String apiCode;
+
+    @ApiModelProperty(value = "手机号码")
+    private String mobile;
+
+    @ApiModelProperty(value = "短信内容")
+    private String content;
+
+    @ApiModelProperty(value = "接收人工号")
+    private String userCode;
+
+    @ApiModelProperty(value = "扩展号")
+    private String extend;
+
+    @ApiModelProperty(value = "验证码")
+    private String verifyCode;
+
+    public SmsEventcs(String mobile, String apiCode) {
+        this.mobile = mobile;
+        this.apiCode = apiCode;
+    }
+}