From 848778b8b54f1c02575aa7431d9431ec938ab35c Mon Sep 17 00:00:00 2001 From: MSuMshk <2039814060@qq.com> Date: Sat, 21 Feb 2026 07:42:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=A7=84=E6=A0=BC?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=9F=A5=E8=AF=A2=E5=B9=B6=E5=8F=91DbContext?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CopyProductSpecTemplateCommandHandler.cs | 15 +++++++++------ .../GetProductSpecTemplateListQueryHandler.cs | 16 +++++++++++----- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Application/TakeoutSaaS.Application/App/Products/Handlers/CopyProductSpecTemplateCommandHandler.cs b/src/Application/TakeoutSaaS.Application/App/Products/Handlers/CopyProductSpecTemplateCommandHandler.cs index d9fabce..290f5b9 100644 --- a/src/Application/TakeoutSaaS.Application/App/Products/Handlers/CopyProductSpecTemplateCommandHandler.cs +++ b/src/Application/TakeoutSaaS.Application/App/Products/Handlers/CopyProductSpecTemplateCommandHandler.cs @@ -61,12 +61,15 @@ public sealed class CopyProductSpecTemplateCommandHandler( await productRepository.SaveChangesAsync(cancellationToken); // 4. 复制选项与关联商品。 - var sourceOptionsTask = productRepository.GetSpecTemplateOptionsByTemplateIdsAsync([source.Id], tenantId, cancellationToken); - var sourceRelationsTask = productRepository.GetSpecTemplateProductsByTemplateIdsAsync([source.Id], tenantId, request.StoreId, cancellationToken); - await Task.WhenAll(sourceOptionsTask, sourceRelationsTask); - - var sourceOptions = await sourceOptionsTask; - var sourceRelations = await sourceRelationsTask; + var sourceOptions = await productRepository.GetSpecTemplateOptionsByTemplateIdsAsync( + [source.Id], + tenantId, + cancellationToken); + var sourceRelations = await productRepository.GetSpecTemplateProductsByTemplateIdsAsync( + [source.Id], + tenantId, + request.StoreId, + cancellationToken); if (sourceOptions.Count > 0) { diff --git a/src/Application/TakeoutSaaS.Application/App/Products/Handlers/GetProductSpecTemplateListQueryHandler.cs b/src/Application/TakeoutSaaS.Application/App/Products/Handlers/GetProductSpecTemplateListQueryHandler.cs index 94883e2..a544d4d 100644 --- a/src/Application/TakeoutSaaS.Application/App/Products/Handlers/GetProductSpecTemplateListQueryHandler.cs +++ b/src/Application/TakeoutSaaS.Application/App/Products/Handlers/GetProductSpecTemplateListQueryHandler.cs @@ -55,15 +55,21 @@ public sealed class GetProductSpecTemplateListQueryHandler( } var templateIds = filteredList.Select(item => item.Id).ToList(); - var optionsTask = productRepository.GetSpecTemplateOptionsByTemplateIdsAsync(templateIds, tenantId, cancellationToken); - var relationsTask = productRepository.GetSpecTemplateProductsByTemplateIdsAsync(templateIds, tenantId, request.StoreId, cancellationToken); - await Task.WhenAll(optionsTask, relationsTask); + var options = await productRepository.GetSpecTemplateOptionsByTemplateIdsAsync( + templateIds, + tenantId, + cancellationToken); + var relations = await productRepository.GetSpecTemplateProductsByTemplateIdsAsync( + templateIds, + tenantId, + request.StoreId, + cancellationToken); // 4. 构建查找字典并映射 DTO。 - var optionsLookup = (await optionsTask) + var optionsLookup = options .GroupBy(x => x.TemplateId) .ToDictionary(group => group.Key, group => group.OrderBy(item => item.SortOrder).ThenBy(item => item.Id).ToList()); - var productIdsLookup = (await relationsTask) + var productIdsLookup = relations .GroupBy(x => x.TemplateId) .ToDictionary(group => group.Key, group => group.Select(item => item.ProductId).ToList());