|
|
@@ -0,0 +1,81 @@
|
|
|
+package com.nb.web.service.bus.listener;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.nb.common.config.annotation.TenantIgnore;
|
|
|
+import com.nb.core.entity.MqttMessage;
|
|
|
+import com.nb.core.enums.MqttTopicEnum;
|
|
|
+import com.nb.core.handler.AbstractMqttMessageHandler;
|
|
|
+import com.nb.web.service.bus.entity.BusPatientEntity;
|
|
|
+import com.nb.web.service.bus.mapper.BusPatientMapper;
|
|
|
+import com.nb.web.service.bus.service.LocalBusClinicService;
|
|
|
+import com.nb.web.service.bus.service.LocalBusInfusionHistoryService;
|
|
|
+import com.nb.web.service.bus.service.dto.ManualUndoConfig;
|
|
|
+import com.nb.web.service.bus.service.dto.MqttUndoDTO;
|
|
|
+import jodd.io.StreamUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 撤泵信息下发主题监听器
|
|
|
+ * 处理 bus/undo 主题的MQTT消息
|
|
|
+ *
|
|
|
+ * @author YourName
|
|
|
+ * @version 1.0.0
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class BusUndoMessageListener extends AbstractMqttMessageHandler {
|
|
|
+ @Autowired
|
|
|
+ private BusPatientMapper patientMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LocalBusInfusionHistoryService infusionHistoryService;
|
|
|
+ /**
|
|
|
+ * 定义支持的主题模式
|
|
|
+ * @return 支持的主题模式
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ protected String getSupportedTopicPattern() {
|
|
|
+ return MqttTopicEnum.BUS_UNDO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理MQTT消息
|
|
|
+ * @param message MQTT消息实体
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @TenantIgnore
|
|
|
+ public void handle(MqttMessage message) {
|
|
|
+ log.info("接收到撤泵信息下发消息,主题: {}, 内容: {}", message.getTopic(), message.getPayload());
|
|
|
+ try {
|
|
|
+ // 解析消息内容为MqttUndoDTO对象
|
|
|
+ MqttUndoDTO mqttUndoDTO = JSONUtil.toBean(message.getPayload(), MqttUndoDTO.class);
|
|
|
+ ManualUndoConfig manualUndoConfig = mqttUndoDTO.getManualUndoConfig();
|
|
|
+
|
|
|
+ log.info("撤泵配置信息:{}", JSONUtil.toJsonStr(manualUndoConfig));
|
|
|
+ BusPatientEntity patient = patientMapper.selectOne(new LambdaQueryWrapper<BusPatientEntity>()
|
|
|
+ .eq(BusPatientEntity::getOriginCode, manualUndoConfig.getPatientCode())
|
|
|
+ .last("limit 1"));
|
|
|
+ if(ObjectUtil.isNull(patient)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ manualUndoConfig.setClinicId(patient.getClinicId());
|
|
|
+ manualUndoConfig.setPatientId(patient.getId());
|
|
|
+ manualUndoConfig.setTenantId(patient.getTenantId());
|
|
|
+ if(StrUtil.isNotEmpty(patient.getInfusionId())){
|
|
|
+ manualUndoConfig.setInfusionIds(Arrays.asList(patient.getInfusionId()));
|
|
|
+ }
|
|
|
+ infusionHistoryService.undo(manualUndoConfig,mqttUndoDTO.getFinishClinic());
|
|
|
+
|
|
|
+ log.info("撤泵信息处理完成");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("处理撤泵信息时发生错误: ", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|