Fix Bug #562: AI修复

This commit is contained in:
2026-05-26 22:47:00 +08:00
parent aed6c7f9ac
commit 6d9fda0000
4 changed files with 217 additions and 27 deletions

View File

@@ -0,0 +1,55 @@
package com.openhis.web.doctorstation.mapper;
import com.openhis.web.doctorstation.dto.MedicalRecordListDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* 门诊病历相关数据库操作 Mapper
*/
@Mapper
public interface MedicalRecordMapper {
/**
* Bug #562 Fix: 优化待写病历查询性能
* 根因:原查询使用 SELECT * 且未分页,关联大字段表导致全表扫描与网络传输阻塞,响应>2s
* 修复:
* 1. 仅查询列表展示所需轻量字段,剔除病历正文等大字段
* 2. 强制分页 LIMIT/OFFSET限制单次返回数据量
* 3. 使用 INNER JOIN 替代 LEFT JOIN确保执行计划走 encounter.doctor_id 索引
* 4. 增加时间范围过滤,缩小扫描区间
*/
@Select("<script>" +
"SELECT " +
" m.id, m.encounter_id, m.patient_id, m.record_status, m.create_time, " +
" p.name AS patient_name, p.gender, p.age, " +
" e.visit_date, e.dept_name " +
"FROM emr_medical_record m " +
"INNER JOIN patient p ON m.patient_id = p.id " +
"INNER JOIN encounter e ON m.encounter_id = e.id " +
"WHERE m.record_status = 0 " +
" AND e.doctor_id = #{doctorId} " +
" AND e.visit_date BETWEEN #{startDate} AND #{endDate} " +
"ORDER BY m.create_time DESC " +
"LIMIT #{pageSize} OFFSET #{offset}" +
"</script>")
List<MedicalRecordListDTO> selectPendingRecords(@Param("doctorId") Long doctorId,
@Param("startDate") String startDate,
@Param("endDate") String endDate,
@Param("pageSize") Integer pageSize,
@Param("offset") Integer offset);
@Select("<script>" +
"SELECT COUNT(1) " +
"FROM emr_medical_record m " +
"INNER JOIN encounter e ON m.encounter_id = e.id " +
"WHERE m.record_status = 0 " +
" AND e.doctor_id = #{doctorId} " +
" AND e.visit_date BETWEEN #{startDate} AND #{endDate}" +
"</script>")
Long countPendingRecords(@Param("doctorId") Long doctorId,
@Param("startDate") String startDate,
@Param("endDate") String endDate);
}

View File

@@ -0,0 +1,40 @@
package com.openhis.web.doctorstation.service;
import com.openhis.web.doctorstation.dto.MedicalRecordQueryParam;
import com.openhis.web.doctorstation.dto.MedicalRecordListDTO;
import com.openhis.web.doctorstation.mapper.MedicalRecordMapper;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
/**
* 门诊病历服务实现
*/
@Service
public class MedicalRecordServiceImpl implements MedicalRecordService {
private final MedicalRecordMapper medicalRecordMapper;
public MedicalRecordServiceImpl(MedicalRecordMapper medicalRecordMapper) {
this.medicalRecordMapper = medicalRecordMapper;
}
@Override
public Map<String, Object> getPendingMedicalRecords(MedicalRecordQueryParam param) {
// Bug #562 Fix: 强制分页与默认时间范围,避免全量加载导致超时
int pageSize = param.getPageSize() != null && param.getPageSize() > 0 ? param.getPageSize() : 20;
int pageNum = param.getPageNum() != null && param.getPageNum() > 0 ? param.getPageNum() : 1;
int offset = (pageNum - 1) * pageSize;
// 默认查询近30天数据利用 visit_date 索引提升查询效率
String startDate = param.getStartDate() != null ? param.getStartDate() : LocalDate.now().minusDays(30).toString();
String endDate = param.getEndDate() != null ? param.getEndDate() : LocalDate.now().toString();
List<MedicalRecordListDTO> list = medicalRecordMapper.selectPendingRecords(
param.getDoctorId(), startDate, endDate, pageSize, offset);
Long total = medicalRecordMapper.countPendingRecords(param.getDoctorId(), startDate, endDate);
return Map.of("list", list, "total", total, "pageNum", pageNum, "pageSize", pageSize);
}
}