lifang 3 viikkoa sitten
vanhempi
commit
f6f25e9319

+ 65 - 65
nb-core/src/main/java/com/nb/core/utils/MqttClientUtil.java

@@ -121,71 +121,71 @@ public class MqttClientUtil implements ApplicationContextAware {
         }
     }
 
-    
-    /**
-     * 订阅主题
-     * @param topic 主题
-     * @param messageHandler 消息处理器
-     */
-    public void subscribe(String topic, MessageHandler messageHandler) {
-        try {
-            if (mqttClientFactory == null) {
-                return;
-            }
-            // 如果已经订阅了该主题,则先取消订阅
-            if (subscribers.containsKey(topic)) {
-                unsubscribe(topic);
-            }
-            
-            MqttPahoMessageDrivenChannelAdapter adapter = 
-                new MqttPahoMessageDrivenChannelAdapter(CLIENT_ID, mqttClientFactory, topic);
-            adapter.setConverter(new DefaultPahoMessageConverter());
-            adapter.setOutputChannel(mqttInputChannel);
-            
-            // 创建一个带有处理逻辑的通道
-            DirectChannel channel = new DirectChannel();
-            channel.subscribe(messageHandler);
-            adapter.setOutputChannel(channel);
-            
-            adapter.start();
-            
-            subscribers.put(topic, adapter);
-        } catch (Exception e) {
-            throw new RuntimeException("订阅MQTT主题失败: " + e.getMessage(), e);
-        }
-    }
-    
-    /**
-     * 订阅主题(使用函数式接口处理消息)
-     * @param topic 主题
-     * @param messageConsumer 消息消费者
-     */
-    public void subscribe(String topic, Consumer<String> messageConsumer) {
-        MessageHandler handler = new MessageHandler() {
-            @Override
-            public void handleMessage(org.springframework.messaging.Message<?> message) throws MessagingException {
-                String payload = new String((byte[]) message.getPayload());
-                messageConsumer.accept(payload);
-            }
-        };
-        subscribe(topic, handler);
-    }
-    
-    /**
-     * 取消订阅
-     * @param topic 主题
-     */
-    public void unsubscribe(String topic) {
-        MqttPahoMessageDrivenChannelAdapter adapter = subscribers.get(topic);
-        if (adapter != null) {
-            try {
-                adapter.stop();
-            } catch (Exception e) {
-                // 忽略停止异常
-            }
-            subscribers.remove(topic);
-        }
-    }
+//
+//    /**
+//     * 订阅主题
+//     * @param topic 主题
+//     * @param messageHandler 消息处理器
+//     */
+//    public void subscribe(String topic, MessageHandler messageHandler) {
+//        try {
+//            if (mqttClientFactory == null) {
+//                return;
+//            }
+//            // 如果已经订阅了该主题,则先取消订阅
+//            if (subscribers.containsKey(topic)) {
+//                unsubscribe(topic);
+//            }
+//
+//            MqttPahoMessageDrivenChannelAdapter adapter =
+//                new MqttPahoMessageDrivenChannelAdapter(CLIENT_ID, mqttClientFactory, topic);
+//            adapter.setConverter(new DefaultPahoMessageConverter());
+//            adapter.setOutputChannel(mqttInputChannel);
+//
+//            // 创建一个带有处理逻辑的通道
+//            DirectChannel channel = new DirectChannel();
+//            channel.subscribe(messageHandler);
+//            adapter.setOutputChannel(channel);
+//
+//            adapter.start();
+//
+//            subscribers.put(topic, adapter);
+//        } catch (Exception e) {
+//            throw new RuntimeException("订阅MQTT主题失败: " + e.getMessage(), e);
+//        }
+//    }
+//
+//    /**
+//     * 订阅主题(使用函数式接口处理消息)
+//     * @param topic 主题
+//     * @param messageConsumer 消息消费者
+//     */
+//    public void subscribe(String topic, Consumer<String> messageConsumer) {
+//        MessageHandler handler = new MessageHandler() {
+//            @Override
+//            public void handleMessage(org.springframework.messaging.Message<?> message) throws MessagingException {
+//                String payload = new String((byte[]) message.getPayload());
+//                messageConsumer.accept(payload);
+//            }
+//        };
+//        subscribe(topic, handler);
+//    }
+//
+//    /**
+//     * 取消订阅
+//     * @param topic 主题
+//     */
+//    public void unsubscribe(String topic) {
+//        MqttPahoMessageDrivenChannelAdapter adapter = subscribers.get(topic);
+//        if (adapter != null) {
+//            try {
+//                adapter.stop();
+//            } catch (Exception e) {
+//                // 忽略停止异常
+//            }
+//            subscribers.remove(topic);
+//        }
+//    }
 
     /**
      * 异步发布消息

+ 19 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/service/LocalBusPatientService.java

@@ -819,6 +819,25 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
                 result.setEvaluate(ObjectUtil.compare(date,now)>0?1:2);
             }
         }
+        if(CollectionUtil.isEmpty(results)){
+            return results;
+        }
+        List<BusDeviceEntity> deviceList = deviceService.getBaseMapper().selectList(new LambdaQueryWrapper<BusDeviceEntity>()
+                .select(BusDeviceEntity::getDeviceId,BusDeviceEntity::getAlias,BusDeviceEntity::getProductNo)
+                .eq(BusDeviceEntity::getTenantId,query.getTenantId())
+                .in(BusDeviceEntity::getId,results.stream().map(DoctorPatientMonitorResult::getDeviceId).collect(Collectors.toList())));
+        Map<String, BusDeviceEntity> deviceMap=new HashMap<>();
+        if(CollectionUtil.isNotEmpty(deviceList)){
+            deviceMap = deviceList.stream()
+                    .collect(Collectors.groupingBy(BusDeviceEntity::getDeviceId, Collectors.collectingAndThen(Collectors.toList(), CollectionUtil::getFirst)));
+        }
+        for (DoctorPatientMonitorResult result : results) {
+            BusDeviceEntity device = deviceMap.get(result.getDeviceId());
+            if(ObjectUtil.isNotNull(device)){
+                result.setDeviceAlias(device.getAlias());
+            }
+        }
+
         return results;
     }
 

+ 2 - 2
nb-service/web-service/src/main/resources/mapper/bus/BusPatientMapper.xml

@@ -581,7 +581,7 @@
         c.monitor_start_time as monitor_start_time,
         <!-- 设备与输注信息 -->
         i.device_id AS device_id,
-        d.alias AS device_alias,   <!-- 假设来自设备表,若未关联需调整 -->
+--         d.alias AS device_alias,   <!-- 假设来自设备表,若未关联需调整 -->
         i.clinic_id AS clinic_id,
         i.total_dose AS total_dose,
         i.first_dose AS first_dose,
@@ -623,7 +623,7 @@
         JOIN bus_clinic c ON p.clinic_id = c.id          <!-- 患者与临床信息关联 -->
         JOIN bus_infusion_history i ON p.infusion_id = i.id  <!-- 患者与输注记录关联 -->
         <!-- 设备表左连接(若 device_alias 来自设备表) -->
-        LEFT JOIN bus_device d ON i.device_id = d.id
+--         LEFT JOIN bus_device d ON i.device_id = d.id
         <if test="query.consult != null and query.consult == true">
             LEFT JOIN (select * from assistant_user_bind where status = '1' and doctor_id = #{query.userId}) aub on aub.patient_id = p.id
         </if>