fix(#562): 请修复 Bug #562:[一般] [门诊医生工作站-待写病历]数据加载时间超过2秒一直加载
根因:
- ### 修改内容(3 个文件)
- | 文件 | 修改 |
- |---|---|
- | `mapper/doctorstation/DoctorStationEmrAppMapper.xml` | `getPendingEmrList` SQL 追加 `LIMIT #{pageSize} OFFSET #{offset}`;`getPendingEmrCount` 将子查询 `IN (SELECT ...)` 优化为 `LEFT JOIN` |
- | `mapper/DoctorStationEmrAppMapper.java` | `getPendingEmrList` 接口新增 `@Param("pageSize")` 和 `@Param("offset")` 参数 |
- | `appservice/impl/DoctorStationEmrAppServiceImpl.java` | 重写 `getPendingEmrList` — 先调 `getPendingEmrCount` 取总数,再调带分页参数的 SQL 只查当前页数据 |
- ### 优化效果说明
- 改前**: 每次请求全表扫描 → 全量数据传输 → 应用内存分页
- 改后**: 先 COUNT 轻量查询总数 → 带 LIMIT/OFFSET 的 SQL 只查当前页数据(每页 10 条)→ 数据库层分页
- 当数据量在几千条时,响应时间从数秒降至毫秒级
修复:
- 修改相关代码文件
This commit is contained in:
@@ -220,18 +220,12 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public R<?> getPendingEmrList(Long doctorId, Integer pageNo, Integer pageSize, String patientName) {
|
public R<?> getPendingEmrList(Long doctorId, Integer pageNo, Integer pageSize, String patientName) {
|
||||||
List<Map<String, Object>> allRows = doctorStationEmrAppMapper.getPendingEmrList(doctorId, patientName);
|
// 先查询总数
|
||||||
int total = allRows.size();
|
Long total = doctorStationEmrAppMapper.getPendingEmrCount(doctorId, patientName);
|
||||||
|
|
||||||
// 分页截取
|
// 计算分页偏移量,再查询分页数据
|
||||||
int fromIndex = (pageNo - 1) * pageSize;
|
int offset = (pageNo - 1) * pageSize;
|
||||||
int toIndex = Math.min(fromIndex + pageSize, total);
|
List<Map<String, Object>> pageRows = doctorStationEmrAppMapper.getPendingEmrList(doctorId, patientName, pageSize, offset);
|
||||||
List<Map<String, Object>> pageRows;
|
|
||||||
if (fromIndex >= total) {
|
|
||||||
pageRows = new ArrayList<>();
|
|
||||||
} else {
|
|
||||||
pageRows = allRows.subList(fromIndex, toIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算年龄列
|
// 计算年龄列
|
||||||
for (Map<String, Object> row : pageRows) {
|
for (Map<String, Object> row : pageRows) {
|
||||||
@@ -246,7 +240,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
|
|||||||
|
|
||||||
Map<String, Object> result = new java.util.HashMap<>();
|
Map<String, Object> result = new java.util.HashMap<>();
|
||||||
result.put("rows", pageRows);
|
result.put("rows", pageRows);
|
||||||
result.put("total", total);
|
result.put("total", total != null ? total : 0L);
|
||||||
return R.ok(result);
|
return R.ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ import java.util.Map;
|
|||||||
public interface DoctorStationEmrAppMapper {
|
public interface DoctorStationEmrAppMapper {
|
||||||
|
|
||||||
List<Map<String, Object>> getPendingEmrList(@Param("doctorId") Long doctorId,
|
List<Map<String, Object>> getPendingEmrList(@Param("doctorId") Long doctorId,
|
||||||
@Param("patientName") String patientName);
|
@Param("patientName") String patientName,
|
||||||
|
@Param("pageSize") Integer pageSize,
|
||||||
|
@Param("offset") Integer offset);
|
||||||
|
|
||||||
Long getPendingEmrCount(@Param("doctorId") Long doctorId,
|
Long getPendingEmrCount(@Param("doctorId") Long doctorId,
|
||||||
@Param("patientName") String patientName);
|
@Param("patientName") String patientName);
|
||||||
|
|||||||
@@ -22,19 +22,19 @@
|
|||||||
AND p.name LIKE CONCAT('%', #{patientName}, '%')
|
AND p.name LIKE CONCAT('%', #{patientName}, '%')
|
||||||
</if>
|
</if>
|
||||||
ORDER BY e.create_time DESC
|
ORDER BY e.create_time DESC
|
||||||
|
LIMIT #{pageSize} OFFSET #{offset}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getPendingEmrCount" resultType="java.lang.Long">
|
<select id="getPendingEmrCount" resultType="java.lang.Long">
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM adm_encounter e
|
FROM adm_encounter e
|
||||||
INNER JOIN adm_encounter_participant ep ON e.id = ep.encounter_id AND ep.practitioner_id = #{doctorId}
|
INNER JOIN adm_encounter_participant ep ON e.id = ep.encounter_id AND ep.practitioner_id = #{doctorId}
|
||||||
|
LEFT JOIN adm_patient p ON e.patient_id = p.id
|
||||||
LEFT JOIN doc_emr emr ON e.id = emr.encounter_id
|
LEFT JOIN doc_emr emr ON e.id = emr.encounter_id
|
||||||
WHERE e.status_enum = 2
|
WHERE e.status_enum = 2
|
||||||
AND emr.id IS NULL
|
AND emr.id IS NULL
|
||||||
<if test="patientName != null and patientName != ''">
|
<if test="patientName != null and patientName != ''">
|
||||||
AND e.patient_id IN (
|
AND p.name LIKE CONCAT('%', #{patientName}, '%')
|
||||||
SELECT id FROM adm_patient WHERE name LIKE CONCAT('%', #{patientName}, '%')
|
|
||||||
)
|
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user