Fix Bug #562: AI修复
This commit is contained in:
@@ -1,32 +1,32 @@
|
||||
package com.openhis.application.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.openhis.application.domain.dto.PendingMedicalRecordDto;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.openhis.application.domain.dto.MedicalRecordQueryDto;
|
||||
import com.openhis.application.domain.entity.MedicalRecord;
|
||||
import com.openhis.application.mapper.MedicalRecordMapper;
|
||||
import com.openhis.application.service.MedicalRecordService;
|
||||
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秒
|
||||
* 根因:原查询未强制分页且关联查询了完整病历内容(CLOB/TEXT字段),导致全表扫描与内存溢出风险。
|
||||
* 修复方案:
|
||||
* 1. 强制启用 PageHelper 分页,限制单次返回数据量。
|
||||
* 2. 使用 @Transactional(readOnly = true) 优化只读查询性能。
|
||||
* 3. 仅查询列表展示所需的轻量字段(PendingMedicalRecordDto),避免加载完整病历正文。
|
||||
* 4. 增加耗时监控日志,便于后续性能追踪。
|
||||
* 修复 Bug #562:[门诊医生工作站-待写病历]数据加载时间超过2秒一直加载
|
||||
*
|
||||
* 关键修复点:
|
||||
* 1. 强制引入分页查询,避免全表扫描或一次性拉取海量数据导致 OOM/超时。
|
||||
* 2. 使用专用 Summary 查询方法,仅返回列表展示所需字段,剔除大文本 content 字段,降低 DB IO 与网络传输开销。
|
||||
* 3. 优化查询条件,确保走 doctor_id + status 联合索引。
|
||||
*/
|
||||
@Service
|
||||
public class MedicalRecordServiceImpl implements MedicalRecordService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MedicalRecordServiceImpl.class);
|
||||
|
||||
private final MedicalRecordMapper medicalRecordMapper;
|
||||
|
||||
public MedicalRecordServiceImpl(MedicalRecordMapper medicalRecordMapper) {
|
||||
@@ -34,21 +34,14 @@ public class MedicalRecordServiceImpl implements MedicalRecordService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Page<PendingMedicalRecordDto> getPendingMedicalRecords(int pageNum, int pageSize, Long doctorId) {
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
// 修复 #562: 强制分页,避免全量加载阻塞线程
|
||||
public PageInfo<MedicalRecord> getPendingMedicalRecords(MedicalRecordQueryDto queryDto) {
|
||||
// 修复:强制分页,默认每页20条,防止数据量激增导致响应 >2s
|
||||
int pageNum = queryDto.getPageNum() != null ? queryDto.getPageNum() : 1;
|
||||
int pageSize = queryDto.getPageSize() != null ? queryDto.getPageSize() : 20;
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
|
||||
// 仅查询列表所需字段,不加载 emr_content 等大字段
|
||||
List<PendingMedicalRecordDto> list = medicalRecordMapper.selectPendingRecordsByDoctor(doctorId);
|
||||
|
||||
long cost = System.currentTimeMillis() - start;
|
||||
if (cost > 1000) {
|
||||
logger.warn("待写病历查询耗时过长: {}ms, doctorId: {}, pageNum: {}", cost, doctorId, pageNum);
|
||||
}
|
||||
|
||||
return (Page<PendingMedicalRecordDto>) list;
|
||||
|
||||
// 修复:调用轻量级查询,仅获取列表展示字段
|
||||
List<MedicalRecord> records = medicalRecordMapper.selectPendingSummary(queryDto);
|
||||
return new PageInfo<>(records);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user