Browse Source

vo、util

G 1 week ago
parent
commit
cc8cf8dfb4

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


+ 3 - 3
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/controller/BusClinicController.java

@@ -71,8 +71,8 @@ public class BusClinicController extends BaseController{
     }
 
     @Operation(summary = "根据临床id获取患者治疗详情", description = "phototherapy:clinic:query")
-    @GetMapping("/getPatientTherapyDetail/{clinicId}")
-    public CommonResult<PatientTherapyDetailDTO> getPatientTherapyDetail(@PathVariable("clinicId") String clinicId){
-        return CommonResult.success(busClinicService.getPatientTherapyDetailById(clinicId));
+    @GetMapping("/getPatientTherapyDetail/{patientUniqueId}")
+    public CommonResult<PatientTherapyDetailDTO> getPatientTherapyDetail(@PathVariable("patientUniqueId") String patientUniqueId){
+        return CommonResult.success(busClinicService.getPatientTherapyDetailById(patientUniqueId));
     }
 }

+ 53 - 0
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/handle/TimeRangeHandler.java

@@ -0,0 +1,53 @@
+package cn.tr.module.phototherapy.common.handle;
+
+import java.time.LocalDate;
+
+/**
+ * 时间范围处理器
+ * 负责各类时间范围参数的标准化处理
+ */
+public class TimeRangeHandler {
+
+    /**
+     * 处理预设时间范围
+     * @param startDate 原始开始日期
+     * @param endDate 原始结束日期
+     * @param timeRangeType 时间范围类型(1-今日,2-近一周...)
+     * @return 处理后的[startDate, endDate]数组
+     */
+    public static LocalDate[] handleTimeRange(LocalDate startDate, LocalDate endDate, Integer timeRangeType) {
+        if (timeRangeType != null && timeRangeType > 0) {
+            LocalDate now = LocalDate.now();
+            switch (timeRangeType) {
+                case 1: // 今日数据
+                    startDate = now;
+                    endDate = now;
+                    break;
+                case 2: // 最近一周
+                    startDate = now.minusWeeks(1);
+                    endDate = now;
+                    break;
+                case 3: // 最近两周
+                    startDate = now.minusWeeks(2);
+                    endDate = now;
+                    break;
+                case 4: // 最近三周
+                    startDate = now.minusWeeks(3);
+                    endDate = now;
+                    break;
+                case 5: // 最近一月
+                    startDate = now.minusMonths(1);
+                    endDate = now;
+                    break;
+                case 6: // 最近半年
+                    startDate = now.minusMonths(6);
+                    endDate = now;
+                    break;
+                default:
+                    // 未知类型,保留原始值
+                    break;
+            }
+        }
+        return new LocalDate[]{startDate, endDate};
+    }
+}

+ 50 - 0
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/mapper/TherapyRecordConvertMapper.java

@@ -0,0 +1,50 @@
+package cn.tr.module.phototherapy.common.mapper;
+
+import cn.tr.module.phototherapy.common.dto.TherapyRecordDetailDTO;
+
+import cn.tr.module.phototherapy.common.vo.TherapyRecordDetailVO;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.Named;
+
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.List;
+
+/**
+ * @ClassName TherapyRecordConvertMapper
+ * @Description 患者治疗记录转换映射器
+ * @Date 2026/1/21 9:20
+ * @Version 1.0.0
+ */
+@Mapper(componentModel = "spring")
+public interface TherapyRecordConvertMapper {
+
+    @Mapping(target = "therapyDate", source = "therapyStartTime", qualifiedByName = "localDateTimeToDate")
+    @Mapping(target = "phaseType", source = "phaseType")
+    @Mapping(target = "therapyDuration", source = "therapyDuration")
+    @Mapping(target = "therapyPlan", expression = "java(buildTherapyPlan(source.getPhaseFreq(), source.getPhaseDurationMin()))")
+    TherapyRecordDetailDTO toTherapyRecordDetailDTO(TherapyRecordDetailVO source);
+
+    List<TherapyRecordDetailDTO> toTherapyRecordDetailDTOList(List<TherapyRecordDetailVO> source);
+
+    @Named("localDateTimeToDate")
+    default LocalDate localDateTimeToDate(LocalDateTime dateTime) {
+        return dateTime != null ? dateTime.toLocalDate() : null;
+    }
+
+    default String buildTherapyPlan(String phaseFreq, Integer phaseDurationMin) {
+        StringBuilder therapyPlan = new StringBuilder();
+        if (phaseFreq != null && !phaseFreq.trim().isEmpty()) {
+            therapyPlan.append(phaseFreq);
+        }
+        if (phaseDurationMin != null) {
+            if (therapyPlan.length() > 0) {
+                therapyPlan.append("; ");
+            }
+            therapyPlan.append("每次").append(phaseDurationMin).append("min");
+        }
+        return therapyPlan.length() > 0 ? therapyPlan.toString() : "";
+    }
+}

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

