diff --git a/src/Oms.Application/Services/Orders/OrderService.Helpers.cs b/src/Oms.Application/Services/Orders/OrderService.Helpers.cs
index 9e91592..c64ecff 100644
--- a/src/Oms.Application/Services/Orders/OrderService.Helpers.cs
+++ b/src/Oms.Application/Services/Orders/OrderService.Helpers.cs
@@ -298,7 +298,7 @@ public partial class OrderService
}
///
- /// 列表页专用映射:不加载申报明细/费用明细,并行 enrichment,减小 JSON 与 DB 开销。
+ /// 列表页专用映射:不加载申报明细/费用明细,批量 enrichment,减小 JSON 与 DB 开销。
///
private async Task> MapOrderListOutputsAsync(IReadOnlyCollection orders)
{
@@ -335,58 +335,32 @@ public partial class OrderService
.Distinct()
.ToArray();
- var sendersTask = OrderRepository.GetSendersByOrderIdsAsync(orderIds);
- var recipientsTask = OrderRepository.GetRecipientsByOrderIdsAsync(orderIds);
- var weightsTask = OrderRepository.GetWeightsByOrderIdsAsync(orderIds);
- var receivableSumTask = OrderRepository.GetReceivableSumByOrderIdsAsync(orderIds);
- var warehousesTask = warehouseIds.Length == 0
- ? Task.FromResult(new List())
- : WarehouseAddressRepository.GetListAsync(x => warehouseIds.Contains(x.Id));
- var productsTask = productCodes.Length == 0
- ? Task.FromResult(new List())
- : SalesProductRepository.GetListAsync(x => productCodes.Contains(x.ProductCode));
- var channelsTask = channelCodes.Length == 0
- ? Task.FromResult(new List())
- : ServiceChannelRepository.GetListAsync(x => channelCodes.Contains(x.ChannelCode));
- var countriesTask = countryCodes.Length == 0
- ? Task.FromResult(new List())
- : CountryRepository.GetListAsync(x => countryCodes.Contains(x.CountryCode));
- var auditUserNameTask = UserDisplayNameResolver.ResolveManyAsync(
+ // SqlSugarScope 共用同一 MySqlConnection,不能 Task.WhenAll 并发查库(会报 already in use)
+ var senders = await OrderRepository.GetSendersByOrderIdsAsync(orderIds);
+ var recipients = await OrderRepository.GetRecipientsByOrderIdsAsync(orderIds);
+ var weights = await OrderRepository.GetWeightsByOrderIdsAsync(orderIds);
+ var receivableSumMap = await OrderRepository.GetReceivableSumByOrderIdsAsync(orderIds);
+ var warehouses = warehouseIds.Length == 0
+ ? []
+ : await WarehouseAddressRepository.GetListAsync(x => warehouseIds.Contains(x.Id));
+ var products = productCodes.Length == 0
+ ? []
+ : await SalesProductRepository.GetListAsync(x => productCodes.Contains(x.ProductCode));
+ var channels = channelCodes.Length == 0
+ ? []
+ : await ServiceChannelRepository.GetListAsync(x => channelCodes.Contains(x.ChannelCode));
+ var countries = countryCodes.Length == 0
+ ? []
+ : await CountryRepository.GetListAsync(x => countryCodes.Contains(x.CountryCode));
+ var auditUserNameMap = await UserDisplayNameResolver.ResolveManyAsync(
orders.SelectMany(x => new[] { x.CreateUserId, x.UpdateUserId }));
- var customersTask = customerIds.Length == 0
- ? Task.FromResult(new List())
- : CustomerRepository.GetListAsync(x => customerIds.Contains(x.Id));
- var pickupOrdersTask = pickupOrderIds.Length == 0
- ? Task.FromResult(new List())
- : PickupOrderRepository.GetListAsync(x => pickupOrderIds.Contains(x.Id));
- var bindSummaryTask = LoadStockBindListSummariesAsync(orderIds);
-
- await Task.WhenAll(
- sendersTask,
- recipientsTask,
- weightsTask,
- receivableSumTask,
- warehousesTask,
- productsTask,
- channelsTask,
- countriesTask,
- auditUserNameTask,
- customersTask,
- pickupOrdersTask,
- bindSummaryTask);
-
- var senders = await sendersTask;
- var recipients = await recipientsTask;
- var weights = await weightsTask;
- var receivableSumMap = await receivableSumTask;
- var warehouses = await warehousesTask;
- var products = await productsTask;
- var channels = await channelsTask;
- var countries = await countriesTask;
- var auditUserNameMap = await auditUserNameTask;
- var customers = await customersTask;
- var pickupOrders = await pickupOrdersTask;
- var bindSummaryMap = await bindSummaryTask;
+ var customers = customerIds.Length == 0
+ ? []
+ : await CustomerRepository.GetListAsync(x => customerIds.Contains(x.Id));
+ var pickupOrders = pickupOrderIds.Length == 0
+ ? []
+ : await PickupOrderRepository.GetListAsync(x => pickupOrderIds.Contains(x.Id));
+ var bindSummaryMap = await LoadStockBindListSummariesAsync(orderIds);
var senderMap = senders.GroupBy(x => x.OrderId).ToDictionary(x => x.Key, x => x.First());
var recipientMap = recipients.GroupBy(x => x.OrderId).ToDictionary(x => x.Key, x => x.First());