This commit is contained in:
2025-07-29 00:30:32 +08:00
parent 10d086414b
commit 83530c0f9b
15 changed files with 710 additions and 37 deletions

View File

@@ -41,3 +41,21 @@ type UpdateProductCommand struct {
type DeleteProductCommand struct {
ID string `json:"-" uri:"id" binding:"required,uuid" comment:"产品ID"`
}
// CreateProductApiConfigCommand 创建产品API配置命令
type CreateProductApiConfigCommand struct {
ProductID string `json:"product_id" binding:"required,uuid" comment:"产品ID"`
ApiEndpoint string `json:"api_endpoint" binding:"required,url" comment:"API端点"`
ApiKey string `json:"api_key" binding:"required" comment:"API密钥"`
ApiSecret string `json:"api_secret" binding:"required" comment:"API密钥"`
Config string `json:"config" binding:"omitempty" comment:"配置信息"`
}
// UpdateProductApiConfigCommand 更新产品API配置命令
type UpdateProductApiConfigCommand struct {
ProductID string `json:"product_id" binding:"required,uuid" comment:"产品ID"`
ApiEndpoint string `json:"api_endpoint" binding:"required,url" comment:"API端点"`
ApiKey string `json:"api_key" binding:"required" comment:"API密钥"`
ApiSecret string `json:"api_secret" binding:"required" comment:"API密钥"`
Config string `json:"config" binding:"omitempty" comment:"配置信息"`
}

View File

@@ -22,8 +22,8 @@ type ProductInfoResponse struct {
CategoryID string `json:"category_id" comment:"产品分类ID"`
Price float64 `json:"price" comment:"产品价格"`
IsEnabled bool `json:"is_enabled" comment:"是否启用"`
IsVisible bool `json:"is_visible" comment:"是否展示"`
IsPackage bool `json:"is_package" comment:"是否组合包"`
IsSubscribed *bool `json:"is_subscribed,omitempty" comment:"当前用户是否已订阅"`
// SEO信息
SEOTitle string `json:"seo_title" comment:"SEO标题"`
@@ -65,6 +65,7 @@ type ProductSimpleResponse struct {
Category *CategorySimpleResponse `json:"category,omitempty" comment:"分类信息"`
Price float64 `json:"price" comment:"产品价格"`
IsPackage bool `json:"is_package" comment:"是否组合包"`
IsSubscribed *bool `json:"is_subscribed,omitempty" comment:"当前用户是否已订阅"`
}
// ProductStatsResponse 产品统计响应

View File

@@ -17,6 +17,7 @@ type ProductApplicationService interface {
GetProductByID(ctx context.Context, query *queries.GetProductQuery) (*responses.ProductInfoResponse, error)
ListProducts(ctx context.Context, filters map[string]interface{}, options interfaces.ListOptions) (*responses.ProductListResponse, error)
ListProductsWithSubscriptionStatus(ctx context.Context, filters map[string]interface{}, options interfaces.ListOptions) (*responses.ProductListResponse, error)
GetProductsByIDs(ctx context.Context, query *queries.GetProductsByIDsQuery) ([]*responses.ProductInfoResponse, error)
// 业务查询

View File

@@ -18,10 +18,10 @@ import (
// ProductApplicationServiceImpl 产品应用服务实现
// 负责业务流程编排、事务管理、数据转换,不直接操作仓库
type ProductApplicationServiceImpl struct {
productManagementService *product_service.ProductManagementService
productSubscriptionService *product_service.ProductSubscriptionService
productApiConfigAppService ProductApiConfigApplicationService
logger *zap.Logger
productManagementService *product_service.ProductManagementService
productSubscriptionService *product_service.ProductSubscriptionService
productApiConfigAppService ProductApiConfigApplicationService
logger *zap.Logger
}
// NewProductApplicationService 创建产品应用服务
@@ -32,10 +32,10 @@ func NewProductApplicationService(
logger *zap.Logger,
) ProductApplicationService {
return &ProductApplicationServiceImpl{
productManagementService: productManagementService,
productSubscriptionService: productSubscriptionService,
productApiConfigAppService: productApiConfigAppService,
logger: logger,
productManagementService: productManagementService,
productSubscriptionService: productSubscriptionService,
productApiConfigAppService: productApiConfigAppService,
logger: logger,
}
}
@@ -99,6 +99,11 @@ func (s *ProductApplicationServiceImpl) DeleteProduct(ctx context.Context, cmd *
// ListProducts 获取产品列表
// 业务流程1. 获取产品列表 2. 构建响应数据
func (s *ProductApplicationServiceImpl) ListProducts(ctx context.Context, filters map[string]interface{}, options interfaces.ListOptions) (*responses.ProductListResponse, error) {
// 检查是否有用户ID如果有则使用带订阅状态的方法
if userID, ok := filters["user_id"].(string); ok && userID != "" {
return s.ListProductsWithSubscriptionStatus(ctx, filters, options)
}
// 调用领域服务获取产品列表
products, total, err := s.productManagementService.ListProducts(ctx, filters, options)
if err != nil {
@@ -119,6 +124,36 @@ func (s *ProductApplicationServiceImpl) ListProducts(ctx context.Context, filter
}, nil
}
// ListProductsWithSubscriptionStatus 获取产品列表(包含订阅状态)
// 业务流程1. 获取产品列表和订阅状态 2. 构建响应数据
func (s *ProductApplicationServiceImpl) ListProductsWithSubscriptionStatus(ctx context.Context, filters map[string]interface{}, options interfaces.ListOptions) (*responses.ProductListResponse, error) {
// 调用领域服务获取产品列表(包含订阅状态)
products, subscriptionStatusMap, total, err := s.productManagementService.ListProductsWithSubscriptionStatus(ctx, filters, options)
if err != nil {
return nil, err
}
// 转换为响应对象
items := make([]responses.ProductInfoResponse, len(products))
for i := range products {
item := s.convertToProductInfoResponse(products[i])
// 设置订阅状态
if isSubscribed, exists := subscriptionStatusMap[products[i].ID]; exists {
item.IsSubscribed = &isSubscribed
}
items[i] = *item
}
return &responses.ProductListResponse{
Total: total,
Page: options.Page,
Size: options.PageSize,
Items: items,
}, nil
}
// GetProductsByIDs 根据ID列表获取产品
// 业务流程1. 获取产品列表 2. 构建响应数据
func (s *ProductApplicationServiceImpl) GetProductsByIDs(ctx context.Context, query *appQueries.GetProductsByIDsQuery) ([]*responses.ProductInfoResponse, error) {
@@ -353,21 +388,20 @@ func (s *ProductApplicationServiceImpl) GetAvailableProducts(ctx context.Context
// convertToProductInfoResponse 转换为产品信息响应
func (s *ProductApplicationServiceImpl) convertToProductInfoResponse(product *entities.Product) *responses.ProductInfoResponse {
response := &responses.ProductInfoResponse{
ID: product.ID,
Name: product.Name,
Code: product.Code,
Description: product.Description,
Content: product.Content,
CategoryID: product.CategoryID,
Price: product.Price.InexactFloat64(),
IsEnabled: product.IsEnabled,
IsVisible: product.IsVisible,
IsPackage: product.IsPackage,
SEOTitle: product.SEOTitle,
ID: product.ID,
Name: product.Name,
Code: product.Code,
Description: product.Description,
Content: product.Content,
CategoryID: product.CategoryID,
Price: product.Price.InexactFloat64(),
IsEnabled: product.IsEnabled,
IsPackage: product.IsPackage,
SEOTitle: product.SEOTitle,
SEODescription: product.SEODescription,
SEOKeywords: product.SEOKeywords,
CreatedAt: product.CreatedAt,
UpdatedAt: product.UpdatedAt,
SEOKeywords: product.SEOKeywords,
CreatedAt: product.CreatedAt,
UpdatedAt: product.UpdatedAt,
}
// 添加分类信息
@@ -423,4 +457,4 @@ func (s *ProductApplicationServiceImpl) UpdateProductApiConfig(ctx context.Conte
// DeleteProductApiConfig 删除产品API配置
func (s *ProductApplicationServiceImpl) DeleteProductApiConfig(ctx context.Context, configID string) error {
return s.productApiConfigAppService.DeleteProductApiConfig(ctx, configID)
}
}