|
@@ -4,15 +4,26 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.nb.web.api.entity.BusDeviceAlarmEntity;
|
|
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.nb.web.service.system.service.ISysConfigService;
|
|
|
|
|
+import com.rabbitmq.client.Channel;
|
|
|
import com.rabbitmq.client.Connection;
|
|
import com.rabbitmq.client.Connection;
|
|
|
import com.rabbitmq.client.ConnectionFactory;
|
|
import com.rabbitmq.client.ConnectionFactory;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Component;
|
|
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.*;
|
|
|
|
|
+import java.util.concurrent.TimeoutException;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @ClassName : YanShiKeAlarmPushServiceImpl
|
|
* @ClassName : YanShiKeAlarmPushServiceImpl
|
|
|
* @Description : 本地化部署时浙江眼视科医院报警信息推送
|
|
* @Description : 本地化部署时浙江眼视科医院报警信息推送
|
|
@@ -47,8 +58,44 @@ public class YanShiKeAlarmPushServiceImpl implements IAlarmPushService{
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
//todo 开始推送
|
|
//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
|
|
* @return
|