|
|
@@ -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){
|