diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java index fb16f5140..b589aa44d 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationAdviceAppServiceImpl.java @@ -1920,7 +1920,7 @@ public class DoctorStationAdviceAppServiceImpl implements IDoctorStationAdviceAp Surgery surgery = iSurgeryService.getOne( new LambdaQueryWrapper() .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() .eq(InventoryItem::getItemId, dispense.getMedicationId()) .eq(InventoryItem::getLotNumber, dispense.getLotNumber()) - ); + .last("LIMIT 1")); if (inventoryItem != null) { // 计算回滚后的数量(加上已发放的数量) diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationEmrAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationEmrAppServiceImpl.java index 9647fb3fc..07e5085d3 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationEmrAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationEmrAppServiceImpl.java @@ -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().eq(Emr::getEncounterId, emr.getEncounterId())); + Emr patientEmr = emrService.getOne(new LambdaQueryWrapper().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().eq(Emr::getEncounterId, encounterId)); + Emr emrDetail = emrService.getOne(new LambdaQueryWrapper().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().eq(Emr::getEncounterId, encounterId) + new LambdaQueryWrapper().eq(Emr::getEncounterId, encounterId).last("LIMIT 1") ); // 如果没有病历,则需要写病历 diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationLabApplyServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationLabApplyServiceImpl.java index 00a70ab1e..7f13b7531 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationLabApplyServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationLabApplyServiceImpl.java @@ -274,7 +274,7 @@ public class DoctorStationLabApplyServiceImpl implements IDoctorStationInspectio new QueryWrapper() .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() .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().eq("apply_no", applyNo) - ); + .last("LIMIT 1")); if (inspectionLabApply == null) { log.warn("未找到申请单号为 [{}] 的检验申请单", applyNo); diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationMainAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationMainAppServiceImpl.java index 660cf1c69..8fcd33f83 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationMainAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/appservice/impl/DoctorStationMainAppServiceImpl.java @@ -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());