perf(doctorstation): 优化数据库查询性能添加LIMIT 1限制

- 在手术记录查询中添加.last("LIMIT 1")避免全表扫描
- 在费用项查询中添加.last("LIMIT 1")提高查询效率
- 在库存项查询中添加.last("LIMIT 1")减少数据检索量
- 在病历查询中添加.last("LIMIT 1")并按创建时间降序排列
- 在组织机构查询中添加.last("LIMIT 1")限制返回结果
- 在检验申请单查询中添加.last("LIMIT 1)")优化查找性能
- 在分诊队列项查询中添加.last("LIMIT 1)")提升检索速度
This commit is contained in:
2026-05-29 21:31:31 +08:00
parent 19233876a4
commit 10835d24d1
4 changed files with 13 additions and 13 deletions

View File

@@ -1920,7 +1920,7 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
Surgery surgery = iSurgeryService.getOne(
new LambdaQueryWrapper<Surgery>()
.eq(Surgery::getSurgeryNo, prescriptionNo)
.and(w -> w.isNull(Surgery::getDeleteFlag).or().eq(Surgery::getDeleteFlag, "0")));
.and(w -> w.isNull(Surgery::getDeleteFlag).or().eq(Surgery::getDeleteFlag, "0")).last("LIMIT 1"));
if (surgery != null) {
iSurgeryService.removeById(surgery.getId());
log.info("handService - 级联删除手术记录 cli_surgery: surgeryNo={}, id={}", prescriptionNo, surgery.getId());
@@ -2186,7 +2186,7 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
.eq(ChargeItem::getServiceId, adviceSaveDto.getRequestId())
.eq(ChargeItem::getServiceTable, CommonConstants.TableName.WOR_SERVICE_REQUEST)
.eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode())
);
.last("LIMIT 1"));
log.info("BugFix#328: 通过requestId查询费用项requestId={}, chargeItem={}",
adviceSaveDto.getRequestId(), existingChargeItem != null ? existingChargeItem.getId() : "null");
}
@@ -2295,7 +2295,7 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
new LambdaQueryWrapper<InventoryItem>()
.eq(InventoryItem::getItemId, dispense.getMedicationId())
.eq(InventoryItem::getLotNumber, dispense.getLotNumber())
);
.last("LIMIT 1"));
if (inventoryItem != null) {
// 计算回滚后的数量(加上已发放的数量)

View File

@@ -75,7 +75,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
Emr emr = new Emr();
BeanUtils.copyProperties(patientEmrDto, emr);
String contextStr = patientEmrDto.getContextJson().toString();
Emr patientEmr = emrService.getOne(new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, emr.getEncounterId()));
Emr patientEmr = emrService.getOne(new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, emr.getEncounterId()).last("LIMIT 1"));
boolean saveSuccess;
// 如果已经保存病历,再次保存走更新
if (patientEmr != null) {
@@ -137,7 +137,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
@Override
public R<?> getEmrDetail(Long encounterId) {
// 先查询门诊病历(emr表)
Emr emrDetail = emrService.getOne(new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, encounterId));
Emr emrDetail = emrService.getOne(new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, encounterId).orderByDesc(Emr::getCreateTime).last("LIMIT 1"));
if (emrDetail != null) {
return R.ok(emrDetail);
}
@@ -266,7 +266,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
public R<?> checkNeedWriteEmr(Long encounterId) {
// 检查该就诊记录是否已经有病历
Emr existingEmr = emrService.getOne(
new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, encounterId)
new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, encounterId).last("LIMIT 1")
);
// 如果没有病历,则需要写病历

View File

@@ -274,7 +274,7 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
new QueryWrapper<Organization>()
.eq("bus_no", performDeptCode)
.eq("delete_flag", "0")
);
.last("LIMIT 1"));
if (organization != null) {
positionId = organization.getId();
} else {
@@ -410,7 +410,7 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
new QueryWrapper<InspectionLabApply>()
.eq("apply_no", applyNo)
.eq("delete_flag", DelFlag.NO.getCode())
);
.last("LIMIT 1"));
if (mainEntity == null) {
return null;
@@ -532,7 +532,7 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
// 1. 根据申请单号查询检验申请单信息
InspectionLabApply inspectionLabApply = inspectionLabApplyService.getOne(
new QueryWrapper<InspectionLabApply>().eq("apply_no", applyNo)
);
.last("LIMIT 1"));
if (inspectionLabApply == null) {
log.warn("未找到申请单号为 [{}] 的检验申请单", applyNo);

View File

@@ -215,7 +215,7 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
// 限定当天日期,避免复诊患者匹配到历史队列记录
.eq(TriageQueueItem::getQueueDate, LocalDate.now())
.eq(TriageQueueItem::getDeleteFlag, "0")
);
.last("LIMIT 1"));
if (queueItem != null) {
// 使用 TriageQueueStatus 枚举替代原有硬编码数字 20保证状态值一致性
queueItem.setStatus(TriageQueueStatus.IN_CLINIC.getValue());
@@ -282,7 +282,7 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
.eq(TriageQueueItem::getEncounterId, encounterId)
.eq(TriageQueueItem::getQueueDate, LocalDate.now())
.eq(TriageQueueItem::getDeleteFlag, "0")
);
.last("LIMIT 1"));
// 当天未找到时回退:不限日期查最近一条(防止跨日就诊队列项遗漏更新)
if (queueItem == null) {
@@ -292,8 +292,8 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
.eq(TriageQueueItem::getEncounterId, encounterId)
.eq(TriageQueueItem::getDeleteFlag, "0")
.orderByDesc(TriageQueueItem::getQueueDate)
.last("LIMIT 1")
);
.last("LIMIT 1"));
if (queueItem != null) {
log.warn("完诊:当天队列项未找到,回退使用最近队列记录 queueDate={}, id={}",
queueItem.getQueueDate(), queueItem.getId());