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:
@@ -1920,7 +1920,7 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
|||||||
Surgery surgery = iSurgeryService.getOne(
|
Surgery surgery = iSurgeryService.getOne(
|
||||||
new LambdaQueryWrapper<Surgery>()
|
new LambdaQueryWrapper<Surgery>()
|
||||||
.eq(Surgery::getSurgeryNo, prescriptionNo)
|
.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) {
|
if (surgery != null) {
|
||||||
iSurgeryService.removeById(surgery.getId());
|
iSurgeryService.removeById(surgery.getId());
|
||||||
log.info("handService - 级联删除手术记录 cli_surgery: surgeryNo={}, id={}", prescriptionNo, 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::getServiceId, adviceSaveDto.getRequestId())
|
||||||
.eq(ChargeItem::getServiceTable, CommonConstants.TableName.WOR_SERVICE_REQUEST)
|
.eq(ChargeItem::getServiceTable, CommonConstants.TableName.WOR_SERVICE_REQUEST)
|
||||||
.eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode())
|
.eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode())
|
||||||
);
|
.last("LIMIT 1"));
|
||||||
log.info("BugFix#328: 通过requestId查询费用项,requestId={}, chargeItem={}",
|
log.info("BugFix#328: 通过requestId查询费用项,requestId={}, chargeItem={}",
|
||||||
adviceSaveDto.getRequestId(), existingChargeItem != null ? existingChargeItem.getId() : "null");
|
adviceSaveDto.getRequestId(), existingChargeItem != null ? existingChargeItem.getId() : "null");
|
||||||
}
|
}
|
||||||
@@ -2295,7 +2295,7 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp
|
|||||||
new LambdaQueryWrapper<InventoryItem>()
|
new LambdaQueryWrapper<InventoryItem>()
|
||||||
.eq(InventoryItem::getItemId, dispense.getMedicationId())
|
.eq(InventoryItem::getItemId, dispense.getMedicationId())
|
||||||
.eq(InventoryItem::getLotNumber, dispense.getLotNumber())
|
.eq(InventoryItem::getLotNumber, dispense.getLotNumber())
|
||||||
);
|
.last("LIMIT 1"));
|
||||||
|
|
||||||
if (inventoryItem != null) {
|
if (inventoryItem != null) {
|
||||||
// 计算回滚后的数量(加上已发放的数量)
|
// 计算回滚后的数量(加上已发放的数量)
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
|
|||||||
Emr emr = new Emr();
|
Emr emr = new Emr();
|
||||||
BeanUtils.copyProperties(patientEmrDto, emr);
|
BeanUtils.copyProperties(patientEmrDto, emr);
|
||||||
String contextStr = patientEmrDto.getContextJson().toString();
|
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;
|
boolean saveSuccess;
|
||||||
// 如果已经保存病历,再次保存走更新
|
// 如果已经保存病历,再次保存走更新
|
||||||
if (patientEmr != null) {
|
if (patientEmr != null) {
|
||||||
@@ -137,7 +137,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
|
|||||||
@Override
|
@Override
|
||||||
public R<?> getEmrDetail(Long encounterId) {
|
public R<?> getEmrDetail(Long encounterId) {
|
||||||
// 先查询门诊病历(emr表)
|
// 先查询门诊病历(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) {
|
if (emrDetail != null) {
|
||||||
return R.ok(emrDetail);
|
return R.ok(emrDetail);
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ public class DoctorStationEmrAppServiceImpl implements IDoctorStationEmrAppServi
|
|||||||
public R<?> checkNeedWriteEmr(Long encounterId) {
|
public R<?> checkNeedWriteEmr(Long encounterId) {
|
||||||
// 检查该就诊记录是否已经有病历
|
// 检查该就诊记录是否已经有病历
|
||||||
Emr existingEmr = emrService.getOne(
|
Emr existingEmr = emrService.getOne(
|
||||||
new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, encounterId)
|
new LambdaQueryWrapper<Emr>().eq(Emr::getEncounterId, encounterId).last("LIMIT 1")
|
||||||
);
|
);
|
||||||
|
|
||||||
// 如果没有病历,则需要写病历
|
// 如果没有病历,则需要写病历
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
|
|||||||
new QueryWrapper<Organization>()
|
new QueryWrapper<Organization>()
|
||||||
.eq("bus_no", performDeptCode)
|
.eq("bus_no", performDeptCode)
|
||||||
.eq("delete_flag", "0")
|
.eq("delete_flag", "0")
|
||||||
);
|
.last("LIMIT 1"));
|
||||||
if (organization != null) {
|
if (organization != null) {
|
||||||
positionId = organization.getId();
|
positionId = organization.getId();
|
||||||
} else {
|
} else {
|
||||||
@@ -410,7 +410,7 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
|
|||||||
new QueryWrapper<InspectionLabApply>()
|
new QueryWrapper<InspectionLabApply>()
|
||||||
.eq("apply_no", applyNo)
|
.eq("apply_no", applyNo)
|
||||||
.eq("delete_flag", DelFlag.NO.getCode())
|
.eq("delete_flag", DelFlag.NO.getCode())
|
||||||
);
|
.last("LIMIT 1"));
|
||||||
|
|
||||||
if (mainEntity == null) {
|
if (mainEntity == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -532,7 +532,7 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio
|
|||||||
// 1. 根据申请单号查询检验申请单信息
|
// 1. 根据申请单号查询检验申请单信息
|
||||||
InspectionLabApply inspectionLabApply = inspectionLabApplyService.getOne(
|
InspectionLabApply inspectionLabApply = inspectionLabApplyService.getOne(
|
||||||
new QueryWrapper<InspectionLabApply>().eq("apply_no", applyNo)
|
new QueryWrapper<InspectionLabApply>().eq("apply_no", applyNo)
|
||||||
);
|
.last("LIMIT 1"));
|
||||||
|
|
||||||
if (inspectionLabApply == null) {
|
if (inspectionLabApply == null) {
|
||||||
log.warn("未找到申请单号为 [{}] 的检验申请单", applyNo);
|
log.warn("未找到申请单号为 [{}] 的检验申请单", applyNo);
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
|
|||||||
// 限定当天日期,避免复诊患者匹配到历史队列记录
|
// 限定当天日期,避免复诊患者匹配到历史队列记录
|
||||||
.eq(TriageQueueItem::getQueueDate, LocalDate.now())
|
.eq(TriageQueueItem::getQueueDate, LocalDate.now())
|
||||||
.eq(TriageQueueItem::getDeleteFlag, "0")
|
.eq(TriageQueueItem::getDeleteFlag, "0")
|
||||||
);
|
.last("LIMIT 1"));
|
||||||
if (queueItem != null) {
|
if (queueItem != null) {
|
||||||
// 使用 TriageQueueStatus 枚举替代原有硬编码数字 20,保证状态值一致性
|
// 使用 TriageQueueStatus 枚举替代原有硬编码数字 20,保证状态值一致性
|
||||||
queueItem.setStatus(TriageQueueStatus.IN_CLINIC.getValue());
|
queueItem.setStatus(TriageQueueStatus.IN_CLINIC.getValue());
|
||||||
@@ -282,7 +282,7 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
|
|||||||
.eq(TriageQueueItem::getEncounterId, encounterId)
|
.eq(TriageQueueItem::getEncounterId, encounterId)
|
||||||
.eq(TriageQueueItem::getQueueDate, LocalDate.now())
|
.eq(TriageQueueItem::getQueueDate, LocalDate.now())
|
||||||
.eq(TriageQueueItem::getDeleteFlag, "0")
|
.eq(TriageQueueItem::getDeleteFlag, "0")
|
||||||
);
|
.last("LIMIT 1"));
|
||||||
|
|
||||||
// 当天未找到时回退:不限日期查最近一条(防止跨日就诊队列项遗漏更新)
|
// 当天未找到时回退:不限日期查最近一条(防止跨日就诊队列项遗漏更新)
|
||||||
if (queueItem == null) {
|
if (queueItem == null) {
|
||||||
@@ -292,8 +292,8 @@ public class DoctorStationMainAppServiceImpl implements IDoctorStationMainAppSer
|
|||||||
.eq(TriageQueueItem::getEncounterId, encounterId)
|
.eq(TriageQueueItem::getEncounterId, encounterId)
|
||||||
.eq(TriageQueueItem::getDeleteFlag, "0")
|
.eq(TriageQueueItem::getDeleteFlag, "0")
|
||||||
.orderByDesc(TriageQueueItem::getQueueDate)
|
.orderByDesc(TriageQueueItem::getQueueDate)
|
||||||
.last("LIMIT 1")
|
.last("LIMIT 1"));
|
||||||
);
|
|
||||||
if (queueItem != null) {
|
if (queueItem != null) {
|
||||||
log.warn("完诊:当天队列项未找到,回退使用最近队列记录 queueDate={}, id={}",
|
log.warn("完诊:当天队列项未找到,回退使用最近队列记录 queueDate={}, id={}",
|
||||||
queueItem.getQueueDate(), queueItem.getId());
|
queueItem.getQueueDate(), queueItem.getId());
|
||||||
|
|||||||
Reference in New Issue
Block a user