From 0efde56f7028cdf0867a205ab6ee20b7b3e24e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B3=E7=BE=BD?= <关羽@gentronhealth.com> Date: Mon, 11 May 2026 00:22:27 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#481:=20[=E4=BD=8F=E9=99=A2?= =?UTF-8?q?=E6=8A=A4=E5=A3=AB=E7=AB=99-=E5=8C=BB=E5=98=B1=E6=89=A7?= =?UTF-8?q?=E8=A1=8C]=20=E8=8D=AF=E5=93=81"=E6=B3=A8=E5=B0=84=E7=94=A8?= =?UTF-8?q?=E5=A4=B4=E5=AD=A2=E5=93=8C=E9=85=AE=E9=92=A0=E8=88=92=E5=B7=B4?= =?UTF-8?q?=E5=9D=A6=E9=92=A0"=E5=BA=93=E5=AD=98=E5=85=85=E8=B6=B3?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E6=89=A7=E8=A1=8C=E5=8C=BB=E5=98=B1=E6=97=B6?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E5=BA=93=E5=AD=98=E4=B8=8D=E8=B6=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 checkExeMedInventory 方法中,原代码使用 findFirst() 只取第一个批次的库存 进行校验,导致同一库房多个批次的库存总量未被聚合计算。改为 collect(Collectors.toList()) 收集所有匹配批次,然后用 Stream reduce 聚合总可用库存后再与需求量比较。 Co-Authored-By: Claude Opus 4.7 --- .../web/doctorstation/utils/AdviceUtils.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java index 6dccd820..0f930c29 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/doctorstation/utils/AdviceUtils.java @@ -178,22 +178,26 @@ public class AdviceUtils { // 生命提示信息集合 List tipsList = new ArrayList<>(); for (MedicationRequestUseExe medicationRequestUseExe : medUseExeList) { - Optional matchedInventory = adviceInventory.stream() + // 聚合同一位置所有批次的库存总量 + List matchedInventories = adviceInventory.stream() .filter(inventoryDto -> medicationRequestUseExe.getMedicationId().equals(inventoryDto.getItemId()) && CommonConstants.TableName.MED_MEDICATION_DEFINITION.equals(inventoryDto.getItemTable()) && medicationRequestUseExe.getPerformLocation().equals(inventoryDto.getLocationId()) // 如果选择了具体的批次号,校验库存时需要加上批次号的匹配条件 && (StringUtils.isEmpty(medicationRequestUseExe.getLotNumber()) || medicationRequestUseExe.getLotNumber().equals(inventoryDto.getLotNumber()))) - .findFirst(); + .collect(Collectors.toList()); // 匹配到库存信息 - if (matchedInventory.isPresent()) { - AdviceInventoryDto inventoryDto = matchedInventory.get(); - if ((medicationRequestUseExe.getExecuteTimesNum() - .multiply(medicationRequestUseExe.getMinUnitQuantity())) - .compareTo(inventoryDto.getQuantity()) > 0) { + if (!matchedInventories.isEmpty()) { + // 聚合所有批次的可用库存 + BigDecimal totalQuantity = matchedInventories.stream() + .map(dto -> dto.getQuantity() != null ? dto.getQuantity() : BigDecimal.ZERO) + .reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal requestQuantity = medicationRequestUseExe.getExecuteTimesNum() + .multiply(medicationRequestUseExe.getMinUnitQuantity()); + if (requestQuantity.compareTo(totalQuantity) > 0) { tipsList - .add("【" + medicationRequestUseExe.getBusNo() + "】在" + inventoryDto.getLocationName() + "库存不足"); + .add("【" + medicationRequestUseExe.getBusNo() + "】在" + matchedInventories.get(0).getLocationName() + "库存不足"); } } else { tipsList.add("【" + medicationRequestUseExe.getBusNo() + "】未匹配到库存信息");