|
|
@@ -0,0 +1,98 @@
|
|
|
+package com.nb.web.service.bus.alarmPush;
|
|
|
+
|
|
|
+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.nb.web.api.entity.BusDeviceAlarmEntity;
|
|
|
+import com.nb.web.service.system.service.ISysConfigService;
|
|
|
+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 java.util.*;
|
|
|
+/**
|
|
|
+ * @ClassName : YanShiKeAlarmPushServiceImpl
|
|
|
+ * @Description : 本地化部署时浙江眼视科医院报警信息推送
|
|
|
+ * @Author : LF
|
|
|
+ * @Date: 2024年10月09日
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class YanShiKeAlarmPushServiceImpl implements IAlarmPushService{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Lazy
|
|
|
+ private ISysConfigService configService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void pushAlarmMsg(BusDeviceAlarmEntity entity) {
|
|
|
+ String msg=errorMsg(entity);
|
|
|
+ List<String> staffCodeList = getStaffCodeList();
|
|
|
+ if(CollectionUtil.isNotEmpty(staffCodeList)){
|
|
|
+ //没有设置值班人员工号
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ RabbitMqConfigPropertyDTO mqConfigProperty = getMqConfigProperty();
|
|
|
+ if (ObjectUtil.isNull(mqConfigProperty)) {
|
|
|
+ //没有设置mq配置
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Connection connection = fetchOneMqConnection(mqConfigProperty);
|
|
|
+ if(ObjectUtil.isNull(connection)){
|
|
|
+ //mq配置错误
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //todo 开始推送
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取值班人员的工号
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<String> getStaffCodeList(){
|
|
|
+ String staffCode = configService.getConfigValueByKey("ysg_staff_code");
|
|
|
+ if(StrUtil.isBlank(staffCode)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ staffCode =StrUtil.replace(staffCode, ",", ",");
|
|
|
+ return StrUtil.split(staffCode,",");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Connection fetchOneMqConnection(RabbitMqConfigPropertyDTO mqConfigProperty){
|
|
|
+ ConnectionFactory factory = new ConnectionFactory();
|
|
|
+ factory.setHost(mqConfigProperty.getHost());
|
|
|
+ factory.setPort(mqConfigProperty.getPort());
|
|
|
+ factory.setUsername(mqConfigProperty.getUserName());
|
|
|
+ factory.setPassword(mqConfigProperty.getPws());
|
|
|
+ try {
|
|
|
+ return factory.newConnection();
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("浙江眼视光医院MQ配置错误,",e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private RabbitMqConfigPropertyDTO getMqConfigProperty(){
|
|
|
+ String mqConfig = configService.getConfigValueByKey("ysg_mq_config");
|
|
|
+ if(StrUtil.isBlank(mqConfig)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return JSONUtil.toBean(mqConfig, RabbitMqConfigPropertyDTO.class);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("浙江眼视光医院MQ配置解析错误,",e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String errorMsg(BusDeviceAlarmEntity entity){
|
|
|
+ String alarmPattern="设备号:%s,住院号:%s,报警信息:%";
|
|
|
+ return String.format(alarmPattern,entity.getDeviceId(),entity.getPatientCode(),entity.getAlarmState().getText());
|
|
|
+ }
|
|
|
+
|
|
|
+}
|