Skip to content

Commit

Permalink
产品的统计显示基础数据接口调通
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrix-X committed Oct 9, 2023
1 parent 22e0ef7 commit e842cd9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/admin/crm/product/productstatistics.api
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type (

type (
GetProductStatisticsRequest struct {
ProductStatisticsId int64 `path:"id"`
ProductId int64 `path:"id"`
}

GetProductStatisticsReply struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (l *GetProductSpecificLogic) GetProductSpecific(req *types.GetProductSpecif
return
}

func TransformProductSpecificToProductSpecificReply(specific *product2.ProductSpecific) (specificReply *types.ProductSpecific) {
func TransformProductSpecificToReply(specific *product2.ProductSpecific) (specificReply *types.ProductSpecific) {
if specific == nil {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TransformProductSpecificsToReply(specifics []*product2.ProductSpecific) (sp

specificsReply = []*types.ProductSpecific{}
for _, entry := range specifics {
specificsReply = append(specificsReply, TransformProductSpecificToProductSpecificReply(entry))
specificsReply = append(specificsReply, TransformProductSpecificToReply(entry))

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package productstatistics

import (
product2 "PowerX/internal/model/crm/product"
"context"

"PowerX/internal/svc"
Expand All @@ -24,7 +25,26 @@ func NewGetProductStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContex
}

func (l *GetProductStatisticsLogic) GetProductStatistics(req *types.GetProductStatisticsRequest) (resp *types.GetProductStatisticsReply, err error) {
// todo: add your logic here and delete this line

return
statistics, err := l.svcCtx.PowerX.ProductStatistics.GetProductStatisticsByProductId(l.ctx, req.ProductId)
return &types.GetProductStatisticsReply{
ProductStatistics: TransformProductStatisticsToReply(statistics),
}, nil
}

func TransformProductStatisticsToReply(specific *product2.ProductStatistics) (specificReply *types.ProductStatistics) {
if specific == nil {
return nil
}

return &types.ProductStatistics{
Id: specific.Id,
ProductId: specific.ProductId,
SoldAmount: specific.SoldAmount,
InventoryQuantity: specific.InventoryQuantity,
ViewCount: specific.ViewCount,
BaseSoldAmount: specific.BaseSoldAmount,
BaseInventoryQuantity: specific.BaseInventoryQuantity,
BaseViewCount: specific.BaseViewCount,
}
}
2 changes: 1 addition & 1 deletion internal/types/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions internal/uc/powerx/crm/product/productstatistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ func (uc *ProductStatisticsUseCase) GetProductStatistics(ctx context.Context, id
return &ProductStatistics, nil
}

func (uc *ProductStatisticsUseCase) GetProductStatisticsByProductId(ctx context.Context, productId int64) (*product.ProductStatistics, error) {
var ProductStatistics product.ProductStatistics
if err := uc.db.WithContext(ctx).
First(&ProductStatistics).
//Debug().
Where("product_id", productId).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errorx.WithCause(errorx.ErrBadRequest, "未找到价格手册")
}
panic(err)
}
return &ProductStatistics, nil
}

func (uc *ProductStatisticsUseCase) DeleteProductStatistics(ctx context.Context, id int64) error {
result := uc.db.WithContext(ctx).Delete(&product.ProductStatistics{}, id)
if err := result.Error; err != nil {
Expand Down

0 comments on commit e842cd9

Please sign in to comment.