diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inventorymanage/appservice/impl/RequisitionIssueAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inventorymanage/appservice/impl/RequisitionIssueAppServiceImpl.java index ed0af2260..33888bab9 100755 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inventorymanage/appservice/impl/RequisitionIssueAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inventorymanage/appservice/impl/RequisitionIssueAppServiceImpl.java @@ -256,6 +256,9 @@ public class RequisitionIssueAppServiceImpl implements IRequisitionIssueAppServi */ @Override public R submitApproval(String busNo) { + // 提交审批前校验库存,防止超库存单据进入审批流 + this.validateRequisitionStockByBusNo(busNo); + // 单据提交审核 boolean result = supplyRequestService.submitApproval(busNo); return result ? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00004, null)) @@ -419,4 +422,80 @@ public class RequisitionIssueAppServiceImpl implements IRequisitionIssueAppServi } } } + + /** + * 根据单据号校验领用数量是否超过源仓库实际库存(提交审批前调用) + * + * @param busNo 单据号 + */ + private void validateRequisitionStockByBusNo(String busNo) { + Integer tenantId = SecurityUtils.getLoginUser().getTenantId(); + // 通过单据详情查询已保存的单据明细 + R> detailResult = this.getDetail(busNo); + if (detailResult.getCode() != 200 || detailResult.getData() == null) { + return; + } + List detailList = detailResult.getData(); + for (IssueDetailDto detail : detailList) { + Long itemId = detail.getItemId(); + String lotNumber = detail.getLotNumber(); + Long sourceLocationId = detail.getSourceLocationId(); + BigDecimal reqQuantity = detail.getItemQuantity(); + String itemTable = CommonConstants.TableName.MED_MEDICATION_DEFINITION; + // 根据药品类型判断表名 + if (ItemType.DEVICE.getValue().equals(detail.getItemType())) { + itemTable = CommonConstants.TableName.ADM_DEVICE_DEFINITION; + } + + // 查询定义信息(拆零比、单位) + BigDecimal partPercent = BigDecimal.ONE; + String unitCode = detail.getUnitCode(); + String minUnitCode = detail.getMinUnitCode(); + + if (CommonConstants.TableName.MED_MEDICATION_DEFINITION.equals(itemTable)) { + MedicationDefinition medDef = medicationDefinitionService.getById(itemId); + if (medDef != null) { + unitCode = medDef.getUnitCode(); + minUnitCode = medDef.getMinUnitCode(); + if (medDef.getPartPercent() != null) { + partPercent = medDef.getPartPercent(); + } + } + } else if (CommonConstants.TableName.ADM_DEVICE_DEFINITION.equals(itemTable)) { + DeviceDefinition devDef = deviceDefinitionService.getById(itemId); + if (devDef != null) { + unitCode = devDef.getUnitCode(); + minUnitCode = devDef.getMinUnitCode(); + if (devDef.getPartPercent() != null) { + partPercent = devDef.getPartPercent(); + } + } + } + + // 计算领用数量折合最小单位的值 + BigDecimal reqQuantityInMinUnit; + if (unitCode != null && detail.getUnitCode().equals(unitCode)) { + reqQuantityInMinUnit = reqQuantity.multiply(partPercent); + } else { + reqQuantityInMinUnit = reqQuantity; + } + + // 查询源仓库实际库存 + List inventoryItemList = inventoryItemService.selectInventoryByItemId( + itemId, lotNumber, sourceLocationId, tenantId); + + // 累加总库存 + BigDecimal totalStock = BigDecimal.ZERO; + for (InventoryItem inventoryItem : inventoryItemList) { + if (inventoryItem.getLocationId().equals(sourceLocationId)) { + totalStock = totalStock.add(inventoryItem.getQuantity()); + } + } + + // 比较领用数量与库存 + if (reqQuantityInMinUnit.compareTo(totalStock) > 0) { + throw new ServiceException("提交失败,单据中存在领用数量超过库存的明细,请核对后重新保存"); + } + } + } } diff --git a/openhis-ui-vue3/src/views/medicationmanagement/requisitionManagement/requisitionManagement/index.vue b/openhis-ui-vue3/src/views/medicationmanagement/requisitionManagement/requisitionManagement/index.vue index 1d56b6da6..02c6df268 100755 --- a/openhis-ui-vue3/src/views/medicationmanagement/requisitionManagement/requisitionManagement/index.vue +++ b/openhis-ui-vue3/src/views/medicationmanagement/requisitionManagement/requisitionManagement/index.vue @@ -982,6 +982,16 @@ function handleSubmitApproval() { } else if (!form.purchaseinventoryList[length - 1].isSave) { proxy.$modal.msgWarning('第' + length + '行单据未保存,请先保存'); } else { + // 提交审批前逐行校验库存,防止超库存单据进入审批 + for (let i = 0; i < form.purchaseinventoryList.length; i++) { + const line = form.purchaseinventoryList[i]; + if (!line) continue; + const err = validateRequisitionQtyVsStock(line, i + 1); + if (err) { + proxy.$modal.msgWarning(err); + return; + } + } submitApproval(receiptHeaderForm.busNo).then((response) => { if (response.code == 200) { proxy.$modal.msgSuccess('提交审批成功');