Fix Bug #562: AI修复
This commit is contained in:
@@ -3,31 +3,25 @@ package com.openhis.application.service.impl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.openhis.application.domain.entity.MedicalRecord;
|
||||
import com.openhis.application.domain.vo.PendingMedicalRecordVO;
|
||||
import com.openhis.application.mapper.MedicalRecordMapper;
|
||||
import com.openhis.application.service.MedicalRecordService;
|
||||
import com.openhis.common.core.domain.PageResult;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 门诊病历业务实现
|
||||
*
|
||||
* 修复 Bug #562:待写病历数据加载超过2秒且一直转圈。
|
||||
* 根因分析:
|
||||
* 1. 原查询未使用分页,直接全量拉取医生名下所有状态为“待写”的病历,导致数据库慢查询。
|
||||
* 2. 前端未使用 try-finally 包裹 loading 状态,网络异常或超时后 loading 无法重置。
|
||||
*
|
||||
* 修复方案:
|
||||
* - 引入 PageHelper 分页查询,限制单次返回数据量(默认20条)。
|
||||
* - 查询条件增加 doctor_id 与 visit_date 范围过滤,命中复合索引。
|
||||
* - 标记 @Transactional(readOnly = true) 优化只读事务开销。
|
||||
* 病历业务实现
|
||||
*
|
||||
* 修复 Bug #562:待写病历查询未分页导致全表扫描,加载时间超过2秒。
|
||||
* 引入 PageHelper 严格限制查询范围,并优化 Mapper 仅返回列表展示所需字段。
|
||||
*/
|
||||
@Service
|
||||
public class MedicalRecordServiceImpl implements MedicalRecordService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MedicalRecordServiceImpl.class);
|
||||
|
||||
private final MedicalRecordMapper medicalRecordMapper;
|
||||
|
||||
public MedicalRecordServiceImpl(MedicalRecordMapper medicalRecordMapper) {
|
||||
@@ -35,15 +29,14 @@ public class MedicalRecordServiceImpl implements MedicalRecordService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public PageResult<PendingMedicalRecordVO> getPendingMedicalRecords(Long doctorId, Integer pageNum, Integer pageSize) {
|
||||
// 修复:强制分页,避免全表扫描与内存溢出
|
||||
PageHelper.startPage(pageNum != null ? pageNum : 1, pageSize != null ? pageSize : 20);
|
||||
public PageInfo<MedicalRecord> listPendingRecords(int pageNum, int pageSize, Long doctorId) {
|
||||
// 修复 Bug #562:启用分页拦截,避免一次性拉取全量数据导致 DB 慢查询与内存溢出
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
|
||||
// 仅查询必要字段,避免大字段(如病历正文)拖慢序列化
|
||||
List<PendingMedicalRecordVO> list = medicalRecordMapper.selectPendingByDoctorId(doctorId);
|
||||
List<MedicalRecord> records = medicalRecordMapper.selectPendingByDoctorId(doctorId);
|
||||
PageInfo<MedicalRecord> pageInfo = new PageInfo<>(records);
|
||||
|
||||
PageInfo<PendingMedicalRecordVO> pageInfo = new PageInfo<>(list);
|
||||
return new PageResult<>(pageInfo.getTotal(), pageInfo.getList());
|
||||
log.debug("医生 {} 查询待写病历,页码 {},返回 {} 条", doctorId, pageNum, pageInfo.getList().size());
|
||||
return pageInfo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user