fix:算法请求调整

This commit is contained in:
momo 2023-10-10 17:17:28 +08:00
parent 21475d7d52
commit fec42ad634
20 changed files with 98 additions and 99 deletions

View File

@ -16,18 +16,17 @@ type Repositories struct {
}
type NewAllRepositorieData struct {
GormDB *gorm.DB
BLMServiceUrl *string
BLMServicePorts []string
AwsSession *session.Session
DelayQueue *queue.DelayMessage
GormDB *gorm.DB
BLMServiceUrls []string
AwsSession *session.Session
DelayQueue *queue.DelayMessage
}
func NewAllRepositories(newData *NewAllRepositorieData) *Repositories {
return &Repositories{
ImageHandle: repositories.NewImageHandle(newData.GormDB, newData.BLMServiceUrl, newData.BLMServicePorts, newData.AwsSession),
NewShoppingCart: repositories.NewShoppingCart(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession),
NewResource: repositories.NewResource(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession),
NewOrder: repositories.NewOrder(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession, newData.DelayQueue),
ImageHandle: repositories.NewImageHandle(newData.GormDB, newData.BLMServiceUrls, newData.AwsSession),
NewShoppingCart: repositories.NewShoppingCart(newData.GormDB, newData.BLMServiceUrls, newData.AwsSession),
NewResource: repositories.NewResource(newData.GormDB, newData.BLMServiceUrls, newData.AwsSession),
NewOrder: repositories.NewOrder(newData.GormDB, newData.AwsSession, newData.DelayQueue),
}
}

View File

@ -156,7 +156,10 @@ type OrderProductInter struct {
FittingInfo *OrderProductFittingInfo `json:"fitting_info"`
IsHighlyCustomized int64 `json:"is_highly_customized"`
RenderImage string `json:"render_image"`
ExpectedDeliveryTime ExpectedDelivery `json:"expected_delivery_time"` // 预计到货时间
ActualDeliveryTime ExpectedDelivery `json:"actual_delivery_time"` // 实际到货时间
}
type OrderMetadata struct {
ExpectedDeliveryTime ExpectedDelivery `json:"expected_delivery_time"` // 预计到货时间
ActualDeliveryTime ExpectedDelivery `json:"actual_delivery_time"` // 实际到货时间
}

View File

@ -36,9 +36,7 @@ type Config struct {
}
}
BLMService struct {
Url string
LogoCombine struct {
Url string
}
Version string
Urls []string
}
}

View File

@ -38,9 +38,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
SharedState: nil,
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
GormDB: initalize.InitMysql(c.SourceMysql),
BLMServiceUrl: &c.BLMService.Url,
AwsSession: session.Must(session.NewSession(&config)),
GormDB: initalize.InitMysql(c.SourceMysql),
BLMServiceUrls: c.BLMService.Urls,
AwsSession: session.Must(session.NewSession(&config)),
}),
}
}

View File

@ -21,9 +21,7 @@ type Config struct {
}
}
BLMService struct {
Url string
LogoCombine struct {
Url string
}
Version string
Urls []string
}
}

View File

@ -5,10 +5,11 @@ import (
"fmt"
"fusenapi/server/product-template-tag/internal/config"
"fusenapi/shared"
"net/http"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"net/http"
"fusenapi/initalize"
"fusenapi/model/gmodel"
@ -38,9 +39,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
SharedState: nil,
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
GormDB: conn,
BLMServiceUrl: &c.BLMService.Url,
AwsSession: session.Must(session.NewSession(&config)),
GormDB: conn,
BLMServiceUrls: c.BLMService.Urls,
AwsSession: session.Must(session.NewSession(&config)),
}),
}
}

View File

@ -21,10 +21,8 @@ type Config struct {
}
}
BLMService struct {
Url string
LogoCombine struct {
Url string
}
Version string
Urls []string
}
Unity struct {
Host string

View File

@ -5,10 +5,11 @@ import (
"fmt"
"fusenapi/server/product/internal/config"
"fusenapi/shared"
"net/http"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"net/http"
"fusenapi/initalize"
"fusenapi/model/gmodel"
@ -39,9 +40,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
AwsSession: session.Must(session.NewSession(&config)),
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
GormDB: conn,
BLMServiceUrl: &c.BLMService.Url,
AwsSession: session.Must(session.NewSession(&config)),
GormDB: conn,
BLMServiceUrls: c.BLMService.Urls,
AwsSession: session.Must(session.NewSession(&config)),
}),
}
}

View File

@ -22,7 +22,6 @@ type Config struct {
}
BLMService struct {
Version string
Url string
Ports []string
Urls []string
}
}

View File

@ -42,10 +42,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
AwsSession: session.Must(session.NewSession(&config)),
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
GormDB: initalize.InitMysql(c.SourceMysql),
BLMServiceUrl: &c.BLMService.Url,
BLMServicePorts: c.BLMService.Ports,
AwsSession: session.Must(session.NewSession(&config)),
GormDB: initalize.InitMysql(c.SourceMysql),
BLMServiceUrls: c.BLMService.Urls,
AwsSession: session.Must(session.NewSession(&config)),
}),
Tracing: middleware.NewTracingMiddleware().Handle,
}