@@ -1,8 +1,10 @@
 package cn.tr.module.phototherapy.common.repository;
 
+import cn.tr.module.phototherapy.common.vo.PatientTherapyDetailVO;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
 import cn.tr.module.phototherapy.common.po.BusClinicPO;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 /**
@@ -14,4 +16,10 @@ import org.springframework.stereotype.Repository;
 @Repository
 @Mapper
 public interface BusClinicRepository extends BaseMapper<BusClinicPO> {
+    /**
+     * 根据clinicId查询患者详情
+     * @param patientUniqueId
+     * @return cn.tr.module.phototherapy.common.vo.PatientTherapyDetailVO
+     **/
+    PatientTherapyDetailVO selectPatientTherapyDetailById(@Param("patientUniqueId") String patientUniqueId);
 }

+ 2 - 2
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/service/IBusClinicService.java

@@ -57,8 +57,8 @@ public interface IBusClinicService{
 
     /**
      * 根据临床id获取患者治疗详情
-     * @param   clinicId 临床id
+      * @param  patientUniqueId 患者唯一标识
      * @date    2026-01-20
      */
-    PatientTherapyDetailDTO getPatientTherapyDetailById(String clinicId);
+    PatientTherapyDetailDTO getPatientTherapyDetailById(String patientUniqueId);
 }

+ 105 - 152
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/service/impl/BusClinicServiceImpl.java

@@ -7,6 +7,7 @@ import cn.tr.module.phototherapy.common.po.BusTherapyPlanPO;
 import cn.tr.module.phototherapy.common.po.BusTherapyRecordPO;
 import cn.tr.module.phototherapy.common.repository.BusTherapyPlanRepository;
 import cn.tr.module.phototherapy.common.repository.BusTherapyRecordRepository;
+import cn.tr.module.phototherapy.common.vo.PatientTherapyDetailVO;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
@@ -37,203 +38,155 @@ import cn.tr.core.exception.TRExcCode;
 public class BusClinicServiceImpl extends ServiceImpl<BusClinicRepository, BusClinicPO> implements IBusClinicService {
 
     @Resource
-    private BusTherapyPlanRepository therapyPlanRepository;
-
-    @Resource
-    private BusTherapyRecordRepository therapyRecordRepository;
+    private BusClinicRepository busClinicRepository;
 
 
     /**
-    * 根据条件查询临床表
-    * @param    query 查询参数
-    * @author   CodeGenerator
-    * @date     2026-01-12
-    */
+     * 根据条件查询临床表
+     *
+     * @param query 查询参数
+     * @author CodeGenerator
+     * @date 2026-01-12
+     */
     @Override
-    public List<BusClinicDTO> selectBusClinicList(BusClinicQueryDTO query){
+    public List<BusClinicDTO> selectBusClinicList(BusClinicQueryDTO query) {
         return BusClinicMapper.INSTANCE.convertDtoList(
                 this.list(new LambdaQueryWrapper<BusClinicPO>()
-                    .eq(ObjectUtil.isNotNull(query.getId()), BusClinicPO::getId, query.getId())
-                    .eq(ObjectUtil.isNotNull(query.getPatientUniqueId()), BusClinicPO::getPatientUniqueId, query.getPatientUniqueId())
-                    .eq(ObjectUtil.isNotNull(query.getUserId()), BusClinicPO::getUserId, query.getUserId())
-                    .eq(ObjectUtil.isNotNull(query.getLastTreatmentTime()), BusClinicPO::getLastTreatmentTime, query.getLastTreatmentTime())
-                    .eq(ObjectUtil.isNotNull(query.getTherapyPlanId()), BusClinicPO::getTherapyPlanId, query.getTherapyPlanId())
-                    .like(ObjectUtil.isNotNull(query.getPatientName()), BusClinicPO::getPatientName, query.getPatientName())
-                    .eq(ObjectUtil.isNotNull(query.getPatientAge()), BusClinicPO::getPatientAge, query.getPatientAge())
-                    .eq(ObjectUtil.isNotNull(query.getPatientGender()), BusClinicPO::getPatientGender, query.getPatientGender())
-                    .like(ObjectUtil.isNotNull(query.getPatientPhone()), BusClinicPO::getPatientPhone, query.getPatientPhone())
-                    .like(ObjectUtil.isNotNull(query.getPatientAddress()), BusClinicPO::getPatientAddress, query.getPatientAddress())
-                    .eq(ObjectUtil.isNotNull(query.getDeviceId()), BusClinicPO::getDeviceId, query.getDeviceId())
-                    .eq(ObjectUtil.isNotNull(query.getTenantId()), BusClinicPO::getTenantId, query.getTenantId())
+                        .eq(ObjectUtil.isNotNull(query.getId()), BusClinicPO::getId, query.getId())
+                        .eq(ObjectUtil.isNotNull(query.getPatientUniqueId()), BusClinicPO::getPatientUniqueId, query.getPatientUniqueId())
+                        .eq(ObjectUtil.isNotNull(query.getUserId()), BusClinicPO::getUserId, query.getUserId())
+                        .eq(ObjectUtil.isNotNull(query.getLastTreatmentTime()), BusClinicPO::getLastTreatmentTime, query.getLastTreatmentTime())
+                        .eq(ObjectUtil.isNotNull(query.getTherapyPlanId()), BusClinicPO::getTherapyPlanId, query.getTherapyPlanId())
+                        .like(ObjectUtil.isNotNull(query.getPatientName()), BusClinicPO::getPatientName, query.getPatientName())
+                        .eq(ObjectUtil.isNotNull(query.getPatientAge()), BusClinicPO::getPatientAge, query.getPatientAge())
+                        .eq(ObjectUtil.isNotNull(query.getPatientGender()), BusClinicPO::getPatientGender, query.getPatientGender())
+                        .like(ObjectUtil.isNotNull(query.getPatientPhone()), BusClinicPO::getPatientPhone, query.getPatientPhone())
+                        .like(ObjectUtil.isNotNull(query.getPatientAddress()), BusClinicPO::getPatientAddress, query.getPatientAddress())
+                        .eq(ObjectUtil.isNotNull(query.getDeviceId()), BusClinicPO::getDeviceId, query.getDeviceId())
+                        .eq(ObjectUtil.isNotNull(query.getTenantId()), BusClinicPO::getTenantId, query.getTenantId())
                 )
         );
-    };
+    }
+
+    ;
 
     /**
-    * 根据id查询临床表
-    * @param    id 主键id
-    * @author   CodeGenerator
-    * @date     2026-01-12
-    */
+     * 根据id查询临床表
+     *
+     * @param id 主键id
+     * @author CodeGenerator
+     * @date 2026-01-12
+     */
     @Override
-    public BusClinicDTO selectBusClinicById(String id){
+    public BusClinicDTO selectBusClinicById(String id) {
         return BusClinicMapper.INSTANCE.convertDto(this.getById(id));
-    };
+    }
+
+    ;
 
     /**
-    * 编辑临床表
-    * @param   source 编辑实体类
-    * @author  CodeGenerator
-    * @date    2026-01-12
-    */
+     * 编辑临床表
+     *
+     * @param source 编辑实体类
+     * @author CodeGenerator
+     * @date 2026-01-12
+     */
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public boolean updateBusClinicById(BusClinicDTO source){
-            return this.updateById(BusClinicMapper.INSTANCE.convertPO(source));
-    };
+    public boolean updateBusClinicById(BusClinicDTO source) {
+        return this.updateById(BusClinicMapper.INSTANCE.convertPO(source));
+    }
+
+    ;
 
     /**
-    * 新增临床表
-    * @param   source 新增实体类
-    * @author CodeGenerator
-    * @date 2026-01-12
-    */
+     * 新增临床表
+     *
+     * @param source 新增实体类
+     * @author CodeGenerator
+     * @date 2026-01-12
+     */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public boolean insertBusClinic(BusClinicDTO source){
+    public boolean insertBusClinic(BusClinicDTO source) {
         return this.save(BusClinicMapper.INSTANCE.convertPO(source));
-    };
+    }
+
+    ;
 
     /**
-    * 删除临床表详情
-    * @param  ids 删除主键集合
-    * @author CodeGenerator
-    * @date   2026-01-12
-    */
+     * 删除临床表详情
+     *
+     * @param ids 删除主键集合
+     * @author CodeGenerator
+     * @date 2026-01-12
+     */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public boolean removeBusClinicByIds(Collection<String> ids){
-        if(CollectionUtil.isEmpty(ids)){
-            throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"请选择要删除的数据");
+    public boolean removeBusClinicByIds(Collection<String> ids) {
+        if (CollectionUtil.isEmpty(ids)) {
+            throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "请选择要删除的数据");
         }
         return this.removeByIds(ids);
-    };
+    }
+
+    ;
 
     /***
      * 根据临床表id获取患者治疗详情
-     * @param clinicId
+     * @param patientUniqueId
      * @date 2026-01-20
      **/
     @Override
-    public PatientTherapyDetailDTO getPatientTherapyDetailById(String clinicId) {
-        // 查询临床信息
-        BusClinicPO clinicPO = this.getById(clinicId);
-        if (ObjectUtil.isNull(clinicPO)) {
-            throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "临床信息不存在");
-        }
+    public PatientTherapyDetailDTO getPatientTherapyDetailById(String patientUniqueId) {
+        // 通过多表联查获取数据
+        PatientTherapyDetailVO detailVO = busClinicRepository.selectPatientTherapyDetailById(patientUniqueId);
 
-        // 查询治疗方案信息
-        BusTherapyPlanPO therapyPlanPO = therapyPlanRepository.selectById(clinicPO.getTherapyPlanId());
-
-        // 查询治疗记录信息
-        LambdaQueryWrapper<BusTherapyRecordPO> therapyRecordQuery = new LambdaQueryWrapper<>();
-        therapyRecordQuery.eq(BusTherapyRecordPO::getClinicId, clinicId)
-                .eq(BusTherapyRecordPO::getIsDelete, 0)
-                .orderByDesc(BusTherapyRecordPO::getTherapyStartTime);
-
-        List<BusTherapyRecordPO> therapyRecords = therapyRecordRepository.selectList(therapyRecordQuery);
+        if (detailVO == null) {
+            throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "患者临床信息不存在");
+        }
 
-        // 组装患者治疗详情DTO
+        // 转换为 DTO 并进行必要的业务逻辑处理
         PatientTherapyDetailDTO detailDTO = new PatientTherapyDetailDTO();
 
-        // 设置患者信息(来自bus_clinic表)
-        detailDTO.setPatientName(clinicPO.getPatientName());
-        detailDTO.setPatientAge(clinicPO.getPatientAge());
-        detailDTO.setPatientGender(clinicPO.getPatientGender());
-        detailDTO.setPatientUniqueId(clinicPO.getPatientUniqueId());
-        detailDTO.setPatientPhone(clinicPO.getPatientPhone());
-        detailDTO.setPatientAddress(clinicPO.getPatientAddress());
-        detailDTO.setLastTreatmentTime(clinicPO.getLastTreatmentTime());
-        detailDTO.setGroupType(clinicPO.getGroupType());
-
-        // 统计治疗次数(按天求和)
-        Set<Date> therapyDays = new HashSet<>();
-        if (CollectionUtil.isNotEmpty(therapyRecords)) {
-            for (BusTherapyRecordPO record : therapyRecords) {
-                if (ObjectUtil.isNotNull(record.getTherapyStartTime())) {
-                    therapyDays.add(record.getTherapyStartTime());
-                }
-            }
+        // 基本信息直接复制
+        detailDTO.setPatientName(detailVO.getPatientName());
+        detailDTO.setPatientAge(detailVO.getPatientAge());
+        detailDTO.setPatientGender(detailVO.getPatientGender());
+        detailDTO.setPatientUniqueId(detailVO.getPatientUniqueId());
+        detailDTO.setPatientPhone(detailVO.getPatientPhone());
+        detailDTO.setPatientAddress(detailVO.getPatientAddress());
+        detailDTO.setLastTreatmentTime(detailVO.getLastTreatmentTime());
+        detailDTO.setGroupType(detailVO.getGroupType());
+        detailDTO.setTherapyCount(detailVO.getTherapyCount());
+        detailDTO.setTherapyStatus(String.valueOf(detailVO.getTherapyStatus())); // 转换为字符串
+        detailDTO.setStartTime(detailVO.getStartTime());
+        detailDTO.setPhaseType(detailVO.getPhaseType());
+
+        // 拼接治疗方案
+        StringBuilder therapyPlan = new StringBuilder();
+        if (detailVO.getPhaseFreq() != null && !detailVO.getPhaseFreq().trim().isEmpty()) {
+            therapyPlan.append(detailVO.getPhaseFreq());
         }
-        detailDTO.setTherapyCount(therapyDays.size());
-
-/*        // 计算依从性(这里简化处理,实际需要根据治疗记录和计划计算)
-        detailDTO.setCompliance(0);*/
-
-        // 判断今日治疗状态
-        LocalDate today = LocalDate.now();
-        LambdaQueryWrapper<BusTherapyRecordPO> todayTherapyQuery = new LambdaQueryWrapper<>();
-        todayTherapyQuery.eq(BusTherapyRecordPO::getClinicId, clinicId)
-                .ge(BusTherapyRecordPO::getTherapyStartTime, today.atStartOfDay())
-                .le(BusTherapyRecordPO::getTherapyStartTime, today.atTime(23, 59, 59))
-                .eq(BusTherapyRecordPO::getIsDelete, 0);
-
-        List<BusTherapyRecordPO> todayTherapyRecords = therapyRecordRepository.selectList(todayTherapyQuery);
-        if (CollectionUtil.isEmpty(todayTherapyRecords)) {
-            detailDTO.setTherapyStatus(TherapyStatusEnum.NOT_STARTED.getText()); // 状态为未进行
-        } else {
-            // 根据最新的治疗记录判断状态
-            BusTherapyRecordPO latestTherapyRecord = todayTherapyRecords.get(0);
-            if (ObjectUtil.isNotNull(latestTherapyRecord.getTherapyStatus())) {
-                TherapyStatusEnum statusEnum = TherapyStatusEnum.getByValue(latestTherapyRecord.getTherapyStatus());
-                if (ObjectUtil.isNotNull(statusEnum)) {
-                    detailDTO.setTherapyStatus(statusEnum.getText()); // 不为空,获取当前状态
-                } else {
-                    detailDTO.setTherapyStatus("未知");
-                }
-            } else {
-                detailDTO.setTherapyStatus("未知");
+        if (detailVO.getPhaseDurationMin() != null) {
+            if (therapyPlan.length() > 0) {
+                therapyPlan.append("; ");
             }
+            therapyPlan.append("每次").append(detailVO.getPhaseDurationMin()).append("min");
         }
+        detailDTO.setTherapyPlan(therapyPlan.toString());
 
-        // 设置光疗方案信息
-        if (ObjectUtil.isNotNull(therapyPlanPO)) {
-            // 使用继承的createTime字段
-            if (ObjectUtil.isNotNull(therapyPlanPO.getCreateTime())) {
-                detailDTO.setStartTime(therapyPlanPO.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
-            }
-            detailDTO.setPhaseType(therapyPlanPO.getPhaseType());
-
-            // 组装治疗方案描述
-            String therapyPlan = "";
-            if (ObjectUtil.isNotNull(therapyPlanPO.getPhaseFreq())) {
-                therapyPlan += therapyPlanPO.getPhaseFreq();
-            }
-            if (ObjectUtil.isNotNull(therapyPlanPO.getPhaseDurationMin())) {
-                therapyPlan += "; 每次" + therapyPlanPO.getPhaseDurationMin() + "min";
-            }
-            detailDTO.setTherapyPlan(therapyPlan);
-
-            detailDTO.setPlanDoctor(therapyPlanPO.getPlanDoctor());
-        }
+        detailDTO.setPlanDoctor(detailVO.getPlanDoctor());
 
-        // 设置设备信息
-        detailDTO.setDeviceId(clinicPO.getDeviceId());
-
-        // 查询设备绑定信息
-        // 查询设备绑定信息 - 使用clinic表中的isCurrentBind字段判断是否为当前绑定
-        if (ObjectUtil.isNotNull(clinicPO.getDeviceId()) &&
-                ObjectUtil.isNotNull(clinicPO.getIsCurrentBind()) &&
-                clinicPO.getIsCurrentBind().equals(IsCurrentBindEnum.CURRENT_BIND.getValue()) &&
-                ObjectUtil.isNotNull(clinicPO.getBindStartTime())) {
-            // 如果是当前绑定,则显示绑定开始时间
-            detailDTO.setBindStartTime(clinicPO.getBindStartTime());
+        // 设备信息处理 - 根据当前绑定状态决定是否显示设备
+        if (detailVO.getDeviceId() != null &&
+                detailVO.getBindStartTime() != null) {
+            detailDTO.setDeviceId(detailVO.getDeviceId());
+            detailDTO.setBindStartTime(detailVO.getBindStartTime());
         } else {
-            // 如果不是当前绑定,显示无设备
-            detailDTO.setDeviceId(null); // TODO设置为"无设备"等提示信息
+            detailDTO.setDeviceId(null);
         }
 
         return detailDTO;
-
     }
 }

+ 36 - 0
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/utils/QueryParamUtil.java

@@ -0,0 +1,36 @@
+package cn.tr.module.phototherapy.common.utils;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+
+/**
+ * 通用查询参数工具类
+ * 封装日期→时间转换逻辑,
+ */
+public class QueryParamUtil {
+
+    /**
+     * 将LocalDate转换为当日开始时间(00:00:00.000000)
+     *
+     */
+    public static LocalDateTime convertToStartOfDay(LocalDate localDate) {
+        if (localDate == null) {
+            return null;
+        }
+        // 转为当日0点的LocalDateTime,
+        return localDate.atStartOfDay();
+    }
+
+    /**
+     * 将LocalDate转换为当日结束时间(23:59:59.999999)
+     *
+     */
+    public static LocalDateTime convertToEndOfDay(LocalDate localDate) {
+        if (localDate == null) {
+            return null;
+        }
+        // LocalTime.MAX会自动适配为23:59:59.999999999,
+        return localDate.atTime(LocalTime.MAX);
+    }
+}

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

@@ -0,0 +1,73 @@
+package cn.tr.module.phototherapy.common.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+/**
+ * @ClassName PatientTherapyDetailVO
+ * @Description 患者治疗详情页视图
+ * @Date 2026/1/21 11:01
+ * @Version 1.0.0
+ */
+
+@Data
+@Schema(description = "患者治疗详情视图对象")
+public class PatientTherapyDetailVO {
+
+    // 患者基本信息
+    @Schema(description = "患者姓名")
+    private String patientName;
+
+    @Schema(description = "患者年龄")
+    private Integer patientAge;
+
+    @Schema(description = "患者性别")
+    private Integer patientGender;
+
+    @Schema(description = "患者唯一标识")
+    private String patientUniqueId;
+
+    @Schema(description = "患者电话")
+    private String patientPhone;
+
+    @Schema(description = "患者地址")
+    private String patientAddress;
+
+    @Schema(description = "最后治疗时间")
+    private LocalDateTime lastTreatmentTime;
+
+    @Schema(description = "分组类型")
+    private Integer groupType;
+
+    @Schema(description = "治疗次数")
+    private Integer therapyCount;
+
+    @Schema(description = "治疗状态")
+    private Integer therapyStatus;
+
+    @Schema(description = "开始时间")
+    private LocalDateTime startTime;
+
+    @Schema(description = "干预期")
+    private String phaseType;
+
+    @Schema(description = "阶段频率")
+    private String phaseFreq;
+
+    @Schema(description = "阶段持续时间(分钟)")
+    private Integer phaseDurationMin;
+
+    @Schema(description = "治疗方案")
+    private String therapyPlan;  // 用于存储拼接phaseFreq  phaseDurationMin后的结果
+
+    @Schema(description = "方案医生")
+    private String planDoctor;
+
+    @Schema(description = "设备ID")
+    private String deviceId;
+
+    @Schema(description = "绑定开始时间")
+    private LocalDateTime bindStartTime;
+}

+ 34 - 0
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/vo/TherapyRecordDetailVO.java

@@ -0,0 +1,34 @@
+package cn.tr.module.phototherapy.common.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+
+/**
+ * 治疗记录视图对象
+ *
+ * @Date 2026/1/121 9:14
+ */
+
+@Data
+@Schema(description = "治疗记录视图对象")
+public class TherapyRecordDetailVO {
+
+    @Schema(description = "治疗开始时间")
+    private LocalDateTime therapyStartTime;
+
+    @Schema(description = "治疗时长")
+    private Integer therapyDuration;
+
+    @Schema(description = "阶段类型")
+    private String phaseType;
+
+    @Schema(description = "阶段频率")
+    private String phaseFreq;
+
+    @Schema(description = "阶段持续时间(分钟)")
+    private Integer phaseDurationMin;
+}

+ 38 - 0
tr-modules/tr-modules-phototherapy/src/main/resources/mapper/phototherapy/BusClinicRepository.xml

@@ -0,0 +1,38 @@
+<?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="selectPatientTherapyDetailByPatientUniqueId" resultType="cn.tr.module.phototherapy.common.vo.PatientTherapyDetailVO">
+        SELECT
+            c.patient_name,
+            c.patient_age,
+            c.patient_gender,
+            c.patient_unique_id,
+            c.patient_phone,
+            c.patient_address,
+            c.last_treatment_time,
+            c.group_type,
+            COUNT(DISTINCT DATE(r.therapy_start_time)) as therapy_count,
+            COALESCE(MAX(r_today.therapy_status), 0) as therapy_status,
+            tp.create_time as startTime,
+            tp.phase_type,
+            tp.phase_freq,
+            tp.phase_duration_min,
+            tp.plan_doctor,
+            c.device_id,
+            c.bind_start_time
+        FROM bus_clinic c
+                 LEFT JOIN bus_therapy_plan tp ON c.therapy_plan_id = tp.id
+                 LEFT JOIN bus_therapy_record r ON c.id = r.clinic_id AND r.is_delete = 0
+                 LEFT JOIN bus_therapy_record r_today ON c.id = r_today.clinic_id
+            AND r_today.is_delete = 0
+            AND DATE(r_today.therapy_start_time) = DATE(NOW())
+        WHERE c.patient_unique_id = #{patientUniqueId}
+          AND c.is_delete = 0
+        GROUP BY
+            c.patient_name, c.patient_age, c.patient_gender, c.patient_unique_id,
+            c.patient_phone, c.patient_address, c.last_treatment_time, c.group_type,
+            tp.create_time, tp.phase_type, tp.phase_freq,
+            tp.phase_duration_min, tp.plan_doctor, c.device_id, c.bind_start_time
+    </select>
+</mapper>

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

@@ -0,0 +1,37 @@
+<?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.BusTherapyRecordRepository">
+
+    <resultMap id="TherapyRecordVOMap" type="cn.tr.module.phototherapy.common.vo.TherapyRecordDetailVO">
+        <result column="therapy_start_time" property="therapyStartTime"/>
+        <result column="therapy_duration" property="therapyDuration"/>
+        <result column="phase_type" property="phaseType"/>
+        <result column="phase_freq" property="phaseFreq"/>
+        <result column="phase_duration_min" property="phaseDurationMin"/>
+    </resultMap>
+
+    <select id="selectTherapyRecordWithPlan" resultMap="TherapyRecordVOMap">
+        SELECT
+        r.therapy_start_time,
+        r.therapy_duration,
+        p.phase_type,
+        p.phase_freq,
+        p.phase_duration_min
+        FROM bus_therapy_record r
+        LEFT JOIN bus_clinic c ON r.clinic_id = c.id
+        LEFT JOIN bus_therapy_plan p ON c.therapy_plan_id = p.id
+        WHERE r.clinic_id = #{clinicId}
+        AND r.is_delete = 0
+        <if test="startDateTime != null">
+            AND r.therapy_start_time >= #{startDateTime}
+        </if>
+        <if test="endDateTime != null">
+            AND r.therapy_start_time &lt;= #{endDateTime}
+        </if>
+        ORDER BY r.therapy_start_time DESC
+    </select>
+
+
+</mapper>