Commit 17fe7a73 authored by zhengyaoqiu's avatar zhengyaoqiu

feat(colorway): 入库接口时间打印

parent 68a0b2e2
...@@ -8,6 +8,8 @@ import ( ...@@ -8,6 +8,8 @@ import (
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"log"
"time"
) )
type UploadLogic struct { type UploadLogic struct {
...@@ -25,16 +27,20 @@ func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogi ...@@ -25,16 +27,20 @@ func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogi
} }
func (l *UploadLogic) Upload(in *colorway.ProductUploadRequest) (*colorway.ProductUploadResponse, error) { func (l *UploadLogic) Upload(in *colorway.ProductUploadRequest) (*colorway.ProductUploadResponse, error) {
start := time.Now()
productList, err := l.svcCtx.Pc4RpcService.Product.GetListByDesignerIds(l.ctx, &product.ProductGetListByDesignerIdsRequest{ productList, err := l.svcCtx.Pc4RpcService.Product.GetListByDesignerIds(l.ctx, &product.ProductGetListByDesignerIdsRequest{
DesignerIds: in.GetStyleNumbers(), DesignerIds: in.GetStyleNumbers(),
}) })
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Println("GetListByDesignerIds ", time.Now().Sub(start).Seconds())
start = time.Now()
ps, err := l.svcCtx.ProductConvert.Convert(productList.GetDesignerProducts()) ps, err := l.svcCtx.ProductConvert.Convert(productList.GetDesignerProducts())
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Println("Convert ", time.Now().Sub(start).Seconds())
var writeModels []mongo.WriteModel var writeModels []mongo.WriteModel
for _, p := range ps { for _, p := range ps {
filter := bson.M{ filter := bson.M{
...@@ -45,6 +51,8 @@ func (l *UploadLogic) Upload(in *colorway.ProductUploadRequest) (*colorway.Produ ...@@ -45,6 +51,8 @@ func (l *UploadLogic) Upload(in *colorway.ProductUploadRequest) (*colorway.Produ
} }
writeModels = append(writeModels, mongo.NewUpdateOneModel().SetFilter(filter).SetUpdate(update).SetUpsert(true)) writeModels = append(writeModels, mongo.NewUpdateOneModel().SetFilter(filter).SetUpdate(update).SetUpsert(true))
} }
start = time.Now()
_, err = l.svcCtx.MongoManager.ProductModel.BulkWrite(l.ctx, writeModels) _, err = l.svcCtx.MongoManager.ProductModel.BulkWrite(l.ctx, writeModels)
log.Println("BulkWrite ", time.Now().Sub(start).Seconds())
return &colorway.ProductUploadResponse{}, err return &colorway.ProductUploadResponse{}, err
} }
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
"git.chillcy.com/golang/chillcy/pkg/gender" "git.chillcy.com/golang/chillcy/pkg/gender"
math2 "git.chillcy.com/golang/chillcy/pkg/math" math2 "git.chillcy.com/golang/chillcy/pkg/math"
"git.chillcy.com/golang/chillcy/pkg/platform" "git.chillcy.com/golang/chillcy/pkg/platform"
"git.chillcy.com/golang/chillcy/pkg/sdk/pc3"
"git.chillcy.com/golang/chillcy/pkg/slice" "git.chillcy.com/golang/chillcy/pkg/slice"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/pb/pc4" "git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/pb/pc4"
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo" "git.chillcy.com/golang/colorway/internal/pkg/database/mongo"
...@@ -46,8 +45,7 @@ func (receiver *PlatformStoreSku) Convert(product *pc4.ProductModel, sku *pc4.Sk ...@@ -46,8 +45,7 @@ func (receiver *PlatformStoreSku) Convert(product *pc4.ProductModel, sku *pc4.Sk
}) })
categoryIds := product.GetCategoryIds() categoryIds := product.GetCategoryIds()
for _, sitePlatformPriceConfig := range sitePlatformPriceConfigs { for _, sitePlatformPriceConfig := range sitePlatformPriceConfigs {
var pc3SkuModel pc3.ModelSku platformPriceSku, err := receiver.calculatePlatformPrice(product, sku, oldProduct, categoryIds, sitePlatformPriceConfig)
platformPriceSku, err := receiver.calculatePlatformPrice(product, sku, oldProduct, pc3SkuModel, categoryIds, sitePlatformPriceConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -57,19 +55,19 @@ func (receiver *PlatformStoreSku) Convert(product *pc4.ProductModel, sku *pc4.Sk ...@@ -57,19 +55,19 @@ func (receiver *PlatformStoreSku) Convert(product *pc4.ProductModel, sku *pc4.Sk
return platformStoreSkus, nil return platformStoreSkus, nil
} }
func (receiver *PlatformStoreSku) calculatePlatformPrice(product *pc4.ProductModel, sku *pc4.SkuModel, oldProduct *productModel.Product, pc3SkuModel pc3.ModelSku, categories []string, priceConfig sitePlatformPriceConfigModel.SitePlatformPriceConfig) (productModel.ProductColorSkuPlatformStoreSku, error) { func (receiver *PlatformStoreSku) calculatePlatformPrice(product *pc4.ProductModel, sku *pc4.SkuModel, oldProduct *productModel.Product, categories []string, priceConfig sitePlatformPriceConfigModel.SitePlatformPriceConfig) (productModel.ProductColorSkuPlatformStoreSku, error) {
var psSku productModel.ProductColorSkuPlatformStoreSku var psSku productModel.ProductColorSkuPlatformStoreSku
if !priceConfig.IsValid() { if !priceConfig.IsValid() {
return psSku, fmt.Errorf("路线价格配置不合法") return psSku, fmt.Errorf("路线价格配置不合法")
} }
psSku, err := receiver.calculateRoutePrice(product, sku, oldProduct, pc3SkuModel, categories, priceConfig.RoutePriceConfig, priceConfig.Seller) psSku, err := receiver.calculateRoutePrice(product, sku, oldProduct, categories, priceConfig.RoutePriceConfig, priceConfig.Seller)
if err != nil { if err != nil {
return psSku, err return psSku, err
} }
return psSku, nil return psSku, nil
} }
func (receiver *PlatformStoreSku) calculateRoutePrice(product *pc4.ProductModel, sku *pc4.SkuModel, oldProduct *productModel.Product, pc3SkuModel pc3.ModelSku, categories []string, routeConfig sitePlatformPriceConfigModel.RoutePriceConfig, seller types.Seller) (productModel.ProductColorSkuPlatformStoreSku, error) { func (receiver *PlatformStoreSku) calculateRoutePrice(product *pc4.ProductModel, sku *pc4.SkuModel, oldProduct *productModel.Product, categories []string, routeConfig sitePlatformPriceConfigModel.RoutePriceConfig, seller types.Seller) (productModel.ProductColorSkuPlatformStoreSku, error) {
var platformStoreSku productModel.ProductColorSkuPlatformStoreSku var platformStoreSku productModel.ProductColorSkuPlatformStoreSku
adapter, err := priceRouteAdapter.SelectAdapter(routeConfig.Route) adapter, err := priceRouteAdapter.SelectAdapter(routeConfig.Route)
...@@ -77,7 +75,7 @@ func (receiver *PlatformStoreSku) calculateRoutePrice(product *pc4.ProductModel, ...@@ -77,7 +75,7 @@ func (receiver *PlatformStoreSku) calculateRoutePrice(product *pc4.ProductModel,
return platformStoreSku, err return platformStoreSku, err
} }
currencyRate, err := receiver.rate.GetRate(seller.Store, pc3SkuModel.PriceDetail.Currency, routeConfig.Currency.String()) currencyRate, err := receiver.rate.GetRate(seller.Store, sku.PriceDetail.Currency, routeConfig.Currency.String())
if err != nil { if err != nil {
return platformStoreSku, err return platformStoreSku, err
} }
...@@ -106,33 +104,33 @@ func (receiver *PlatformStoreSku) calculateRoutePrice(product *pc4.ProductModel, ...@@ -106,33 +104,33 @@ func (receiver *PlatformStoreSku) calculateRoutePrice(product *pc4.ProductModel,
if fixMargin != 0 { if fixMargin != 0 {
margin = 1 + (fixMargin / 100) margin = 1 + (fixMargin / 100)
} else { } else {
margin, err = receiver.calculateMargin(product, sku, routeConfig, pc3SkuModel, seller) margin, err = receiver.calculateMargin(product, sku, routeConfig, sku, seller)
if err != nil { if err != nil {
return platformStoreSku, err return platformStoreSku, err
} }
} }
margin = math2.Round(math.Max(1.0, margin), 3) // 保底1.0 margin = math2.Round(math.Max(1.0, margin), 3) // 保底1.0
freight, err := receiver.calculateFreight(pc3SkuModel, categories, routeConfig.FreightConfig, seller.Store) freight, err := receiver.calculateFreight(sku, categories, routeConfig.FreightConfig, seller.Store)
if err != nil { if err != nil {
return platformStoreSku, err return platformStoreSku, err
} }
priceDetail := priceRouteAdapter.RoutePriceDetail{ priceDetail := priceRouteAdapter.RoutePriceDetail{
Route: routeConfig.Route, Route: routeConfig.Route,
Currency: string(routeConfig.Currency), Currency: string(routeConfig.Currency),
OriginCurrency: pc3SkuModel.PriceDetail.Currency, OriginCurrency: sku.PriceDetail.Currency,
Rate: currencyRate, Rate: currencyRate,
Margin: margin, Margin: margin,
SubjectRate: subjectRate, SubjectRate: subjectRate,
Subject: subjectId, Subject: subjectId,
DiscountRate: pc3SkuModel.PriceDetail.Discount, DiscountRate: sku.PriceDetail.Discount,
TotalDiscount: pc3SkuModel.PriceDetail.Discount * subjectRate, TotalDiscount: sku.PriceDetail.Discount * subjectRate,
TaxRate: 1 + routeConfig.TaxRate, TaxRate: 1 + routeConfig.TaxRate,
Freight: freight, Freight: freight,
Express: receiver.calculateExpress(categories, routeConfig.ExpressConfig), Express: receiver.calculateExpress(categories, routeConfig.ExpressConfig),
} }
// 计算最终价格 // 计算最终价格
priceDetail.Price, err = adapter.GetPrice(pc3SkuModel.PriceDetail.Now, priceDetail, platform.Platform(seller.Platform)) priceDetail.Price, err = adapter.GetPrice(sku.PriceDetail.Now, priceDetail, platform.Platform(seller.Platform))
if err != nil { if err != nil {
return platformStoreSku, err return platformStoreSku, err
} }
...@@ -285,7 +283,7 @@ func (receiver *PlatformStoreSku) isSuitcases(categoryIds []string) bool { ...@@ -285,7 +283,7 @@ func (receiver *PlatformStoreSku) isSuitcases(categoryIds []string) bool {
return false return false
} }
func (receiver *PlatformStoreSku) calculateFreight(pc3Sku pc3.ModelSku, categoryIds []string, config sitePlatformPriceConfigModel.FreightConfig, store types.Store) (float64, error) { func (receiver *PlatformStoreSku) calculateFreight(sk *pc4.SkuModel, categoryIds []string, config sitePlatformPriceConfigModel.FreightConfig, store types.Store) (float64, error) {
switch config.FreightStyle { switch config.FreightStyle {
case sitePlatformPriceConfigModel.FreightStyleDefault: case sitePlatformPriceConfigModel.FreightStyleDefault:
return config.Freight, nil return config.Freight, nil
...@@ -301,11 +299,11 @@ func (receiver *PlatformStoreSku) calculateFreight(pc3Sku pc3.ModelSku, category ...@@ -301,11 +299,11 @@ func (receiver *PlatformStoreSku) calculateFreight(pc3Sku pc3.ModelSku, category
// 其他分类就用250 // 其他分类就用250
return 100, nil return 100, nil
case sitePlatformPriceConfigModel.FreightStylePrice: case sitePlatformPriceConfigModel.FreightStylePrice:
if pc3Sku.PriceDetail.Price < 1500 { if sk.PriceDetail.Price < 1500 {
return 30, nil return 30, nil
} else if pc3Sku.PriceDetail.Price < 2500 { } else if sk.PriceDetail.Price < 2500 {
return 50, nil return 50, nil
} else if pc3Sku.PriceDetail.Price < 3500 { } else if sk.PriceDetail.Price < 3500 {
return 80, nil return 80, nil
} else { } else {
return 100, nil return 100, nil
...@@ -317,7 +315,7 @@ func (receiver *PlatformStoreSku) calculateFreight(pc3Sku pc3.ModelSku, category ...@@ -317,7 +315,7 @@ func (receiver *PlatformStoreSku) calculateFreight(pc3Sku pc3.ModelSku, category
return 0, err return 0, err
} }
limitPrice := float64(config.OverFreight) * currencyRate limitPrice := float64(config.OverFreight) * currencyRate
goodCnyPrice := pc3Sku.PriceDetail.Price * pc3Sku.PriceDetail.SubjectRate goodCnyPrice := sk.PriceDetail.Price * sk.PriceDetail.SubjectRate
if goodCnyPrice >= limitPrice { if goodCnyPrice >= limitPrice {
return 0, nil return 0, nil
} }
...@@ -334,7 +332,7 @@ func StringSliceToGenders(gs []string) gender.Genders { ...@@ -334,7 +332,7 @@ func StringSliceToGenders(gs []string) gender.Genders {
return genders return genders
} }
func (receiver *PlatformStoreSku) calculateMargin(product *pc4.ProductModel, sku *pc4.SkuModel, routeConfig sitePlatformPriceConfigModel.RoutePriceConfig, pc3Sku pc3.ModelSku, seller types.Seller) (float64, error) { func (receiver *PlatformStoreSku) calculateMargin(product *pc4.ProductModel, sku *pc4.SkuModel, routeConfig sitePlatformPriceConfigModel.RoutePriceConfig, sk *pc4.SkuModel, seller types.Seller) (float64, error) {
floatMargin := 1.0 floatMargin := 1.0
if routeConfig.Route == types.RouteComplex { if routeConfig.Route == types.RouteComplex {
...@@ -391,7 +389,7 @@ func (receiver *PlatformStoreSku) calculateMargin(product *pc4.ProductModel, sku ...@@ -391,7 +389,7 @@ func (receiver *PlatformStoreSku) calculateMargin(product *pc4.ProductModel, sku
if marginConfig.IsValidLadders() { if marginConfig.IsValidLadders() {
marginConfig.FormatLadders() marginConfig.FormatLadders()
for _, ladder := range marginConfig.Ladders { for _, ladder := range marginConfig.Ladders {
if ladder.IsMatch(pc3Sku.PriceDetail.Price) { if ladder.IsMatch(sk.PriceDetail.Price) {
return (1 + ladder.Margin) * floatMargin, nil return (1 + ladder.Margin) * floatMargin, nil
} }
} }
......
package rate package rate
import ( import (
"fmt"
"git.chillcy.com/golang/chillcy/pkg/sdk/rate" "git.chillcy.com/golang/chillcy/pkg/sdk/rate"
"git.chillcy.com/golang/colorway/pkg/types" "git.chillcy.com/golang/colorway/pkg/types"
) )
...@@ -21,5 +20,7 @@ func (receiver *Rate) GetRate(store types.Store, from, to string) (float64, erro ...@@ -21,5 +20,7 @@ func (receiver *Rate) GetRate(store types.Store, from, to string) (float64, erro
case types.StoreTmall2bHK, types.StoreTmall2bEUR, types.StoreTmall2bUS: case types.StoreTmall2bHK, types.StoreTmall2bEUR, types.StoreTmall2bUS:
return receiver.rateClient.Net(from, to) return receiver.rateClient.Net(from, to)
} }
return 0, fmt.Errorf("未配置店铺汇率 %s", store) // todo 配置店铺汇率
return receiver.rateClient.Net(from, to)
//return 0, fmt.Errorf("未配置店铺汇率 %s", store)
} }
...@@ -32,6 +32,7 @@ func NewServiceContext(c config.Config) *ServiceContext { ...@@ -32,6 +32,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
} }
if etcd.GetEnv() == etcd.EnvDev { if etcd.GetEnv() == etcd.EnvDev {
pc4RpcProductServiceTarget = "127.0.0.1:5100" pc4RpcProductServiceTarget = "127.0.0.1:5100"
etcd.SetEtcd(etcd.KeyHttpRateApiUri.String(), "http://127.0.0.1:6060")
} }
svc := &ServiceContext{ svc := &ServiceContext{
Config: c, Config: c,
......
...@@ -21,7 +21,7 @@ func MemberMethodCall(obj any, methodName string, in []reflect.Value) error { ...@@ -21,7 +21,7 @@ func MemberMethodCall(obj any, methodName string, in []reflect.Value) error {
method := field.MethodByName(methodName) method := field.MethodByName(methodName)
if !method.IsValid() { if !method.IsValid() {
//log.Println(fmt.Errorf("字段 %s 没有 %s 方法\n", fieldType.Name, methodName)) //log.Println(fmt.Errorf("字段 %s 没有 %s 方法\n", fieldType.Name, methodName))
return nil continue
} }
// 调用 methodName 方法 // 调用 methodName 方法
......
package time
import "time"
func ConsumeSeconds(f func()) float64 {
start := time.Now()
f()
return time.Now().Sub(start).Seconds()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment