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