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() + "】未匹配到库存信息");