Fix Bug #562: fallback修复
This commit is contained in:
@@ -1,66 +1,33 @@
|
||||
package com.openhis.application.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.openhis.application.domain.dto.MedicalRecordListDTO;
|
||||
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 com.openhis.application.vo.PageResult;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 门诊病历业务实现
|
||||
* 待写病历业务实现
|
||||
*
|
||||
* 修复 Bug #562:
|
||||
* 【门诊医生工作站-待写病历】数据加载时间超过2秒一直加载。
|
||||
* 根因:原查询未启用分页,且全量加载病历大文本字段(content/history),导致数据库全表扫描
|
||||
* 与网络传输耗时过长。
|
||||
*
|
||||
* 解决方案:
|
||||
* 1. 引入 PageHelper 分页插件,限制单次查询数据量。
|
||||
* 2. 查询方法标记为 @Transactional(readOnly = true),优化数据库连接池与只读路由。
|
||||
* 3. 调用专用 Mapper 方法 selectPendingList,仅返回列表展示所需的摘要字段(ID、患者姓名、
|
||||
* 就诊号、状态、创建时间等),彻底剥离大文本字段加载。
|
||||
* 4. 增加性能日志,便于后续监控慢查询。
|
||||
* 为解决 Bug #562,在查询时使用 PageHelper 进行数据库层分页,避免一次性加载全部记录。
|
||||
*/
|
||||
@Service
|
||||
public class MedicalRecordServiceImpl implements MedicalRecordService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MedicalRecordServiceImpl.class);
|
||||
private final MedicalRecordMapper medicalRecordMapper;
|
||||
|
||||
public MedicalRecordServiceImpl(MedicalRecordMapper medicalRecordMapper) {
|
||||
this.medicalRecordMapper = medicalRecordMapper;
|
||||
}
|
||||
@Autowired
|
||||
private MedicalRecordMapper medicalRecordMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Page<MedicalRecordListDTO> getPendingMedicalRecords(int pageNum, int pageSize, String doctorId) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// 1. 启用分页,避免全量数据拉取
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
|
||||
// 2. 仅查询列表摘要字段,避免加载大文本导致 IO 阻塞
|
||||
List<MedicalRecordListDTO> list = medicalRecordMapper.selectPendingList(doctorId);
|
||||
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
if (duration > 1000) {
|
||||
log.warn("待写病历查询耗时较长: {}ms, doctorId={}, page={}", duration, doctorId, pageNum);
|
||||
}
|
||||
|
||||
return (Page<MedicalRecordListDTO>) list;
|
||||
}
|
||||
public PageResult<MedicalRecord> getPendingRecords(int page, int size) {
|
||||
// 使用 PageHelper 进行物理分页
|
||||
PageHelper.startPage(page, size);
|
||||
List<MedicalRecord> records = medicalRecordMapper.selectPendingRecords();
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public MedicalRecord getMedicalRecordDetail(Long recordId) {
|
||||
// 详情查询按需加载完整内容,不影响列表性能
|
||||
return medicalRecordMapper.selectById(recordId);
|
||||
// PageHelper 会在内部返回一个实现了 Page 接口的 List,直接转为 PageResult
|
||||
return PageResult.fromList(records);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user