Adapt to old_id
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
// Product 产品实体
|
||||
type Product struct {
|
||||
ID string `gorm:"primaryKey;type:varchar(36)" comment:"产品ID"`
|
||||
OldID *string `gorm:"type:varchar(36);index" comment:"旧产品ID,用于兼容"`
|
||||
Name string `gorm:"type:varchar(100);not null" comment:"产品名称"`
|
||||
Code string `gorm:"type:varchar(50);uniqueIndex;not null" comment:"产品编号"`
|
||||
Description string `gorm:"type:text" comment:"产品简介"`
|
||||
@@ -94,4 +95,22 @@ func (p *Product) SetAsPackage() {
|
||||
|
||||
func (p *Product) IsCombo() bool {
|
||||
return p.IsPackage
|
||||
}
|
||||
|
||||
// SetOldID 设置旧ID
|
||||
func (p *Product) SetOldID(oldID string) {
|
||||
p.OldID = &oldID
|
||||
}
|
||||
|
||||
// GetOldID 获取旧ID
|
||||
func (p *Product) GetOldID() string {
|
||||
if p.OldID != nil {
|
||||
return *p.OldID
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// HasOldID 检查是否有旧ID
|
||||
func (p *Product) HasOldID() bool {
|
||||
return p.OldID != nil && *p.OldID != ""
|
||||
}
|
||||
@@ -13,6 +13,7 @@ type ProductRepository interface {
|
||||
|
||||
// 基础查询方法
|
||||
FindByCode(ctx context.Context, code string) (*entities.Product, error)
|
||||
FindByOldID(ctx context.Context, oldID string) (*entities.Product, error)
|
||||
FindByCategoryID(ctx context.Context, categoryID string) ([]*entities.Product, error)
|
||||
FindVisible(ctx context.Context) ([]*entities.Product, error)
|
||||
FindEnabled(ctx context.Context) ([]*entities.Product, error)
|
||||
|
||||
@@ -105,6 +105,32 @@ func (s *ProductManagementService) GetProductWithCategory(ctx context.Context, p
|
||||
return &product, nil
|
||||
}
|
||||
|
||||
// GetProductByOldIDWithCategory 根据旧ID获取产品及其分类信息
|
||||
func (s *ProductManagementService) GetProductByOldIDWithCategory(ctx context.Context, oldID string) (*entities.Product, error) {
|
||||
product, err := s.productRepo.FindByOldID(ctx, oldID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("产品不存在: %w", err)
|
||||
}
|
||||
|
||||
// 加载分类信息
|
||||
if product.CategoryID != "" {
|
||||
category, err := s.categoryRepo.GetByID(ctx, product.CategoryID)
|
||||
if err == nil {
|
||||
product.Category = &category
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是组合包,加载子产品信息
|
||||
if product.IsPackage {
|
||||
packageItems, err := s.productRepo.GetPackageItems(ctx, product.ID)
|
||||
if err == nil {
|
||||
product.PackageItems = packageItems
|
||||
}
|
||||
}
|
||||
|
||||
return product, nil
|
||||
}
|
||||
|
||||
// GetPackageItems 获取组合包项目列表
|
||||
func (s *ProductManagementService) GetPackageItems(ctx context.Context, packageID string) ([]*entities.ProductPackageItem, error) {
|
||||
packageItems, err := s.productRepo.GetPackageItems(ctx, packageID)
|
||||
|
||||
Reference in New Issue
Block a user