View File

@ -2,6 +2,7 @@ package config
import (
"fusenapi/server/shopping-cart/internal/types"
"github.com/zeromicro/go-zero/rest"
)
@ -20,10 +21,8 @@ type Config struct {
}
}
BLMService struct {
Url string
LogoCombine struct {
Url string
}
Version string
Urls []string
}
Unity struct {
Host string

View File

@ -4,6 +4,7 @@ import (
"fusenapi/initalize"
"fusenapi/model/gmodel"
"fusenapi/server/shopping-cart/internal/config"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
@ -31,9 +32,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
AwsSession: session.Must(session.NewSession(&config)),
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
GormDB: conn,
BLMServiceUrl: &c.BLMService.Url,
AwsSession: session.Must(session.NewSession(&config)),
GormDB: conn,
BLMServiceUrls: c.BLMService.Urls,
AwsSession: session.Must(session.NewSession(&config)),
}),
}
}

View File

@ -23,7 +23,6 @@ type Config struct {
}
BLMService struct {
Version string
Url string
Ports []string
Urls []string
}
}

View File

@ -41,10 +41,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
AwsSession: session.Must(session.NewSession(&config)),
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
GormDB: initalize.InitMysql(c.SourceMysql),
BLMServiceUrl: &c.BLMService.Url,
BLMServicePorts: c.BLMService.Ports,
AwsSession: session.Must(session.NewSession(&config)),
GormDB: initalize.InitMysql(c.SourceMysql),
BLMServiceUrls: c.BLMService.Urls,
AwsSession: session.Must(session.NewSession(&config)),
}),
}
}

View File

@ -22,10 +22,8 @@ type Config struct {
}
}
BLMService struct {
Url string
LogoCombine struct {
Url string
}
Version string
Urls []string
}
Unity struct {
Host string

View File

@ -41,9 +41,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
AwsSession: session.Must(session.NewSession(&config)),
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
GormDB: conn,
BLMServiceUrl: &c.BLMService.Url,
AwsSession: session.Must(session.NewSession(&config)),
GormDB: conn,
BLMServiceUrls: c.BLMService.Urls,
AwsSession: session.Must(session.NewSession(&config)),
}),
}
}

View File

