Skip to content

Commit

Permalink
Merge pull request #263 from ArtisanCloud/dev/michaelhu
Browse files Browse the repository at this point in the history
Dev/michaelhu
  • Loading branch information
Matrix-X committed Oct 9, 2023
2 parents d1002df + e842cd9 commit 5362ffc
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 126 deletions.
45 changes: 13 additions & 32 deletions api/admin/crm/product/productstatistics.api
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,38 @@ info(
)

service PowerX {
@doc "查询产品规格列表"
@doc "查询产品统计列表"
@handler ListProductStatisticsPage
get /product-statistics/page-list (ListProductStatisticsPageRequest) returns (ListProductStatisticsPageReply)

@doc "查询产品规格详情"
@doc "查询产品统计详情"
@handler GetProductStatistics
get /product-statistics/:id (GetProductStatisticsRequest) returns (GetProductStatisticsReply)


@doc "创建产品规格"
@handler CreateProductStatistics
post /product-statistics (CreateProductStatisticsRequest) returns (CreateProductStatisticsReply)

@doc "配置产品规格"
@doc "配置产品统计"
@handler ConfigProductStatistics
post /product-statistics/config (ConfigProductStatisticsRequest) returns (ConfigProductStatisticsReply)


@doc "全量产品规格"
@doc "全量产品统计"
@handler PutProductStatistics
put /product-statistics/:id (PutProductStatisticsRequest) returns (PutProductStatisticsReply)

@doc "增量产品规格"
@doc "增量产品统计"
@handler PatchProductStatistics
patch /product-statistics/:id (PatchProductStatisticsRequest) returns (PatchProductStatisticsReply)


@doc "删除产品规格"
@handler DeleteProductStatistics
delete /product-statistics/:id (DeleteProductStatisticsRequest) returns (DeleteProductStatisticsReply)
}

type (
ProductStatistics {
Id int64 `json:"id,optional"`
ProductId int64 `json:"productId"`
SoldAmount int64 `json:"soldAmountoptional"`
InventoryQuantity int64 `json:"inventoryQuantityoptional"`
ViewCount int64 `json:"viewCountoptional"`
BaseSoldAmount int64 `json:"baseSoldAmountoptional"`
BaseInventoryQuantity int64 `json:"baseInventoryQuantityoptional"`
BaseViewCount int64 `json:"baseViewCountoptional"`
SoldAmount int64 `json:"soldAmount,optional"`
InventoryQuantity int64 `json:"inventoryQuantity,optional"`
ViewCount int64 `json:"viewCount,optional"`
BaseSoldAmount int64 `json:"baseSoldAmount,optional"`
BaseInventoryQuantity int64 `json:"baseInventoryQuantity,optional"`
BaseViewCount int64 `json:"baseViewCount,optional"`
}
)

Expand All @@ -78,19 +68,10 @@ type (
}
)

type (
CreateProductStatisticsRequest struct {
ProductStatistics
}

CreateProductStatisticsReply struct {
ProductStatisticsId int64 `json:"id"`
}
)

