fix: 修复规格模板查询并发DbContext异常
All checks were successful
Build and Deploy TenantApi / build-and-deploy (push) Successful in 44s
All checks were successful
Build and Deploy TenantApi / build-and-deploy (push) Successful in 44s
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user