From 16b2703cbae29966b69cf38585b67c8d333424b6 Mon Sep 17 00:00:00 2001 From: BXY <103352887+BXY0414@users.noreply.github.com> Date: Mon, 2 Nov 2026 09:52:30 +0800 Subject: [PATCH] feat: add DistributionProductDetailJSON to GroupBrandProductItemRecord and update related logic --- internal/repository/product_repository.go | 17 ++++++++++------- internal/server/category_image_ids_test.go | 13 +++++++++---- internal/server/product_server.go | 5 +++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/internal/repository/product_repository.go b/internal/repository/product_repository.go index 66f5b14..3a5440a 100644 --- a/internal/repository/product_repository.go +++ b/internal/repository/product_repository.go @@ -407,8 +407,9 @@ type GroupBrandProductRecord struct { // GroupBrandProductItemRecord is one product and its SPU number in a brand group. type GroupBrandProductItemRecord struct { - ProductID string - SPUNo string + ProductID string + SPUNo string + DistributionProductDetailJSON string } // CreateCatalogCategoryTree inserts a catalog-category subtree of arbitrary @@ -4543,7 +4544,8 @@ SELECT c.id, ELSE b.name END AS brand_name, p.id, - COALESCE(p.spu_no, '') AS spu_no + COALESCE(p.spu_no, '') AS spu_no, + p.distribution_product_detail::text FROM product.catalog_category AS c JOIN product.product_catalog_bindings AS binding ON binding.category_id = c.id AND binding.deleted_at IS NULL @@ -4585,8 +4587,8 @@ ORDER BY c.id ASC, lastBrandKey := make(map[string]string, len(groupsByID)) for rows.Next() { var groupID, brandID, productID int64 - var name, spuNo string - if err := rows.Scan(&groupID, &brandID, &name, &productID, &spuNo); err != nil { + var name, spuNo, distributionProductDetailJSON string + if err := rows.Scan(&groupID, &brandID, &name, &productID, &spuNo, &distributionProductDetailJSON); err != nil { return fmt.Errorf("scan group brand product: %w", err) } groupKey := formatID(groupID) @@ -4609,8 +4611,9 @@ ORDER BY c.id ASC, } brand := &group.BrandProducts[len(group.BrandProducts)-1] brand.Products = append(brand.Products, GroupBrandProductItemRecord{ - ProductID: formatID(productID), - SPUNo: spuNo, + ProductID: formatID(productID), + SPUNo: spuNo, + DistributionProductDetailJSON: distributionProductDetailJSON, }) } if err := rows.Err(); err != nil { diff --git a/internal/server/category_image_ids_test.go b/internal/server/category_image_ids_test.go index d00ee87..fc7fb4b 100644 --- a/internal/server/category_image_ids_test.go +++ b/internal/server/category_image_ids_test.go @@ -48,11 +48,13 @@ func TestGroupNodeIncludesBrandProductsOnlyForLeafGroups(t *testing.T) { BrandID: "3001", BrandName: "Brand", Products: []repository.GroupBrandProductItemRecord{{ - ProductID: "2002", - SPUNo: "SPU-2", + ProductID: "2002", + SPUNo: "SPU-2", + DistributionProductDetailJSON: `{"channel":"partner"}`, }, { - ProductID: "2001", - SPUNo: "SPU-1", + ProductID: "2001", + SPUNo: "SPU-1", + DistributionProductDetailJSON: `[1,2]`, }}, }}, }) @@ -62,6 +64,9 @@ func TestGroupNodeIncludesBrandProductsOnlyForLeafGroups(t *testing.T) { if got := leaf.GetBrands()[0].GetProducts(); len(got) != 2 || got[0].GetProductId() != "2002" || got[0].GetSpuNo() != "SPU-2" || got[1].GetProductId() != "2001" || got[1].GetSpuNo() != "SPU-1" { t.Fatalf("brand products = %#v", got) } + if got := leaf.GetBrands()[0].GetProducts(); got[0].GetDistributionProductDetail() != `{"channel":"partner"}` || got[1].GetDistributionProductDetail() != `[1,2]` { + t.Fatalf("distribution product details = %#v", got) + } emptyLeaf := toProtoGroupNode(&repository.CategoryRecord{ID: "1003", Level: 2, IsLeaf: true}) if got := emptyLeaf.GetBrands(); got == nil || len(got) != 0 { diff --git a/internal/server/product_server.go b/internal/server/product_server.go index 071ceef..2dd9cea 100644 --- a/internal/server/product_server.go +++ b/internal/server/product_server.go @@ -3296,8 +3296,9 @@ func toProtoGroupNode(group *repository.CategoryRecord) *productv1.GroupNode { protoBrand.Products = make([]*productv1.GroupBrandProduct, 0, len(brand.Products)) for _, product := range brand.Products { protoBrand.Products = append(protoBrand.Products, &productv1.GroupBrandProduct{ - ProductId: product.ProductID, - SpuNo: product.SPUNo, + ProductId: product.ProductID, + SpuNo: product.SPUNo, + DistributionProductDetail: product.DistributionProductDetailJSON, }) } }