type (
ConfigProductStatisticsRequest struct {
ProductStatisticss []ProductStatistics `json:"productStatisticss"`
*ProductStatistics
}

ConfigProductStatisticsReply struct {
Expand All @@ -100,7 +81,7 @@ type (

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

GetProductStatisticsReply struct {
Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions internal/handler/routes.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewConfigProductSpecificLogic(ctx context.Context, svcCtx *svc.ServiceConte

func (l *ConfigProductSpecificLogic) ConfigProductSpecific(req *types.ConfigProductSpecificRequest) (resp *types.ConfigProductSpecificReply, err error) {

specifics := TransformProductSpecificsRequestToProductSpecifics(req.ProductSpecifics)
specifics := TransformRequestToProductSpecifics(req.ProductSpecifics)
options := GetOptionsFromProductSpecificsRequest(specifics)
//fmt.Dump(specifics)
err = l.svcCtx.PowerX.ProductSpecific.ConfigProductSpecific(l.ctx, specifics, options)
Expand All @@ -51,7 +51,7 @@ func (l *ConfigProductSpecificLogic) ConfigProductSpecific(req *types.ConfigProd
}, nil
}

func TransformProductSpecificsRequestToProductSpecifics(specificsRequest []types.ProductSpecific) []*product2.ProductSpecific {
func TransformRequestToProductSpecifics(specificsRequest []types.ProductSpecific) []*product2.ProductSpecific {

specifics := []*product2.ProductSpecific{}
for _, specificRequest := range specificsRequest {
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,8 @@
package productstatistics

import (
"PowerX/internal/model/crm/product"
"PowerX/internal/types/errorx"
"context"

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

func (l *ConfigProductStatisticsLogic) ConfigProductStatistics(req *types.ConfigProductStatisticsRequest) (resp *types.ConfigProductStatisticsReply, err error) {
// todo: add your logic here and delete this line

return
staticstics := TransformRequestToProductStaticstics(req.ProductStatistics)

staticstics, err = l.svcCtx.PowerX.ProductStatistics.UpsertProductStatistics(l.ctx, staticstics)
if err != nil {
return nil, errorx.WithCause(errorx.ErrBadRequest, err.Error())
}

return &types.ConfigProductStatisticsReply{
Result: true,
}, nil
}

func TransformRequestToProductStaticstics(statistics *types.ProductStatistics) *product.ProductStatistics {

return &product.ProductStatistics{
ProductId: statistics.ProductId,
BaseSoldAmount: statistics.BaseSoldAmount,
BaseInventoryQuantity: statistics.BaseInventoryQuantity,
BaseViewCount: statistics.BaseViewCount,
}
}

This file was deleted.

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,
}
}
4 changes: 2 additions & 2 deletions internal/model/crm/product/productstatistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "PowerX/internal/model/powermodel"
type ProductStatistics struct {
powermodel.PowerModel

ProductId int64 `gorm:"comment:产品Id" json:"productId"`
ProductId int64 `gorm:"comment:产品Id; unique" json:"productId"`
SoldAmount int64 `gorm:"comment:销量" json:"soldAmount"`
InventoryQuantity int64 `gorm:"comment:库存;" json:"inventoryQuantity"`
ViewCount int64 `gorm:"comment:浏览量;" json:"viewCount"`
Expand All @@ -14,4 +14,4 @@ type ProductStatistics struct {
BaseViewCount int64 `gorm:"comment:浏览量;" json:"baseViewCount"`
}

const ProductStatisticsUniqueId = powermodel.UniqueId
const ProductStatisticsUniqueId = "product_id"
24 changes: 8 additions & 16 deletions internal/types/types.go

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

2 changes: 2 additions & 0 deletions internal/uc/powerx.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type PowerXUseCase struct {
Customer *customerDomainUC.CustomerUseCase
Lead *customerDomainUC.LeadUseCase
Product *productUC.ProductUseCase
ProductStatistics *productUC.ProductStatisticsUseCase
ProductSpecific *productUC.ProductSpecificUseCase
SKU *productUC.SKUUseCase
ProductCategory *productUC.ProductCategoryUseCase
Expand Down Expand Up @@ -107,6 +108,7 @@ func NewPowerXUseCase(conf *config.Config) (uc *PowerXUseCase, clean func()) {

// 加载产品服务UseCase
uc.ProductSpecific = productUC.NewProductSpecificUseCase(db)
uc.ProductStatistics = productUC.NewProductStatisticsUseCase(db)
uc.SKU = productUC.NewSKUUseCase(db)
uc.Product = productUC.NewProductUseCase(db)
uc.ProductCategory = productUC.NewProductCategoryUseCase(db)
Expand Down
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 5362ffc

Please sign in to comment.