diff --git a/api/generated/v1/yandexmarket/products/products.pb.go b/api/generated/v1/yandexmarket/products/products.pb.go index 03121cd..21fa215 100644 --- a/api/generated/v1/yandexmarket/products/products.pb.go +++ b/api/generated/v1/yandexmarket/products/products.pb.go @@ -25,7 +25,7 @@ type CalculateProductTariffsRequest struct { state protoimpl.MessageState `protogen:"open.v1"` MarketplaceId int64 `protobuf:"varint,1,opt,name=marketplace_id,json=marketplaceId,proto3" json:"marketplace_id,omitempty"` Parameters *CalculateProductTariffsRequest_Parameters `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` - Offers []*CalculateProductTariffsRequest_Offers `protobuf:"bytes,3,rep,name=offers,proto3" json:"offers,omitempty"` + Offers []*CalculateProductTariffsRequest_Offer `protobuf:"bytes,3,rep,name=offers,proto3" json:"offers,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -74,7 +74,7 @@ func (x *CalculateProductTariffsRequest) GetParameters() *CalculateProductTariff return nil } -func (x *CalculateProductTariffsRequest) GetOffers() []*CalculateProductTariffsRequest_Offers { +func (x *CalculateProductTariffsRequest) GetOffers() []*CalculateProductTariffsRequest_Offer { if x != nil { return x.Offers } @@ -221,33 +221,33 @@ func (x *GetProductsResponse) GetOffers() []*GetProductsResponse_Offer { return nil } -type CalculateProductTariffsRequest_Offers struct { +type CalculateProductTariffsRequest_Offer struct { state protoimpl.MessageState `protogen:"open.v1"` CategoryId int64 `protobuf:"varint,1,opt,name=category_id,json=categoryId,proto3" json:"category_id,omitempty"` - Price int64 `protobuf:"varint,2,opt,name=price,proto3" json:"price,omitempty"` - Length int64 `protobuf:"varint,3,opt,name=length,proto3" json:"length,omitempty"` - Width int64 `protobuf:"varint,4,opt,name=width,proto3" json:"width,omitempty"` - Height int64 `protobuf:"varint,5,opt,name=height,proto3" json:"height,omitempty"` - Weight int64 `protobuf:"varint,6,opt,name=weight,proto3" json:"weight,omitempty"` + Price float32 `protobuf:"fixed32,2,opt,name=price,proto3" json:"price,omitempty"` + Length float32 `protobuf:"fixed32,3,opt,name=length,proto3" json:"length,omitempty"` + Width float32 `protobuf:"fixed32,4,opt,name=width,proto3" json:"width,omitempty"` + Height float32 `protobuf:"fixed32,5,opt,name=height,proto3" json:"height,omitempty"` + Weight float32 `protobuf:"fixed32,6,opt,name=weight,proto3" json:"weight,omitempty"` Quantity int64 `protobuf:"varint,7,opt,name=quantity,proto3" json:"quantity,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *CalculateProductTariffsRequest_Offers) Reset() { - *x = CalculateProductTariffsRequest_Offers{} +func (x *CalculateProductTariffsRequest_Offer) Reset() { + *x = CalculateProductTariffsRequest_Offer{} mi := &file_yandexmarket_products_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *CalculateProductTariffsRequest_Offers) String() string { +func (x *CalculateProductTariffsRequest_Offer) String() string { return protoimpl.X.MessageStringOf(x) } -func (*CalculateProductTariffsRequest_Offers) ProtoMessage() {} +func (*CalculateProductTariffsRequest_Offer) ProtoMessage() {} -func (x *CalculateProductTariffsRequest_Offers) ProtoReflect() protoreflect.Message { +func (x *CalculateProductTariffsRequest_Offer) ProtoReflect() protoreflect.Message { mi := &file_yandexmarket_products_proto_msgTypes[4] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -259,54 +259,54 @@ func (x *CalculateProductTariffsRequest_Offers) ProtoReflect() protoreflect.Mess return mi.MessageOf(x) } -// Deprecated: Use CalculateProductTariffsRequest_Offers.ProtoReflect.Descriptor instead. -func (*CalculateProductTariffsRequest_Offers) Descriptor() ([]byte, []int) { +// Deprecated: Use CalculateProductTariffsRequest_Offer.ProtoReflect.Descriptor instead. +func (*CalculateProductTariffsRequest_Offer) Descriptor() ([]byte, []int) { return file_yandexmarket_products_proto_rawDescGZIP(), []int{0, 0} } -func (x *CalculateProductTariffsRequest_Offers) GetCategoryId() int64 { +func (x *CalculateProductTariffsRequest_Offer) GetCategoryId() int64 { if x != nil { return x.CategoryId } return 0 } -func (x *CalculateProductTariffsRequest_Offers) GetPrice() int64 { +func (x *CalculateProductTariffsRequest_Offer) GetPrice() float32 { if x != nil { return x.Price } return 0 } -func (x *CalculateProductTariffsRequest_Offers) GetLength() int64 { +func (x *CalculateProductTariffsRequest_Offer) GetLength() float32 { if x != nil { return x.Length } return 0 } -func (x *CalculateProductTariffsRequest_Offers) GetWidth() int64 { +func (x *CalculateProductTariffsRequest_Offer) GetWidth() float32 { if x != nil { return x.Width } return 0 } -func (x *CalculateProductTariffsRequest_Offers) GetHeight() int64 { +func (x *CalculateProductTariffsRequest_Offer) GetHeight() float32 { if x != nil { return x.Height } return 0 } -func (x *CalculateProductTariffsRequest_Offers) GetWeight() int64 { +func (x *CalculateProductTariffsRequest_Offer) GetWeight() float32 { if x != nil { return x.Weight } return 0 } -func (x *CalculateProductTariffsRequest_Offers) GetQuantity() int64 { +func (x *CalculateProductTariffsRequest_Offer) GetQuantity() int64 { if x != nil { return x.Quantity } @@ -384,11 +384,11 @@ func (x *CalculateProductTariffsRequest_Parameters) GetCurrency() string { type CalculateProductTariffsResponse_Offer struct { state protoimpl.MessageState `protogen:"open.v1"` CategoryId int64 `protobuf:"varint,1,opt,name=category_id,json=categoryId,proto3" json:"category_id,omitempty"` - Price int64 `protobuf:"varint,2,opt,name=price,proto3" json:"price,omitempty"` - Length int64 `protobuf:"varint,3,opt,name=length,proto3" json:"length,omitempty"` - Width int64 `protobuf:"varint,4,opt,name=width,proto3" json:"width,omitempty"` - Height int64 `protobuf:"varint,5,opt,name=height,proto3" json:"height,omitempty"` - Weight int64 `protobuf:"varint,6,opt,name=weight,proto3" json:"weight,omitempty"` + Price float32 `protobuf:"fixed32,2,opt,name=price,proto3" json:"price,omitempty"` + Length float32 `protobuf:"fixed32,3,opt,name=length,proto3" json:"length,omitempty"` + Width float32 `protobuf:"fixed32,4,opt,name=width,proto3" json:"width,omitempty"` + Height float32 `protobuf:"fixed32,5,opt,name=height,proto3" json:"height,omitempty"` + Weight float32 `protobuf:"fixed32,6,opt,name=weight,proto3" json:"weight,omitempty"` Quantity int64 `protobuf:"varint,7,opt,name=quantity,proto3" json:"quantity,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache @@ -431,35 +431,35 @@ func (x *CalculateProductTariffsResponse_Offer) GetCategoryId() int64 { return 0 } -func (x *CalculateProductTariffsResponse_Offer) GetPrice() int64 { +func (x *CalculateProductTariffsResponse_Offer) GetPrice() float32 { if x != nil { return x.Price } return 0 } -func (x *CalculateProductTariffsResponse_Offer) GetLength() int64 { +func (x *CalculateProductTariffsResponse_Offer) GetLength() float32 { if x != nil { return x.Length } return 0 } -func (x *CalculateProductTariffsResponse_Offer) GetWidth() int64 { +func (x *CalculateProductTariffsResponse_Offer) GetWidth() float32 { if x != nil { return x.Width } return 0 } -func (x *CalculateProductTariffsResponse_Offer) GetHeight() int64 { +func (x *CalculateProductTariffsResponse_Offer) GetHeight() float32 { if x != nil { return x.Height } return 0 } -func (x *CalculateProductTariffsResponse_Offer) GetWeight() int64 { +func (x *CalculateProductTariffsResponse_Offer) GetWeight() float32 { if x != nil { return x.Weight } @@ -829,21 +829,21 @@ var File_yandexmarket_products_proto protoreflect.FileDescriptor const file_yandexmarket_products_proto_rawDesc = "" + "\n" + - "\x1byandexmarket/products.proto\x12\x15yandexmarket.products\"\xce\x04\n" + + "\x1byandexmarket/products.proto\x12\x15yandexmarket.products\"\xcc\x04\n" + "\x1eCalculateProductTariffsRequest\x12%\n" + "\x0emarketplace_id\x18\x01 \x01(\x03R\rmarketplaceId\x12`\n" + "\n" + "parameters\x18\x02 \x01(\v2@.yandexmarket.products.CalculateProductTariffsRequest.ParametersR\n" + - "parameters\x12T\n" + - "\x06offers\x18\x03 \x03(\v2<.yandexmarket.products.CalculateProductTariffsRequest.OffersR\x06offers\x1a\xb9\x01\n" + - "\x06Offers\x12\x1f\n" + + "parameters\x12S\n" + + "\x06offers\x18\x03 \x03(\v2;.yandexmarket.products.CalculateProductTariffsRequest.OfferR\x06offers\x1a\xb8\x01\n" + + "\x05Offer\x12\x1f\n" + "\vcategory_id\x18\x01 \x01(\x03R\n" + "categoryId\x12\x14\n" + - "\x05price\x18\x02 \x01(\x03R\x05price\x12\x16\n" + - "\x06length\x18\x03 \x01(\x03R\x06length\x12\x14\n" + - "\x05width\x18\x04 \x01(\x03R\x05width\x12\x16\n" + - "\x06height\x18\x05 \x01(\x03R\x06height\x12\x16\n" + - "\x06weight\x18\x06 \x01(\x03R\x06weight\x12\x1a\n" + + "\x05price\x18\x02 \x01(\x02R\x05price\x12\x16\n" + + "\x06length\x18\x03 \x01(\x02R\x06length\x12\x14\n" + + "\x05width\x18\x04 \x01(\x02R\x05width\x12\x16\n" + + "\x06height\x18\x05 \x01(\x02R\x06height\x12\x16\n" + + "\x06weight\x18\x06 \x01(\x02R\x06weight\x12\x1a\n" + "\bquantity\x18\a \x01(\x03R\bquantity\x1a\x90\x01\n" + "\n" + "Parameters\x12\x1f\n" + @@ -857,11 +857,11 @@ const file_yandexmarket_products_proto_rawDesc = "" + "\x05Offer\x12\x1f\n" + "\vcategory_id\x18\x01 \x01(\x03R\n" + "categoryId\x12\x14\n" + - "\x05price\x18\x02 \x01(\x03R\x05price\x12\x16\n" + - "\x06length\x18\x03 \x01(\x03R\x06length\x12\x14\n" + - "\x05width\x18\x04 \x01(\x03R\x05width\x12\x16\n" + - "\x06height\x18\x05 \x01(\x03R\x06height\x12\x16\n" + - "\x06weight\x18\x06 \x01(\x03R\x06weight\x12\x1a\n" + + "\x05price\x18\x02 \x01(\x02R\x05price\x12\x16\n" + + "\x06length\x18\x03 \x01(\x02R\x06length\x12\x14\n" + + "\x05width\x18\x04 \x01(\x02R\x05width\x12\x16\n" + + "\x06height\x18\x05 \x01(\x02R\x06height\x12\x16\n" + + "\x06weight\x18\x06 \x01(\x02R\x06weight\x12\x1a\n" + "\bquantity\x18\a \x01(\x03R\bquantity\x1a5\n" + "\tParameter\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12\x14\n" + @@ -917,7 +917,7 @@ var file_yandexmarket_products_proto_goTypes = []any{ (*CalculateProductTariffsResponse)(nil), // 1: yandexmarket.products.CalculateProductTariffsResponse (*GetProductsRequest)(nil), // 2: yandexmarket.products.GetProductsRequest (*GetProductsResponse)(nil), // 3: yandexmarket.products.GetProductsResponse - (*CalculateProductTariffsRequest_Offers)(nil), // 4: yandexmarket.products.CalculateProductTariffsRequest.Offers + (*CalculateProductTariffsRequest_Offer)(nil), // 4: yandexmarket.products.CalculateProductTariffsRequest.Offer (*CalculateProductTariffsRequest_Parameters)(nil), // 5: yandexmarket.products.CalculateProductTariffsRequest.Parameters (*CalculateProductTariffsResponse_Offer)(nil), // 6: yandexmarket.products.CalculateProductTariffsResponse.Offer (*CalculateProductTariffsResponse_Parameter)(nil), // 7: yandexmarket.products.CalculateProductTariffsResponse.Parameter @@ -929,7 +929,7 @@ var file_yandexmarket_products_proto_goTypes = []any{ } var file_yandexmarket_products_proto_depIdxs = []int32{ 5, // 0: yandexmarket.products.CalculateProductTariffsRequest.parameters:type_name -> yandexmarket.products.CalculateProductTariffsRequest.Parameters - 4, // 1: yandexmarket.products.CalculateProductTariffsRequest.offers:type_name -> yandexmarket.products.CalculateProductTariffsRequest.Offers + 4, // 1: yandexmarket.products.CalculateProductTariffsRequest.offers:type_name -> yandexmarket.products.CalculateProductTariffsRequest.Offer 9, // 2: yandexmarket.products.CalculateProductTariffsResponse.offers:type_name -> yandexmarket.products.CalculateProductTariffsResponse.Offers 10, // 3: yandexmarket.products.GetProductsResponse.offers:type_name -> yandexmarket.products.GetProductsResponse.Offer 7, // 4: yandexmarket.products.CalculateProductTariffsResponse.Tariff.parameters:type_name -> yandexmarket.products.CalculateProductTariffsResponse.Parameter diff --git a/api/proto/v1 b/api/proto/v1 index ac9d54c..8aea1ed 160000 --- a/api/proto/v1 +++ b/api/proto/v1 @@ -1 +1 @@ -Subproject commit ac9d54c95f1884b15ad5c59facfbe978ba6053d0 +Subproject commit 8aea1ed4114058f4ab8904e552d1e3787a0fd04a diff --git a/cmd/server/main.go b/cmd/server/main.go index a1ac166..dc14b5f 100755 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -16,6 +16,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" "github.com/joho/godotenv" "google.golang.org/grpc" + _ "google.golang.org/grpc/encoding/gzip" ) func logMessage(level string, format string, a ...interface{}) { diff --git a/internal/ym/products/entities.go b/internal/ym/products/entities.go index e30d322..1a53168 100644 --- a/internal/ym/products/entities.go +++ b/internal/ym/products/entities.go @@ -6,7 +6,7 @@ import ( type PbCalculateProductTariffsRequest = pb.CalculateProductTariffsRequest type PbCalculateProductTariffsResponse = pb.CalculateProductTariffsResponse -type PbOffer = pb.CalculateProductTariffsRequest_Offers +type PbOffer = pb.CalculateProductTariffsRequest_Offer type PbResponseOffer = pb.CalculateProductTariffsResponse_Offers type PbParameters = pb.CalculateProductTariffsRequest_Parameters type PbGetProductsOffer = pb.GetProductsResponse_Offer diff --git a/internal/ym/products/mapping/converter.go b/internal/ym/products/mapping/converter.go index b2f0a36..07695de 100644 --- a/internal/ym/products/mapping/converter.go +++ b/internal/ym/products/mapping/converter.go @@ -1,8 +1,9 @@ package mapping import ( - "git.denco.store/fakz9/yandex-go-client" proto "sipro-mps/api/generated/v1/yandexmarket/products" + + "git.denco.store/fakz9/yandex-go-client" ) //go:generate go run github.com/jmattheis/goverter/cmd/goverter gen . @@ -16,7 +17,7 @@ import ( // goverter:useZeroValueOnPointerInconsistency yes // goverter:extend Int64ToFloat32 Int64ToInt32 Float32ToInt64 Int32ToInt64 PointerInt32ToInt64 type Converter interface { - ProtoOfferToYmOffer(details *proto.CalculateProductTariffsRequest_Offers) *ymclient.CalculateTariffsOfferDTO + ProtoOfferToYmOffer(details *proto.CalculateProductTariffsRequest_Offer) *ymclient.CalculateTariffsOfferDTO ProtoParametersToYmParameters(details *proto.CalculateProductTariffsRequest_Parameters) *ymclient.CalculateTariffsParametersDTO // Response converters diff --git a/internal/ym/products/mapping/generated/generated.go b/internal/ym/products/mapping/generated/generated.go index 6ab3209..bdf1906 100644 --- a/internal/ym/products/mapping/generated/generated.go +++ b/internal/ym/products/mapping/generated/generated.go @@ -11,16 +11,16 @@ import ( type ConverterImpl struct{} -func (c *ConverterImpl) ProtoOfferToYmOffer(source *products.CalculateProductTariffsRequest_Offers) *yandexgoclient.CalculateTariffsOfferDTO { +func (c *ConverterImpl) ProtoOfferToYmOffer(source *products.CalculateProductTariffsRequest_Offer) *yandexgoclient.CalculateTariffsOfferDTO { var pYmclientCalculateTariffsOfferDTO *yandexgoclient.CalculateTariffsOfferDTO if source != nil { var ymclientCalculateTariffsOfferDTO yandexgoclient.CalculateTariffsOfferDTO ymclientCalculateTariffsOfferDTO.CategoryId = (*source).CategoryId - ymclientCalculateTariffsOfferDTO.Price = mapping.Int64ToFloat32((*source).Price) - ymclientCalculateTariffsOfferDTO.Length = mapping.Int64ToFloat32((*source).Length) - ymclientCalculateTariffsOfferDTO.Width = mapping.Int64ToFloat32((*source).Width) - ymclientCalculateTariffsOfferDTO.Height = mapping.Int64ToFloat32((*source).Height) - ymclientCalculateTariffsOfferDTO.Weight = mapping.Int64ToFloat32((*source).Weight) + ymclientCalculateTariffsOfferDTO.Price = (*source).Price + ymclientCalculateTariffsOfferDTO.Length = (*source).Length + ymclientCalculateTariffsOfferDTO.Width = (*source).Width + ymclientCalculateTariffsOfferDTO.Height = (*source).Height + ymclientCalculateTariffsOfferDTO.Weight = (*source).Weight pInt32 := mapping.Int64ToInt32((*source).Quantity) ymclientCalculateTariffsOfferDTO.Quantity = &pInt32 pYmclientCalculateTariffsOfferDTO = &ymclientCalculateTariffsOfferDTO @@ -117,11 +117,11 @@ func (c *ConverterImpl) pYmclientOfferWeightDimensionsDTOToPProductsGetProductsR func (c *ConverterImpl) ymclientCalculateTariffsOfferDTOToPProductsCalculateProductTariffsResponse_Offer(source yandexgoclient.CalculateTariffsOfferDTO) *products.CalculateProductTariffsResponse_Offer { var productsCalculateProductTariffsResponse_Offer products.CalculateProductTariffsResponse_Offer productsCalculateProductTariffsResponse_Offer.CategoryId = source.CategoryId - productsCalculateProductTariffsResponse_Offer.Price = mapping.Float32ToInt64(source.Price) - productsCalculateProductTariffsResponse_Offer.Length = mapping.Float32ToInt64(source.Length) - productsCalculateProductTariffsResponse_Offer.Width = mapping.Float32ToInt64(source.Width) - productsCalculateProductTariffsResponse_Offer.Height = mapping.Float32ToInt64(source.Height) - productsCalculateProductTariffsResponse_Offer.Weight = mapping.Float32ToInt64(source.Weight) + productsCalculateProductTariffsResponse_Offer.Price = source.Price + productsCalculateProductTariffsResponse_Offer.Length = source.Length + productsCalculateProductTariffsResponse_Offer.Width = source.Width + productsCalculateProductTariffsResponse_Offer.Height = source.Height + productsCalculateProductTariffsResponse_Offer.Weight = source.Weight if source.Quantity != nil { productsCalculateProductTariffsResponse_Offer.Quantity = mapping.Int32ToInt64(*source.Quantity) } diff --git a/internal/ym/products/repository_api.go b/internal/ym/products/repository_api.go index ba4d875..faad7b0 100644 --- a/internal/ym/products/repository_api.go +++ b/internal/ym/products/repository_api.go @@ -184,6 +184,7 @@ func (r *apiRepository) processOfferMappings(offerMappings []ymclient.GetOfferMa resultOffers = append(resultOffers, &pb.GetProductsResponse_Offer{}) continue } + protoOffer.MarketCategoryId = *offerMapping.Mapping.MarketCategoryId resultOffers = append(resultOffers, protoOffer) } @@ -233,15 +234,22 @@ func (r *apiRepository) setTariffsRateLimit() { } // processTariffChunk processes a single chunk of offers for tariff calculation -func (r *apiRepository) processTariffChunk(ctx context.Context, client *ymclient.APIClient, ymParameters *ymclient.CalculateTariffsParametersDTO, offerChunk []*pb.CalculateProductTariffsRequest_Offers, chunkIndex int) (*pb.CalculateProductTariffsResponse, error) { +func (r *apiRepository) processTariffChunk(ctx context.Context, client *ymclient.APIClient, ymParameters *ymclient.CalculateTariffsParametersDTO, offerChunk []*pb.CalculateProductTariffsRequest_Offer, chunkIndex int) (*pb.CalculateProductTariffsResponse, error) { ymOffers := r.convertOffersToYM(offerChunk) if len(ymOffers) == 0 { fmt.Printf("Skipping chunk %d: no valid offers\n", chunkIndex+1) return nil, nil } - ymRequest := ymclient.NewCalculateTariffsRequest(*ymParameters, ymOffers) + if ymParameters.CampaignId != nil && *ymParameters.CampaignId > 0 { + ymParameters.SellingProgram = nil + ymParameters.Frequency = nil + ymParameters.Currency = nil + } else { + ymParameters.CampaignId = nil + } + ymRequest := ymclient.NewCalculateTariffsRequest(*ymParameters, ymOffers) response, httpResp, err := client.TariffsAPI.CalculateTariffs(ctx). CalculateTariffsRequest(*ymRequest). Execute() @@ -263,7 +271,7 @@ func (r *apiRepository) processTariffChunk(ctx context.Context, client *ymclient } // convertOffersToYM converts protobuf offers to Yandex Market format -func (r *apiRepository) convertOffersToYM(offers []*pb.CalculateProductTariffsRequest_Offers) []ymclient.CalculateTariffsOfferDTO { +func (r *apiRepository) convertOffersToYM(offers []*pb.CalculateProductTariffsRequest_Offer) []ymclient.CalculateTariffsOfferDTO { var ymOffers []ymclient.CalculateTariffsOfferDTO for _, offer := range offers { ymOffer := r.converter.ProtoOfferToYmOffer(offer)