From 1c93227fadc2f67704cc2fd0dfdd9c7345875961 Mon Sep 17 00:00:00 2001 From: Ranyunqiao <2499115710@qq.com> Date: Sat, 9 May 2026 14:21:54 +0800 Subject: [PATCH] =?UTF-8?q?484=20[=E4=BD=8F=E9=99=A2=E6=8A=A4=E5=A3=AB?= =?UTF-8?q?=E7=AB=99]=20=E5=8C=BB=E5=98=B1=E6=89=A7=E8=A1=8C=E6=8A=A5?= =?UTF-8?q?=E2=80=9C=E5=BA=93=E5=AD=98=E4=B8=8D=E8=B6=B3=E2=80=9D=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E5=8F=91=E8=8D=AF=E6=98=8E=E7=BB=86=E5=8D=95=E4=BB=8D?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BA=A7=E7=94=9F=E5=BE=85=E5=8F=91=E8=8D=AF?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=EF=BC=88=E6=95=B0=E6=8D=AE=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E6=80=A7=E7=BC=BA=E9=99=B7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/AdviceProcessAppServiceImpl.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inhospitalnursestation/appservice/impl/AdviceProcessAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inhospitalnursestation/appservice/impl/AdviceProcessAppServiceImpl.java index d146e5b2..95061f5f 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inhospitalnursestation/appservice/impl/AdviceProcessAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inhospitalnursestation/appservice/impl/AdviceProcessAppServiceImpl.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.springframework.transaction.annotation.Transactional; import com.core.common.core.domain.R; import com.core.common.enums.TenantOptionDict; import com.core.common.exception.ServiceException; @@ -377,6 +378,7 @@ public class AdviceProcessAppServiceImpl implements IAdviceProcessAppService { * @return 操作结果 */ @Override + @Transactional(rollbackFor = Exception.class) public R adviceExecute(AdviceExecuteParam adviceExecuteParam) { // 实际执行时间 Date exeDate = adviceExecuteParam.getExeDate(); @@ -804,12 +806,6 @@ public class AdviceProcessAppServiceImpl implements IAdviceProcessAppService { chargeItemService.saveOrUpdate(chargeItem); } else { // 批次售卖情况 - // 需要的药品数量(小单位) - BigDecimal minUnitQuantity = medicationRequestUseExe.getMinUnitQuantity(); - if (minUnitQuantity == null || minUnitQuantity.compareTo(BigDecimal.ZERO) <= 0) { - throw new RuntimeException("药品执行数量异常,medicationId: " - + finalLongMedicationRequest.getMedicationId()); - } // 库存集合 List inventoryList = advice.getInventoryList(); if (inventoryList == null || inventoryList.isEmpty()) { @@ -822,9 +818,23 @@ public class AdviceProcessAppServiceImpl implements IAdviceProcessAppService { throw new RuntimeException("未找到药品匹配的定价信息: " + finalLongMedicationRequest.getMedicationId()); } + // 需要的药品数量(小单位) + BigDecimal minUnitQuantity = medicationRequestUseExe.getMinUnitQuantity(); + if (minUnitQuantity == null || minUnitQuantity.compareTo(BigDecimal.ZERO) <= 0) { + throw new RuntimeException("药品执行数量异常,medicationId: " + + finalLongMedicationRequest.getMedicationId()); + } + // 【修复】预先计算总可用库存,确保在写入任何数据前进行校验 + BigDecimal totalAvailableQuantity = inventoryList.stream() + .map(AdviceInventoryDto::getQuantity) + .reduce(BigDecimal.ZERO, BigDecimal::add); + if (totalAvailableQuantity.compareTo(minUnitQuantity) < 0) { + throw new RuntimeException("药品库存不足,medicationId: " + + finalLongMedicationRequest.getMedicationId()); + } // 剩余需要分配的数量 BigDecimal remainingQuantity = minUnitQuantity; - + // 按批次循环分配数量 for (AdviceInventoryDto inventory : inventoryList) { if (remainingQuantity.compareTo(BigDecimal.ZERO) <= 0) { @@ -927,11 +937,6 @@ public class AdviceProcessAppServiceImpl implements IAdviceProcessAppService { chargeItem.setTotalPrice(totalPrice); // 总价 chargeItemService.saveOrUpdate(chargeItem); - - } - if (remainingQuantity.compareTo(BigDecimal.ZERO) > 0) { - throw new RuntimeException("药品库存不足,medicationId: " - + finalLongMedicationRequest.getMedicationId()); } } }