G 5 дней назад
Родитель
Сommit
48a8d51443
21 измененных файлов с 307 добавлено и 59 удалено
  1. BIN
      logs/2026-01/hdis-2026-01-22-1.log.gz
  2. 9 0
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/controller/BusDeviceController.java
  3. 0 51
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/ClinicDetailDTO.java
  4. 2 1
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/DeviceRunningLogDTO.java
  5. 2 1
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/DeviceRunningLogQueryDTO.java
  6. 2 1
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/PatientTherapyDetailDTO.java
  7. 2 1
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/TherapyRecordDetailDTO.java
  8. 2 1
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/TherapyRecordDetailQueryDTO.java
  9. 39 0
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/UnbindDeviceDTO.java
  10. 15 1
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/enums/DeviceStatusEnum.java
  11. 15 0
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/repository/BusClinicRepository.java
  12. 11 0
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/repository/BusDeviceRepository.java
  13. 1 0
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/repository/BusTherapyPlanRepository.java
  14. 11 0
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/repository/BusTherapyRecordRepository.java
  15. 11 0
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/service/IBusDeviceService.java
  16. 85 1
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/service/impl/BusDeviceServiceImpl.java
  17. 2 0
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/vo/PatientTherapyDetailVO.java
  18. 36 0
      tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/vo/UnbindDeviceVO.java
  19. 15 1
      tr-modules/tr-modules-phototherapy/src/main/resources/mapper/phototherapy/BusClinicRepository.xml
  20. 24 0
      tr-modules/tr-modules-phototherapy/src/main/resources/mapper/phototherapy/BusDeviceRepository.xml
  21. 23 0
      tr-modules/tr-modules-phototherapy/src/main/resources/mapper/phototherapy/BusTherapyRecordRepository.xml

BIN
logs/2026-01/hdis-2026-01-22-1.log.gz


+ 9 - 0
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/controller/BusDeviceController.java

@@ -4,6 +4,8 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
 import cn.tr.core.validation.Insert;
 import cn.tr.core.validation.Update;
 import cn.tr.core.pojo.CommonResult;
+import cn.tr.module.phototherapy.common.dto.UnbindDeviceDTO;
+import cn.tr.module.phototherapy.common.vo.UnbindDeviceVO;
 import lombok.AllArgsConstructor;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import io.swagger.v3.oas.annotations.Operation;
@@ -68,4 +70,11 @@ public class BusDeviceController extends BaseController{
     public CommonResult<Boolean> delete(@RequestBody Collection<String> ids) {
         return CommonResult.success(busDeviceService.removeBusDeviceByIds(ids));
     }
+
+    @Operation(summary = "根据患者唯一ID解绑设备", description = "权限: phototherapy:common:edit")
+    @PostMapping("/unbindDevice")
+    @SaCheckPermission("phototherapy:common:edit")
+    public CommonResult<UnbindDeviceVO> unbindDevice(@RequestBody UnbindDeviceDTO source) {
+        return CommonResult.success(busDeviceService.unbindDevice(source));
+    }
 }

+ 0 - 51
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/ClinicDetailDTO.java

@@ -1,51 +0,0 @@
-package cn.tr.module.phototherapy.common.dto;
-
-import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-
-import java.time.LocalDateTime;
-import java.util.Date;
-import java.util.List;
-
-/**
- * @ClassName ClinicDetailDTO
- * @Description 临床详情和治疗记录信息
- * @Date 2026/1/19 9:41
- * @Version 1.0.0
- */
-@Data
-@Schema(description = "临床详情DTO")
-public class ClinicDetailDTO {
-
-    @Schema(description = "患者姓名")
-    private String patientName;
-
-    @Schema(description = "患者年龄")
-    private Integer patientAge;
-
-    @Schema(description = "患者编号")
-    private String patientUniqueId;
-
-    @Schema(description = "患者性别(0女 1男 2未知)")
-    private Integer patientGender;
-
-    @Schema(description = "今日治疗时间(分钟)")
-    private Integer todayTherapyTime;
-
-    @Schema(description = "治疗方案名称")
-    private String planName;
-
-    @Schema(description = "当前阶段类型")
-    private String phaseType;
-
-    @Schema(description = "阶段频率")
-    private Integer phaseFreq;
-
-    @Schema(description = "阶段建议时长(分钟)")
-    private Integer phaseDurationMin;
-
-    @Schema(description = "上次治疗时间")
-    private Date lastTreatmentTime;
-
-}
-

