Fix Bug #504: 护士退回药品医嘱后医生修改保存时"未匹配到库存信息" - 增加两阶段库存匹配逻辑和空值保护
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -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() + "未匹配到库存信息";
|
||||
|
||||
Reference in New Issue
Block a user