@ -21,21 +21,19 @@ import (
var globalBLMServiceIndex int
func NewImageHandle(gormDB *gorm.DB, bLMServiceUrl *string, bLMServicePorts []string, awsSession *session.Session) ImageHandle {
func NewImageHandle(gormDB *gorm.DB, bLMServiceUrls []string, awsSession *session.Session) ImageHandle {
return &defaultImageHandle{
MysqlConn: gormDB,
BLMServiceUrl: bLMServiceUrl,
BLMServicePorts: bLMServicePorts,
AwsSession: awsSession,
MysqlConn: gormDB,
BLMServiceUrls: bLMServiceUrls,
AwsSession: awsSession,
}
}
type (
defaultImageHandle struct {
MysqlConn *gorm.DB
BLMServiceUrl *string
BLMServicePorts []string
AwsSession *session.Session
MysqlConn *gorm.DB
BLMServiceUrls []string
AwsSession *session.Session
}
ImageHandle = interface {
@ -174,8 +172,8 @@ type (
func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq) (*LogoInfoSetRes, error) {
fmt.Println("算法请求轮训下标:", globalBLMServiceIndex)
var bLMServicePort = l.BLMServicePorts[globalBLMServiceIndex]
if len(l.BLMServicePorts) == (globalBLMServiceIndex + 1) {
var bLMServicePort = l.BLMServiceUrls[globalBLMServiceIndex]
if len(l.BLMServiceUrls) == (globalBLMServiceIndex + 1) {
globalBLMServiceIndex = 0
} else {
globalBLMServiceIndex = globalBLMServiceIndex + 1
@ -328,8 +326,8 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
postMap["param_data"] = combineParam
fmt.Println("算法请求轮训下标:", globalBLMServiceIndex)
var bLMServicePort = l.BLMServicePorts[globalBLMServiceIndex]
if len(l.BLMServicePorts) == (globalBLMServiceIndex + 1) {
var bLMServicePort = l.BLMServiceUrls[globalBLMServiceIndex]
if len(l.BLMServiceUrls) == (globalBLMServiceIndex + 1) {
globalBLMServiceIndex = 0
} else {
globalBLMServiceIndex = globalBLMServiceIndex + 1
@ -473,8 +471,8 @@ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardR
postMap["proportion"] = in.Proportion
fmt.Println("算法请求轮训下标:", globalBLMServiceIndex)
var bLMServicePort = l.BLMServicePorts[globalBLMServiceIndex]
if len(l.BLMServicePorts) == (globalBLMServiceIndex + 1) {
var bLMServicePort = l.BLMServiceUrls[globalBLMServiceIndex]
if len(l.BLMServiceUrls) == (globalBLMServiceIndex + 1) {
globalBLMServiceIndex = 0
} else {
globalBLMServiceIndex = globalBLMServiceIndex + 1

View File

@ -21,7 +21,7 @@ import (
"gorm.io/gorm"
)
func NewOrder(gormDB *gorm.DB, bLMServiceUrl *string, awsSession *session.Session, delayQueue *queue.DelayMessage) Order {
func NewOrder(gormDB *gorm.DB, awsSession *session.Session, delayQueue *queue.DelayMessage) Order {
return &defaultOrder{
MysqlConn: gormDB,
DelayQueue: delayQueue,
@ -1099,6 +1099,14 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
Name: in.DeliveryAddress.Name,
}
}
// 预计交付时间
var expectedDeliveryTime = gmodel.ExpectedDelivery{
Current: in.ExpectedDeliveryTime,
Initiate: in.ExpectedDeliveryTime,
}
// 实际交付时间
var actualDeliveryTime gmodel.ExpectedDelivery
for _, shoppingCart := range shoppingCartList {
// 购物车快照
@ -1186,9 +1194,11 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
Cm: shoppingCartSnapshot.SizeInfo.Cm,
},
},
IsHighlyCustomized: *shoppingCart.IsHighlyCustomized,
RenderImage: shoppingCartSnapshot.RenderImage,
CartId: shoppingCart.Id,
IsHighlyCustomized: *shoppingCart.IsHighlyCustomized,
RenderImage: shoppingCartSnapshot.RenderImage,
CartId: shoppingCart.Id,
ExpectedDeliveryTime: expectedDeliveryTime,
ActualDeliveryTime: actualDeliveryTime,
}
orderProductList = append(orderProductList, &productInter)
shoppingProductSnapshotList = append(shoppingProductSnapshotList, shoppingCart.ShoppingCartProduct)
@ -1268,10 +1278,8 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
byteShoppingProductSnapshot, _ := json.Marshal(shoppingProductSnapshotList)
byteStatusLink, _ := json.Marshal(statusLink)
byteOrderMetadata, _ := json.Marshal(gmodel.OrderMetadata{
ExpectedDeliveryTime: gmodel.ExpectedDelivery{
Current: in.ExpectedDeliveryTime,
Initiate: in.ExpectedDeliveryTime,
},
ExpectedDeliveryTime: expectedDeliveryTime,
ActualDeliveryTime: actualDeliveryTime,
})
// 创建订单
@ -1525,16 +1533,17 @@ func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel
}
orderProductItem := gmodel.OrderProduct{
TotalPrice: order.GetAmountInfoFormat(&productValue.TotalPrice),
ItemPrice: order.GetAmountInfoFormat(&productValue.ItemPrice),
ExpectedDeliveryTime: &expectedTime,
PurchaseQuantity: *productValue.PurchaseQuantity,
TotalPrice: order.GetAmountInfoFormat(&productValue.TotalPrice),
ItemPrice: order.GetAmountInfoFormat(&productValue.ItemPrice),
ProductId: productValue.ProductId,
ProductSn: productValue.ProductSn,
ProductName: productValue.ProductName,
ProductCover: productValue.ProductCover,
ProductCoverMetadata: productValue.ProductCoverMetadata,
ShoppingCartSnapshot: &shoppingCartSnapshotData,
ExpectedDeliveryTime: &productValue.ExpectedDeliveryTime.Current,
PurchaseQuantity: *productValue.PurchaseQuantity,
DiyInformation: productValue.DiyInformation,
SizeInfo: productValue.SizeInfo,

View File

@ -10,19 +10,19 @@ import (
"gorm.io/gorm"
)
func NewResource(gormDB *gorm.DB, bLMServiceUrl *string, awsSession *session.Session) Resource {
func NewResource(gormDB *gorm.DB, bLMServiceUrls []string, awsSession *session.Session) Resource {
return &defaultResource{
MysqlConn: gormDB,
BLMServiceUrl: bLMServiceUrl,
AwsSession: awsSession,
MysqlConn: gormDB,
BLMServiceUrls: bLMServiceUrls,
AwsSession: awsSession,
}
}
type (
defaultResource struct {
MysqlConn *gorm.DB
BLMServiceUrl *string
AwsSession *session.Session
MysqlConn *gorm.DB
BLMServiceUrls []string
AwsSession *session.Session
}
Resource interface {
// 更新metadata

View File

@ -11,19 +11,19 @@ import (
"gorm.io/gorm"
)
func NewShoppingCart(gormDB *gorm.DB, bLMServiceUrl *string, awsSession *session.Session) ShoppingCart {
func NewShoppingCart(gormDB *gorm.DB, bLMServiceUrls []string, awsSession *session.Session) ShoppingCart {
return &defaultShoppingCart{
MysqlConn: gormDB,
BLMServiceUrl: bLMServiceUrl,
AwsSession: awsSession,
MysqlConn: gormDB,
BLMServiceUrls: bLMServiceUrls,
AwsSession: awsSession,
}
}
type (
defaultShoppingCart struct {
MysqlConn *gorm.DB
BLMServiceUrl *string
AwsSession *session.Session
MysqlConn *gorm.DB
BLMServiceUrls []string
AwsSession *session.Session
}
ShoppingCart interface {
// 校验订单