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

@ -409,6 +409,7 @@ type GroupBrandProductRecord struct {
type GroupBrandProductItemRecord struct {
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)
@ -4611,6 +4613,7 @@ ORDER BY c.id ASC,
brand.Products = append(brand.Products, GroupBrandProductItemRecord{
ProductID: formatID(productID),
SPUNo: spuNo,
DistributionProductDetailJSON: distributionProductDetailJSON,
})
}
if err := rows.Err(); err != nil {

View File

@ -50,9 +50,11 @@ func TestGroupNodeIncludesBrandProductsOnlyForLeafGroups(t *testing.T) {
Products: []repository.GroupBrandProductItemRecord{{
ProductID: "2002",
SPUNo: "SPU-2",
DistributionProductDetailJSON: `{"channel":"partner"}`,
}, {
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 {

View File

@ -3298,6 +3298,7 @@ func toProtoGroupNode(group *repository.CategoryRecord) *productv1.GroupNode {
protoBrand.Products = append(protoBrand.Products, &productv1.GroupBrandProduct{
ProductId: product.ProductID,
SpuNo: product.SPUNo,
DistributionProductDetail: product.DistributionProductDetailJSON,
})
}
}