feat: add DistributionProductDetailJSON to GroupBrandProductItemRecord and update related logic

This commit is contained in:
BXY 2026-11-02 09:52:30 +08:00
parent e4e16458a0
commit 16b2703cba
3 changed files with 22 additions and 13 deletions

View File

@ -407,8 +407,9 @@ type GroupBrandProductRecord struct {
// GroupBrandProductItemRecord is one product and its SPU number in a brand group. // GroupBrandProductItemRecord is one product and its SPU number in a brand group.
type GroupBrandProductItemRecord struct { type GroupBrandProductItemRecord struct {
ProductID string ProductID string
SPUNo string SPUNo string
DistributionProductDetailJSON string
} }
// CreateCatalogCategoryTree inserts a catalog-category subtree of arbitrary // CreateCatalogCategoryTree inserts a catalog-category subtree of arbitrary
@ -4543,7 +4544,8 @@ SELECT c.id,
ELSE b.name ELSE b.name
END AS brand_name, END AS brand_name,
p.id, 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 FROM product.catalog_category AS c
JOIN product.product_catalog_bindings AS binding ON binding.category_id = c.id JOIN product.product_catalog_bindings AS binding ON binding.category_id = c.id
AND binding.deleted_at IS NULL AND binding.deleted_at IS NULL
@ -4585,8 +4587,8 @@ ORDER BY c.id ASC,
lastBrandKey := make(map[string]string, len(groupsByID)) lastBrandKey := make(map[string]string, len(groupsByID))
for rows.Next() { for rows.Next() {
var groupID, brandID, productID int64 var groupID, brandID, productID int64
var name, spuNo string var name, spuNo, distributionProductDetailJSON string
if err := rows.Scan(&groupID, &brandID, &name, &productID, &spuNo); err != nil { if err := rows.Scan(&groupID, &brandID, &name, &productID, &spuNo, &distributionProductDetailJSON); err != nil {
return fmt.Errorf("scan group brand product: %w", err) return fmt.Errorf("scan group brand product: %w", err)
} }
groupKey := formatID(groupID) groupKey := formatID(groupID)
@ -4609,8 +4611,9 @@ ORDER BY c.id ASC,
} }
brand := &group.BrandProducts[len(group.BrandProducts)-1] brand := &group.BrandProducts[len(group.BrandProducts)-1]
brand.Products = append(brand.Products, GroupBrandProductItemRecord{ brand.Products = append(brand.Products, GroupBrandProductItemRecord{
ProductID: formatID(productID), ProductID: formatID(productID),
SPUNo: spuNo, SPUNo: spuNo,
DistributionProductDetailJSON: distributionProductDetailJSON,
}) })
} }
if err := rows.Err(); err != nil { if err := rows.Err(); err != nil {

View File

@ -48,11 +48,13 @@ func TestGroupNodeIncludesBrandProductsOnlyForLeafGroups(t *testing.T) {
BrandID: "3001", BrandID: "3001",
BrandName: "Brand", BrandName: "Brand",
Products: []repository.GroupBrandProductItemRecord{{ Products: []repository.GroupBrandProductItemRecord{{
ProductID: "2002", ProductID: "2002",
SPUNo: "SPU-2", SPUNo: "SPU-2",
DistributionProductDetailJSON: `{"channel":"partner"}`,
}, { }, {
ProductID: "2001", ProductID: "2001",
SPUNo: "SPU-1", 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" { 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) 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}) emptyLeaf := toProtoGroupNode(&repository.CategoryRecord{ID: "1003", Level: 2, IsLeaf: true})
if got := emptyLeaf.GetBrands(); got == nil || len(got) != 0 { if got := emptyLeaf.GetBrands(); got == nil || len(got) != 0 {

View File

@ -3296,8 +3296,9 @@ func toProtoGroupNode(group *repository.CategoryRecord) *productv1.GroupNode {
protoBrand.Products = make([]*productv1.GroupBrandProduct, 0, len(brand.Products)) protoBrand.Products = make([]*productv1.GroupBrandProduct, 0, len(brand.Products))
for _, product := range brand.Products { for _, product := range brand.Products {
protoBrand.Products = append(protoBrand.Products, &productv1.GroupBrandProduct{ protoBrand.Products = append(protoBrand.Products, &productv1.GroupBrandProduct{
ProductId: product.ProductID, ProductId: product.ProductID,
SpuNo: product.SPUNo, SpuNo: product.SPUNo,
DistributionProductDetail: product.DistributionProductDetailJSON,
}) })
} }
} }