f
This commit is contained in:
@@ -435,3 +435,46 @@ func (s *ProductManagementService) ListProductsWithSubscriptionStatus(ctx contex
|
||||
|
||||
return products, subscriptionStatusMap, total, nil
|
||||
}
|
||||
|
||||
// GetAllProductsForDictionary 获取所有启用且可见的产品(用于导出产品字典)
|
||||
func (s *ProductManagementService) GetAllProductsForDictionary(ctx context.Context) ([]*entities.Product, error) {
|
||||
// 构建查询条件:启用且可见
|
||||
isEnabled := true
|
||||
isVisible := true
|
||||
|
||||
filters := map[string]interface{}{
|
||||
"is_enabled": isEnabled,
|
||||
"is_visible": isVisible,
|
||||
}
|
||||
|
||||
options := interfaces.ListOptions{
|
||||
Page: 1,
|
||||
PageSize: 1000, // 获取所有产品
|
||||
Sort: "sort", // 使用 products 表的 sort 字段,排序后再按分类分组
|
||||
Order: "asc",
|
||||
}
|
||||
|
||||
// 获取产品列表
|
||||
products, _, err := s.ListProducts(ctx, filters, options)
|
||||
if err != nil {
|
||||
s.logger.Error("获取产品字典数据失败", zap.Error(err))
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user