perf(database): 优化数据库查询性能和前端请求处理
- 优化ActivityDefinitionManageMapper.xml中的分页查询,减少JOIN操作并使用索引友好的写法 - 修复purchaseinventory组件中API调用的数据传递格式问题 - 将前端请求超时时间从60秒增加到120秒以配合后端超时设置 - 在手术申请页面添加远程搜索防抖功能,避免频繁API调用 - 重构SurgeryAppServiceImpl中的名称字段填充逻辑,使用批量查询减少数据库访问次数 - 优化SurgeryMapper.xml中的分页查询,使用子查询预加载关联数据并减少不必要的JOIN
This commit is contained in:
@@ -533,94 +533,94 @@ public class SurgeryAppServiceImpl implements ISurgeryAppService {
|
||||
|
||||
/**
|
||||
* 填充手术记录中的名称字段
|
||||
* 根据ID反向查询用户表、机构表、手术室表、患者表、就诊表,填充对应的名称字段
|
||||
* 优化:使用批量查询减少数据库访问次数
|
||||
*
|
||||
* @param surgery 手术实体对象
|
||||
*/
|
||||
private void fillSurgeryNameFields(Surgery surgery) {
|
||||
// 收集所有需要查询的ID
|
||||
Set<Long> practitionerIds = new HashSet<>();
|
||||
Set<Long> orgIds = new HashSet<>();
|
||||
Set<Long> otherIds = new HashSet<>();
|
||||
|
||||
// 收集Practitioner IDs
|
||||
if (surgery.getMainSurgeonId() != null) practitionerIds.add(surgery.getMainSurgeonId());
|
||||
if (surgery.getAnesthetistId() != null) practitionerIds.add(surgery.getAnesthetistId());
|
||||
if (surgery.getAssistant1Id() != null) practitionerIds.add(surgery.getAssistant1Id());
|
||||
if (surgery.getAssistant2Id() != null) practitionerIds.add(surgery.getAssistant2Id());
|
||||
if (surgery.getScrubNurseId() != null) practitionerIds.add(surgery.getScrubNurseId());
|
||||
if (surgery.getApplyDoctorId() != null) practitionerIds.add(surgery.getApplyDoctorId());
|
||||
|
||||
// 收集Organization IDs
|
||||
if (surgery.getOrgId() != null) orgIds.add(surgery.getOrgId());
|
||||
if (surgery.getApplyDeptId() != null) orgIds.add(surgery.getApplyDeptId());
|
||||
|
||||
// 批量查询并缓存结果
|
||||
Map<Long, String> practitionerNameMap = new HashMap<>();
|
||||
Map<Long, String> orgNameMap = new HashMap<>();
|
||||
|
||||
// 批量查询Practitioner
|
||||
if (!practitionerIds.isEmpty()) {
|
||||
List<com.openhis.administration.domain.Practitioner> practitioners = practitionerService.listByIds(practitionerIds);
|
||||
for (com.openhis.administration.domain.Practitioner p : practitioners) {
|
||||
practitionerNameMap.put(p.getId(), p.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// 批量查询Organization
|
||||
if (!orgIds.isEmpty()) {
|
||||
List<Organization> orgs = organizationService.listByIds(orgIds);
|
||||
for (Organization o : orgs) {
|
||||
orgNameMap.put(o.getId(), o.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// 填充患者姓名
|
||||
if (surgery.getPatientId() != null) {
|
||||
if (surgery.getPatientId() != null && surgery.getPatientName() == null) {
|
||||
Patient patient = patientService.getById(surgery.getPatientId());
|
||||
if (patient != null) {
|
||||
surgery.setPatientName(patient.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// 填充主刀医生姓名(使用practitionerId查询Practitioner表)
|
||||
if (surgery.getMainSurgeonId() != null) {
|
||||
com.openhis.administration.domain.Practitioner mainSurgeon = practitionerService.getById(surgery.getMainSurgeonId());
|
||||
if (mainSurgeon != null) {
|
||||
surgery.setMainSurgeonName(mainSurgeon.getName());
|
||||
}
|
||||
// 使用缓存填充名称
|
||||
if (surgery.getMainSurgeonId() != null && surgery.getMainSurgeonName() == null) {
|
||||
surgery.setMainSurgeonName(practitionerNameMap.get(surgery.getMainSurgeonId()));
|
||||
}
|
||||
|
||||
// 填充麻醉医生姓名(使用practitionerId查询Practitioner表)
|
||||
if (surgery.getAnesthetistId() != null) {
|
||||
com.openhis.administration.domain.Practitioner anesthetist = practitionerService.getById(surgery.getAnesthetistId());
|
||||
if (anesthetist != null) {
|
||||
surgery.setAnesthetistName(anesthetist.getName());
|
||||
}
|
||||
if (surgery.getAnesthetistId() != null && surgery.getAnesthetistName() == null) {
|
||||
surgery.setAnesthetistName(practitionerNameMap.get(surgery.getAnesthetistId()));
|
||||
}
|
||||
|
||||
// 填充助手1姓名(使用practitionerId查询Practitioner表)
|
||||
if (surgery.getAssistant1Id() != null) {
|
||||
com.openhis.administration.domain.Practitioner assistant1 = practitionerService.getById(surgery.getAssistant1Id());
|
||||
if (assistant1 != null) {
|
||||
surgery.setAssistant1Name(assistant1.getName());
|
||||
}
|
||||
if (surgery.getAssistant1Id() != null && surgery.getAssistant1Name() == null) {
|
||||
surgery.setAssistant1Name(practitionerNameMap.get(surgery.getAssistant1Id()));
|
||||
}
|
||||
|
||||
// 填充助手2姓名(使用practitionerId查询Practitioner表)
|
||||
if (surgery.getAssistant2Id() != null) {
|
||||
com.openhis.administration.domain.Practitioner assistant2 = practitionerService.getById(surgery.getAssistant2Id());
|
||||
if (assistant2 != null) {
|
||||
surgery.setAssistant2Name(assistant2.getName());
|
||||
}
|
||||
if (surgery.getAssistant2Id() != null && surgery.getAssistant2Name() == null) {
|
||||
surgery.setAssistant2Name(practitionerNameMap.get(surgery.getAssistant2Id()));
|
||||
}
|
||||
|
||||
// 填充巡回护士姓名(使用practitionerId查询Practitioner表)
|
||||
if (surgery.getScrubNurseId() != null) {
|
||||
com.openhis.administration.domain.Practitioner scrubNurse = practitionerService.getById(surgery.getScrubNurseId());
|
||||
if (scrubNurse != null) {
|
||||
surgery.setScrubNurseName(scrubNurse.getName());
|
||||
}
|
||||
if (surgery.getScrubNurseId() != null && surgery.getScrubNurseName() == null) {
|
||||
surgery.setScrubNurseName(practitionerNameMap.get(surgery.getScrubNurseId()));
|
||||
}
|
||||
if (surgery.getApplyDoctorId() != null && surgery.getApplyDoctorName() == null) {
|
||||
surgery.setApplyDoctorName(practitionerNameMap.get(surgery.getApplyDoctorId()));
|
||||
}
|
||||
|
||||
// 填充手术室名称
|
||||
if (surgery.getOperatingRoomId() != null) {
|
||||
if (surgery.getOperatingRoomId() != null && surgery.getOperatingRoomName() == null) {
|
||||
OperatingRoom operatingRoom = operatingRoomService.getById(surgery.getOperatingRoomId());
|
||||
if (operatingRoom != null) {
|
||||
surgery.setOperatingRoomName(operatingRoom.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// 填充执行科室名称
|
||||
if (surgery.getOrgId() != null) {
|
||||
Organization org = organizationService.getById(surgery.getOrgId());
|
||||
if (org != null) {
|
||||
surgery.setOrgName(org.getName());
|
||||
}
|
||||
// 使用缓存填充组织名称
|
||||
if (surgery.getOrgId() != null && surgery.getOrgName() == null) {
|
||||
surgery.setOrgName(orgNameMap.get(surgery.getOrgId()));
|
||||
}
|
||||
if (surgery.getApplyDeptId() != null && surgery.getApplyDeptName() == null) {
|
||||
surgery.setApplyDeptName(orgNameMap.get(surgery.getApplyDeptId()));
|
||||
}
|
||||
|
||||
// 填充申请科室名称(如果还没有设置)
|
||||
if (surgery.getApplyDeptId() != null && (surgery.getApplyDeptName() == null || surgery.getApplyDeptName().isEmpty())) {
|
||||
Organization applyDept = organizationService.getById(surgery.getApplyDeptId());
|
||||
if (applyDept != null) {
|
||||
surgery.setApplyDeptName(applyDept.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// 填充申请医生姓名(如果还没有设置) - 使用practitionerId查询Practitioner表
|
||||
if (surgery.getApplyDoctorId() != null && (surgery.getApplyDoctorName() == null || surgery.getApplyDoctorName().isEmpty())) {
|
||||
com.openhis.administration.domain.Practitioner applyDoctor = practitionerService.getById(surgery.getApplyDoctorId());
|
||||
if (applyDoctor != null) {
|
||||
surgery.setApplyDoctorName(applyDoctor.getName());
|
||||
}
|
||||
}
|
||||
|
||||
log.info("填充手术名称字段完成 - patientName: {}, mainSurgeonName: {}, anesthetistName: {}, assistant1Name: {}, assistant2Name: {}, scrubNurseName: {}, operatingRoomName: {}, orgName: {}",
|
||||
surgery.getPatientName(), surgery.getMainSurgeonName(), surgery.getAnesthetistName(), surgery.getAssistant1Name(),
|
||||
surgery.getAssistant2Name(), surgery.getScrubNurseName(), surgery.getOperatingRoomName(), surgery.getOrgName());
|
||||
log.debug("填充手术名称字段完成 - patientName: {}, mainSurgeonName: {}, orgName: {}",
|
||||
surgery.getPatientName(), surgery.getMainSurgeonName(), surgery.getOrgName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user