This commit is contained in:
Mrx
2026-05-27 13:10:00 +08:00
parent 5cee8ff035
commit 9e136bbd6b
6 changed files with 15 additions and 30 deletions

View File

@@ -449,8 +449,8 @@ func (s *ProductManagementService) GetAllProductsForDictionary(ctx context.Conte
options := interfaces.ListOptions{
Page: 1,
PageSize: 1000, // 获取所有产品
Sort: "sort", // 使用 products 表的 sort 字段排序后再按分类分组
PageSize: 1000, // 获取所有产品
Sort: "category.sort", // 按分类的排序字段排序
Order: "asc",
}
@@ -461,20 +461,5 @@ func (s *ProductManagementService) GetAllProductsForDictionary(ctx context.Conte
return nil, fmt.Errorf("获取产品字典数据失败: %w", err)
}
// 预加载分类信息
for _, product := range products {
if product.CategoryID != "" {
category, _ := s.categoryRepo.GetByID(ctx, product.CategoryID)
product.Category = &category
}
if product.SubCategoryID != nil && *product.SubCategoryID != "" {
subCategory, err := s.subCategoryRepo.GetByID(ctx, *product.SubCategoryID)
if err == nil && subCategory != nil {
product.SubCategory = subCategory
}
}
}
return products, nil
}