From 50a0e1a2b405f9764198ce6afba5384645d65892 Mon Sep 17 00:00:00 2001 From: zhaoyun Date: Sun, 17 May 2026 20:24:22 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#504:=20=E6=8A=A4=E5=A3=AB=E9=80=80?= =?UTF-8?q?=E5=9B=9E=E8=8D=AF=E5=93=81=E5=8C=BB=E5=98=B1=E5=90=8E=E5=8C=BB?= =?UTF-8?q?=E7=94=9F=E4=BF=AE=E6=94=B9=E4=BF=9D=E5=AD=98=E6=97=B6"?= =?UTF-8?q?=E6=9C=AA=E5=8C=B9=E9=85=8D=E5=88=B0=E5=BA=93=E5=AD=98=E4=BF=A1?= =?UTF-8?q?=E6=81=AF"=20-=20=E5=A2=9E=E5=8A=A0=E4=B8=A4=E9=98=B6=E6=AE=B5?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E5=8C=B9=E9=85=8D=E9=80=BB=E8=BE=91=E5=92=8C?= =?UTF-8?q?=E7=A9=BA=E5=80=BC=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- .../web/doctorstation/utils/AdviceUtils.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) 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 37b1a3cc9..87854494d 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 @@ -108,14 +108,18 @@ public class AdviceUtils { if (saveDto.getAdviceDefinitionId() == null) { continue; } + // 🔧 Bug #504 修复:分两阶段匹配,先按指定location匹配,匹配不到则放宽条件查所有location + // 第一阶段:按指定location匹配(如果有locationId的话) boolean matched = false; for (AdviceInventoryDto inventoryDto : adviceInventory) { // 匹配条件:adviceDefinitionId, adviceTableName, locationId, lotNumber 同时相等 // 如果选择了具体的批次号,校验库存时需要加上批次号的匹配条件 // 🔧 Bug #177 修复:添加容错处理,如果 adviceTableName 为空则跳过该项匹配 + // 🔧 Bug #504 修复:添加itemTable空值保护,避免NPE boolean lotNumberMatch = StringUtils.isEmpty(saveDto.getLotNumber()) || saveDto.getLotNumber().equals(inventoryDto.getLotNumber()); boolean tableNameMatch = StringUtils.isEmpty(saveDto.getAdviceTableName()) + || StringUtils.isEmpty(inventoryDto.getItemTable()) || inventoryDto.getItemTable().equals(saveDto.getAdviceTableName()); // 🔧 Bug #504 修复:退回医嘱可能locationId为空,跳过location匹配 boolean locationMatch = saveDto.getLocationId() == null @@ -146,6 +150,37 @@ public class AdviceUtils { break; } } + // 🔧 Bug #504 修复:如果指定location没有匹配到库存,则放宽条件查询所有location的库存 + if (!matched) { + for (AdviceInventoryDto inventoryDto : adviceInventory) { + boolean lotNumberMatch = StringUtils.isEmpty(saveDto.getLotNumber()) + || saveDto.getLotNumber().equals(inventoryDto.getLotNumber()); + boolean tableNameMatch = StringUtils.isEmpty(saveDto.getAdviceTableName()) + || StringUtils.isEmpty(inventoryDto.getItemTable()) + || inventoryDto.getItemTable().equals(saveDto.getAdviceTableName()); + if (inventoryDto.getItemId().equals(saveDto.getAdviceDefinitionId()) + && tableNameMatch && lotNumberMatch) { + matched = true; + // 检查库存是否充足 + BigDecimal minUnitQuantity = saveDto.getMinUnitQuantity(); + if (minUnitQuantity == null) { + if (CommonConstants.TableName.ADM_DEVICE_DEFINITION.equals(inventoryDto.getItemTable())) { + minUnitQuantity = saveDto.getQuantity(); + } else { + return saveDto.getAdviceName() + "的小单位数量不能为空"; + } + } + BigDecimal chineseHerbsDoseQuantity = saveDto.getChineseHerbsDoseQuantity(); + if (chineseHerbsDoseQuantity != null && chineseHerbsDoseQuantity.compareTo(BigDecimal.ZERO) > 0) { + minUnitQuantity = minUnitQuantity.multiply(chineseHerbsDoseQuantity); + } + if (minUnitQuantity.compareTo(inventoryDto.getQuantity()) > 0) { + return saveDto.getAdviceName() + "在" + inventoryDto.getLocationName() + "库存不足"; + } + break; + } + } + } // 如果没有匹配到库存 if (!matched) { return saveDto.getAdviceName() + "未匹配到库存信息";