Преглед изворни кода

add
浙江温州眼视光医院推送报警信息

18339543638 пре 1 година
родитељ
комит
7a52879d81

+ 6 - 0
nb-service-api/web-service-api/src/main/java/com/nb/web/api/entity/BusDeviceAlarmEntity.java

@@ -83,6 +83,10 @@ public class BusDeviceAlarmEntity extends TenantGenericEntity<String,String> {
     @TableField(updateStrategy = FieldStrategy.IGNORED)
     private FlowStatusEnum warnFlow;
 
+    @ApiModelProperty("住院号")
+    @TableField(exist = false)
+    private String patientCode;
+
     public static BusDeviceAlarmEntity parseHistory(BusDeviceHistoryEntity history){
         BusDeviceAlarmEntity entity = new BusDeviceAlarmEntity();
         entity.setDeviceId(history.getDeviceId());
@@ -100,6 +104,7 @@ public class BusDeviceAlarmEntity extends TenantGenericEntity<String,String> {
         entity.setWarnFlow(history.getWarnFlow());
         entity.setTenantId(history.getTenantId());
         entity.setDeviceType(history.getType());
+        entity.setPatientCode(history.getPatientCode());
         return entity;
     }
 
@@ -120,6 +125,7 @@ public class BusDeviceAlarmEntity extends TenantGenericEntity<String,String> {
         entity.setWarnFlow(source.getWarnFlow());
         entity.setTenantId(source.getTenantId());
         entity.setDeviceType(source.getType());
+        entity.setPatientCode(source.getPatientCode());
         return entity;
     }
 

+ 5 - 0
nb-service/web-service/pom.xml

@@ -87,5 +87,10 @@
             <artifactId>easy-captcha</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.springframework.amqp</groupId>
+            <artifactId>spring-rabbit</artifactId>
+        </dependency>
+
     </dependencies>
 </project>

+ 18 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/alarmPush/IAlarmPushService.java

@@ -0,0 +1,18 @@
+package com.nb.web.service.bus.alarmPush;
+
+import com.nb.web.api.entity.BusDeviceAlarmEntity;
+
+/**
+ * @ClassName : IAlarmPushService
+ * @Description : 设备报警信息推送
+ * @Author : LF
+ * @Date: 2024年10月08日
+ */
+
+public interface IAlarmPushService {
+    /**
+     * 推送信息
+     * @param entity
+     */
+    void pushAlarmMsg(BusDeviceAlarmEntity entity);
+}

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

@@ -0,0 +1,42 @@
+package com.nb.web.service.bus.alarmPush;
+
+import lombok.Data;
+
+/**
+ * @ClassName : RabbitMqDTO
+ * @Description :
+ * @Author : LF
+ * @Date: 2024年10月09日
+ */
+@Data
+public class RabbitMqConfigPropertyDTO {
+    /**
+     * 主机地址
+     */
+    private String host;
+
+    /**
+     * 端口
+     */
+    private Integer port;
+
+    /**
+     * 交换机名称
+     */
+    private String exchangeName;
+
+    /**
+     * 用户名称
+     */
+    private String userName;
+
+    /**
+     * 密码
+     */
+    private String pws;
+
+    /**
+     * 虚拟机名称
+     */
+    private String virtualHost;
+}

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

@@ -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());
+    }
+
+}

+ 7 - 2
nb-service/web-service/src/main/java/com/nb/web/service/bus/service/LocalBusDeviceAlarmService.java

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.nb.web.api.entity.BusDeviceAlarmEntity;
 import com.nb.web.api.feign.IDeviceAlarmClient;
 import com.nb.web.api.feign.query.AlarmQuery;
+import com.nb.web.service.bus.alarmPush.IAlarmPushService;
 import com.nb.web.service.bus.entity.BusHospitalEntity;
 import com.nb.web.api.entity.BusInfusionHistoryEntity;
 import com.nb.web.api.enums.DeviceAlarmEnum;
@@ -37,9 +38,11 @@ import java.util.Map;
  */
 @Service
 @Slf4j
-@AllArgsConstructor
 public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper, BusDeviceAlarmEntity,String> implements IDeviceAlarmClient {
 
+    @Autowired(required = false)
+    private IAlarmPushService alarmPushService;
+
     @Autowired
     @Lazy
     private LocalBusHospitalService hospitalService;
@@ -98,7 +101,9 @@ public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper
                return false;
            }
        }
-
+       if(ObjectUtil.isNotNull(alarmPushService)&&Boolean.TRUE.equals(entity.getAlarm())){
+           alarmPushService.pushAlarmMsg(entity);
+       }
         //再判断是否报警或提示是否发生重复
         //满足以上条件进行保存
         return super.save(entity);

+ 7 - 0
pom.xml

@@ -48,6 +48,7 @@
         <poi.tl.verison>1.12.0</poi.tl.verison>
         <poi.version>5.2.2</poi.version>
         <flyway.version>7.15.0</flyway.version>
+        <rabbit.version>3.1.7</rabbit.version>
     </properties>
 
     <modules>
@@ -388,6 +389,12 @@
                 <version>${flyway.version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>org.springframework.amqp</groupId>
+                <artifactId>spring-rabbit</artifactId>
+                <version>${rabbit.version}</version>
+            </dependency>
+
         </dependencies>
     </dependencyManagement>