wangzl пре 4 месеци
родитељ
комит
196df388f3

+ 53 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/config/PatientMonitorListener.java

@@ -7,8 +7,10 @@ import cn.tr.core.utils.JsonUtils;
 import cn.tr.module.api.sys.tenant.SysTenantApi;
 import cn.tr.module.api.sys.tenant.SysTenantPojo;
 import cn.tr.module.smart.common.dto.NbPumpInfusionDTO;
+import cn.tr.module.smart.common.enums.FlowStatusEnum;
 import cn.tr.module.smart.common.enums.InfusionBindType;
 import cn.tr.module.smart.common.enums.RabbitMQConstant;
+import cn.tr.module.smart.common.mapper.BizDeviceAlarmMapper;
 import cn.tr.module.smart.common.mapper.BizDeviceHistoryMapper;
 import cn.tr.module.smart.common.mapper.BizDeviceMapper;
 import cn.tr.module.smart.common.mapper.BizInfusionHistoryMapper;
@@ -23,6 +25,12 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+
 @Slf4j
 @Service
 @AllArgsConstructor
@@ -33,6 +41,7 @@ public class PatientMonitorListener {
     private final BizPatientRepository patientRepository;
     private final BizDeviceHistoryRepository deviceHistoryRepository;
     private final BizDeviceRepository deviceRepository;
+    private final BizDeviceAlarmRepository deviceAlarmRepository;
     @RabbitListener(queues = RabbitMQConstant.QUEUE_PATIENT_MONITOR)
     @TenantIgnore
     @Transactional(rollbackFor = Exception.class)
@@ -92,6 +101,11 @@ public class PatientMonitorListener {
             log.debug("插入新的设备记录");
             deviceRepository.insert(device);
         }
+        //处理设备报警信息
+        BizDeviceAlarmPO bizDeviceAlarmPO = handleAlarmData(infusionHistory,oldInfusionHistory, deviceHistory);
+        if(ObjectUtil.isNotNull(bizDeviceAlarmPO)){
+            deviceAlarmRepository.insert(bizDeviceAlarmPO);
+        }
         // 根据住院号查找患者信息
         log.debug("开始精确查找患者信息,住院号: {}", source.getPatientCode());
         BizPatientPO patientPO=patientRepository.selectOne(new LambdaQueryWrapper<BizPatientPO>()
@@ -144,4 +158,43 @@ public class PatientMonitorListener {
 
         log.info("患者监护数据处理完成");
     }
+
+    /**
+     * @description: 处理报警信息
+     * @author wangzl
+     * @date 2025/8/8
+     */
+    public BizDeviceAlarmPO handleAlarmData(BizInfusionHistoryPO infusionHistory, BizInfusionHistoryPO oldInfusionHistory, BizDeviceHistoryPO deviceHistory) {
+        //如果输入数据相同,则不处理
+        if(isEqual(infusionHistory, oldInfusionHistory)){
+            return null;
+        }
+        log.info("开始处理报警信息 新输注ID {}  ,设备ID {}", infusionHistory.getId(),  deviceHistory.getId());
+        BizDeviceAlarmPO alarmPO = BizDeviceAlarmMapper.INSTANCE.convertInfusionToPO(infusionHistory);
+        alarmPO.setDeviceType(deviceHistory.getDeviceType());
+        alarmPO.setDeviceId(deviceHistory.getId());
+        Function<BizInfusionHistoryPO, Boolean> check = o -> StrUtil.isNotBlank(o.getDeviceAlarm())
+                && !o.getDeviceAlarm().equals(FlowStatusEnum.None.name());
+        alarmPO.setAlarm(check.apply(infusionHistory));
+        return alarmPO;
+    }
+
+    /**
+     * @description: 校验输液历史记录是否相同
+     * @author wangzl
+     * @date 2025/8/8
+     */
+    public boolean isEqual(BizInfusionHistoryPO infusionHistory, BizInfusionHistoryPO oldInfusionHistory) {
+        if (infusionHistory == null && oldInfusionHistory == null) return true;
+        if (oldInfusionHistory == null || infusionHistory == null) return false;
+        List<BiFunction<BizInfusionHistoryPO, BizInfusionHistoryPO, Boolean>> checks = Arrays.asList(
+                (o, n) -> Objects.equals(o.getDeviceAlarm(), n.getDeviceAlarm()),
+                (o, n) -> Objects.equals(o.getWarnFlow(), n.getWarnFlow()),
+                (o, n) -> Objects.equals(o.getWarnAnalgesicPoor(), n.getWarnAnalgesicPoor()),
+                (o, n) -> Objects.equals(o.getWarnWillFinished(), n.getWarnWillFinished()),
+                (o, n) -> Objects.equals(o.getWarnLowBattery(), n.getWarnLowBattery())
+        );
+        return checks.stream().allMatch(check -> check.apply(oldInfusionHistory, infusionHistory));
+    }
+
 }

+ 32 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/mapper/BizDeviceAlarmMapper.java

@@ -0,0 +1,32 @@
+package cn.tr.module.smart.common.mapper;
+
+
+import cn.tr.module.smart.common.po.BizDeviceAlarmPO;
+import cn.tr.module.smart.common.po.BizInfusionHistoryPO;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.Mappings;
+import org.mapstruct.factory.Mappers;
+
+/**
+* 设备-设备报警表映射工具
+*
+* @author wangzl
+* @date  2025/08/08 08:19
+**/
+@Mapper
+public interface BizDeviceAlarmMapper {
+    BizDeviceAlarmMapper INSTANCE = Mappers.getMapper(BizDeviceAlarmMapper.class);
+    @Mappings({
+            @Mapping(source = "id", target = "infusionId"),
+            @Mapping(source = "lastUploadTime", target = "uploadTime"),
+            @Mapping(source = "deviceRunState", target = "runState"),
+            @Mapping(source = "deviceAlarm", target = "alarmState"),
+            @Mapping(source = "warnFlow", target = "warnFlow"),
+            @Mapping(source = "warnLowBattery", target = "warnLowBattery"),
+            @Mapping(source = "warnWillFinished", target = "warnWillFinished"),
+            @Mapping(source = "warnAnalgesicPoor", target = "warnAnalgesicPoor"),
+            @Mapping(source = "id", target = "historyId"),
+    })
+    BizDeviceAlarmPO convertInfusionToPO(BizInfusionHistoryPO source);
+}

+ 81 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/po/BizDeviceAlarmPO.java

@@ -0,0 +1,81 @@
+package cn.tr.module.smart.common.po;
+
+import cn.tr.plugin.mybatis.pojo.TenantPO;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+
+import java.util.Date;
+/**
+ * 设备-设备报警表实体
+ *
+ * @author wangzl
+ * @date  2025/08/08 08:19
+ **/
+@Data
+@TableName(value="biz_device_alarm",autoResultMap = true)
+@EqualsAndHashCode(callSuper = true)
+@ToString
+public class BizDeviceAlarmPO extends TenantPO {
+
+    /** 主键id */
+    @TableId
+    @ApiModelProperty(value = "主键id", position = 1)
+    private String id;
+
+    /** 设备唯一编码 */
+    @ApiModelProperty(value = "设备唯一编码", position = 2)
+    private String deviceId;
+
+    /** 设备数据上传时间 */
+    @ApiModelProperty(value = "设备数据上传时间", position = 3)
+    private Date uploadTime;
+
+    /** 设备类型 */
+    @ApiModelProperty(value = "设备类型", position = 4)
+    private String deviceType;
+
+    /** 报警原因 */
+    @ApiModelProperty(value = "报警原因", position = 5)
+    private String cause;
+
+    /** 报警内容 */
+    @ApiModelProperty(value = "报警内容", position = 6)
+    private Boolean alarm;
+
+    /** 对应报警的历史记录 */
+    @ApiModelProperty(value = "对应报警的历史记录", position = 7)
+    private String historyId;
+
+    /** 输注记录 */
+    @ApiModelProperty(value = "输注记录", position = 8)
+    private String infusionId;
+
+    /** 设备运行状态 */
+    @ApiModelProperty(value = "设备运行状态", position = 9)
+    private String runState;
+
+    /** 设备报警状态 */
+    @ApiModelProperty(value = "设备报警状态", position = 10)
+    private String alarmState;
+
+    /** 智能泵提醒 */
+    @ApiModelProperty(value = "智能泵提醒", position = 11)
+    private String warnFlow;
+
+    /** 输液结束提醒 */
+    @ApiModelProperty(value = "输液结束提醒", position = 12)
+    private Boolean warnWillFinished;
+
+    /** 低电量提醒 */
+    @ApiModelProperty(value = "低电量提醒", position = 13)
+    private Boolean warnLowBattery;
+
+    /** 镇痛不足提醒 */
+    @ApiModelProperty(value = "镇痛不足提醒", position = 14)
+    private Boolean warnAnalgesicPoor;
+
+}

+ 16 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/repository/BizDeviceAlarmRepository.java

@@ -0,0 +1,16 @@
+package cn.tr.module.smart.common.repository;
+
+import cn.tr.module.smart.common.po.BizDeviceAlarmPO;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+/**
+ * 设备-设备报警表Mapper接口
+ *
+ * @author wangzl
+ * @date  2025/08/08 08:19
+ **/
+@Repository
+@Mapper
+public interface BizDeviceAlarmRepository extends BaseMapper<BizDeviceAlarmPO> {
+}

+ 11 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/service/IBizDeviceAlarmService.java

@@ -0,0 +1,11 @@
+package cn.tr.module.smart.common.service;
+
+/**
+ * 设备-设备报警表Service接口
+ *
+ * @author wangzl
+ * @date  2025/08/08 08:19
+ **/
+public interface IBizDeviceAlarmService {
+
+}

+ 19 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/service/impl/BizDeviceAlarmServiceImpl.java

@@ -0,0 +1,19 @@
+package cn.tr.module.smart.common.service.impl;
+
+import cn.tr.module.smart.common.repository.BizDeviceAlarmRepository;
+import cn.tr.module.smart.common.service.IBizDeviceAlarmService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+/**
+ * 设备-设备报警表Service接口实现类
+ *
+ * @author wangzl
+ * @date  2025/08/08 08:19
+ **/
+@Service
+public class BizDeviceAlarmServiceImpl implements IBizDeviceAlarmService {
+    @Autowired
+    private BizDeviceAlarmRepository baseRepository;
+
+
+}

+ 4 - 4
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/web/controller/BizDeviceController.java

@@ -57,14 +57,14 @@ public class BizDeviceController extends BaseController {
 
     @ApiOperationSupport(author = "wangzl", order = 4)
     @ApiOperation(value = "查询报警信息", notes = "权限: 无")
-    @GetMapping("/alarm/{deviceId}")
-    public CommonResult<String> queryAlarm(@PathVariable String deviceId) {
+    @GetMapping("/alarm/{infusionId}")
+    public CommonResult<String> queryAlarm(@PathVariable String infusionId) {
         return CommonResult.success(null);
     }
     @ApiOperationSupport(author = "wangzl", order = 5)
     @ApiOperation(value = "查询输注折线图", notes = "权限: 无")
-    @GetMapping("/infusion/graph/{deviceId}")
-    public CommonResult<String> infusionGraph(@PathVariable String deviceId) {
+    @GetMapping("/infusion/graph/{infusionId}")
+    public CommonResult<String> infusionGraph(@PathVariable String infusionId) {
         return CommonResult.success(null);
     }