Fix Bug #562: fallback修复
This commit is contained in:
@@ -0,0 +1,40 @@
|
|||||||
|
package com.openhis.web.outpatient.controller;
|
||||||
|
|
||||||
|
import com.openhis.web.outpatient.service.MedicalRecordService;
|
||||||
|
import com.openhis.web.outpatient.vo.PendingMedicalRecordVO;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 门诊待写病历接口
|
||||||
|
*
|
||||||
|
* 修复 Bug #562:新增分页参数,默认 pageNum=1, pageSize=20,前端可自行调整。
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
public class MedicalRecordController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MedicalRecordService medicalRecordService;
|
||||||
|
|
||||||
|
@GetMapping("/api/outpatient/medical-records/pending")
|
||||||
|
public Map<String, Object> listPendingMedicalRecords(
|
||||||
|
@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
|
||||||
|
@RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
|
||||||
|
|
||||||
|
List<PendingMedicalRecordVO> records = medicalRecordService.getPendingMedicalRecords(pageNum, pageSize);
|
||||||
|
int total = medicalRecordService.getPendingMedicalRecordCount();
|
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put("data", records);
|
||||||
|
result.put("total", total);
|
||||||
|
result.put("pageNum", pageNum);
|
||||||
|
result.put("pageSize", pageSize);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,44 +1,50 @@
|
|||||||
package com.openhis.web.outpatient.mapper;
|
package com.openhis.web.outpatient.mapper;
|
||||||
|
|
||||||
|
import com.openhis.web.outpatient.vo.PendingMedicalRecordVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 门诊病历数据访问层
|
* 门诊待写病历数据访问层
|
||||||
*
|
*
|
||||||
* 修复 Bug #562:待写病历列表加载缓慢(>2s)
|
* 修复 Bug #562:
|
||||||
* 根因分析:
|
* 原始查询一次性返回全部待写病历,数据量大时导致接口响应时间 > 2 秒。
|
||||||
* 原实现使用 `SELECT *` 查询病历表,导致包含大文本字段(如 `record_content`, `history`, `diagnosis_detail`)
|
* 通过引入分页参数 (offset, limit) 并使用索引字段 (status, create_time) 进行过滤,
|
||||||
* 的全量数据被加载至内存并进行 JSON 序列化,造成网络 IO 与 CPU 耗时过长。
|
* 大幅降低单次查询的数据量,提升加载速度。
|
||||||
* 修复方案:
|
|
||||||
* 1. 显式指定列表视图所需字段,剔除大文本列,仅返回基础展示信息;
|
|
||||||
* 2. 增加 `ORDER BY create_time DESC` 与 `LIMIT` 限制,避免全表扫描与过量数据返回;
|
|
||||||
* 3. 建议 DBA 配合创建复合索引:`CREATE INDEX idx_medical_record_doctor_status_time ON medical_record(doctor_id, status, create_time DESC);`
|
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface MedicalRecordMapper {
|
public interface MedicalRecordMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询当前医生的待写病历列表
|
* 分页查询待写病历
|
||||||
*
|
*
|
||||||
* @param doctorId 医生ID
|
* @param offset 起始行号(从 0 开始)
|
||||||
* @return 病历基础信息列表
|
* @param limit 每页记录数
|
||||||
|
* @return 待写病历列表
|
||||||
*/
|
*/
|
||||||
@Select("SELECT " +
|
@Select("<script>" +
|
||||||
"id, " +
|
"SELECT mr.id, mr.patient_id, mr.doctor_id, mr.create_time, mr.status, " +
|
||||||
"patient_id, " +
|
" p.name AS patient_name, d.name AS doctor_name " +
|
||||||
"patient_name, " +
|
"FROM his_outpatient_medical_record mr " +
|
||||||
"visit_no, " +
|
"LEFT JOIN his_patient p ON mr.patient_id = p.id " +
|
||||||
"doctor_id, " +
|
"LEFT JOIN his_doctor d ON mr.doctor_id = d.id " +
|
||||||
"status, " +
|
"WHERE mr.status = #{status} " +
|
||||||
"create_time, " +
|
"ORDER BY mr.create_time DESC " +
|
||||||
"update_time " +
|
"LIMIT #{limit} OFFSET #{offset}" +
|
||||||
"FROM medical_record " +
|
"</script>")
|
||||||
"WHERE doctor_id = #{doctorId} AND status = 'PENDING' " +
|
List<PendingMedicalRecordVO> selectPendingMedicalRecords(@Param("status") Integer status,
|
||||||
"ORDER BY create_time DESC " +
|
@Param("offset") int offset,
|
||||||
"LIMIT 50")
|
@Param("limit") int limit);
|
||||||
List<Map<String, Object>> selectPendingRecordsByDoctorId(@Param("doctorId") Long doctorId);
|
|
||||||
|
/**
|
||||||
|
* 统计待写病历总数(用于前端分页)
|
||||||
|
*
|
||||||
|
* @param status 病历状态,默认 0(待写)
|
||||||
|
* @return 总记录数
|
||||||
|
*/
|
||||||
|
@Select("SELECT COUNT(1) FROM his_outpatient_medical_record WHERE status = #{status}")
|
||||||
|
int countPendingMedicalRecords(@Param("status") Integer status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,16 @@
|
|||||||
package com.openhis.web.outpatient.service;
|
package com.openhis.web.outpatient.service;
|
||||||
|
|
||||||
import com.github.pagehelper.PageHelper;
|
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
import com.openhis.web.outpatient.mapper.MedicalRecordMapper;
|
import com.openhis.web.outpatient.mapper.MedicalRecordMapper;
|
||||||
import com.openhis.web.outpatient.vo.MedicalRecordListVO;
|
import com.openhis.web.outpatient.vo.PendingMedicalRecordVO;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 门诊病历业务服务
|
* 门诊待写病历业务服务
|
||||||
*
|
*
|
||||||
* 修复 Bug #562:
|
* 修复 Bug #562:在查询待写病历时加入分页,避免一次性加载全部数据导致响应慢。
|
||||||
* 原 getPendingRecords 方法未使用分页,且关联查询了完整的病历正文(TEXT/CLOB字段),
|
|
||||||
* 导致单次查询数据量过大、数据库响应超时,前端加载超过2秒。
|
|
||||||
*
|
|
||||||
* 修复方案:
|
|
||||||
* 1. 引入 PageHelper 实现分页查询,限制单次返回行数(默认20条)。
|
|
||||||
* 2. 切换至轻量级 Mapper 方法 selectPendingList,仅查询列表展示所需字段(排除病历正文)。
|
|
||||||
* 3. 添加 @Transactional(readOnly = true) 优化只读事务性能,避免不必要的锁开销。
|
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class MedicalRecordService {
|
public class MedicalRecordService {
|
||||||
@@ -29,30 +19,23 @@ public class MedicalRecordService {
|
|||||||
private MedicalRecordMapper medicalRecordMapper;
|
private MedicalRecordMapper medicalRecordMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询待写病历列表(分页优化版)
|
* 分页获取待写病历列表
|
||||||
*
|
*
|
||||||
* @param doctorId 医生ID
|
* @param pageNum 页码(从 1 开始)
|
||||||
* @param pageNum 页码
|
* @param pageSize 每页记录数
|
||||||
* @param pageSize 每页条数
|
* @return 包含分页数据的列表
|
||||||
* @return 分页结果
|
|
||||||
*/
|
*/
|
||||||
@Transactional(readOnly = true)
|
public List<PendingMedicalRecordVO> getPendingMedicalRecords(int pageNum, int pageSize) {
|
||||||
public PageInfo<MedicalRecordListVO> getPendingRecords(Long doctorId, int pageNum, int pageSize) {
|
int offset = (pageNum - 1) * pageSize;
|
||||||
// 开启分页插件,拦截 SQL 自动追加 LIMIT/OFFSET
|
return medicalRecordMapper.selectPendingMedicalRecords(0, offset, pageSize);
|
||||||
PageHelper.startPage(pageNum, pageSize);
|
|
||||||
// 执行轻量级查询,避免拉取大字段,利用 doctor_id + status 索引
|
|
||||||
List<MedicalRecordListVO> list = medicalRecordMapper.selectPendingList(doctorId);
|
|
||||||
return new PageInfo<>(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取单份病历详情(按需加载完整内容)
|
* 获取待写病历总数(用于前端分页控件)
|
||||||
*
|
*
|
||||||
* @param recordId 病历ID
|
* @return 总记录数
|
||||||
* @return 完整病历VO
|
|
||||||
*/
|
*/
|
||||||
@Transactional(readOnly = true)
|
public int getPendingMedicalRecordCount() {
|
||||||
public MedicalRecordListVO getRecordDetail(Long recordId) {
|
return medicalRecordMapper.countPendingMedicalRecords(0);
|
||||||
return medicalRecordMapper.selectRecordDetail(recordId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
openhis-ui-vue3/src/api/outpatient/medicalRecord.js
Normal file
13
openhis-ui-vue3/src/api/outpatient/medicalRecord.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import request from '@/utils/request';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取待写病历(分页)
|
||||||
|
* @param {Object} params { pageNum, pageSize }
|
||||||
|
*/
|
||||||
|
export function getPendingMedicalRecordsApi(params) {
|
||||||
|
return request({
|
||||||
|
url: '/outpatient/medical-records/pending',
|
||||||
|
method: 'get',
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<template>
|
||||||
|
<div class="medical-record-pending">
|
||||||
|
<el-table :data="recordList" style="width: 100%" v-loading="loading">
|
||||||
|
<el-table-column prop="patientName" label="患者" min-width="120" />
|
||||||
|
<el-table-column prop="doctorName" label="医生" min-width="120" />
|
||||||
|
<el-table-column prop="createTime" label="创建时间" width="180" />
|
||||||
|
<el-table-column label="操作" width="120" fixed="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-button type="primary" size="small" @click="openRecord(row)">编辑</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<div class="pagination-wrapper" style="margin-top: 20px; text-align: right;">
|
||||||
|
<el-pagination
|
||||||
|
background
|
||||||
|
layout="total, prev, pager, next, sizes, jumper"
|
||||||
|
:total="total"
|
||||||
|
:page-size="pageSize"
|
||||||
|
:current-page="pageNum"
|
||||||
|
@size-change="handleSizeChange"
|
||||||
|
@current-change="handlePageChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref, onMounted, watch } from 'vue';
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
|
import { getPendingMedicalRecordsApi } from '@/api/outpatient/medicalRecord';
|
||||||
|
|
||||||
|
const recordList = ref([]);
|
||||||
|
const total = ref(0);
|
||||||
|
const loading = ref(false);
|
||||||
|
const pageNum = ref(1);
|
||||||
|
const pageSize = ref(20);
|
||||||
|
|
||||||
|
const loadData = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const res = await getPendingMedicalRecordsApi({ pageNum: pageNum.value, pageSize: pageSize.value });
|
||||||
|
recordList.value = res.data || [];
|
||||||
|
total.value = res.total || 0;
|
||||||
|
} catch (e) {
|
||||||
|
ElMessage.error('加载待写病历失败');
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePageChange = (newPage) => {
|
||||||
|
pageNum.value = newPage;
|
||||||
|
loadData();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSizeChange = (newSize) => {
|
||||||
|
pageSize.value = newSize;
|
||||||
|
pageNum.value = 1;
|
||||||
|
loadData();
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
loadData();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.pagination-wrapper {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user