feat: enhance inventory release logic in ExpirePendingOrdersService and InventoryService
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 8m27s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 8m27s
This commit is contained in:
+38
-1
@@ -79,10 +79,47 @@ public class ExpirePendingOrdersService : BackgroundService
|
||||
// آزادسازی رزرو موجودی
|
||||
foreach (var detail in order.OrderDetails)
|
||||
{
|
||||
var inventoryItem = await inventoryService.GetInventoryAsync(
|
||||
detail.ProductId,
|
||||
ProductType.DiscountProduct,
|
||||
null,
|
||||
cancellationToken);
|
||||
|
||||
if (inventoryItem == null)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Skipping inventory release for expired order #{OrderId}, ProductId={ProductId} because InventoryItem was not found",
|
||||
order.Id,
|
||||
detail.ProductId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (inventoryItem.ReservedQuantity <= 0)
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"Skipping inventory release for expired order #{OrderId}, ProductId={ProductId} because no reserved quantity remains",
|
||||
order.Id,
|
||||
detail.ProductId);
|
||||
continue;
|
||||
}
|
||||
|
||||
var releaseQuantity = Math.Min(detail.Count, inventoryItem.ReservedQuantity);
|
||||
|
||||
if (releaseQuantity < detail.Count)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Partial reservation release for expired order #{OrderId}, ProductId={ProductId}: requested={Requested}, reserved={Reserved}, releasing={Released}",
|
||||
order.Id,
|
||||
detail.ProductId,
|
||||
detail.Count,
|
||||
inventoryItem.ReservedQuantity,
|
||||
releaseQuantity);
|
||||
}
|
||||
|
||||
await inventoryService.ReleaseReservationAsync(
|
||||
detail.ProductId,
|
||||
ProductType.DiscountProduct,
|
||||
detail.Count,
|
||||
releaseQuantity,
|
||||
order.Id,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user