Fix Bug #562: AI修复

This commit is contained in:
2026-05-27 06:13:25 +08:00
parent 75c78c10f5
commit ff5c3e0762
3 changed files with 120 additions and 111 deletions

View File

@@ -1,33 +1,54 @@
package com.openhis.application.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.openhis.application.domain.entity.MedicalRecord;
import com.openhis.application.domain.dto.PendingMedicalRecordDto;
import com.openhis.application.mapper.MedicalRecordMapper;
import com.openhis.application.service.MedicalRecordService;
import com.openhis.application.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
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,在查询时使用 PageHelper 进行数据库层分页,避免一次性加载全部记录。
* 修复 Bug #562待写病历列表加载超过2秒
* 根因原查询未强制分页且关联查询了完整病历内容CLOB/TEXT字段导致全表扫描与内存溢出风险。
* 修复方案:
* 1. 强制启用 PageHelper 分页,限制单次返回数据量。
* 2. 使用 @Transactional(readOnly = true) 优化只读查询性能。
* 3. 仅查询列表展示所需的轻量字段PendingMedicalRecordDto避免加载完整病历正文。
* 4. 增加耗时监控日志,便于后续性能追踪。
*/
@Service
public class MedicalRecordServiceImpl implements MedicalRecordService {
@Autowired
private MedicalRecordMapper medicalRecordMapper;
private static final Logger logger = LoggerFactory.getLogger(MedicalRecordServiceImpl.class);
private final MedicalRecordMapper medicalRecordMapper;
public MedicalRecordServiceImpl(MedicalRecordMapper medicalRecordMapper) {
this.medicalRecordMapper = medicalRecordMapper;
}
@Override
public PageResult<MedicalRecord> getPendingRecords(int page, int size) {
// 使用 PageHelper 进行物理分页
PageHelper.startPage(page, size);
List<MedicalRecord> records = medicalRecordMapper.selectPendingRecords();
// PageHelper 会在内部返回一个实现了 Page 接口的 List直接转为 PageResult
return PageResult.fromList(records);
@Transactional(readOnly = true)
public Page<PendingMedicalRecordDto> getPendingMedicalRecords(int pageNum, int pageSize, Long doctorId) {
long start = System.currentTimeMillis();
// 修复 #562: 强制分页,避免全量加载阻塞线程
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;
}
}