From eb0ae8e12af30ff02b6b66274298a0e6a6a5ee2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=BA=91?= <赵云@gentronhealth.com> Date: Mon, 11 May 2026 00:18:33 +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 根因:AdviceUtils.checkExeMedInventory() 中使用 findFirst() 只匹配单个批次库存进行校验, 但同一药品在同一库房可能有多个批次(如66瓶+200瓶=266瓶),导致只校验了第一个批次的库存量。 修复:改用 collect(Collectors.toList()) 收集所有匹配批次的库存,累加总量后再与需求量比较。 Co-Authored-By: Claude Opus 4.7 --- .../web/doctorstation/utils/AdviceUtils.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 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..59a2db34 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 @@ -175,25 +175,31 @@ public class AdviceUtils { // 预减库存 List adviceInventory = this.subtractInventory(adviceInventoryList, adviceDraftInventoryList); - // 生命提示信息集合 + // 提示信息集合 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 totalAvailableQuantity = matchedInventories.stream() + .map(AdviceInventoryDto::getQuantity) + .reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal totalRequiredQuantity = medicationRequestUseExe.getExecuteTimesNum() + .multiply(medicationRequestUseExe.getMinUnitQuantity()); + if (totalRequiredQuantity.compareTo(totalAvailableQuantity) > 0) { + // 取第一个匹配的位置名称用于提示 + String locationName = matchedInventories.get(0).getLocationName(); tipsList - .add("【" + medicationRequestUseExe.getBusNo() + "】在" + inventoryDto.getLocationName() + "库存不足"); + .add("【" + medicationRequestUseExe.getBusNo() + "】在" + locationName + "库存不足"); } } else { tipsList.add("【" + medicationRequestUseExe.getBusNo() + "】未匹配到库存信息");