+ 2 - 1
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/DeviceRunningLogDTO.java

@@ -1,5 +1,6 @@
 package cn.tr.module.phototherapy.common.dto;
 
+import cn.tr.core.pojo.BaseDTO;
 import cn.tr.module.phototherapy.common.enums.DeviceAlarmEnum;
 import cn.tr.module.phototherapy.common.enums.DeviceRunStateEnum;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -16,7 +17,7 @@ import java.util.Date;
  */
 @Data
 @Schema(description = "设备运行日志查询")
-public class DeviceRunningLogDTO {
+public class DeviceRunningLogDTO extends BaseDTO {
 
     //device_history表
     @Schema(description = "设备ID")

+ 2 - 1
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/DeviceRunningLogQueryDTO.java

@@ -3,6 +3,7 @@ package cn.tr.module.phototherapy.common.dto;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
+import java.io.Serializable;
 import java.util.Date;
 
 /**
@@ -13,7 +14,7 @@ import java.util.Date;
  */
 @Data
 @Schema(description = "设备运行日志查询参数")
-public class DeviceRunningLogQueryDTO {
+public class DeviceRunningLogQueryDTO implements Serializable {
 
 
     @Schema(description = "患者唯一标识")

+ 2 - 1
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/PatientTherapyDetailDTO.java

@@ -1,5 +1,6 @@
 package cn.tr.module.phototherapy.common.dto;
 
+import cn.tr.core.pojo.BaseDTO;
 import cn.tr.module.phototherapy.common.enums.*;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.v3.oas.annotations.media.Schema;
@@ -17,7 +18,7 @@ import java.util.List;
  */
 @Data
 @Schema(description = "患者治疗详情DTO")
-public class PatientTherapyDetailDTO {
+public class PatientTherapyDetailDTO extends BaseDTO {
 
     // 患者信息(来自bus_clinic表)
     @Schema(description = "患者姓名")

+ 2 - 1
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/TherapyRecordDetailDTO.java

@@ -1,5 +1,6 @@
 package cn.tr.module.phototherapy.common.dto;
 
+import cn.tr.core.pojo.BaseDTO;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
@@ -16,7 +17,7 @@ import java.util.Date;
  */
 @Data
 @Schema(description = "治疗记录详情DTO")
-public class TherapyRecordDetailDTO {
+public class TherapyRecordDetailDTO extends BaseDTO {
 
     @Schema(description = "治疗日期")
     @JsonFormat(pattern = "yyyy-MM-dd")

+ 2 - 1
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/TherapyRecordDetailQueryDTO.java

@@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
 import jakarta.validation.constraints.NotBlank;
 import lombok.Data;
 
+import java.io.Serializable;
 import java.util.Date;
 
 /**
@@ -15,7 +16,7 @@ import java.util.Date;
  */
 @Data
 @Schema(description = "治疗记录查询参数")
-public class TherapyRecordDetailQueryDTO {
+public class TherapyRecordDetailQueryDTO implements Serializable {
 
     @Schema(description = "患者唯一ID" , required = true)
     @NotBlank(message = "患者唯一ID不能为空")

+ 39 - 0
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/dto/UnbindDeviceDTO.java

@@ -0,0 +1,39 @@
+package cn.tr.module.phototherapy.common.dto;
+
+import cn.tr.core.pojo.BaseDTO;
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotBlank;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @ClassName UnBindDeviceDTO
+ * @Description 设备解绑传输对象
+ * @Date 2026/1/23 11:51
+ * @Version 1.0.0
+ */
+@Data
+@Schema(description = "设备解绑传输对象")
+public class UnbindDeviceDTO extends BaseDTO {
+
+    @Schema(description = "患者唯一ID")
+    @NotBlank(message = "患者唯一ID不能为空")
+    private String patientUniqueId;
+
+    @Schema(description = "设备ID")
+    @NotBlank(message = "设备ID不能为空")
+    private String deviceId;
+
+    @Schema(description = "是否当前绑定", hidden = true)
+    private Integer isCurrentBind;
+
+    @Schema(description = "绑定结束时间", hidden = true)
+    private Date bindEndTime;
+
+    @Schema(description = "设备状态", hidden = true)
+    private Integer deviceStatus;
+
+    @Schema(description = "治疗状态", hidden = true)
+    private Integer therapyStatus;
+}

+ 15 - 1
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/enums/DeviceStatusEnum.java

@@ -19,7 +19,7 @@ public enum DeviceStatusEnum implements IEnum<Integer> {
 
     Shutdown(0,"在线"),
     StartUp(1,"离线"),
-    NoDevice(2,"无设备");
+    NoDevice(2,"未使用");
 
 
 
@@ -33,4 +33,18 @@ public enum DeviceStatusEnum implements IEnum<Integer> {
     @Schema(defaultValue = "运行状态内容")
     private String text;
 
+    /**
+     * 根据值获取枚举
+     *
+     * @param value 值
+     * @return 枚举
+     */
+    public static DeviceStatusEnum getByValue(Integer value) {
+        for (DeviceStatusEnum status : values()) {
+            if (status.value.equals(value)) {
+                return status;
+            }
+        }
+        return null;
+    }
 }

+ 15 - 0
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/repository/BusClinicRepository.java

@@ -2,6 +2,7 @@ package cn.tr.module.phototherapy.common.repository;
 
 import cn.tr.module.phototherapy.common.dto.BusPatientListQueryDTO;
 import cn.tr.module.phototherapy.common.dto.PatientTherapyDetailDTO;
+import cn.tr.module.phototherapy.common.dto.UnbindDeviceDTO;
 import cn.tr.module.phototherapy.common.vo.PatientTherapyDetailVO;
 import cn.tr.module.phototherapy.common.vo.PatientTherapyRecordVO;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@@ -34,4 +35,18 @@ public interface BusClinicRepository extends BaseMapper<BusClinicPO> {
      * @return java.util.List<cn.tr.module.phototherapy.common.vo.PatientTherapyRecordVO>
      **/
     List<PatientTherapyRecordVO> selectPatientLists(@Param("query") BusPatientListQueryDTO query);
+
+    /**
+     * 根据条件更新绑定关系
+     * @param source
+     * @return int
+     **/
+    int updateClinicForUnbind(UnbindDeviceDTO source);
+
+    /**
+     * 根据patientUniqueId查询临床表
+     * @param patientUniqueId
+     * @return cn.tr.module.phototherapy.common.po.BusClinicPO
+     **/
+    BusClinicPO selectByPatientUniqueId(@Param("patientUniqueId") String patientUniqueId);
 }

+ 11 - 0
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/repository/BusDeviceRepository.java

@@ -1,8 +1,10 @@
 package cn.tr.module.phototherapy.common.repository;
 
+import cn.tr.module.phototherapy.common.dto.UnbindDeviceDTO;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
 import cn.tr.module.phototherapy.common.po.BusDevicePO;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 /**
@@ -14,4 +16,13 @@ import org.springframework.stereotype.Repository;
 @Repository
 @Mapper
 public interface BusDeviceRepository extends BaseMapper<BusDevicePO> {
+    /**
+     * 更新设备表(解除绑定)
+     */
+    int updateDeviceForUnbind(UnbindDeviceDTO dto);
+
+    /**
+     * 根据患者ID查询设备信息
+     */
+    BusDevicePO selectByDeviceId(@Param("deviceId") String deviceId);
 }

+ 1 - 0
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/repository/BusTherapyPlanRepository.java

@@ -14,4 +14,5 @@ import org.springframework.stereotype.Repository;
 @Repository
 @Mapper
 public interface BusTherapyPlanRepository extends BaseMapper<BusTherapyPlanPO> {
+
 }

+ 11 - 0
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/repository/BusTherapyRecordRepository.java

@@ -1,5 +1,6 @@
 package cn.tr.module.phototherapy.common.repository;
 
+import cn.tr.module.phototherapy.common.dto.UnbindDeviceDTO;
 import cn.tr.module.phototherapy.common.vo.TherapyRecordDetailVO;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
@@ -34,4 +35,14 @@ public interface BusTherapyRecordRepository extends BaseMapper<BusTherapyRecordP
             @Param("patientUniqueId") String patientUniqueId,
             @Param("startDateTime") Date startDateTime,
             @Param("endDateTime") Date endDateTime);
+
+    /**
+     * 更新治疗状态(解除绑定)
+     */
+    int updateTherapyStatusForUnbind(UnbindDeviceDTO dto);
+
+    /**
+     * 查询患者最新治疗记录
+     */
+    BusTherapyRecordPO   selectLatestByPatientId(@Param("patientUniqueId") String patientUniqueId);
 }

+ 11 - 0
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/service/IBusDeviceService.java

@@ -2,6 +2,9 @@ package cn.tr.module.phototherapy.common.service;
 
 import cn.tr.module.phototherapy.common.dto.BusDeviceDTO;
 import cn.tr.module.phototherapy.common.dto.BusDeviceQueryDTO;
+import cn.tr.module.phototherapy.common.dto.UnbindDeviceDTO;
+import cn.tr.module.phototherapy.common.vo.UnbindDeviceVO;
+
 import java.util.*;
 import java.util.Collection;
 
@@ -52,4 +55,12 @@ public interface IBusDeviceService{
      * @date   2026-01-13
      */
     boolean removeBusDeviceByIds(Collection<String> ids);
+
+    /**
+     * 解绑设备
+     * @param   source 解绑实体类
+     * @author  CodeGenerator
+     * @date    2026-01-23
+     */
+    UnbindDeviceVO unbindDevice(UnbindDeviceDTO source);
 }

+ 85 - 1
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/service/impl/BusDeviceServiceImpl.java

@@ -1,5 +1,18 @@
 package cn.tr.module.phototherapy.common.service.impl;
 
+import cn.tr.module.phototherapy.common.dto.UnbindDeviceDTO;
+import cn.tr.module.phototherapy.common.enums.DeviceStatusEnum;
+import cn.tr.module.phototherapy.common.enums.IsCurrentBindEnum;
+import cn.tr.module.phototherapy.common.enums.TherapyStatusEnum;
+import cn.tr.module.phototherapy.common.mapper.BusClinicMapper;
+import cn.tr.module.phototherapy.common.mapper.BusTherapyPlanMapper;
+import cn.tr.module.phototherapy.common.mapper.BusTherapyRecordMapper;
+import cn.tr.module.phototherapy.common.po.BusTherapyPlanPO;
+import cn.tr.module.phototherapy.common.po.BusTherapyRecordPO;
+import cn.tr.module.phototherapy.common.repository.BusClinicRepository;
+import cn.tr.module.phototherapy.common.repository.BusTherapyPlanRepository;
+import cn.tr.module.phototherapy.common.repository.BusTherapyRecordRepository;
+import cn.tr.module.phototherapy.common.vo.UnbindDeviceVO;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import cn.tr.module.phototherapy.common.po.BusClinicPO;
@@ -27,7 +40,14 @@ import cn.tr.core.exception.TRExcCode;
  **/
 @Service
 public class BusDeviceServiceImpl extends ServiceImpl<BusDeviceRepository, BusDevicePO> implements IBusDeviceService {
-
+    @Autowired
+    private BusClinicRepository busClinicRepository;
+    @Autowired
+    private BusDeviceRepository busDeviceRepository;
+    @Autowired
+    private BusTherapyRecordRepository busTherapyRecordRepository;
+    @Autowired
+    private BusTherapyPlanRepository busTherapyPlanRepository;
     /**
     * 根据条件查询设备表
     * @param    query 查询参数
@@ -103,4 +123,68 @@ public class BusDeviceServiceImpl extends ServiceImpl<BusDeviceRepository, BusDe
         }
         return this.removeByIds(ids);
     };
+
+    /**
+     * 解绑设备
+     * @param   source 解绑实体类
+     * @date    2026-01-23
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public UnbindDeviceVO unbindDevice(UnbindDeviceDTO source) {
+        UnbindDeviceVO vo = new UnbindDeviceVO();
+        try {
+            //  1. 封装数据库更新参数
+            source.setIsCurrentBind(IsCurrentBindEnum.HISTORY_BIND.getValue());        // 改为历史绑定
+            source.setBindEndTime(new Date());                                        // 绑定结束时间=当前时间
+            source.setDeviceStatus(DeviceStatusEnum.NoDevice.getValue());            // 设备状态改为“未使用”
+            source.setTherapyStatus(TherapyStatusEnum.NOT_STARTED.getValue());      // 治疗状态改为“未进行”
+
+            // 2. 执行数据库更新
+            // 更新bus_clinic(绑定关系表)
+            busClinicRepository.updateClinicForUnbind(source);
+            // 更新bus_device(设备表)
+            busDeviceRepository.updateDeviceForUnbind(source);
+            // 更新bus_therapy_record(治疗记录表)
+                        //先查询患者最新治疗记录的当前状态
+            BusTherapyRecordPO latestTherapyRecord = busTherapyRecordRepository.selectLatestByPatientId(source.getPatientUniqueId());
+            if (latestTherapyRecord != null) {
+                Integer currentTherapyStatus = latestTherapyRecord.getTherapyStatus();
+                // 判断逻辑改为:只要状态≠2(未进行),就执行更新
+                if (!TherapyStatusEnum.NOT_STARTED.getValue().equals(currentTherapyStatus)) {
+                    busTherapyRecordRepository.updateTherapyStatusForUnbind(source);
+                }
+                vo.setMessage("解除绑定成功");
+            } else {
+                // 无治疗记录,跳过更新
+                vo.setMessage("解除绑定成功");
+            }
+
+            // 3. 独立查询最新状态(不复用,直接查库)
+            // 3.1 查询绑定状态
+            BusClinicPO clinic = busClinicRepository.selectByPatientUniqueId(source.getPatientUniqueId());
+            IsCurrentBindEnum isCurrentBindEnum = IsCurrentBindEnum.getByValue(clinic.getIsCurrentBind());
+            vo.setIsCurrentBind(isCurrentBindEnum);
+
+            // 3.2 查询治疗状态
+            BusTherapyRecordPO therapyRecord = busTherapyRecordRepository.selectLatestByPatientId(source.getPatientUniqueId());
+            TherapyStatusEnum therapyStatusEnum = TherapyStatusEnum.getByValue(therapyRecord.getTherapyStatus());
+            vo.setTherapyStatus(therapyStatusEnum);
+
+            // 3.4 查询设备状态
+            BusDevicePO device = busDeviceRepository.selectByDeviceId(clinic.getDeviceId());
+            DeviceStatusEnum deviceStatusEnum = DeviceStatusEnum.getByValue(device.getDeviceStatus());
+            vo.setDeviceStatus(deviceStatusEnum);
+
+            // 4. 设置操作结果
+            vo.setSuccess(true);
+            vo.setBindEndTime(new Date());
+
+        } catch (Exception e) {
+            // 异常处理:回滚事务,返回失败信息
+            vo.setSuccess(false);
+            vo.setMessage("解除绑定失败:" + e.getMessage());
+        }
+        return vo;
+    }
 }

+ 2 - 0
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/vo/PatientTherapyDetailVO.java

@@ -3,6 +3,7 @@ package cn.tr.module.phototherapy.common.vo;
 import cn.tr.module.phototherapy.common.enums.*;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotBlank;
 import lombok.Data;
 
 
@@ -30,6 +31,7 @@ public class PatientTherapyDetailVO {
     private PatientGenderEnum patientGender;
 
     @Schema(description = "患者唯一标识")
+    @NotBlank(message = "患者唯一标识不能为空")
     private String patientUniqueId;
 
     @Schema(description = "患者电话")

+ 36 - 0
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/vo/UnbindDeviceVO.java

@@ -0,0 +1,36 @@
+package cn.tr.module.phototherapy.common.vo;
+
+import cn.tr.module.phototherapy.common.enums.DeviceRunStateEnum;
+import cn.tr.module.phototherapy.common.enums.DeviceStatusEnum;
+import cn.tr.module.phototherapy.common.enums.IsCurrentBindEnum;
+import cn.tr.module.phototherapy.common.enums.TherapyStatusEnum;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @ClassName UnbindDeviceVO
+ * @Description 设备解绑VO
+ * @Date 2026/1/23 13:15
+ * @Version 1.0.0
+ */
+
+@Data
+@Schema(description = "设备解绑VO")
+public class UnbindDeviceVO {
+
+    private Boolean success;
+    private String message;
+    private Date bindEndTime;
+
+    @Schema(description = "设备状态")
+    private DeviceStatusEnum deviceStatus;
+
+    @Schema(description = "治疗状态")
+    private TherapyStatusEnum therapyStatus;
+
+    @Schema(description = "是否当前绑定")
+    private IsCurrentBindEnum isCurrentBind;
+
+}

+ 15 - 1
tr-modules/tr-modules-phototherapy/src/main/resources/mapper/phototherapy/BusClinicRepository.xml

@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.tr.module.phototherapy.common.repository.BusClinicRepository">
-
     <select id="selectPatientTherapyDetailById" resultType="cn.tr.module.phototherapy.common.dto.PatientTherapyDetailDTO">
         SELECT c.patient_name,
                c.patient_age,
@@ -100,4 +99,19 @@
 
 
     </select>
+
+    <update id="updateClinicForUnbind" parameterType="cn.tr.module.phototherapy.common.dto.UnbindDeviceDTO">
+        UPDATE bus_clinic
+        SET is_current_bind = #{isCurrentBind},
+            bind_end_time = #{bindEndTime}
+        WHERE patient_unique_id = #{patientUniqueId}  AND is_delete = 0
+    </update>
+    <!-- 根据患者ID查询绑定信息 -->
+    <select id="selectByPatientUniqueId" parameterType="String" resultType="cn.tr.module.phototherapy.common.po.BusClinicPO">
+        SELECT is_current_bind, bind_end_time, bind_start_time, device_id
+        FROM bus_clinic
+        WHERE patient_unique_id = #{patientUniqueId}
+            LIMIT 1
+    </select>
+
 </mapper>

+ 24 - 0
tr-modules/tr-modules-phototherapy/src/main/resources/mapper/phototherapy/BusDeviceRepository.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.tr.module.phototherapy.common.repository.BusDeviceRepository">
+
+    <!-- 更新设备表(解除绑定) -->
+    <update id="updateDeviceForUnbind" parameterType="cn.tr.module.phototherapy.common.dto.UnbindDeviceDTO">
+        UPDATE bus_device
+        SET patient_unique_id = NULL,
+            device_status = #{deviceStatus}
+        WHERE patient_unique_id = #{patientUniqueId}
+            AND is_delete = 0
+    </update>
+
+    <!-- 根据患者ID查询设备信息 -->
+    <select id="selectByDeviceId" parameterType="String" resultType="cn.tr.module.phototherapy.common.po.BusDevicePO">
+        SELECT device_status
+        FROM bus_device
+        WHERE device_id = #{deviceId}
+          AND is_delete = 0
+            LIMIT 1
+        </select>
+</mapper>

+ 23 - 0
tr-modules/tr-modules-phototherapy/src/main/resources/mapper/phototherapy/BusTherapyRecordRepository.xml

@@ -33,5 +33,28 @@
         ORDER BY r.therapy_start_time DESC
     </select>
 
+    <!-- 更新治疗状态(解除绑定) -->
+    <update id="updateTherapyStatusForUnbind" parameterType="cn.tr.module.phototherapy.common.dto.UnbindDeviceDTO">
+        UPDATE bus_therapy_record
+        SET therapy_status = #{therapyStatus}
+        WHERE id = (
+            SELECT id
+            FROM bus_therapy_record
+            WHERE patient_unique_id = #{patientUniqueId}
+              AND is_delete = 0
+            ORDER BY create_time DESC
+            LIMIT 1
+            )
+    </update>
+
+    <!-- 查询最新治疗记录 -->
+    <select id="selectLatestByPatientId" resultType="cn.tr.module.phototherapy.common.po.BusTherapyRecordPO">
+        SELECT therapy_status
+        FROM bus_therapy_record
+        WHERE patient_unique_id = #{patientUniqueId}
+         AND is_delete = 0
+        ORDER BY create_time DESC
+            LIMIT 1
+    </select>
 
 </mapper>